Class: Startback::Web::MagicAssets
- Inherits:
-
Object
- Object
- Startback::Web::MagicAssets
- Defined in:
- lib/startback/web/magic_assets.rb,
lib/startback/web/magic_assets/rake_tasks.rb,
lib/startback/web/magic_assets/ng_html_transformer.rb
Overview
Rack application & middleware that can be used to simplify javascript and css assets management, using Sprockets.
Example:
# Used as rack app, typically under a path
Rack::Builder.new do
map '/assets' do
run Startback::Web::MagicAssets.new({
folder: "/path/to/assets/src"
})
end
run MyApp
end
# Used as a rack middleware, e.g. in a Sinatra application
use Startback::Web::MagicAssets, {
folder: "/path/to/assets/src",
path: "/assets"
}
Sprocket configuration can be done through the ‘:sprocket` option:
use Startback::Web::MagicAssets, {
sprockets: {
:css_compressor => :scss
}
}
Defined Under Namespace
Classes: NgHtmlTransformer, RakeTasks
Constant Summary collapse
- DEFAULT_OPTIONS =
{ sprockets: {}, plugins: {} }
Instance Attribute Summary collapse
-
#sprockets ⇒ Object
readonly
Returns the value of attribute sprockets.
Instance Method Summary collapse
- #[](*args, &bl) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ MagicAssets
constructor
A new instance of MagicAssets.
Constructor Details
#initialize(app, options = {}) ⇒ MagicAssets
Returns a new instance of MagicAssets.
41 42 43 44 45 46 |
# File 'lib/startback/web/magic_assets.rb', line 41 def initialize(app, = {}) app, = nil, app if app.is_a?(Hash) @app = app @options = DEFAULT_OPTIONS.merge() @sprockets = build_sprockets end |
Instance Attribute Details
#sprockets ⇒ Object (readonly)
Returns the value of attribute sprockets.
47 48 49 |
# File 'lib/startback/web/magic_assets.rb', line 47 def sprockets @sprockets end |
Instance Method Details
#[](*args, &bl) ⇒ Object
57 58 59 |
# File 'lib/startback/web/magic_assets.rb', line 57 def [](*args, &bl) @sprockets.[](*args, &bl) end |
#call(env) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/startback/web/magic_assets.rb', line 49 def call(env) if new_env = is_match?(env) @sprockets.call(new_env) else @app.call(env) end end |