module Padrino::Helpers::TagHelpers
def content_tag(*args, &block)
- Api: - public
Returns:
-
(String)
- The html generated for the tag.
Parameters:
-
block
(Proc
) -- The block returning html content -
options
(Hash
) -- The html options to include in this tag. -
name
(Symbol
) -- The html type of tag. -
options
(Hash
) -- The html options to include in this tag. -
content
(String
) -- The contents in the tag. -
name
(Symbol
) -- The html type of tag.
Overloads:
-
content_tag(name, options, &block)
-
content_tag(name, content, options)
def content_tag(*args, &block) name = args.first options = args.extract_options! tag_html = block_given? ? capture_html(&block) : args[1] tag_result = tag(name, options.merge(:content => tag_html)) block_is_template?(block) ? concat_content(tag_result) : tag_result end
def escape_value(string)
Escape tag values to their HTML/XML entities.
#
def escape_value(string) string.to_s.gsub(Regexp.union(*ESCAPE_VALUES.keys)){|c| ESCAPE_VALUES[c] } end
def identity_tag_attributes
Returns a list of attributes which can only contain an identity value (i.e selected)
#
def identity_tag_attributes [:checked, :disabled, :selected, :multiple] end
def input_tag(type, options = {})
- Api: - semipublic
Returns:
-
(String)
- The html for the input tag.
Parameters:
-
options
(Hash
) -- -
type
(Symbol
) --
def input_tag(type, options = {}) options.reverse_merge!(:type => type) tag(:input, options) end
def tag(name, options={})
- Api: - public
Returns:
-
(String)
- The html for the input tag.
Parameters:
-
options
(Hash
) -- -
type
(Symbol
) --
def tag(name, options={}) content, open_tag = options.delete(:content), options.delete(:open) content = content.join("\n") if content.respond_to?(:join) identity_tag_attributes.each { |attr| options[attr] = attr.to_s if options[attr] } html_attrs = options.map { |a, v| v.nil? || v == false ? nil : "#{a}=\"#{escape_value(v)}\"" }.compact.join(" ") base_tag = (html_attrs.present? ? "<#{name} #{html_attrs}" : "<#{name}") base_tag << (open_tag ? ">" : (content ? ">#{content}</#{name}>" : " />")) end