Class: Opal::Server
- Inherits:
-
Object
- Object
- Opal::Server
- Defined in:
- opal/lib/opal/sprockets/server.rb
Defined Under Namespace
Classes: Index
Constant Summary
- SOURCE_MAPS_PREFIX_PATH =
'/__OPAL_SOURCE_MAPS__'
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#index_path ⇒ Object
Returns the value of attribute index_path.
-
#main ⇒ Object
Returns the value of attribute main.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#public_root ⇒ Object
Returns the value of attribute public_root.
-
#public_urls ⇒ Object
Returns the value of attribute public_urls.
-
#sprockets ⇒ Object
Returns the value of attribute sprockets.
-
#use_index ⇒ Object
Returns the value of attribute use_index.
Instance Method Summary collapse
- #append_path(path) ⇒ Object
- #call(env) ⇒ Object
- #create_app ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Server
constructor
A new instance of Server.
- #public_dir=(dir) ⇒ Object
- #source_map=(enabled) ⇒ Object
- #source_map_enabled ⇒ Object
- #use_gem(gem_name) ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Server
Returns a new instance of Server
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'opal/lib/opal/sprockets/server.rb', line 16 def initialize = {} @use_index = true @public_root = nil @public_urls = ['/'] @sprockets = .fetch(:sprockets, ::Sprockets::Environment.new) @debug = .fetch(:debug, true) @prefix = .fetch(:prefix, '/assets') Opal.paths.each { |p| @sprockets.append_path(p) } yield self if block_given? create_app end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug
13 14 15 |
# File 'opal/lib/opal/sprockets/server.rb', line 13 def debug @debug end |
#index_path ⇒ Object
Returns the value of attribute index_path
13 14 15 |
# File 'opal/lib/opal/sprockets/server.rb', line 13 def index_path @index_path end |
#main ⇒ Object
Returns the value of attribute main
13 14 15 |
# File 'opal/lib/opal/sprockets/server.rb', line 13 def main @main end |
#prefix ⇒ Object
Returns the value of attribute prefix
13 14 15 |
# File 'opal/lib/opal/sprockets/server.rb', line 13 def prefix @prefix end |
#public_root ⇒ Object
Returns the value of attribute public_root
13 14 15 |
# File 'opal/lib/opal/sprockets/server.rb', line 13 def public_root @public_root end |
#public_urls ⇒ Object
Returns the value of attribute public_urls
13 14 15 |
# File 'opal/lib/opal/sprockets/server.rb', line 13 def public_urls @public_urls end |
#sprockets ⇒ Object
Returns the value of attribute sprockets
13 14 15 |
# File 'opal/lib/opal/sprockets/server.rb', line 13 def sprockets @sprockets end |
#use_index ⇒ Object
Returns the value of attribute use_index
13 14 15 |
# File 'opal/lib/opal/sprockets/server.rb', line 13 def use_index @use_index end |
Instance Method Details
#append_path(path) ⇒ Object
43 44 45 |
# File 'opal/lib/opal/sprockets/server.rb', line 43 def append_path path @sprockets.append_path path end |
#call(env) ⇒ Object
78 79 80 |
# File 'opal/lib/opal/sprockets/server.rb', line 78 def call(env) @app.call env end |
#create_app ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'opal/lib/opal/sprockets/server.rb', line 51 def create_app server, sprockets, prefix = self, @sprockets, self.prefix sprockets.logger.level ||= Logger::DEBUG source_map_enabled = self.source_map_enabled if source_map_enabled maps_prefix = SOURCE_MAPS_PREFIX_PATH maps_app = SourceMapServer.new(sprockets, maps_prefix) ::Opal::Sprockets::SourceMapHeaderPatch.inject!(maps_prefix) end @app = Rack::Builder.app do not_found = lambda { |env| [404, {}, []] } use Rack::Deflater use Rack::ShowExceptions use Index, server if server.use_index if source_map_enabled map(maps_prefix) do use Rack::ConditionalGet use Rack::ETag run maps_app end end map(prefix) { run sprockets } run Rack::Static.new(not_found, root: server.public_root, urls: server.public_urls) end end |
#public_dir=(dir) ⇒ Object
30 31 32 33 |
# File 'opal/lib/opal/sprockets/server.rb', line 30 def public_dir=(dir) @public_root = dir @public_urls = ["/"] end |
#source_map=(enabled) ⇒ Object
35 36 37 |
# File 'opal/lib/opal/sprockets/server.rb', line 35 def source_map=(enabled) Opal::Config.source_map_enabled = enabled end |
#source_map_enabled ⇒ Object
39 40 41 |
# File 'opal/lib/opal/sprockets/server.rb', line 39 def source_map_enabled Opal::Config.source_map_enabled end |
#use_gem(gem_name) ⇒ Object
47 48 49 |
# File 'opal/lib/opal/sprockets/server.rb', line 47 def use_gem gem_name @sprockets.use_gem gem_name end |