Class: ActionviewPrecompiler::TemplateParser

Inherits:
Object
  • Object
show all
Defined in:
lib/actionview_precompiler/template_parser.rb

Defined Under Namespace

Classes: FakeTemplate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ TemplateParser

Returns a new instance of TemplateParser.



21
22
23
24
25
26
# File 'lib/actionview_precompiler/template_parser.rb', line 21

def initialize(filename)
  @filename = filename
  @basename = File.basename(filename)
  handler_ext = @basename.split(".").last
  @handler = HANDLERS_FOR_EXTENSION[handler_ext]
end

Instance Attribute Details

#basenameObject (readonly)

Returns the value of attribute basename.



5
6
7
# File 'lib/actionview_precompiler/template_parser.rb', line 5

def basename
  @basename
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/actionview_precompiler/template_parser.rb', line 5

def filename
  @filename
end

#handlerObject (readonly)

Returns the value of attribute handler.



5
6
7
# File 'lib/actionview_precompiler/template_parser.rb', line 5

def handler
  @handler
end

Instance Method Details

#render_callsObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/actionview_precompiler/template_parser.rb', line 28

def render_calls
  src = File.read(@filename)
  if src.include?("render")
    compiled_source = @handler.call(FakeTemplate.new, File.read(@filename))
    compiled_source = "def _template; #{compiled_source}; end"
    RenderParser.new(compiled_source).render_calls
  else
    []
  end
end