Class: SWS::TemplateParser

Inherits:
Object
  • Object
show all
Defined in:
lib/sws/parsers.rb

Overview

Parser for HTML templates of the components.

Constant Summary collapse

@@file_data =
{}

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ TemplateParser

Creates new TemplateParser for given filename.



114
115
116
117
118
119
# File 'lib/sws/parsers.rb', line 114

def initialize ( filename )
  
  $log_sws_parser.debug( "Creating template parser for name #{filename}" )
  @template_filename = filename
        
end

Instance Method Details

#parseObject

Main parsing method - parses definition file into the tree of TemplateToken objects



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/sws/parsers.rb', line 124

def parse ()
  
  begin
    #TODO: implement debug mode which forces sws to reload
    # template file every time parse() is called
    unless( @@file_data[ @template_filename ] )
      @@file_data[ @template_filename ] = File.read( @template_filename )
    end
    template_data = @@file_data[ @template_filename ]

  rescue Exception
    raise "Cannot read template data from file \"#{@template_filename}\""
  end
  
  tokenized_data = template_data.scan( /<!--.*?-->|<[^<>]+>|[^<>]+/ )
  root_token = create_token_tree( tokenized_data )
  
  return root_token
  
end