Sha256: 1d17c507e52c47dd122879042f6311102b5ac901706b8d30cccd746845c88bf9

Contents?: true

Size: 873 Bytes

Versions: 5

Compression:

Stored size: 873 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, true)
    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

5 entries across 5 versions & 1 rubygems

Version Path
volt-0.4.5 lib/volt/server/component_handler.rb
volt-0.4.4 lib/volt/server/component_handler.rb
volt-0.4.3 lib/volt/server/component_handler.rb
volt-0.4.2 lib/volt/server/component_handler.rb
volt-0.4.1 lib/volt/server/component_handler.rb