Sha256: c2d9f05527eba64ccdd7d31943095a313a82521e2b4706d33bc5fa98c0078cbf

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

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

# Serves the main pages
module Volt
  class IndexFiles
    def initialize(rack_app, volt_app, component_paths, opal_files)
      @rack_app        = rack_app
      @volt_app        = volt_app
      @component_paths = component_paths
      @opal_files      = opal_files

      @@router = volt_app.router
    end

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

      return params if params

      false
    end

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

    def html
      # Check for a precompiled
      index_path = File.expand_path(File.join(Volt.root, 'public/index.html'))

      # Next check for one in config/base
      unless File.exists?(index_path)
        index_path = File.expand_path(File.join(Volt.root, 'config/base/index.html'))
      end

      html       = File.read(index_path)

      ERB.new(html, nil, '-').result(binding)
    end

    def javascript_files(*args)
      fail "Deprecation: #javascript_files is deprecated in config/base/index.html, opal 0.8 required a new format."
    end

    def css_files(*args)
      fail "Deprecation: #css_files is deprecated in config/base/index.html, opal 0.8 required a new format."
    end

    def javascript_tags
      # TODO: Cache somehow, this is being loaded every time
      AssetFiles.from_cache(@volt_app.app_url, 'main', @component_paths).javascript_tags(@volt_app)
    end

    def css_tags
      AssetFiles.from_cache(@volt_app.app_url, 'main', @component_paths).css_tags
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
volt-0.9.7.pre8 lib/volt/server/rack/index_files.rb
volt-0.9.7.pre7 lib/volt/server/rack/index_files.rb
volt-0.9.7.pre6 lib/volt/server/rack/index_files.rb
volt-0.9.7.pre5 lib/volt/server/rack/index_files.rb
volt-0.9.7.pre3 lib/volt/server/rack/index_files.rb
volt-0.9.7.pre2 lib/volt/server/rack/index_files.rb