Class: Skellington::Generator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Generator

Returns a new instance of Generator.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/skellington/generator.rb', line 13

def initialize path, options = {}
  @framework = options.fetch('framework', 'sinatra')
  @bootstrap = options.fetch('bootstrap', 3).to_s
  @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']
end

Instance Attribute Details

#bootstrapObject (readonly)

Returns the value of attribute bootstrap.



3
4
5
# File 'lib/skellington/generator.rb', line 3

def bootstrap
  @bootstrap
end

#camelnameObject (readonly)

Returns the value of attribute camelname.



3
4
5
# File 'lib/skellington/generator.rb', line 3

def camelname
  @camelname
end

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/skellington/generator.rb', line 3

def filename
  @filename
end

#filesObject (readonly)

Returns the value of attribute files.



3
4
5
# File 'lib/skellington/generator.rb', line 3

def files
  @files
end

#frameworkObject (readonly)

Returns the value of attribute framework.



3
4
5
# File 'lib/skellington/generator.rb', line 3

def framework
  @framework
end

#gemsObject (readonly)

Returns the value of attribute gems.



3
4
5
# File 'lib/skellington/generator.rb', line 3

def gems
  @gems
end

#licensorObject

Returns the value of attribute licensor.



11
12
13
# File 'lib/skellington/generator.rb', line 11

def licensor
  @licensor
end

#originalnameObject (readonly)

Returns the value of attribute originalname.



3
4
5
# File 'lib/skellington/generator.rb', line 3

def originalname
  @originalname
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/skellington/generator.rb', line 3

def path
  @path
end

Instance Method Details

#configObject



25
26
27
# File 'lib/skellington/generator.rb', line 25

def config
  @config ||= YAML.load File.read File.join File.dirname(__FILE__), '..', '..', 'config/config.yaml'
end

#generateObject



41
42
43
44
45
46
# File 'lib/skellington/generator.rb', line 41

def generate
  @files.each do |k, v|
    t = Template.new k, self
    t.write
  end
end

#git_initObject



71
72
73
# File 'lib/skellington/generator.rb', line 71

def git_init
  Git.init wormname
end

#post_runObject



75
76
77
78
# File 'lib/skellington/generator.rb', line 75

def post_run
  t = Template.new 'post-run', self
  puts t.to_s
end

#renamedObject



67
68
69
# File 'lib/skellington/generator.rb', line 67

def renamed
  @filename != wormname
end

#runObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/skellington/generator.rb', line 29

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

#strap_bootsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/skellington/generator.rb', line 48

def strap_boots
  if @framework == 'jekyll'
    if @bootstrap == '4'
      Object.send(:remove_const, :Bootstrap)
      require 'bootstrap'
    end

    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
end

#wormnameObject



63
64
65
# File 'lib/skellington/generator.rb', line 63

def wormname
  @wormname ||= @filename.gsub('-', '_')
end