class Skellington::Generator

Attributes

bootstrap[R]
camelname[R]
filename[R]
files[R]
framework[R]
gems[R]
licensor[RW]
originalname[R]
path[R]

Public Class Methods

new(path, options = {}) click to toggle source
# 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'].merge Hash[config['common']['files'].map { |f| [f, nil] }]
end

Public Instance Methods

config() click to toggle source
# File lib/skellington/generator.rb, line 25
def config
  @config ||= YAML.load File.read File.join File.dirname(__FILE__), '..', '..', 'config/config.yaml'
end
generate() click to toggle source
# 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() click to toggle source
# File lib/skellington/generator.rb, line 71
def git_init
  Git.init "#{@path}/#{wormname}"
end
post_run() click to toggle source
# File lib/skellington/generator.rb, line 75
def post_run
  t = Template.new 'post-run', self
  puts t.to_s
end
renamed() click to toggle source
# File lib/skellington/generator.rb, line 67
def renamed
  @filename != wormname
end
run() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/skellington/generator.rb, line 63
def wormname
  @wormname ||= @filename.gsub('-', '_')
end