Class: ComponentHandler
Instance Method Summary collapse
- #call(env) ⇒ Object
- #compile_for_component(component_name) ⇒ Object
-
#initialize(component_paths) ⇒ ComponentHandler
constructor
A new instance of ComponentHandler.
Constructor Details
#initialize(component_paths) ⇒ ComponentHandler
Returns a new instance of ComponentHandler.
6 7 8 |
# File 'lib/volt/server/component_handler.rb', line 6 def initialize(component_paths) @component_paths = component_paths end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/volt/server/component_handler.rb', line 10 def call(env) req = Rack::Request.new(env) # TODO: Sanatize template path component_name = req.path.strip.gsub(/^\/components\//, '').gsub(/[.]js$/, '') javascript_code = compile_for_component(component_name) return [200, {"Content-Type" => "text/html; charset=utf-8"}, StringIO.new(javascript_code)] end |
#compile_for_component(component_name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/volt/server/component_handler.rb', line 21 def compile_for_component(component_name) code = ComponentCode.new(component_name, @component_paths).code # Add the lib directory to the load path Opal.append_path(Volt.root + '/lib') # Compile the code javascript_code = Opal.compile(code) return javascript_code end |