Permalink
Browse files

Merge branch 'master' of git@github.com:rails/rails

  • Loading branch information...
2 parents 9c20391 + 74436d2 commit e2af713d1c71b4f319e5435a63011a7bc23f77c3 @dhh dhh committed May 1, 2008
@@ -1,6 +1,7 @@
require 'cgi'
require 'action_view/helpers/date_helper'
require 'action_view/helpers/tag_helper'
+require 'action_view/helpers/form_tag_helper'
module ActionView
module Helpers
@@ -51,7 +52,7 @@ module Helpers
#
# If the object name contains square brackets the id for the object will be inserted. For example:
#
- # <%= text_field "person[]", "name" %>
+ # <%= text_field "person[]", "name" %>
#
# ...will generate the following ERb.
#
@@ -91,7 +92,7 @@ module FormHelper
#
# Even further, the form_for method allows you to more easily escape the instance variable convention. So while the stand-alone
# approach would require <tt>text_field :person, :name, :object => person</tt>
- # to work with local variables instead of instance ones, the form_for calls remain the same. You simply declare once with
+ # to work with local variables instead of instance ones, the form_for calls remain the same. You simply declare once with
# <tt>:person, person</tt> and all subsequent field calls save <tt>:person</tt> and <tt>:object => person</tt>.
#
# Also note that form_for doesn't create an exclusive scope. It's still possible to use both the stand-alone FormHelper methods
@@ -149,7 +150,7 @@ module FormHelper
# ...
# <% end %>
#
- # And for namespaced routes, like admin_post_url:
+ # And for namespaced routes, like admin_post_url:
#
# <% form_for([:admin, @post]) do |f| %>
# ...
@@ -337,7 +338,7 @@ def password_field(object_name, method, options = {})
# hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
# shown.
#
- # ==== Examples
+ # ==== Examples
# hidden_field(:signup, :pass_confirm)
# # => <input type="hidden" id="signup_pass_confirm" name="signup[pass_confirm]" value="#{@signup.pass_confirm}" />
#
@@ -404,7 +405,7 @@ def text_area(object_name, method, options = {})
# is set to 0 which is convenient for boolean values. Since HTTP standards say that unchecked checkboxes don't post anything,
# we add a hidden value with the same name as the checkbox as a work around.
#
- # ==== Examples
+ # ==== Examples
# # Let's say that @post.validated? is 1:
# check_box("post", "validated")
# # => <input type="checkbox" id="post_validated" name="post[validated]" value="1" />
@@ -445,7 +446,7 @@ def radio_button(object_name, method, tag_value, options = {})
end
class InstanceTag #:nodoc:
- include Helpers::TagHelper
+ include Helpers::TagHelper, Helpers::FormTagHelper
attr_reader :method_name, :object_name
@@ -467,11 +468,13 @@ def initialize(object_name, method_name, template_object, local_binding = nil, o
end
def to_label_tag(text = nil, options = {})
+ options = options.stringify_keys
name_and_id = options.dup
add_default_name_and_id(name_and_id)
- options["for"] = name_and_id["id"]
+ options.delete("index")
+ options["for"] ||= name_and_id["id"]
content = (text.blank? ? nil : text.to_s) || method_name.humanize
- content_tag("label", content, options)
+ label_tag(name_and_id["id"], content, options)
end
def to_input_field_tag(field_type, options = {})
@@ -24,7 +24,12 @@ def process_view_paths(*view_paths)
view_paths.flatten.compact.each do |dir|
next if @@processed_view_paths.has_key?(dir)
@@processed_view_paths[dir] = []
- Dir.glob("#{dir}/**/*/**").each do |file|
+
+ #
+ # Dir.glob("#{dir}/**/*/**") reads all the directories in view path and templates inside those directories
+ # Dir.glob("#{dir}/**") reads templates residing at top level of view path
+ #
+ (Dir.glob("#{dir}/**/*/**") | Dir.glob("#{dir}/**")).each do |file|
unless File.directory?(file)
@@processed_view_paths[dir] << file.split(dir).last.sub(/^\//, '')
@@ -23,6 +23,14 @@ def render_hello_world
def render_hello_world_with_forward_slash
render :template => "/test/hello_world"
end
+
+ def render_template_in_top_directory
+ render :template => 'shared'
+ end
+
+ def render_template_in_top_directory_with_slash
+ render :template => '/shared'
+ end
def render_hello_world_from_variable
@person = "david"
@@ -243,6 +251,18 @@ def test_render_with_forward_slash
get :render_hello_world_with_forward_slash
assert_template "test/hello_world"
end
+
+ def test_render_in_top_directory
+ get :render_template_in_top_directory
+ assert_template "shared"
+ assert_equal "Elastica", @response.body
+ end
+
+ def test_render_in_top_directory_with_slash
+ get :render_template_in_top_directory_with_slash
+ assert_template "shared"
+ assert_equal "Elastica", @response.body
+ end
def test_render_from_variable
get :render_hello_world_from_variable
@@ -0,0 +1 @@
+Elastica
Oops, something went wrong.

0 comments on commit e2af713

Please sign in to comment.