Sha256: 54f6b8f2961567687678560bb378fe40a6c3e92263c92cca9b2d7e330b5955ce

Contents?: true

Size: 981 Bytes

Versions: 1

Compression:

Stored size: 981 Bytes

Contents

module Lono
  class OutputTemplate
    def initialize(blueprint, template)
      @blueprint, @template = blueprint, template
    end

    def data
      template_path = "#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
      check_template_exists(template_path)
      YAML.load(IO.read(template_path))
    end

    # Check if the template exists and print friendly error message.  Exits if it
    # does not exist.
    def check_template_exists(template_path)
      unless File.exist?(template_path)
        puts "The template #{template_path} does not exist. Are you sure you use the right template name?  The template name does not require the extension.".color(:red)
        exit 1
      end
    end

    def required_parameters
      parameters.reject { |logical_id, p| p["Default"] }
    end

    def optional_parameters
      parameters.select { |logical_id, p| p["Default"] }
    end

    def parameters
      data["Parameters"] || []
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lono-5.3.0 lib/lono/output_template.rb