class Serenity::XmlReader

Public Class Methods

new(src) click to toggle source
# File lib/serenity/serenity/xml_reader.rb, line 4
def initialize src
  @src = src.force_encoding("UTF-8")
end

Public Instance Methods

each_node() { |text, node_type(text)| ... } click to toggle source
# File lib/serenity/serenity/xml_reader.rb, line 8
def each_node
  last_match_pos = 0

  @src.scan(/<.*?>/) do |node|
    m = Regexp.last_match
    if m.begin(0) > last_match_pos
      text = @src[last_match_pos...m.begin(0)]
      yield text, node_type(text) if text.gsub(/\s+/, '') != ''
    end

    last_match_pos = m.end(0)
    yield node, NodeType::TAG
  end
end
node_type(text) click to toggle source
# File lib/serenity/serenity/xml_reader.rb, line 23
def node_type text
  if text =~ /\s*\{%[^=#].+?%\}\s*/
    NodeType::CONTROL
  else
    NodeType::TEMPLATE
  end
end