Class: Lono::Template::Dsl::Builder

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Context::Loader, Syntax, Util
Defined in:
lib/lono/template/dsl/builder/output.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/syntax.rb,
lib/lono/template/dsl/builder/helpers.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,
lib/lono/template/dsl/builder/section_methods.rb

Overview

Organize core section method syntax here

Defined Under Namespace

Modules: Fn, Helpers, SectionMethods, Syntax Classes: Base, Condition, Mapping, Output, Parameter, Resource, Section

Constant Summary

Constants included from Fn

Fn::FUNCTIONS

Instance Method Summary collapse

Methods included from Helpers::ParamHelper

#conditional_parameter, #normalize_conditional_parameter_options, #optional_ref, #parameter

Methods included from Helpers::CoreHelper

#content, #dimensions, #file_s3_key, #render_file, #render_path, #s3_bucket, #setting, #tag_list, #tags, #user_data

Methods included from SectionMethods

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

define_methods, #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.



9
10
11
12
13
# File 'lib/lono/template/dsl/builder.rb', line 9

def initialize(path, blueprint, options={})
  @path, @blueprint, @options = path, blueprint, options
  @template = @path.sub("#{Lono.config.templates_path}/",'').sub(/\.rb$/,'')
  @cfn = {}
end

Instance Method Details

#buildObject



15
16
17
18
19
20
21
# File 'lib/lono/template/dsl/builder.rb', line 15

def build
  load_context
  evaluate_template_path(@path) # modifies @cfn
  build_template
  write_output
  template
end

#build_templateObject



31
32
33
# File 'lib/lono/template/dsl/builder.rb', line 31

def build_template
  @results = YAML.dump(@cfn)
end

#load_contextObject

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



58
59
60
61
# File 'lib/lono/template/dsl/builder.rb', line 58

def load_context
  load_variables
  load_project_helpers
end

#templateObject

Useful for lono seed to get the template in memory



24
25
26
27
28
# File 'lib/lono/template/dsl/builder.rb', line 24

def template
  load_context
  evaluate_template_path(@path) # modifies @cfn
  @cfn
end

#write_outputObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lono/template/dsl/builder.rb', line 35

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