Sha256: 12625e02ef9468f604eacba2e373be7892a92a9e1c519f07987d6f3b9be13e06

Contents?: true

Size: 844 Bytes

Versions: 3

Compression:

Stored size: 844 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|
        escaped = Temple::Utils.escape_html(value)
        result += " #{key}=#{@quote}#{escaped}#{@quote}"
      end
      result
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hamlit-0.1.2 lib/hamlit/attribute.rb
hamlit-0.1.1 lib/hamlit/attribute.rb
hamlit-0.1.0 lib/hamlit/attribute.rb