Class: Ripe::Blocks::LiquidBlock
- Inherits:
-
WorkingBlock
- Object
- Block
- WorkingBlock
- Ripe::Blocks::LiquidBlock
- Defined in:
- lib/ripe/blocks/liquid_block.rb
Overview
This class represents a working block that should be processed using the Liquid templating engine.
Instance Attribute Summary
Attributes inherited from Block
Class Method Summary collapse
-
.extension ⇒ String
Return expected file extension type for this type of ‘WorkingBlock`.
-
.id ⇒ String
Return string handle for referring to this type of ‘WorkingBlock`.
Instance Method Summary collapse
-
#command ⇒ String
Return the string command of the subtree starting at the current block.
-
#declarations ⇒ Hash<Symbol, Object>
Return liquid block
parameters
as a Hash<Symbol, Object>. -
#initialize(filename, vars = {}) ⇒ LiquidBlock
constructor
Create a new, empty LiquidBlock.
Methods inherited from WorkingBlock
#prune, subclasses, #targets_exist?, #topology
Methods inherited from Block
#+, #prune, #targets_exist?, #topology, #|
Constructor Details
#initialize(filename, vars = {}) ⇒ LiquidBlock
Create a new, empty Ripe::Blocks::LiquidBlock.
21 22 23 |
# File 'lib/ripe/blocks/liquid_block.rb', line 21 def initialize(filename, vars = {}) super(filename, vars) end |
Class Method Details
.extension ⇒ String
Return expected file extension type for this type of ‘WorkingBlock`.
63 64 65 |
# File 'lib/ripe/blocks/liquid_block.rb', line 63 def self.extension 'sh.liquid' end |
.id ⇒ String
Return string handle for referring to this type of ‘WorkingBlock`.
52 53 54 |
# File 'lib/ripe/blocks/liquid_block.rb', line 52 def self.id 'liquid' end |
Instance Method Details
#command ⇒ String
Return the string command of the subtree starting at the current block.
The resulting string contains the render result of the liquid template based on the parameters specified in vars
.
40 41 42 43 |
# File 'lib/ripe/blocks/liquid_block.rb', line 40 def command template = Liquid::Template.parse(File.new(@filename).read) template.render(declarations) end |
#declarations ⇒ Hash<Symbol, Object>
Return liquid block parameters
as a Hash<Symbol, Object>.
30 31 32 |
# File 'lib/ripe/blocks/liquid_block.rb', line 30 def declarations @vars.inject({}) { |memo, (k, v)| memo[k.to_s] = v; memo } end |