class Opal::Server::Index
def call(env)
def call(env) if %w[/ /index.html].include? env['PATH_INFO'] [200, { 'Content-Type' => 'text/html' }, [html]] else @app.call env end end
def html
def html if @index_path raise "index does not exist: #{@index_path}" unless File.exist?(@index_path) Tilt.new(@index_path).render(self) else source end end
def initialize(app, server)
def initialize(app, server) @app = app @server = server @index_path = server.index_path end
def javascript_include_tag name
def javascript_include_tag name sprockets = @server.sprockets prefix = @server.prefix asset = sprockets[name] raise "Cannot find asset: #{name}" if asset.nil? scripts = [] if @server.debug asset.to_a.map do |dependency| scripts << %{<script src="#{prefix}/#{dependency.logical_path}?body=1"></script>} end else scripts << %{<script src="#{prefix}/#{name}.js"></script>} end scripts << %{<script>#{Opal::Processor.load_asset_code(sprockets, name)}</script>} scripts.join "\n" end
def source
def source <<-HTML <!DOCTYPE html> <html> <head> <title>Opal Server</title> </head> <body> #{javascript_include_tag @server.main} </body> </html> HTML end