Class: Concordion::Parser

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/concordion/parser.rb

Constant Summary collapse

@@ALL_ATTRIBUTED_ELEMENTS =
"/html/body//*[@*]"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#concordion_arguments, #concordion_cmd_attr_exists?, #concordion_cmd_attr_for, #concordion_property_reference, #concordion_variable_name, #has_property_reference?, #instrumentation

Methods included from StringUtility

#assignment, #attr_writer_method?, #concordion_assignment, #concordion_method_name, #ends_in_empty_parens?, #escape_single_quotes, #has_arguments?, #has_assignment?, #is_direct_method_call?

Methods included from PluralToSingularUtility

#singular

Methods included from SnakeCaseUtility

#snake_case, #snake_cased_goldmaster_name, #snake_cased_test_name

Methods included from Constants

#concordion_command_attributes, #supported?

Constructor Details

#initialize(reader, concordion) ⇒ Parser

Returns a new instance of Parser.



13
14
15
16
17
18
# File 'lib/concordion/parser.rb', line 13

def initialize(reader, concordion)
  @reader = reader
  @concordion = concordion
  @verifier = concordion.verifier
  @instrumenter = Concordion::Instrumenter.new
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



11
12
13
# File 'lib/concordion/parser.rb', line 11

def body
  @body
end

#htmlObject

Returns the value of attribute html.



11
12
13
# File 'lib/concordion/parser.rb', line 11

def html
  @html
end

#rootObject

Returns the value of attribute root.



11
12
13
# File 'lib/concordion/parser.rb', line 11

def root
  @root
end

Instance Method Details

#each_concordion_element(&block) ⇒ Object



25
26
27
28
29
# File 'lib/concordion/parser.rb', line 25

def each_concordion_element(&block)
  @root.search(@@ALL_ATTRIBUTED_ELEMENTS).each {|elem|
    yield elem
  }
end

#each_eligible_concordion_element(&block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/concordion/parser.rb', line 31

def each_eligible_concordion_element(&block)
  each_concordion_element do |elem|
    if concordion_cmd_attr_exists?(elem)       
      attr = concordion_cmd_attr_for(elem)
      @verifier.update_row(elem)
      if !@instrumenter.instrument_from_headers(elem, attr, @root)
        yield elem
      end
    end
  end
end

#parse(filename) ⇒ Object



20
21
22
23
24
# File 'lib/concordion/parser.rb', line 20

def parse(filename)
  @root = Hpricot.parse(@reader.read(filename))
  @body = @root.at("body")
  @html = @root.at("html")
end