Class: Ripe::Blocks::LiquidBlock

Inherits:
WorkingBlock show all
Defined in:
lib/ripe/blocks/liquid_block.rb

Overview

This class represents a working block that should be processed using the Liquid templating engine.

See Also:

Instance Attribute Summary

Attributes inherited from Block

#blocks, #id, #vars

Class Method Summary collapse

Instance Method Summary collapse

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

.extensionString

Return expected file extension type for this type of ‘WorkingBlock`.

See Also:



63
64
65
# File 'lib/ripe/blocks/liquid_block.rb', line 63

def self.extension
  'sh.liquid'
end

.idString

Return string handle for referring to this type of ‘WorkingBlock`.

See Also:



52
53
54
# File 'lib/ripe/blocks/liquid_block.rb', line 52

def self.id
  'liquid'
end

Instance Method Details

#commandString

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

#declarationsHash<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