Module: Eldr::Rendering::Tags
- Defined in:
- lib/eldr/rendering/tag_helpers.rb
Constant Summary collapse
- ESCAPE_VALUES =
{ '&' => '&', '<' => '<', '>' => '>', '"' => '"' }.freeze
- ESCAPE_REGEXP =
Regexp.union(*ESCAPE_VALUES.keys).freeze
- BOOLEAN_ATTRIBUTES =
[ :autoplay, :autofocus, :formnovalidate, :checked, :disabled, :hidden, :loop, :multiple, :muted, :readonly, :required, :selected, :declare, :defer, :ismap, :itemscope, :noresize, :novalidate ].freeze
- DATA_ATTRIBUTES =
[ :method, :remote, :confirm ].freeze
- NEWLINE =
"\n".html_safe.freeze
Instance Method Summary collapse
- #content_tag(name, content = nil, options = nil, &block) ⇒ Object
- #tag(name, options = nil, open = false) ⇒ Object
Instance Method Details
#content_tag(name, content = nil, options = nil, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/eldr/rendering/tag_helpers.rb', line 51 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 { |item| output.concat item; output.safe_concat NEWLINE } else output.concat content.to_s end output.safe_concat "</#{name}>" output end |
#tag(name, options = nil, open = false) ⇒ Object
45 46 47 48 49 |
# File 'lib/eldr/rendering/tag_helpers.rb', line 45 def tag(name, = nil, open = false) = (name, ) attributes = tag_attributes() "<#{name}#{attributes}#{open ? '>' : ' />'}".html_safe end |