Sha256: 9d5412d6dd8d4668e5dec52abf1f387df74d609120fab6154f44fc9c84dae40f

Contents?: true

Size: 1.68 KB

Versions: 13

Compression:

Stored size: 1.68 KB

Contents

class Lono::Template::Dsl
  class Builder
    include Lono::Template::Util
    include Lono::Template::Context::Loader

    include Syntax
    extend Memoist

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

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

    # Useful for lono seed to get the template in memory
    def template
      load_context
      evaluate_template_path(@path) # modifies @cfn
      @cfn
    end
    memoize :template

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

    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

    # 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
    def load_context
      load_variables
      load_project_helpers
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lono-6.1.11 lib/lono/template/dsl/builder.rb
lono-6.1.10 lib/lono/template/dsl/builder.rb
lono-6.1.9 lib/lono/template/dsl/builder.rb
lono-6.1.8 lib/lono/template/dsl/builder.rb
lono-6.1.7 lib/lono/template/dsl/builder.rb
lono-6.1.6 lib/lono/template/dsl/builder.rb
lono-6.1.5 lib/lono/template/dsl/builder.rb
lono-6.1.4 lib/lono/template/dsl/builder.rb
lono-6.1.3 lib/lono/template/dsl/builder.rb
lono-6.1.2 lib/lono/template/dsl/builder.rb
lono-6.1.1 lib/lono/template/dsl/builder.rb
lono-6.1.0 lib/lono/template/dsl/builder.rb
lono-6.0.1 lib/lono/template/dsl/builder.rb