Class: FrontKit::MetaContainer

Inherits:
Object
  • Object
show all
Defined in:
lib/frontkit-rails/meta_container.rb

Constant Summary collapse

VALID_ATTRS =
%w(name property content)
ESCAPE_ATTRS =
%w(content)

Instance Method Summary collapse

Constructor Details

#initializeMetaContainer

Returns a new instance of MetaContainer.



6
7
8
# File 'lib/frontkit-rails/meta_container.rb', line 6

def initialize
  @container = []
end

Instance Method Details

#each(&block) ⇒ Object



25
26
27
# File 'lib/frontkit-rails/meta_container.rb', line 25

def each(&block)
  @container.uniq.each { |escaped_hash| block.call(escaped_hash) }
end

#push(hash) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/frontkit-rails/meta_container.rb', line 10

def push(hash)      
  escaped_hash = hash.inject(Hash.new) do |memo, (key, value)|
    key = key.to_s.downcase
    value = CGI.escapeHTML(value) if key.in?(ESCAPE_ATTRS)
    memo[key] = value; memo
  end
  
  invalid_attrs = escaped_hash.keys - VALID_ATTRS
  if invalid_attrs.any?
    raise ArgumentError, "Illegal meta tag attributes: #{invalid_attrs * ', '}"
  end

  @container.push(escaped_hash)
end