Class: Haml::I18n::Extractor::HamlParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/haml-i18n-extractor/extraction/haml_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(haml) ⇒ HamlParser

Returns a new instance of HamlParser.



8
9
10
# File 'lib/haml-i18n-extractor/extraction/haml_parser.rb', line 8

def initialize(haml)
  super(haml, Haml::Options.new)
end

Instance Method Details

#flatten_tree_attrs(node, array) ⇒ Object

recurse the tree and return an array of the lines don’t care about the tree structure, we don’t care about context, just line-by-line but we want the haml::parser metadata for all the lines, iterated over



24
25
26
27
28
29
30
# File 'lib/haml-i18n-extractor/extraction/haml_parser.rb', line 24

def flatten_tree_attrs(node,array)
  array << node_attributes(node)
  node.children.each do |child|
    flatten_tree_attrs(child,array)
  end
  array
end

#flattened_valuesObject Also known as: metadata



12
13
14
15
16
17
18
# File 'lib/haml-i18n-extractor/extraction/haml_parser.rb', line 12

def flattened_values
  # make the haml we passed in a parse tree!
  @ht_parse_tree = self.parse 
  ret = flatten_tree_attrs(@ht_parse_tree,[])
  ret[1..-2] # we only want the actual lines, not the root node and last line which don't really exist
  #ret
end