Class: Lono::Template::Dsl::Builder
- Inherits:
-
Object
- Object
- Lono::Template::Dsl::Builder
- Extended by:
- Memoist
- Defined in:
- lib/lono/template/dsl/builder/helper.rb,
lib/lono/template/dsl/builder.rb,
lib/lono/template/dsl/builder/fn.rb,
lib/lono/template/dsl/builder/base.rb,
lib/lono/template/dsl/builder/output.rb,
lib/lono/template/dsl/builder/syntax.rb,
lib/lono/template/dsl/builder/mapping.rb,
lib/lono/template/dsl/builder/section.rb,
lib/lono/template/dsl/builder/resource.rb,
lib/lono/template/dsl/builder/condition.rb,
lib/lono/template/dsl/builder/parameter.rb
Overview
Implements:
template - uses @definition to build a CloudFormation template section
Defined Under Namespace
Modules: Fn, Helper, Syntax Classes: Base, Condition, Mapping, Output, Parameter, Resource, Section
Constant Summary
Constants included from Fn
Instance Method Summary collapse
- #build ⇒ Object
- #build_template ⇒ Object
- #camelize(data) ⇒ Object
-
#initialize(path, blueprint, options = {}) ⇒ Builder
constructor
A new instance of Builder.
-
#load_context ⇒ Object
Not using Lono::Template::Context because that works differently.
-
#template ⇒ Object
Useful for lono seed to get the template in memory.
- #write_output ⇒ Object
Methods included from Syntax
#aws_template_format_version, #condition, #description, #mapping, #metadata, #output, #parameter, #resource, #section, #transform
Methods included from Evaluate
#evaluate_template_path, #template_evaluation_error
Methods included from Helper
#current_region, #extract_scripts, #indent, #partial, #partial_exist?, #scripts_name, #scripts_s3_path, #template_params, #template_s3_path, #user_data
Methods included from Fn
#fn, #fn_id, #get_att, #get_azs, included, #join, #ref, #sub
Methods included from Util
#ensure_parent_dir, #handle_yaml_syntax_error, #validate_yaml
Constructor Details
#initialize(path, blueprint, options = {}) ⇒ Builder
Returns a new instance of Builder.
12 13 14 15 16 |
# File 'lib/lono/template/dsl/builder.rb', line 12 def initialize(path, blueprint, ={}) @path, @blueprint, @options = path, blueprint, @template = @path.sub("#{Lono.config.templates_path}/",'').sub(/\.rb$/,'') @cfn = {} end |
Instance Method Details
#build ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/lono/template/dsl/builder.rb', line 18 def build load_context evaluate_template_path(@path) # modifies @cfn build_template write_output template end |
#build_template ⇒ Object
34 35 36 |
# File 'lib/lono/template/dsl/builder.rb', line 34 def build_template @results = YAML.dump(camelize(@cfn)) end |
#camelize(data) ⇒ Object
54 55 56 |
# File 'lib/lono/template/dsl/builder.rb', line 54 def camelize(data) CfnCamelizer.transform(data) end |
#load_context ⇒ Object
Not using Lono::Template::Context because that works differently. That is used to load a context object that is passed to RenderMePretty’s context. So that we can load context for params files and erb templates.
In this case builder is actually the dsl context. We want to load variables and helpers into this builder context directly. This loads additional context. It looks very similar to Lono::Template::Context
65 66 67 68 |
# File 'lib/lono/template/dsl/builder.rb', line 65 def load_context load_variables load_project_helpers end |
#template ⇒ Object
Useful for lono seed to get the template in memory
27 28 29 30 31 |
# File 'lib/lono/template/dsl/builder.rb', line 27 def template load_context evaluate_template_path(@path) # modifies @cfn camelize(@cfn) end |
#write_output ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lono/template/dsl/builder.rb', line 38 def write_output output_path = "#{Lono.config.output_path}/#{@blueprint}/templates" FileUtils.mkdir_p(output_path) path = "#{output_path}/#{@template}.yml" ensure_parent_dir(path) IO.write(path, @results) validate_yaml(path) unless @options[:quiet] pretty_path = path.sub("#{Lono.root}/",'') puts " #{pretty_path}" end end |