Class: IndexFiles
Overview
Serves the main pages
Instance Method Summary collapse
- #call(env) ⇒ Object
- #css_files ⇒ Object
- #html ⇒ Object
-
#initialize(app, component_paths, opal_files) ⇒ IndexFiles
constructor
A new instance of IndexFiles.
- #javascript_files ⇒ Object
- #route_match?(path) ⇒ Boolean
Constructor Details
#initialize(app, component_paths, opal_files) ⇒ IndexFiles
Returns a new instance of IndexFiles.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/volt/server/rack/index_files.rb', line 6 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('home') route_file = File.read("#{home_path}/config/routes.rb") eval(route_file) end end |
Instance Method Details
#call(env) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/volt/server/rack/index_files.rb', line 27 def call(env) if route_match?(env['PATH_INFO']) [200, { 'Content-Type' => 'text/html' }, [html]] else @app.call env end end |
#css_files ⇒ Object
47 48 49 |
# File 'lib/volt/server/rack/index_files.rb', line 47 def css_files AssetFiles.new('home', @component_paths).css_files end |
#html ⇒ Object
35 36 37 38 39 40 |
# File 'lib/volt/server/rack/index_files.rb', line 35 def html index_path = File.(File.join(Volt.root, "public/index.html")) html = File.read(index_path) ERB.new(html).result(binding) end |
#javascript_files ⇒ Object
42 43 44 45 |
# File 'lib/volt/server/rack/index_files.rb', line 42 def javascript_files # TODO: Cache somehow, this is being loaded every time AssetFiles.new('home', @component_paths).javascript_files(@opal_files) end |
#route_match?(path) ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/volt/server/rack/index_files.rb', line 19 def route_match?(path) @@router.path_matchers.each do |path_matcher| return true if path =~ path_matcher end return false end |