Method: Padrino::Helpers::TagHelpers#content_tag

Defined in:
padrino-helpers/lib/padrino-helpers/tag_helpers.rb

#content_tag(name, content, options = nil) ⇒ String #content_tag(name, options = nil, &block) ⇒ String

Creates an HTML tag with given name, content, and options.

Examples:

(:p, 'Hello World', :class => 'light')

# => <p class="light">
# =>   Hello World
# => </p>

(:p, :class => 'dark') do
  link_to 'Padrino', 'http://www.padrinorb.com'
end

# => <p class="dark">
# =>   <a href="http://www.padrinorb.com">Padrino</a>
# => </p>

Overloads:

  • #content_tag(name, content, options = nil) ⇒ String

    Parameters:

    • name (Symbol)

      The name of the HTML tag to create.

    • content (String)

      The content inside of the tag.

    • options (Hash) (defaults to: nil)

      The HTML options to include in this tag.

  • #content_tag(name, options = nil, &block) ⇒ String

    Parameters:

    • name (Symbol)

      The name of the HTML tag to create.

    • options (Hash) (defaults to: nil)

      The HTML options to include in this tag.

    • block (Proc)

      The block returning HTML content.

Parameters:

  • options (Hash) (defaults to: nil)

    a customizable set of options

Options Hash (options):

  • :id (String)

    Specifies a unique identifier for the element.

  • :class (String)

    Specifies the stylesheet class of the element.

  • :title (String)

    Specifies the title for the element.

  • :accesskey (String)

    Specifies a shortcut key to access the element.

  • :dropzone (Symbol)

    Specifies what happens when dragged items are dropped on the element. (:copy, :link, :move)

  • :hidden (Boolean)

    Specifies whether or not the element is hidden from view.

  • :draggable (Boolean)

    Specifies whether or not the element is draggable. (true, false, :auto)

  • :contenteditable (Boolean)

    Specifies whether or not the element is editable.

Returns:

  • (String)

    Generated HTML with specified options.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'padrino-helpers/lib/padrino-helpers/tag_helpers.rb', line 119

def (name, content = nil, options = nil, &block)
  if block_given?
    options = content if content.is_a?(Hash)
    content = capture_html(&block)
  end

  options    = parse_data_options(name, options)
  attributes = tag_attributes(options)
  output = SafeBuffer.new
  output.safe_concat "<#{name}#{attributes}>"
  if content.respond_to?(:each) && !content.is_a?(String)
    content.each{ |item| output.concat item; output.safe_concat NEWLINE }
  else
    output.concat content.to_s
  end
  output.safe_concat "</#{name}>"

  block_is_template?(block) ? concat_content(output) : output
end