Class: Kryo::Generators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kryo/generators/base.rb

Overview

The base class for all generators to inherit from.

Author:

  • Matthew A. Johnston (warmwaffles)

Direct Known Subclasses

PostGenerator, SiteGenerator

Class Method Summary collapse

Class Method Details

.create(src, destination, options = {}, &block) ⇒ Boolean

Creates a file based off of the template provided.

Parameters:

  • src (String)

    the source of the template file

  • destination (String)

    the destination of where the generated file will go

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :name (String)

    The name of the template to be written as

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kryo/generators/base.rb', line 17

def self.create src, destination, options={}, &block

  paths = File.split(src)
  template_name = paths.last
  template_path = paths.first
  path = File.join(File.dirname(__FILE__), template_path, "#{template_name}.erb")

  yield if block

  erb    = ERB.new(File.read(path))
  output = File.join(destination, options[:name] || template_name)

  file = File.open(output, 'w+')
  file.write(erb.result(binding))
  file.close
  true
end