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(opts = {}) ⇒ Server
constructor
A new instance of Server.
- #setup_dirs(opts) ⇒ Object
- #setup_env(opts) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Server
13 14 15 16 17 18 19 20 |
# File 'lib/inesita/server.rb', line 13 def initialize(opts = {}) setup_dirs(opts) setup_env(opts) @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
33 34 35 36 37 38 39 |
# File 'lib/inesita/server.rb', line 33 def assets_code assets_prefix = @dist ? nil : Config::ASSETS_PREFIX %( <link rel="stylesheet" type="text/css" href="#{assets_prefix}/stylesheet.css"> #{Opal::Sprockets.javascript_include_tag('application', sprockets: @assets_app, prefix: assets_prefix, debug: !@dist)} ) end |
#call(env) ⇒ Object
96 97 98 |
# File 'lib/inesita/server.rb', line 96 def call(env) @app.call(env) end |
#configure_sprockets(sprockets) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/inesita/server.rb', line 84 def configure_sprockets(sprockets) sprockets.register_engine '.slim', Slim::Template sprockets.context_class.class_eval do include SprocketsContext end end |
#create_app ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/inesita/server.rb', line 41 def create_app assets_app = @assets_app source_maps_app = @source_maps_app static_dir = @static_dir Rack::Builder.new do use Rack::Static, :urls => [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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/inesita/server.rb', line 63 def create_assets_app Opal::Server.new do |s| s.append_path @app_dir if @dist s.append_path @app_dist_dir else s.append_path @app_dev_dir end 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
91 92 93 94 |
# File 'lib/inesita/server.rb', line 91 def create_source_maps_app ::Opal::Sprockets::SourceMapHeaderPatch.inject!(Config::SOURCE_MAP_PREFIX) Opal::SourceMapServer.new(@assets_app, Config::SOURCE_MAP_PREFIX) end |
#setup_dirs(opts) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/inesita/server.rb', line 26 def setup_dirs(opts) @static_dir = opts[:static_dir] || Config::STATIC_DIR @app_dir = opts[:app_dir] || Config::APP_DIR @app_dist_dir = opts[:app_dist_dir] || Config::APP_DIST_DIR @app_dev_dir = opts[:app_dev_dir] || Config::APP_DEV_DIR end |
#setup_env(opts) ⇒ Object
22 23 24 |
# File 'lib/inesita/server.rb', line 22 def setup_env(opts) @dist = opts[:dist] || false end |