Class: Startback::Web::MagicAssets

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options = {})
  app, options = nil, app if app.is_a?(Hash)
  @app = app
  @options = DEFAULT_OPTIONS.merge(options)
  @sprockets = build_sprockets
end

Instance Attribute Details

#sprocketsObject (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