Class: Skellington::Generator
- Inherits:
-
Object
- Object
- Skellington::Generator
- Defined in:
- lib/skellington/generator.rb
Instance Attribute Summary collapse
-
#bootstrap ⇒ Object
readonly
Returns the value of attribute bootstrap.
-
#camelname ⇒ Object
readonly
Returns the value of attribute camelname.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#framework ⇒ Object
readonly
Returns the value of attribute framework.
-
#gems ⇒ Object
readonly
Returns the value of attribute gems.
-
#licensor ⇒ Object
Returns the value of attribute licensor.
-
#originalname ⇒ Object
readonly
Returns the value of attribute originalname.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #config ⇒ Object
- #generate ⇒ Object
- #git_init ⇒ Object
-
#initialize(path, options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #post_run ⇒ Object
- #renamed ⇒ Object
- #run ⇒ Object
- #strap_boots ⇒ Object
- #wormname ⇒ Object
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, = {} @framework = .fetch('framework', 'sinatra') @bootstrap = .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
#bootstrap ⇒ Object (readonly)
Returns the value of attribute bootstrap.
3 4 5 |
# File 'lib/skellington/generator.rb', line 3 def bootstrap @bootstrap end |
#camelname ⇒ Object (readonly)
Returns the value of attribute camelname.
3 4 5 |
# File 'lib/skellington/generator.rb', line 3 def camelname @camelname end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/skellington/generator.rb', line 3 def filename @filename end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
3 4 5 |
# File 'lib/skellington/generator.rb', line 3 def files @files end |
#framework ⇒ Object (readonly)
Returns the value of attribute framework.
3 4 5 |
# File 'lib/skellington/generator.rb', line 3 def framework @framework end |
#gems ⇒ Object (readonly)
Returns the value of attribute gems.
3 4 5 |
# File 'lib/skellington/generator.rb', line 3 def gems @gems end |
#licensor ⇒ Object
Returns the value of attribute licensor.
11 12 13 |
# File 'lib/skellington/generator.rb', line 11 def licensor @licensor end |
#originalname ⇒ Object (readonly)
Returns the value of attribute originalname.
3 4 5 |
# File 'lib/skellington/generator.rb', line 3 def originalname @originalname end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/skellington/generator.rb', line 3 def path @path end |
Instance Method Details
#config ⇒ Object
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 |
#generate ⇒ Object
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_init ⇒ Object
71 72 73 |
# File 'lib/skellington/generator.rb', line 71 def git_init Git.init wormname end |
#post_run ⇒ Object
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 |
#renamed ⇒ Object
67 68 69 |
# File 'lib/skellington/generator.rb', line 67 def renamed @filename != wormname end |
#run ⇒ Object
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_boots ⇒ Object
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 |
#wormname ⇒ Object
63 64 65 |
# File 'lib/skellington/generator.rb', line 63 def wormname @wormname ||= @filename.gsub('-', '_') end |