Class: Opal::Sprockets::Server
- Inherits:
-
Object
- Object
- Opal::Sprockets::Server
- Defined in:
- lib/opal/sprockets/server.rb
Defined Under Namespace
Classes: Index
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.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/opal/sprockets/server.rb', line 9 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.
6 7 8 |
# File 'lib/opal/sprockets/server.rb', line 6 def debug @debug end |
#index_path ⇒ Object
Returns the value of attribute index_path.
6 7 8 |
# File 'lib/opal/sprockets/server.rb', line 6 def index_path @index_path end |
#main ⇒ Object
Returns the value of attribute main.
6 7 8 |
# File 'lib/opal/sprockets/server.rb', line 6 def main @main end |
#prefix ⇒ Object
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/opal/sprockets/server.rb', line 6 def prefix @prefix end |
#public_root ⇒ Object
Returns the value of attribute public_root.
6 7 8 |
# File 'lib/opal/sprockets/server.rb', line 6 def public_root @public_root end |
#public_urls ⇒ Object
Returns the value of attribute public_urls.
6 7 8 |
# File 'lib/opal/sprockets/server.rb', line 6 def public_urls @public_urls end |
#sprockets ⇒ Object
Returns the value of attribute sprockets.
6 7 8 |
# File 'lib/opal/sprockets/server.rb', line 6 def sprockets @sprockets end |
#use_index ⇒ Object
Returns the value of attribute use_index.
6 7 8 |
# File 'lib/opal/sprockets/server.rb', line 6 def use_index @use_index end |
Instance Method Details
#append_path(path) ⇒ Object
36 37 38 |
# File 'lib/opal/sprockets/server.rb', line 36 def append_path path @sprockets.append_path path end |
#call(env) ⇒ Object
58 59 60 |
# File 'lib/opal/sprockets/server.rb', line 58 def call(env) @app.call env end |
#create_app ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/opal/sprockets/server.rb', line 44 def create_app server, sprockets, prefix = self, @sprockets, self.prefix sprockets.logger.level ||= Logger::DEBUG @app = Rack::Builder.app do not_found = lambda { |env| [404, {}, []] } use Rack::Deflater use Rack::ShowExceptions use Index, server if server.use_index map(prefix) { run sprockets } run Rack::Static.new(not_found, root: server.public_root, urls: server.public_urls) end end |
#public_dir=(dir) ⇒ Object
23 24 25 26 |
# File 'lib/opal/sprockets/server.rb', line 23 def public_dir=(dir) @public_root = dir @public_urls = ["/"] end |
#source_map=(enabled) ⇒ Object
28 29 30 |
# File 'lib/opal/sprockets/server.rb', line 28 def source_map=(enabled) Opal::Config.source_map_enabled = enabled end |
#source_map_enabled ⇒ Object
32 33 34 |
# File 'lib/opal/sprockets/server.rb', line 32 def source_map_enabled Opal::Config.source_map_enabled end |
#use_gem(gem_name) ⇒ Object
40 41 42 |
# File 'lib/opal/sprockets/server.rb', line 40 def use_gem gem_name @sprockets.use_gem gem_name end |