Class: EZCoffee::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/generate.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Generator

Returns a new instance of Generator.


10
11
12
# File 'lib/generate.rb', line 10

def initialize(project)
  @project = project
end

Class Method Details

.generate(project) ⇒ Object


6
7
8
# File 'lib/generate.rb', line 6

def self.generate(project)
  new(project).generate
end

Instance Method Details

#generateObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generate.rb', line 14

def generate
  project_coffee = "./#{@project}/src/#{@project}.coffee"
  project_index  = "./#{@project}/index.html"

  abort "#{@project} already exists" if File.exists?(@project)

  # Make the directories
  FileUtils.mkdir @project
  FileUtils.mkdir_p "./#{@project}/src"
  FileUtils.mkdir_p "./#{@project}/js"

  # Generate the files
  File.open(project_index, 'w+')  { |f| f.puts html }
  File.open(project_coffee, 'w+') { |f| f.puts "# Generated by ezcoffee" }
end

#htmlObject


30
31
32
33
# File 'lib/generate.rb', line 30

def html
  template = File.read("#{File.dirname(__FILE__)}/index.erb")
  ERB.new(template).result(binding)
end