Class: Inesita::Server
- Inherits:
-
Object
- Object
- Inesita::Server
- Defined in:
- lib/inesita/server.rb
Instance Attribute Summary collapse
-
#assets_app ⇒ Object
readonly
Returns the value of attribute assets_app.
Instance Method Summary collapse
- #assets_code ⇒ Object
- #call(env) ⇒ Object
- #configure_sprockets(sprockets) ⇒ Object
- #create_app ⇒ Object
- #create_assets_app ⇒ Object
- #create_source_maps_app ⇒ Object
-
#initialize ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
13 14 15 16 17 18 |
# File 'lib/inesita/server.rb', line 13 def initialize @assets_app = create_assets_app @source_maps_app = create_source_maps_app @app = create_app Inesita.assets_code = assets_code end |
Instance Attribute Details
#assets_app ⇒ Object (readonly)
Returns the value of attribute assets_app.
11 12 13 |
# File 'lib/inesita/server.rb', line 11 def assets_app @assets_app end |
Instance Method Details
#assets_code ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/inesita/server.rb', line 20 def assets_code assets_prefix = Inesita.env == :development ? Config::ASSETS_PREFIX : nil %( <link rel="stylesheet" type="text/css" href="#{assets_prefix}/stylesheet.css"> #{Opal::Sprockets.javascript_include_tag('application', sprockets: @assets_app, prefix: assets_prefix, debug: Inesita.env == :development)} ) end |
#call(env) ⇒ Object
77 78 79 |
# File 'lib/inesita/server.rb', line 77 def call(env) @app.call(env) end |
#configure_sprockets(sprockets) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/inesita/server.rb', line 65 def configure_sprockets(sprockets) sprockets.register_engine '.slim', Slim::Template sprockets.context_class.class_eval do include SprocketsContext end end |
#create_app ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/inesita/server.rb', line 28 def create_app assets_app = @assets_app source_maps_app = @source_maps_app Rack::Builder.new do use Rack::Static, :urls => [Config::STATIC_DIR] use Rack::Rewrite do rewrite(/^(?!#{Config::ASSETS_PREFIX}|#{Config::SOURCE_MAP_PREFIX}).*/, Config::ASSETS_PREFIX) end map Config::ASSETS_PREFIX do run assets_app end map Config::SOURCE_MAP_PREFIX do run source_maps_app end end end |
#create_assets_app ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/inesita/server.rb', line 49 def create_assets_app Opal::Server.new do |s| s.append_path Config::APP_DIR Opal.paths.each do |p| s.append_path p end RailsAssets.load_paths.each do |p| s.append_path p end if defined?(RailsAssets) configure_sprockets(s.sprockets) end.sprockets end |
#create_source_maps_app ⇒ Object
72 73 74 75 |
# File 'lib/inesita/server.rb', line 72 def create_source_maps_app ::Opal::Sprockets::SourceMapHeaderPatch.inject!(Config::SOURCE_MAP_PREFIX) Opal::SourceMapServer.new(@assets_app, Config::SOURCE_MAP_PREFIX) end |