class Opal::Sprockets::Server::Index

Public Class Methods

new(app, server) click to toggle source
# File lib/opal/sprockets/server.rb, line 64
def initialize(app, server)
  @app = app
  @server = server
  @index_path = server.index_path
end

Public Instance Methods

call(env) click to toggle source
# File lib/opal/sprockets/server.rb, line 70
def call(env)
  if %w[/ /index.html].include? env['PATH_INFO']
    [200, { 'Content-Type' => 'text/html' }, [html]]
  else
    @app.call env
  end
end
html() click to toggle source

Returns the html content for the root path. Supports ERB

# File lib/opal/sprockets/server.rb, line 79
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) click to toggle source
# File lib/opal/sprockets/server.rb, line 89
def javascript_include_tag name
  sprockets = @server.sprockets
  prefix = @server.prefix
  debug = @server.debug

  ::Opal::Sprockets.javascript_include_tag(name, sprockets: sprockets, prefix: prefix, debug: debug)
end
source() click to toggle source
# File lib/opal/sprockets/server.rb, line 97
    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