Class: Opal::Server::Index
- Inherits:
-
Object
- Object
- Opal::Server::Index
- Defined in:
- opal/lib/opal/sprockets/server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#html ⇒ Object
Returns the html content for the root path.
-
#initialize(app, server) ⇒ Index
constructor
A new instance of Index.
- #javascript_include_tag(name) ⇒ Object
- #source ⇒ Object
Constructor Details
#initialize(app, server) ⇒ Index
Returns a new instance of Index
92 93 94 95 96 |
# File 'opal/lib/opal/sprockets/server.rb', line 92 def initialize(app, server) @app = app @server = server @index_path = server.index_path end |
Instance Method Details
#call(env) ⇒ Object
98 99 100 101 102 103 104 |
# File 'opal/lib/opal/sprockets/server.rb', line 98 def call(env) if %w[/ /index.html].include? env['PATH_INFO'] [200, { 'Content-Type' => 'text/html' }, [html]] else @app.call env end end |
#html ⇒ Object
Returns the html content for the root path. Supports ERB
107 108 109 110 111 112 113 114 115 |
# File 'opal/lib/opal/sprockets/server.rb', line 107 def html if @index_path raise "index does not exist: #{@index_path}" unless File.exist?(@index_path) Tilt.new(@index_path).render(self) else raise "Main asset path not configured (set 'main' within Opal::Server.new block)" if @server.main.nil? source end end |
#javascript_include_tag(name) ⇒ Object
117 118 119 120 121 |
# File 'opal/lib/opal/sprockets/server.rb', line 117 def javascript_include_tag name sprockets = @server.sprockets prefix = @server.prefix ::Opal::Sprockets.javascript_include_tag(name, sprockets: @server.sprockets, prefix: @server.prefix, debug: @server.debug) end |
#source ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'opal/lib/opal/sprockets/server.rb', line 123 def source <<-HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Opal Server</title> </head> <body> #{javascript_include_tag @server.main} </body> </html> HTML end |