Class: Serve::DynamicHandler::Parser
- Inherits:
-
Object
- Object
- Serve::DynamicHandler::Parser
- Defined in:
- lib/serve/handlers/dynamic_handler.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#script_filename ⇒ Object
Returns the value of attribute script_filename.
Instance Method Summary collapse
-
#initialize(context) ⇒ Parser
constructor
A new instance of Parser.
- #parse_file(filename) ⇒ Object
Constructor Details
#initialize(context) ⇒ Parser
Returns a new instance of Parser.
66 67 68 69 |
# File 'lib/serve/handlers/dynamic_handler.rb', line 66 def initialize(context) @context = context @context.parser = self end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
64 65 66 |
# File 'lib/serve/handlers/dynamic_handler.rb', line 64 def context @context end |
#script_filename ⇒ Object
Returns the value of attribute script_filename.
64 65 66 |
# File 'lib/serve/handlers/dynamic_handler.rb', line 64 def script_filename @script_filename end |
Instance Method Details
#parse_file(filename) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/serve/handlers/dynamic_handler.rb', line 71 def parse_file(filename) old_script_filename = @script_filename @script_filename = filename lines = IO.read(filename) engine = case File.extname(filename).sub(/^./, '').downcase when 'haml' require 'haml' require 'sass' require 'sass/plugin' Haml::Engine.new(lines, :attr_wrapper => '"', :filename => filename) when 'erb' require 'erb' ERB::Engine.new(lines, :filename => filename) else raise 'extension not supported' end result = engine.render(context) do |*args| context.get_content_for(*args) end @script_filename = old_script_filename result end |