Class: Machined::Sprocket
- Inherits:
-
Sprockets::Environment
- Object
- Sprockets::Environment
- Machined::Sprocket
- Defined in:
- lib/machined/sprocket.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
Default options for a Machined sprocket.
{ :root => ".", :assets => false, :compile => true }.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
A reference to the configuration.
-
#machined ⇒ Object
readonly
A reference to the Machined environment which created this instance.
Instance Method Summary collapse
-
#compile? ⇒ Boolean
Returns true, if this sprocket should be compiled.
-
#initialize(machined, options = {}) ⇒ Sprocket
constructor
Creates a new Machined sprocket.
-
#use_all_templates ⇒ Object
Loops through the available Tilt templates and registers them as processor engines for Sprockets.
Constructor Details
#initialize(machined, options = {}) ⇒ Sprocket
Creates a new Machined sprocket. The API is a bit different than ‘Sprockets::Environment` to allow for per-Sprockets-environment configuration and to keep a reference to the Machined environment.
25 26 27 28 29 30 31 32 33 |
# File 'lib/machined/sprocket.rb', line 25 def initialize(machined, = {}) @machined = machined @config = OpenStruct.new DEFAULT_OPTIONS.dup.merge() super config.root @context_class = Class.new Context use_all_templates unless config.assets end |
Instance Attribute Details
#config ⇒ Object (readonly)
A reference to the configuration.
19 20 21 |
# File 'lib/machined/sprocket.rb', line 19 def config @config end |
#machined ⇒ Object (readonly)
A reference to the Machined environment which created this instance.
16 17 18 |
# File 'lib/machined/sprocket.rb', line 16 def machined @machined end |
Instance Method Details
#compile? ⇒ Boolean
Returns true, if this sprocket should be compiled. Nine times out of ten, you will want your sprocket compiled, but sometimes - like the default views sprocket - it is used as a uncompiled resource.
40 41 42 |
# File 'lib/machined/sprocket.rb', line 40 def compile? config.compile && config.url end |
#use_all_templates ⇒ Object
Loops through the available Tilt templates and registers them as processor engines for Sprockets. By default, Sprockets cherry picks templates that work for web assets. We need to allow use of Haml, Markdown, etc.
49 50 51 52 53 54 |
# File 'lib/machined/sprocket.rb', line 49 def use_all_templates Utils.available_templates.each do |ext, template| next if engines(ext) register_engine ext, template end end |