Class: Opal::Server
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(debug_or_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(debug_or_options = {}) {|_self| ... } ⇒ Server
Returns a new instance of Server
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'opal/lib/opal/sprockets/server.rb', line 70 def initialize = {} unless Hash === warn "passing a boolean to control debug is deprecated.\n"+ "Please pass an Hash instead: Server.new(debug: true)" = {:debug => } else = end @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
67 68 69 |
# File 'opal/lib/opal/sprockets/server.rb', line 67 def debug @debug end |
#index_path ⇒ Object
Returns the value of attribute index_path
67 68 69 |
# File 'opal/lib/opal/sprockets/server.rb', line 67 def index_path @index_path end |
#main ⇒ Object
Returns the value of attribute main
67 68 69 |
# File 'opal/lib/opal/sprockets/server.rb', line 67 def main @main end |
#prefix ⇒ Object
Returns the value of attribute prefix
67 68 69 |
# File 'opal/lib/opal/sprockets/server.rb', line 67 def prefix @prefix end |
#public_root ⇒ Object
Returns the value of attribute public_root
67 68 69 |
# File 'opal/lib/opal/sprockets/server.rb', line 67 def public_root @public_root end |
#public_urls ⇒ Object
Returns the value of attribute public_urls
67 68 69 |
# File 'opal/lib/opal/sprockets/server.rb', line 67 def public_urls @public_urls end |
#sprockets ⇒ Object
Returns the value of attribute sprockets
67 68 69 |
# File 'opal/lib/opal/sprockets/server.rb', line 67 def sprockets @sprockets end |
#use_index ⇒ Object
Returns the value of attribute use_index
67 68 69 |
# File 'opal/lib/opal/sprockets/server.rb', line 67 def use_index @use_index end |
Instance Method Details
#append_path(path) ⇒ Object
105 106 107 |
# File 'opal/lib/opal/sprockets/server.rb', line 105 def append_path path @sprockets.append_path path end |
#call(env) ⇒ Object
129 130 131 |
# File 'opal/lib/opal/sprockets/server.rb', line 129 def call(env) @app.call env end |
#create_app ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'opal/lib/opal/sprockets/server.rb', line 113 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 assets = [] assets << SourceMapServer.new(sprockets, prefix) if server.source_map_enabled assets << sprockets map(prefix) { run Rack::Cascade.new(assets) } run Rack::Static.new(not_found, :root => server.public_root, :urls => server.public_urls) end end |
#public_dir=(dir) ⇒ Object
92 93 94 95 |
# File 'opal/lib/opal/sprockets/server.rb', line 92 def public_dir=(dir) @public_root = dir @public_urls = ["/"] end |
#source_map=(enabled) ⇒ Object
97 98 99 |
# File 'opal/lib/opal/sprockets/server.rb', line 97 def source_map=(enabled) Opal::Processor.source_map_enabled = enabled end |
#source_map_enabled ⇒ Object
101 102 103 |
# File 'opal/lib/opal/sprockets/server.rb', line 101 def source_map_enabled Opal::Processor.source_map_enabled end |
#use_gem(gem_name) ⇒ Object
109 110 111 |
# File 'opal/lib/opal/sprockets/server.rb', line 109 def use_gem gem_name @sprockets.use_gem gem_name end |