Sha256: 3b7e19097a45389592c3177c25a67ba02f163127b03bff8fc1e2829f40cf47eb

Contents?: true

Size: 927 Bytes

Versions: 11

Compression:

Stored size: 927 Bytes

Contents

require 'hamlit/concerns/attribute_builder'
require 'temple/utils'

# Hamlit::Attribute is a module to compile old-style attributes which
# can be compiled only on runtime. If you write old-style attributes
# which is not valid as Ruby hash, the attributes are compiled on runtime.
#
# Note that you should avoid writing such a template for performance.
module Hamlit
  class Attribute
    include Concerns::AttributeBuilder

    def self.build(quote, attributes)
      builder = self.new(quote)
      builder.build(attributes)
    end

    def initialize(quote)
      @quote = quote
    end

    def build(attributes)
      result = ''
      flatten_attributes(attributes).each do |key, value|
        if value == true
          result += " #{key}"
          next
        end

        escaped = Temple::Utils.escape_html(value)
        result += " #{key}=#{@quote}#{escaped}#{@quote}"
      end
      result
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hamlit-0.5.0 lib/hamlit/attribute.rb
hamlit-0.4.3 lib/hamlit/attribute.rb
hamlit-0.4.2 lib/hamlit/attribute.rb
hamlit-0.4.1 lib/hamlit/attribute.rb
hamlit-0.3.4 lib/hamlit/attribute.rb
hamlit-0.3.3 lib/hamlit/attribute.rb
hamlit-0.3.2 lib/hamlit/attribute.rb
hamlit-0.3.1 lib/hamlit/attribute.rb
hamlit-0.3.0 lib/hamlit/attribute.rb
hamlit-0.2.0 lib/hamlit/attribute.rb
hamlit-0.1.3 lib/hamlit/attribute.rb