Module: Hensel::Helpers::TagHelpers
- Included in:
- Builder, Builder::Node
- Defined in:
- lib/hensel/helpers/tag_helpers.rb
Constant Summary collapse
- ESCAPE_VALUES =
{ "'" => "'", "&" => "&", "<" => "<", ">" => ">", '"' => """ }
- ESCAPE_REGEXP =
Regexp.union(*ESCAPE_VALUES.keys)
- BOOLEAN_ATTRIBUTES =
[ :autoplay, :autofocus, :formnovalidate, :checked, :disabled, :hidden, :loop, :multiple, :muted, :readonly, :required, :selected, :declare, :defer, :ismap, :itemscope, :noresize, :novalidate ]
Instance Method Summary collapse
- #append_attribute(attribute, value, hash) ⇒ Object
- #content_tag(name, content = nil, **options, &block) ⇒ Object
- #tag(name, indent: 0, **options) ⇒ Object
Instance Method Details
#append_attribute(attribute, value, hash) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/hensel/helpers/tag_helpers.rb', line 51 def append_attribute(attribute, value, hash) if hash[attribute] unless hash[attribute].to_s.split(" ").include?(value) hash[attribute] = (Array(hash[attribute]) << value) * " " end else hash.merge!(attribute => value) end end |
#content_tag(name, content = nil, **options, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hensel/helpers/tag_helpers.rb', line 33 def content_tag(name, content = nil, **, &block) base = tag(name, ) content = instance_eval(&block) if !content && block_given? if indentation? indent = .fetch(:indent, 0) base << "\n" base << (content.strip.start_with?("<") ? content : (whitespace(indent + 1)) + content) base << "\n" base << "#{whitespace(indent)}</#{name}>" else "#{base}#{content}</#{name}>" end end |
#tag(name, indent: 0, **options) ⇒ Object
47 48 49 |
# File 'lib/hensel/helpers/tag_helpers.rb', line 47 def tag(name, indent: 0, **) "#{indentation? ? whitespace(indent) : ""}<#{name}#{tag_attributes()}>" end |