diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-02-20 22:09:12 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-02-20 22:09:12 +0000 |
commit | e1056530665d5c8eed2c325157fbb88553eb2678 (patch) | |
tree | 30341bae8b9a63faed289f9dc56c1a654a449731 /actionpack/lib/action_view | |
parent | 89cb34c9cfe9d169b79206b74c602e91bc7116a5 (diff) | |
download | rails-e1056530665d5c8eed2c325157fbb88553eb2678.tar.gz rails-e1056530665d5c8eed2c325157fbb88553eb2678.tar.bz2 rails-e1056530665d5c8eed2c325157fbb88553eb2678.zip |
Added .erb and .builder as preferred aliases to the now deprecated .rhtml and .rxml extensions [Chad Fowler]. This is done to separate the renderer from the mime type. .erb templates are often used to render emails, atom, csv, whatever. So labeling them .rhtml doesn't make too much sense. The same goes for .rxml, which can be used to build everything from HTML to Atom to whatever. .rhtml and .rxml will continue to work until Rails 3.0, though. So this is a slow phasing out. All generators and examples will start using the new aliases, though.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6178 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 41 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/capture_helper.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/partials.rb | 10 |
3 files changed, 32 insertions, 27 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 18d03f5a0b..1b3cf5d95e 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -4,8 +4,8 @@ module ActionView #:nodoc: class ActionViewError < StandardError #:nodoc: end - # Action View templates can be written in three ways. If the template file has a +.rhtml+ extension then it uses a mixture of ERb - # (included in Ruby) and HTML. If the template file has a +.rxml+ extension then Jim Weirich's Builder::XmlMarkup library is used. + # Action View templates can be written in three ways. If the template file has a +.erb+ (or +.rhtml+) extension then it uses a mixture of ERb + # (included in Ruby) and HTML. If the template file has a +.builder+ (or +.rxml+) extension then Jim Weirich's Builder::XmlMarkup library is used. # If the template file has a +.rjs+ extension then it will use ActionView::Helpers::PrototypeHelper::JavaScriptGenerator. # # = ERb @@ -77,7 +77,7 @@ module ActionView #:nodoc: # == Builder # # Builder templates are a more programmatic alternative to ERb. They are especially useful for generating XML content. An +XmlMarkup+ object - # named +xml+ is automatically made available to templates with a +.rxml+ extension. + # named +xml+ is automatically made available to templates with a +.builder+ extension. # # Here are some basic examples: # @@ -246,7 +246,6 @@ module ActionView #:nodoc: def render_file(template_path, use_full_path = true, local_assigns = {}) #:nodoc: @first_render ||= template_path template_path_without_extension, template_extension = path_and_extension(template_path) - if use_full_path if template_extension template_file_name = full_template_path(template_path_without_extension, template_extension) @@ -280,7 +279,7 @@ module ActionView #:nodoc: elsif options == :update update_page(&block) elsif options.is_a?(Hash) - options = options.reverse_merge(:type => :rhtml, :locals => {}, :use_full_path => true) + options = options.reverse_merge(:type => :erb, :locals => {}, :use_full_path => true) if options[:file] render_file(options[:file], options[:use_full_path], options[:locals]) @@ -294,7 +293,7 @@ module ActionView #:nodoc: end end - # Renders the +template+ which is given as a string as either rhtml or rxml depending on <tt>template_extension</tt>. + # Renders the +template+ which is given as a string as either erb or builder depending on <tt>template_extension</tt>. # The hash in <tt>local_assigns</tt> is made available as local variables. def render_template(template_extension, template, file_path = nil, local_assigns = {}) #:nodoc: if handler = @@template_handlers[template_extension] @@ -342,15 +341,21 @@ module ActionView #:nodoc: def delegate_template_exists?(template_path)#:nodoc: @@template_handlers.find { |k,| template_exists?(template_path, k) } end - + + def one_of(template_path, *extensions)#:nodoc: + extensions.detect{|ext| template_exists?(template_path, ext)} + end + def erb_template_exists?(template_path)#:nodoc: - template_exists?(template_path, :rhtml) + one_of(template_path, :erb, :rhtml) end - + alias :rhtml_template_exists? :erb_template_exists? + def builder_template_exists?(template_path)#:nodoc: - template_exists?(template_path, :rxml) + one_of(template_path, :builder, :rxml) end - + alias :rxml_template_exists? :builder_template_exists? + def javascript_template_exists?(template_path)#:nodoc: template_exists?(template_path, :rjs) end @@ -361,7 +366,7 @@ module ActionView #:nodoc: template_exists?(template_file_name, template_file_extension) else cached_template_extension(template_path) || - %w(erb builder javascript delegate).any? do |template_type| + %w(erb rhtml builder rxml javascript delegate).any? do |template_type| send("#{template_type}_template_exists?", template_path) end end @@ -401,11 +406,11 @@ module ActionView #:nodoc: def find_template_extension_for(template_path) if match = delegate_template_exists?(template_path) match.first.to_sym - elsif erb_template_exists?(template_path): :rhtml - elsif builder_template_exists?(template_path): :rxml + elsif extension = erb_template_exists?(template_path): extension + elsif extension = builder_template_exists?(template_path): extension elsif javascript_template_exists?(template_path): :rjs else - raise ActionViewError, "No rhtml, rxml, rjs or delegate template found for #{template_path} in #{@view_paths.inspect}" + raise ActionViewError, "No erb, builder, rhtml, rxml, rjs or delegate template found for #{template_path} in #{@view_paths.inspect}" end end @@ -464,7 +469,7 @@ module ActionView #:nodoc: def create_template_source(extension, template, render_symbol, locals) if template_requires_setup?(extension) body = case extension.to_sym - when :rxml + when :rxml, :builder "controller.response.content_type ||= 'application/xml'\n" + "xml = Builder::XmlMarkup.new(:indent => 2)\n" + template @@ -493,7 +498,7 @@ module ActionView #:nodoc: end def templates_requiring_setup - %w(rxml rjs) + %w(builder rxml rjs) end def assign_method_name(extension, template, file_name) @@ -523,7 +528,7 @@ module ActionView #:nodoc: line_offset = @@template_args[render_symbol].size if extension case extension.to_sym - when :rxml, :rjs + when :builder, :rxml, :rjs line_offset += 2 end end diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 1d6ad56004..91cff4f981 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -14,7 +14,7 @@ module ActionView # content_for("name") is a wrapper for capture which will # make the fragment available by name to a yielding layout or template. # - # layout.rhtml: + # layout.erb: # # <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> # <head> @@ -28,7 +28,7 @@ module ActionView # </body> # </html> # - # view.rhtml + # view.erb # # This page shows an alert box! # @@ -42,13 +42,13 @@ module ActionView # instance variable. You can use this instance variable anywhere # in your templates and even in your layout. # - # Example of capture being used in a .rhtml page: + # Example of capture being used in a .erb page: # # <% @greeting = capture do %> # Welcome To my shiny new web page! # <% end %> # - # Example of capture being used in a .rxml page: + # Example of capture being used in a .builder page: # # @greeting = capture do # 'Welcome To my shiny new web page!' diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index 063ff5688d..c6049a4683 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -7,7 +7,7 @@ module ActionView # # <%= render :partial => "account" %> # - # This would render "advertiser/_account.rhtml" and pass the instance variable @account in as a local variable +account+ to + # This would render "advertiser/_account.erb" and pass the instance variable @account in as a local variable +account+ to # the template for display. # # In another template for Advertiser#buy, we could have: @@ -18,8 +18,8 @@ module ActionView # <%= render :partial => "ad", :locals => { :ad => ad } %> # <% end %> # - # This would first render "advertiser/_account.rhtml" with @buyer passed in as the local variable +account+, then render - # "advertiser/_ad.rhtml" and pass the local variable +ad+ to the template for display. + # This would first render "advertiser/_account.erb" with @buyer passed in as the local variable +account+, then render + # "advertiser/_ad.erb" and pass the local variable +ad+ to the template for display. # # == Rendering a collection of partials # @@ -30,7 +30,7 @@ module ActionView # # <%= render :partial => "ad", :collection => @advertisements %> # - # This will render "advertiser/_ad.rhtml" and pass the local variable +ad+ to the template for display. An iteration counter + # This will render "advertiser/_ad.erb" and pass the local variable +ad+ to the template for display. An iteration counter # will automatically be made available to the template with a name of the form +partial_name_counter+. In the case of the # example above, the template would be fed +ad_counter+. # @@ -43,7 +43,7 @@ module ActionView # # <%= render :partial => "advertisement/ad", :locals => { :ad => @advertisement } %> # - # This will render the partial "advertisement/_ad.rhtml" regardless of which controller this is being called from. + # This will render the partial "advertisement/_ad.erb" regardless of which controller this is being called from. module Partials # Deprecated, use render :partial def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc: |