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, rather than the simple bash engine defined in WorkingBlock.
Instance Attribute Summary
Attributes inherited from Block
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
parametersas a Hash<Symbol, Object>. -
#initialize(filename, vars = {}) ⇒ LiquidBlock
constructor
A new instance of LiquidBlock.
Methods inherited from WorkingBlock
#prune, #targets_exist?, #topology
Methods inherited from Block
#+, #prune, #targets_exist?, #topology, #|
Constructor Details
#initialize(filename, vars = {}) ⇒ LiquidBlock
20 21 22 |
# File 'lib/ripe/blocks/liquid_block.rb', line 20 def initialize(filename, vars = {}) super(filename, vars) 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.
39 40 41 42 |
# File 'lib/ripe/blocks/liquid_block.rb', line 39 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>.
29 30 31 |
# File 'lib/ripe/blocks/liquid_block.rb', line 29 def declarations @vars.inject({}) { |memo, (k, v)| memo[k.to_s] = v; memo } end |