Module: Sinatra::MarkupPlugin::TagHelpers
- Defined in:
- lib/sinatra/markup_plugin/tag_helpers.rb
Instance Method Summary collapse
-
#content_tag(*args, &block) ⇒ Object
Creates an html tag with given name, content and options content_tag(:p, “hello”, :class => ‘light’) content_tag(:p, :class => ‘dark’) do …
-
#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 tag(:br, :style => ‘clear:both’) tag(:p, :content => “hello”, :class => ‘large’).
Instance Method Details
#content_tag(*args, &block) ⇒ Object
Creates an html tag with given name, content and options content_tag(:p, “hello”, :class => ‘light’) content_tag(:p, :class => ‘dark’) do … end parameters: content_tag(name, content=nil, options={}, &block)
15 16 17 18 19 20 21 |
# File 'lib/sinatra/markup_plugin/tag_helpers.rb', line 15 def content_tag(*args, &block) name = args.first = args. tag_html = block_given? ? capture_html(&block) : args[1] tag_result = tag(name, .merge(:content => tag_html)) block_is_template?(block) ? concat_content(tag_result) : 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 |
# File 'lib/sinatra/markup_plugin/tag_helpers.rb', line 6 def input_tag(type, = {}) .reverse_merge!(:type => type) tag(:input, ) end |
#tag(name, options = {}) ⇒ Object
Creates an html tag with the given name and options tag(:br, :style => ‘clear:both’) tag(:p, :content => “hello”, :class => ‘large’)
26 27 28 29 30 31 32 |
# File 'lib/sinatra/markup_plugin/tag_helpers.rb', line 26 def tag(name, ={}) content = .delete(:content) 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 << (content ? ">#{content}</#{name}>" : " />") end |