-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.rb
71 lines (60 loc) · 1.69 KB
/
generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
module Skellington
class Generator
attr_reader :path,
:filename,
:originalname,
:camelname,
:files,
:gems,
:framework
attr_accessor :licensor
def initialize path, options = {}
@framework = options.fetch('framework', 'sinatra')
@full_path = path
@path = File.dirname @full_path
@filename = File.basename(@full_path)
@originalname = @filename
@camelname = Skellington.camelise(wormname)
@gems = config[@framework]['gems']
@files = config[@framework]['files'].merge Hash[config['common']['files'].map { |f| [f, nil] }]
end
def config
@config ||= YAML.load File.read File.join File.dirname(__FILE__), '..', '..', 'config/config.yaml'
end
def run
if File.exist? @full_path
$stderr.puts "Path '#{@full_path}' already exists. Quitting"
exit 1
end
generate
strap_boots
git_init
post_run
end
def generate
@files.each do |k, v|
t = Template.new k, self
t.write
end
end
def strap_boots
root = "#{self.path}/#{self.wormname}"
FileUtils.mkdir_p "#{root}/_sass"
FileUtils.cp_r "#{Bootstrap.assets_path}/stylesheets/bootstrap", "#{root}/_sass"
FileUtils.cp "#{Bootstrap.assets_path}/stylesheets/_bootstrap.scss", "#{root}/_sass/bootstrap.scss"
end
def wormname
@wormname ||= @filename.gsub('-', '_')
end
def renamed
@filename != wormname
end
def git_init
Git.init "#{@path}/#{wormname}"
end
def post_run
t = Template.new 'post-run', self
puts t.to_s
end
end
end