Sha256: df263d1d2dcff3af9ac55ba7315fd8ab11ba8ec75017050b16ed7912834d08ad
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
require 'erb' require 'moblues/reader/type' module Moblues module Generator class Base def initialize(params) @output_dir = params.fetch(:output_dir) end protected attr_reader :output_dir def write_header(entity) write_file(header_file(entity), header(entity)) end def write_implementation(entity) write_file(implementation_file(entity), implementation(entity)) end def write_file(file, text) File.open(file, 'w+') do |f| f.write(text) end end def header_file(entity) File.join(output_dir, format_name(entity, 'h')) end def implementation_file(entity) File.join(output_dir, format_name(entity, 'm')) end def format_name(entity, extension) raise NotImplemented end def header(entity) render(header_template, entity) end def implementation(entity) render(implementation_template, entity) end def render(template, entity) ERB.new(template, 0, '-').result(entity.send(:binding)) end def header_template raise NotImplemented end def implementation_template raise NotImplemented end def file_template(name) File.read(File.expand_path("../#{name}.erb", __FILE__)) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
moblues-0.1.0 | lib/moblues/generator/base.rb |
moblues-0.0.1 | lib/moblues/generator/base.rb |