Class: CloudFormula::JsonErb

Inherits:
ERB
  • Object
show all
Defined in:
lib/cloudformula/json_erb.rb

Overview

Custom ERB compiler which causes variable interpolation inside <%= %> to be json encoded. Inside regular <% %>, the variables are used without json encoding.

CloudFormation stack options defaults can be set directly within a template by setting @stack_options. See README.md “CloudFormation stack options” for details.

Basic validation functionality is possible by setting @validations. See README.md “Validations” for details

Defined Under Namespace

Classes: CompilerWithBlock

Instance Method Summary collapse

Instance Method Details

#make_compiler(*args) ⇒ Object



20
21
22
# File 'lib/cloudformula/json_erb.rb', line 20

def make_compiler(*args)
  CompilerWithBlock.new *args
end

#stack_options(b = new_toplevel) ⇒ Hash

Returns the @stack_options value set within the template.

Parameters:

  • b (Binding) (defaults to: new_toplevel)

    accepts a Binding or Proc object which is used to set the context of code evaluation.

Returns:

  • (Hash)

    The stack options set by the template or an empty Hash if none are set.



28
29
30
31
# File 'lib/cloudformula/json_erb.rb', line 28

def stack_options(b = new_toplevel)
  result(b)
  b.eval('@stack_options') || {}
end

#validations(b = new_toplevel) ⇒ Hash

Returns the @validations value set within the template.

Parameters:

  • b (Binding) (defaults to: new_toplevel)

    accepts a Binding or Proc object which is used to set the context of code evaluation.

Returns:

  • (Hash)

    The stack options set by the template or an empty Hash if none are set.



37
38
39
40
# File 'lib/cloudformula/json_erb.rb', line 37

def validations(b = new_toplevel)
  result(b)
  b.eval('@validations') || {}
end