Class: Volt::IndexFiles
Instance Method Summary collapse
- #call(env) ⇒ Object
- #css_files ⇒ Object
- #html ⇒ Object
-
#initialize(app, volt_app, component_paths, opal_files) ⇒ IndexFiles
constructor
A new instance of IndexFiles.
- #javascript_files ⇒ Object
- #route_match?(path) ⇒ Boolean
Constructor Details
#initialize(app, volt_app, component_paths, opal_files) ⇒ IndexFiles
Returns a new instance of IndexFiles.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/volt/server/rack/index_files.rb', line 7 def initialize(app, volt_app, component_paths, opal_files) @app = app @volt_app = volt_app @component_paths = component_paths @opal_files = opal_files @@router = volt_app.router @@router.define do # Load routes for each component component_paths.components.values.flatten.uniq.each do |component_path| routes_path = "#{component_path}/config/routes.rb" if File.exist?(routes_path) route_file = File.read(routes_path) instance_eval(route_file, routes_path, 0) end end end end |
Instance Method Details
#call(env) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/volt/server/rack/index_files.rb', line 36 def call(env) if route_match?(env['PATH_INFO']) [200, { 'Content-Type' => 'text/html; charset=utf-8' }, [html]] else @app.call env end end |
#css_files ⇒ Object
56 57 58 |
# File 'lib/volt/server/rack/index_files.rb', line 56 def css_files AssetFiles.new('main', @component_paths).css_files end |
#html ⇒ Object
44 45 46 47 48 49 |
# File 'lib/volt/server/rack/index_files.rb', line 44 def html index_path = File.(File.join(Volt.root, 'config/base/index.html')) html = File.read(index_path) ERB.new(html, nil, '-').result(binding) end |
#javascript_files ⇒ Object
51 52 53 54 |
# File 'lib/volt/server/rack/index_files.rb', line 51 def javascript_files # TODO: Cache somehow, this is being loaded every time AssetFiles.new('main', @component_paths).javascript_files(@opal_files) end |
#route_match?(path) ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/volt/server/rack/index_files.rb', line 28 def route_match?(path) params = @@router.url_to_params(path) return params if params false end |