Skip to content

Commit

Permalink
<input> should behave correctly as an empty tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Garlick committed Jun 26, 2008
1 parent 9477e60 commit 5265853
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
7 changes: 7 additions & 0 deletions hobo/lib/action_view_extensions/helpers/tag_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ActionView::Helpers::TagHelper
alias_method :tag_without_doctype, :tag
def tag(name, options = nil, open = false, escape = true)
open = !scope.xmldoctype
tag_without_doctype(name, options, open, escape)
end
end
1 change: 1 addition & 0 deletions hobo/lib/hobo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ def enable
require 'active_record/has_many_through_association'
require 'active_record/association_proxy'
require 'active_record/association_reflection'
require 'action_view_extensions/helpers/tag_helper'

ActionView::Template.register_template_handler("dryml", Hobo::Dryml::TemplateHandler)

Expand Down
8 changes: 4 additions & 4 deletions hobo/lib/hobo/dryml/template_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def render_tag(tag_name, attributes)
end


def element(name, attributes, content=nil, escape = true, &block)
def element(name, attributes, content=nil, escape = true, empty = false, &block)
unless attributes.blank?
attrs = []
if escape
Expand All @@ -488,10 +488,10 @@ def element(name, attributes, content=nil, escape = true, &block)
end

content = new_context(&block) if block_given?
res = if content
"<#{name}#{attr_string}>#{content}</#{name}>"
res = if empty
"<#{name}#{attr_string}#{scope.xmldoctype ? ' /' : ''}>"
else
"<#{name}#{attr_string} />"
"<#{name}#{attr_string}>#{content}</#{name}>"
end
if block && eval("defined? _erbout", block.binding) # in erb context
_output(res)
Expand Down
14 changes: 7 additions & 7 deletions hobo/taglibs/rapid_forms.dryml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
auth_token = if method.nil? || method == 'get' || request_forgery_protection_token.nil?
''
else
element(:input, :type => "hidden",
element(:input, {:type => "hidden",
:name => request_forgery_protection_token.to_s,
:value => form_authenticity_token)
:value => form_authenticity_token}, nil, true, true)
end

page_path = if request.post? || request.put? && params[:page_path]
Expand Down Expand Up @@ -100,7 +100,7 @@

<def tag="input"><%=
if attributes[:type]
element :input, attributes
element :input, attributes, nil, true, true
elsif !can_edit?
view
else
Expand Down Expand Up @@ -189,7 +189,7 @@
ajax_attributes[:message] ||= label
func = ajax_updater(url, update, ajax_attributes)
html_attributes.update(:onclick => "var e = this; " + func, :type =>'button', :value => label)
element(:input, html_attributes)
element(:input, html_attributes, nil, true, true)
else
button_to(label, url, html_attributes)
end
Expand All @@ -205,7 +205,7 @@
func = ajax_updater(object_url(this), update, ajax_attributes)
html_attributes.reverse_merge!(:type =>'button', :onclick => func, :value => label)

element :input, add_classes(html_attributes, "button update-button update-#{this.class.name.underscore}-button") %>
element :input, add_classes(html_attributes, "button update-button update-#{this.class.name.underscore}-button"), nil, true, true %>
</def>


Expand Down Expand Up @@ -234,7 +234,7 @@
scope.collection_contains_delete_button = true if fade
attributes[:value] = label
attributes[:onclick] = "Hobo.removeButton(this, '#{url}', #{js_updates(update)}, {fade:#{fade}, confirm: #{confirm.inspect}})"
element(:input, attributes)
element(:input, attributes, nil, true, true)
end
end
else
Expand Down Expand Up @@ -264,7 +264,7 @@
ajax_attributes[:params] = { class_name => fields } unless fields.empty?
func = ajax_updater(object_url(new.class), update, ajax_attributes)
element :input, add_classes(attributes.merge(:type =>'button', :onclick => func, :value => label),
"button create-button create-#{class_name}-button")
"button create-button create-#{class_name}-button"), nil, true, true
end
%></def>

Expand Down
4 changes: 2 additions & 2 deletions hobo/taglibs/rapid_pages.dryml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
%></def>

<def tag="html" attrs="doctype">
<% doctype ||= 'HTML 4.01 STRICT' -%>
<% doctype ||= 'XHTML 1.0 TRANSITIONAL' -%>
<doctype version="&doctype"/>
<% attributes.reverse_merge!(:xmlns => "http://www.w3.org/1999/xhtml") if doctype =~ /^XHTML/ -%>
<%= "<html#{tag_options(attributes)}>" %>
Expand All @@ -309,7 +309,7 @@
</def>

<!-- empty tags should be written as <br> in HTML and <br /> in XHTML -->
<def tag="empty-tag" attrs="tag-name"><%= "<#{tag_name}#{tag_options(attributes.inject({}) {|options, (key,value)| options[key.to_s.dasherize] = value; options})}#{scope.xmldoctype ? ' /' : ''}>" %></def>
<def tag="empty-tag" attrs="tag-name"><%= element(tag_name, attributes, nil, true, true) %></def>
<def tag="base"><empty-tag tag-name="base" merge/></def>
<def tag="meta"><empty-tag tag-name="meta" merge/></def>
<def tag="link"><empty-tag tag-name="link" merge/></def>
Expand Down
2 changes: 1 addition & 1 deletion hobo/taglibs/rapid_plus.dryml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</if>
</th>
</with-field-names>
<th if="&all_parameters[:controls]" class="controls"/>
<th if="&all_parameters[:controls]" class="controls"></th>
</field-heading-row>
</table>
<do param="empty-message" if="empty?">No <name-for-collection lowercase/> to display</do>
Expand Down

0 comments on commit 5265853

Please sign in to comment.