Class: Slim::Splat::Builder Private
- Inherits:
-
Object
- Object
- Slim::Splat::Builder
- Defined in:
- lib/slim/splat/builder.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #attr(name, value) ⇒ Object private
- #build_attrs ⇒ Object private
- #build_tag ⇒ Object private
- #code_attr(name, escape, value) ⇒ Object private
-
#initialize(options) ⇒ Builder
constructor
private
A new instance of Builder.
- #splat_attrs(splat) ⇒ Object private
Constructor Details
#initialize(options) ⇒ Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Builder.
5 6 7 8 |
# File 'lib/slim/splat/builder.rb', line 5 def initialize() @options = @attrs = {} end |
Instance Method Details
#attr(name, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/slim/splat/builder.rb', line 37 def attr(name, value) if @attrs[name] if delim = @options[:merge_attrs][name] @attrs[name] << delim << value else raise("Multiple #{name} attributes specified") end else @attrs[name] = value end end |
#build_attrs ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 62 63 64 |
# File 'lib/slim/splat/builder.rb', line 59 def build_attrs attrs = @options[:sort_attrs] ? @attrs.sort_by(&:first) : @attrs attrs.map do |k, v| " #{k}=#{@options[:attr_quote]}#{v}#{@options[:attr_quote]}" end.join end |
#build_tag ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 52 53 54 55 56 57 |
# File 'lib/slim/splat/builder.rb', line 49 def build_tag tag = @attrs.delete('tag').to_s tag = @options[:default_tag] if tag.empty? if block_given? "<#{tag}#{build_attrs}>#{yield}</#{tag}>" else "<#{tag}#{build_attrs} />" end end |
#code_attr(name, escape, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/slim/splat/builder.rb', line 10 def code_attr(name, escape, value) if delim = @options[:merge_attrs][name] value = Array === value ? value.join(delim) : value.to_s attr(name, escape ? Temple::Utils.escape_html(value) : value) unless value.empty? elsif @options[:hyphen_attrs].include?(name) && Hash === value hyphen_attr(name, escape, value) else case value when false, nil # Boolean false attribute return when true # Boolean true attribute value = '' else value = value.to_s end attr(name, escape ? Temple::Utils.escape_html(value) : value) end end |
#splat_attrs(splat) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 |
# File 'lib/slim/splat/builder.rb', line 31 def splat_attrs(splat) splat.each do |name, value| code_attr(name.to_s, true, value) end end |