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