diff options
author | makoto kuwata <kwa@kuwata-lab.com> | 2007-05-22 21:41:27 +0000 |
---|---|---|
committer | makoto kuwata <kwa@kuwata-lab.com> | 2007-05-22 21:41:27 +0000 |
commit | 3d5da3f51b0563d32ab2d37eb595c04900089b73 (patch) | |
tree | fffe5db374870100e479856be9e9db070eee3db5 /lib | |
parent | 0d3fde5fc7e030dcd9b93c7fb8246e2f29d733ee (diff) | |
download | erubis-3d5da3f51b0563d32ab2d37eb595c04900089b73.tar.gz |
- [enhance] add '-T' (don't expand tab characters)
- [enhance] add 'contrib/erubis-run.rb' (thanks to Andrew R Jackson)
- [update] add description about erubis-run.rb and DeleteIndentEnhancer
Diffstat (limited to 'lib')
-rw-r--r-- | lib/erubis/helpers/rails_helper.rb | 79 | ||||
-rw-r--r-- | lib/erubis/main.rb | 65 |
2 files changed, 39 insertions, 105 deletions
diff --git a/lib/erubis/helpers/rails_helper.rb b/lib/erubis/helpers/rails_helper.rb index d006eca..645b4eb 100644 --- a/lib/erubis/helpers/rails_helper.rb +++ b/lib/erubis/helpers/rails_helper.rb @@ -11,11 +11,11 @@ require 'erubis' module Erubis class Eruby - include ErboutEnhancer + include ErboutEnhancer # will generate '_erbout = _buf = ""; ' end class FastEruby - include ErboutEnhancer + include ErboutEnhancer # will generate '_erbout = _buf = ""; ' end module Helpers @@ -34,7 +34,7 @@ module Erubis ## ## 2. (optional) apply the patch for 'action_view/base.rb' ## - ## $ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/ + ## $ cd /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/ ## $ sudo patch -p1 < /tmp/erubis_2.X.X/contrib/action_view_base_rb.patch ## ## 3. restart web server. @@ -113,80 +113,15 @@ if ActionPack::VERSION::MINOR <= 12 ### Rails 1.1 when :rxml "xml = Builder::XmlMarkup.new(:indent => 2)\n" + "@controller.headers['Content-Type'] ||= 'application/xml'\n" + - template - when :rjs - "@controller.headers['Content-Type'] ||= 'text/javascript'\n" + - "update_page do |page|\n#{template}\nend" - end - else - #body = ERB.new(template, nil, @@erb_trim_mode).src - body = convert_template_into_ruby_code(template) - end - - @@template_args[render_symbol] ||= {} - locals_keys = @@template_args[render_symbol].keys | locals - @@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h } - - locals_code = "" - locals_keys.each do |key| - locals_code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n" - end - - "def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend" - end - - -else ### Rails 1.2 or later - - - # Create source code for given template - def create_template_source(extension, template, render_symbol, locals) - if template_requires_setup?(extension) - body = case extension.to_sym - when :rxml - "controller.response.content_type ||= 'application/xml'\n" + - "xml = Builder::XmlMarkup.new(:indent => 2)\n" + - template - when :rjs - "controller.response.content_type ||= 'text/javascript'\n" + - "update_page do |page|\n#{template}\nend" - end - else - #body = ERB.new(template, nil, @@erb_trim_mode).src - body = convert_template_into_ruby_code(template) - end - - @@template_args[render_symbol] ||= {} - locals_keys = @@template_args[render_symbol].keys | locals - @@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h } - - locals_code = "" - locals_keys.each do |key| - locals_code << "#{key} = local_assigns[:#{key}]\n" - end - - "def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend" - end - - -end ### - - - end - - end - -end - - ## set Erubis as eRuby compiler in Ruby on Rails instead of ERB class ActionView::Base # :nodoc: private def convert_template_into_ruby_code(template) #src = Erubis::Eruby.new(template).src - klass = Erubis::Helpers::RailsHelper.engine_class - properties = Erubis::Helpers::RailsHelper.init_properties - show_src = Erubis::Helpers::RailsHelper.show_src + rails_helper = Erubis::Helpers::RailsHelper + klass = rails_helper.engine_class + properties = rails_helper.init_properties + show_src = rails_helper.show_src src = klass.new(template, properties).src #src.insert(0, '_erbout = ') logger.debug "** Erubis: src==<<'END'\n#{src}END\n" if show_src diff --git a/lib/erubis/main.rb b/lib/erubis/main.rb index 7f81b17..2335d36 100644 --- a/lib/erubis/main.rb +++ b/lib/erubis/main.rb @@ -49,15 +49,15 @@ module Erubis end def initialize - @single_options = "hvxztSbeBXNUC" + @single_options = "hvxztTSbeBXNUC" @arg_options = "pcrfKIlaE" #C @option_names = { ?h => :help, ?v => :version, ?x => :source, ?z => :syntax, - #?T => :notrim, - ?t => :untabify, + ?T => :unexpand, + ?t => :untabify, # obsolete ?S => :intern, ?b => :bodyonly, ?B => :binding, @@ -217,38 +217,37 @@ module Erubis def usage command = File.basename($0) - s = <<END -erubis - embedded program converter for multi-language -Usage: #{command} [..options..] [file ...] - -h, --help : help - -v : version - -x : show converted code - -X : show converted code, only ruby code and no text part - -N : numbering: add line numbers (for '-x/-X') - -U : unique: zip empty lines to a line (for '-x/-X') - -C : compact: remove empty lines (for '-x/-X') - -b : body only: no preamble nor postamble (for '-x/-X') - -z : syntax checking - -e : escape (equal to '--E Escape') - -p pattern : embedded pattern (default '<% %>') - -l lang : convert but no execute (ruby/php/c/java/scheme/perl/js) - -E e1,e2,... : enhancer names (Escape, PercentLine, BiPattern, ...) - -I path : library include path - -K kanji : kanji code (euc/sjis/utf8) (default none) - -c context : context data string (yaml inline style or ruby code) - -f datafile : context data file ('*.yaml', '*.yml', or '*.rb') - -t : expand tab characters in YAML file - -S : convert mapping key from string to symbol in YAML file - -B : invoke 'result(binding)' instead of 'evaluate(context)' - --pi=name : parse '<?name ... ?>' instead of '<% ... %>' - -END + buf = [] + buf << "erubis - embedded program converter for multi-language" + buf << "Usage: #{command} [..options..] [file ...]" + buf << " -h, --help : help" + buf << " -v : version" + buf << " -x : show converted code" + buf << " -X : show converted code, only ruby code and no text part" + buf << " -N : numbering: add line numbers (for '-x/-X')" + buf << " -U : unique: compress empty lines to a line (for '-x/-X')" + buf << " -C : compact: remove empty lines (for '-x/-X')" + buf << " -b : body only: no preamble nor postamble (for '-x/-X')" + buf << " -z : syntax checking" + buf << " -e : escape (equal to '--E Escape')" + buf << " -p pattern : embedded pattern (default '<% %>')" + buf << " -l lang : convert but no execute (ruby/php/c/java/scheme/perl/js)" + buf << " -E e1,e2,... : enhancer names (Escape, PercentLine, BiPattern, ...)" + buf << " -I path : library include path" + buf << " -K kanji : kanji code (euc/sjis/utf8) (default none)" + buf << " -c context : context data string (yaml inline style or ruby code)" + buf << " -f datafile : context data file ('*.yaml', '*.yml', or '*.rb')" + #buf << " -t : expand tab characters in YAML file" + buf << " -T : don't expand tab characters in YAML file" + buf << " -S : convert mapping key from string to symbol in YAML file" + buf << " -B : invoke 'result(binding)' instead of 'evaluate(context)'" + buf << " --pi=name : parse '<?name ... ?>' instead of '<% ... %>'" #' # -T : don't trim spaces around '<% %>' # -c class : class name (XmlEruby/PercentLineEruby/...) (default Eruby) # -r library : require library # -a : action (convert/execute) - return s + return join("\n") end @@ -413,10 +412,10 @@ END filename.strip! test(?f, filename) or raise CommandOptionError.new("#{filename}: file not found.") if filename =~ /\.ya?ml$/ - if opts.untabify - ydoc = YAML.load(untabify(File.read(filename))) - else + if opts.unexpand ydoc = YAML.load_file(filename) + else + ydoc = YAML.load(untabify(File.read(filename))) end ydoc.is_a?(Hash) or raise CommandOptionError.new("#{filename}: root object is not a mapping.") intern_hash_keys(ydoc) if opts.intern |