Sha256: 26ed3b8185fd5daebb6553552ec1281bf1c85fc8144d988fb95bf6ffa685ad1b

Contents?: true

Size: 1.14 KB

Versions: 31

Compression:

Stored size: 1.14 KB

Contents

require 'volt/server/rack/asset_files'
require 'volt/router/routes'

# Serves the main pages
class IndexFiles
  def initialize(app, component_paths, opal_files)
    @app = app
    @component_paths = component_paths
    @opal_files = opal_files

    @@router ||= Routes.new.define do
      # Find the route file
      home_path = component_paths.component_path('main')
      route_file = File.read("#{home_path}/config/routes.rb")
      eval(route_file)
    end
  end

  def route_match?(path)
    params = @@router.url_to_params(path)

    return params if params

    return false
  end

  def call(env)
    if route_match?(env['PATH_INFO'])
      [200, { 'Content-Type' => 'text/html; charset=utf-8' }, [html]]
    else
      @app.call env
    end
  end

  def html
    index_path = File.expand_path(File.join(Volt.root, "public/index.html"))
    html = File.read(index_path)

    ERB.new(html).result(binding)
  end

  def javascript_files
    # TODO: Cache somehow, this is being loaded every time
    AssetFiles.new('main', @component_paths).javascript_files(@opal_files)
  end

  def css_files
    AssetFiles.new('main', @component_paths).css_files
  end



end


Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
volt-0.8.14 lib/volt/server/rack/index_files.rb
volt-0.8.13 lib/volt/server/rack/index_files.rb
volt-0.8.11 lib/volt/server/rack/index_files.rb
volt-0.8.10 lib/volt/server/rack/index_files.rb
volt-0.8.9 lib/volt/server/rack/index_files.rb
volt-0.8.8 lib/volt/server/rack/index_files.rb
volt-0.8.7 lib/volt/server/rack/index_files.rb
volt-0.8.6 lib/volt/server/rack/index_files.rb
volt-0.8.5 lib/volt/server/rack/index_files.rb
volt-0.8.4 lib/volt/server/rack/index_files.rb
volt-0.8.3 lib/volt/server/rack/index_files.rb
volt-0.8.2 lib/volt/server/rack/index_files.rb
volt-0.8.1 lib/volt/server/rack/index_files.rb
volt-0.8.0 lib/volt/server/rack/index_files.rb
volt-0.7.23 lib/volt/server/rack/index_files.rb
volt-0.7.22 lib/volt/server/rack/index_files.rb
volt-0.7.21 lib/volt/server/rack/index_files.rb
volt-0.7.20 lib/volt/server/rack/index_files.rb
volt-0.7.19 lib/volt/server/rack/index_files.rb
volt-0.7.18 lib/volt/server/rack/index_files.rb