Sha256: ad1f8e8a4d2416fe706b3626975524091aeba195bccf642efe943fb51a23f0dd

Contents?: true

Size: 883 Bytes

Versions: 31

Compression:

Stored size: 883 Bytes

Contents

require 'stringio'
require 'volt'
require 'volt/server/rack/component_code'

module Volt
  class ComponentHandler
    def initialize(component_paths)
      @component_paths = component_paths
    end

    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)

      [200, { 'Content-Type' => 'application/javascript; charset=utf-8' }, StringIO.new(javascript_code)]
    end

    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)

      javascript_code
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
volt-0.9.1.pre1 lib/volt/server/component_handler.rb
volt-0.9.0 lib/volt/server/component_handler.rb
volt-0.9.0.pre7 lib/volt/server/component_handler.rb
volt-0.9.0.pre6 lib/volt/server/component_handler.rb
volt-0.9.0.pre5 lib/volt/server/component_handler.rb
volt-0.9.0.pre4 lib/volt/server/component_handler.rb
volt-0.9.0.pre3 lib/volt/server/component_handler.rb
volt-0.9.0.pre2 lib/volt/server/component_handler.rb
volt-0.9.0.pre1 lib/volt/server/component_handler.rb
volt-0.8.27.beta9 lib/volt/server/component_handler.rb
volt-0.8.27.beta8 lib/volt/server/component_handler.rb
volt-0.8.27.beta7 lib/volt/server/component_handler.rb
volt-0.8.27.beta6 lib/volt/server/component_handler.rb
volt-0.8.27.beta5 lib/volt/server/component_handler.rb
volt-0.8.27.beta4 lib/volt/server/component_handler.rb
volt-0.8.27.beta3 lib/volt/server/component_handler.rb
volt-0.8.27.beta2 lib/volt/server/component_handler.rb
volt-0.8.27.beta1 lib/volt/server/component_handler.rb
volt-0.8.26.beta1 lib/volt/server/component_handler.rb
volt-0.8.26 lib/volt/server/component_handler.rb