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.
-
#extension_for_mime_type(type) ⇒ Object
Override the default Sprockets method which incorrectly returns ‘.htm’.
-
#index ⇒ Object
Override to use Machined’s Index.
-
#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 |
# 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 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.
39 40 41 |
# File 'lib/machined/sprocket.rb', line 39 def compile? config.compile && config.url end |
#extension_for_mime_type(type) ⇒ Object
Override the default Sprockets method which incorrectly returns ‘.htm’.
61 62 63 64 |
# File 'lib/machined/sprocket.rb', line 61 def extension_for_mime_type(type) # :nodoc: return '.html' if type == 'text/html' super end |
#index ⇒ Object
Override to use Machined’s Index
44 45 46 |
# File 'lib/machined/sprocket.rb', line 44 def index Index.new(self) 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.
53 54 55 56 57 58 |
# File 'lib/machined/sprocket.rb', line 53 def use_all_templates Utils.available_templates.each do |ext, template| next if engines(ext) register_engine ext, template end end |