Class: Rake::Pipeline::Web::Filters::TiltFilter
- Inherits:
-
Filter
- Object
- Filter
- Rake::Pipeline::Web::Filters::TiltFilter
- Includes:
- FilterWithDependencies
- Defined in:
- lib/rake-pipeline-web-filters/tilt_filter.rb
Overview
A filter that accepts a series of inputs and translates them using the Tilt template interface, which will attempt to guess which template language to use based on the input file extension.
Requires tilt
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
An object to use as the rendering context.
-
#options ⇒ Hash
readonly
A hash of options to pass to Tilt when rendering.
Instance Method Summary collapse
- #external_dependencies ⇒ Object
-
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API.
-
#initialize(options = {}, context = nil, &block) ⇒ TiltFilter
constructor
A new instance of TiltFilter.
Constructor Details
#initialize(options = {}, context = nil, &block) ⇒ TiltFilter
Returns a new instance of TiltFilter.
38 39 40 41 42 |
# File 'lib/rake-pipeline-web-filters/tilt_filter.rb', line 38 def initialize(={}, context = nil, &block) super(&block) = @context = context || Object.new end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns an object to use as the rendering context.
32 33 34 |
# File 'lib/rake-pipeline-web-filters/tilt_filter.rb', line 32 def context @context end |
#options ⇒ Hash (readonly)
Returns a hash of options to pass to Tilt when rendering.
28 29 30 |
# File 'lib/rake-pipeline-web-filters/tilt_filter.rb', line 28 def end |
Instance Method Details
#external_dependencies ⇒ Object
66 67 68 |
# File 'lib/rake-pipeline-web-filters/tilt_filter.rb', line 66 def external_dependencies [ 'tilt' ] end |
#generate_output(inputs, output) ⇒ Object
Implement the #generate_output method required by the Filter API. Attempts to compile each input file with Tilt, passing the file through unchanged if Tilt can't find a template class for the file.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rake-pipeline-web-filters/tilt_filter.rb', line 54 def generate_output(inputs, output) inputs.each do |input| out = if (template_class = Tilt[input.path]) template_class.new(nil, 1, ) { |t| input.read }.render(context) else input.read end output.write out end end |