Sha256: 4e17d3faf05437ccfed95c473b2d57216f29c940bcddddd7f4b65a4afa521c97

Contents?: true

Size: 1.12 KB

Versions: 29

Compression:

Stored size: 1.12 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
      route_file = File.read('app/home/config/routes.rb')
      eval(route_file)
    end
  end
  
  def route_match?(path)
    @@router.path_matchers.each do |path_matcher|
      return true if path =~ path_matcher
    end
    
    return false
  end

  def call(env)
    if route_match?(env['PATH_INFO'])
      [200, { 'Content-Type' => 'text/html' }, [html]]
    else
      @app.call env
    end
  end
  
  def html
    index_path = File.expand_path(File.join(Dir.pwd, "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('home', @component_paths).javascript_files(@opal_files)
  end
  
  def css_files
    AssetFiles.new('home', @component_paths).css_files
  end

  

end


Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
volt-0.6.1 lib/volt/server/rack/index_files.rb
volt-0.6.0 lib/volt/server/rack/index_files.rb
volt-0.5.18 lib/volt/server/rack/index_files.rb
volt-0.5.17 lib/volt/server/rack/index_files.rb
volt-0.5.16 lib/volt/server/rack/index_files.rb
volt-0.5.15 lib/volt/server/rack/index_files.rb
volt-0.5.14 lib/volt/server/rack/index_files.rb
volt-0.5.13 lib/volt/server/rack/index_files.rb
volt-0.5.12 lib/volt/server/rack/index_files.rb
volt-0.5.11 lib/volt/server/rack/index_files.rb
volt-0.5.10 lib/volt/server/rack/index_files.rb
volt-0.5.9 lib/volt/server/rack/index_files.rb
volt-0.5.8 lib/volt/server/rack/index_files.rb
volt-0.5.7 lib/volt/server/rack/index_files.rb
volt-0.5.6 lib/volt/server/rack/index_files.rb
volt-0.5.4 lib/volt/server/rack/index_files.rb
volt-0.5.3 lib/volt/server/rack/index_files.rb
volt-0.5.2 lib/volt/server/rack/index_files.rb
volt-0.5.1 lib/volt/server/rack/index_files.rb
volt-0.5.0 lib/volt/server/rack/index_files.rb