Module: AnyView::Helpers::TagHelpers
- Defined in:
- lib/any_view/tag_helpers.rb
Instance Method Summary collapse
-
#content_tag(*args, &block) ⇒ Object
Creates an html tag with given name, content and options parameters: content_tag(name, content=nil, options={}, &block) Writes directly to the buffer.
-
#input_tag(type, options = {}) ⇒ Object
Creates an html input field with given type and options input_tag :text, :class => “test”.
-
#tag(name, options = {}) ⇒ Object
Creates an html tag with the given name and options.
Instance Method Details
#content_tag(*args, &block) ⇒ Object
Creates an html tag with given name, content and options parameters: content_tag(name, content=nil, options={}, &block) Writes directly to the buffer
18 19 20 21 22 23 24 |
# File 'lib/any_view/tag_helpers.rb', line 18 def content_tag(*args, &block) name = args.first = args. tag_html = block_given? ? capture_content(, &block) : args[1] tag_result = tag(name, .merge(:content => tag_html)) block.nil? ? tag_result : concat_content(tag_result) end |
#input_tag(type, options = {}) ⇒ Object
Creates an html input field with given type and options input_tag :text, :class => “test”
6 7 8 9 10 |
# File 'lib/any_view/tag_helpers.rb', line 6 def input_tag(type, = {}) = .dup [:type] = type tag(:input, ) end |
#tag(name, options = {}) ⇒ Object
Creates an html tag with the given name and options
31 32 33 34 35 36 37 |
# File 'lib/any_view/tag_helpers.rb', line 31 def tag(name, ={}) content, open_tag = .delete(:content), .delete(:open) identity_tag_attributes.each { |attr| [attr] = attr.to_s if [attr] } html_attrs = .collect { |a, v| v.blank? ? nil : "#{a}=\"#{v}\"" }.compact.join(" ") base_tag = (!html_attrs.blank? ? "<#{name} #{html_attrs}" : "<#{name}") base_tag << (open_tag ? ">" : (content ? ">#{content}</#{name}>" : " />")) end |