Class: Ripe::Blocks::ERBBlock
- Inherits:
-
WorkingBlock
- Object
- Block
- WorkingBlock
- Ripe::Blocks::ERBBlock
- Defined in:
- lib/ripe/blocks/erb_block.rb
Overview
This class represents a working block that should be processed using the ERB templating system.
Keys defined as:
vars["some_key"] = "value"
can be substituted in the ERB template using:
<%= vars.some_key %>
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.
-
#initialize(filename, vars = {}) ⇒ ERBBlock
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 = {}) ⇒ ERBBlock
Create a new, empty LiquidBlock.
29 30 31 |
# File 'lib/ripe/blocks/erb_block.rb', line 29 def initialize(filename, vars = {}) super(filename, vars) end |
Class Method Details
.extension ⇒ String
Return expected file extension type for this type of ‘WorkingBlock`.
81 82 83 |
# File 'lib/ripe/blocks/erb_block.rb', line 81 def self.extension 'sh.erb' end |
.id ⇒ String
Return string handle for referring to this type of ‘WorkingBlock`.
70 71 72 |
# File 'lib/ripe/blocks/erb_block.rb', line 70 def self.id 'erb' 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ripe/blocks/erb_block.rb', line 39 def command vars = @vars vars.define_singleton_method(:get_binding) { binding } # Expose private method vars.define_singleton_method(:method_missing) do |name| return self[name] if key? name self.each { |k,v| return v if k.to_s.to_sym == name } # super.method_missing name end template = <<-EOF.gsub(/^[ ]+/, '') # <#{id}> exec 1>"<%= vars.log %>" 2>&1 #{File.new(@filename).read} echo "##.DONE.##" # </#{id}> EOF ERB.new(template).result(vars.get_binding) end |