Module: Padrino::Helpers::TagHelpers
- Included in:
- Middleman::MetaPages::ConfigSetting, Middleman::MetaPages::SitemapResource, MiniTest::Spec
- Defined in:
- lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/tag_helpers.rb
Overview
Helpers related to producing html tags within templates.
Constant Summary collapse
- ESCAPE_VALUES =
Tag values escaped to html entities
{ "<" => "<", ">" => ">", '"' => """ }
- ESCAPE_REGEXP =
Cached Regexp for escaping values to avoid rebuilding one on every escape operation.
Regexp.union(*ESCAPE_VALUES.keys)
- BOOLEAN_ATTRIBUTES =
[ :autoplay, :autofocus, :formnovalidate, :checked, :disabled, :hidden, :loop, :multiple, :muted, :readonly, :required, :selected ]
- DATA_ATTRIBUTES =
Custom data attributes, feel free to update with yours:
Padrino::Helpers::TagHelpers::DATA_ATTRIBUTES.push(:dialog) text_field :foo, :dialog => true # Generates: <input type="text" data-dialog="true" name="foo" />
[ :method, :remote, :confirm ]
- NEWLINE =
A html_safe newline string to avoid allocating a new on each concatenation.
"\n".html_safe.freeze
Instance Method Summary collapse
-
#content_tag(name, content = nil, options = nil, &block) ⇒ String
Creates an HTML tag with given name, content, and options.
-
#input_tag(type, options = {}) ⇒ String
Creates an HTML input field with the given type and options.
-
#safe_content_tag(name, content = nil, options = nil, &block) ⇒ Object
Like #content_tag, but assumes its input to be safe and doesn’t escape.
-
#tag(name, options = nil, open = false) ⇒ String
Creates an HTML tag with the given name and options.
Instance Method Details
#content_tag(name, content, options = nil) ⇒ String #content_tag(name, options = nil, &block) ⇒ String
Creates an HTML tag with given name, content, and options
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/tag_helpers.rb', line 113 def content_tag(name, content = nil, = nil, &block) if block_given? = content if content.is_a?(Hash) content = capture_html(&block) end = (name, ) attributes = tag_attributes() output = ActiveSupport::SafeBuffer.new output.safe_concat "<#{name}#{attributes}>" if content.respond_to?(:each) && !content.is_a?(String) content.each { |c| output.concat c; output.safe_concat NEWLINE } else output.concat content end output.safe_concat "</#{name}>" block_is_template?(block) ? concat_content(output) : output end |
#input_tag(type, options = {}) ⇒ String
Creates an HTML input field with the given type and options
197 198 199 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/tag_helpers.rb', line 197 def input_tag(type, = {}) tag(:input, .reverse_merge!(:type => type)) end |
#safe_content_tag(name, content = nil, options = nil, &block) ⇒ Object
Like #content_tag, but assumes its input to be safe and doesn’t escape. It also returns safe html.
139 140 141 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/tag_helpers.rb', line 139 def safe_content_tag(name, content = nil, = nil, &block) mark_safe(content_tag(name, mark_safe(content), , &block)) end |
#tag(name, options = nil, open = false) ⇒ String
Creates an HTML tag with the given name and options
228 229 230 231 232 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/tag_helpers.rb', line 228 def tag(name, = nil, open = false) = (name, ) attributes = tag_attributes() "<#{name}#{attributes}#{open ? '>' : ' />'}".html_safe end |