Sha256: 33880944f54f7800d051bc110a27f18983f74a95b29515485cc138151ceb58b6

Contents?: true

Size: 867 Bytes

Versions: 8

Compression:

Stored size: 867 Bytes

Contents

require 'stringio'
require 'volt'
require 'volt/server/template_parser'
require 'volt/server/component_templates'
require 'volt/server/rack/component_files'

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$/, '')

    code = ''

    component_files = ComponentFiles.new(component_name, @component_paths)
    component_files.component_paths.each do |component_path, component_name|
      code << ComponentTemplates.new(component_path, component_name).code
      code << "\n\n"
    end
    
    javascript_code = Opal.compile(code)

    # puts "ENV: #{env.inspect}"
    [200, {"Content-Type" => "text/html"}, StringIO.new(javascript_code)]
  end


end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
volt-0.3.7 lib/volt/server/component_handler.rb
volt-0.3.6 lib/volt/server/component_handler.rb
volt-0.3.5 lib/volt/server/component_handler.rb
volt-0.3.4 lib/volt/server/component_handler.rb
volt-0.3.3 lib/volt/server/component_handler.rb
volt-0.3.2 lib/volt/server/component_handler.rb
volt-0.3.1 lib/volt/server/component_handler.rb
volt-0.3.0 lib/volt/server/component_handler.rb