class Filegen::Rubygen

Generator for ruby code

Public Instance Methods

run(source, data) click to toggle source

Generate text

@param [String] source

The template used

@param [Hash] data

The data used within template evaluation

@return [String]

The evaluated template
# File lib/filegen/rubygen.rb, line 13
def run(source, data)
  result = StringIO.new
  source = StringIO.new(source)

  begin
    generator = ErbGenerator.new(Data.new([HashWithIndifferentAccess.new(data)]))
    generator.compile(source, result)
  rescue RuntimeError => e
    Filegen::Ui.error e.message
  rescue Exceptions::ErbTemplateHasSyntaxErrors => e
    Filegen::Ui.error "Syntax error in ERB-Template: \n" + e.message
  end

  result.string
end