Skip to content

Commit

Permalink
Improved generator w/ template support
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterw authored and nielsenramon committed Nov 18, 2015
1 parent 359087c commit 372a410
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@
/tmp/
*.DS_Store
*.sass-cache
*.gem
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in kickster.gemspec
gemspec
3 changes: 2 additions & 1 deletion README.md
@@ -1,4 +1,5 @@
# kickster
Kickster
========

Jekyll starter template with GitHub Pages deploy to kickstart your project.

Expand Down
3 changes: 1 addition & 2 deletions bin/kickster
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../lib/kickster.rb'

require File.dirname(__FILE__) + "/../lib/kickster.rb"
Kickster::Generator.start
Binary file removed kickster-0.1.3.gem
Binary file not shown.
9 changes: 6 additions & 3 deletions kickster.gemspec
@@ -1,6 +1,9 @@
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "kickster/version"

Gem::Specification.new do |spec|
spec.name = "kickster"
spec.version = "0.1.3"
spec.version = Kickster::VERSION
spec.platform = Gem::Platform::RUBY
spec.author = "Nielsen Ramon"
spec.summary = "Hassle-free deploying to GitHub Pages with Jekyll."
Expand All @@ -10,10 +13,10 @@ Gem::Specification.new do |spec|
spec.license = "MIT"

spec.files = `git ls-files`.split("\n")
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_runtime_dependency("thor")
spec.add_runtime_dependency("thor", "~> 0")
spec.add_development_dependency "bundler", "~> 1.8"
spec.add_development_dependency "rake", "~> 10.0"
end
8 changes: 6 additions & 2 deletions lib/kickster.rb
@@ -1,2 +1,6 @@
require "kickster/generator"
require "kickster/version"
require_relative "kickster/version"
require_relative "kickster/install"
require_relative "kickster/generator"

module Kickster
end
56 changes: 5 additions & 51 deletions lib/kickster/generator.rb
@@ -1,62 +1,16 @@
require "fileutils"
require "erb"
require "kickster/version"
require "pathname"
require "thor"

module Kickster
class Generator < Thor
map ['-v', '--version'] => :version
include Thor::Actions

desc 'new', 'Create new folder with the Kickster template'
method_options :path => :string, :force => :boolean
def new(name)
if kickster_files_already_exist?(name) && !options[:force]
puts "Folder already exist, use --force to overwrite."
else
install_files(name)
puts "Kickster template folder successfully created!"
end
end
map ["-v", "--version"] => :version

desc 'version', 'Show Kickster version'
desc "version", "Show Kickster version"
def version
say "kickster-#{Kickster::VERSION}"
end

private

def kickster_files_already_exist?(name)
install_path(name).exist?
end

def install_path(name)
@install_path ||= if options[:path]
Pathname.new(File.join(options[:path], name))
erb = ERB.new(File.read("config.yml"))
site_name = name
puts erb.result(site_name)
else
Pathname.new(name)
end
end

def install_files(name)
FileUtils.mkdir_p(install_path(name))
FileUtils.cp_r(template_files, install_path(name))

end

def template_files
Dir["#{template_directory}/."]
say "Kickster #{Kickster::VERSION}"
end

def template_directory
File.join(top_level_directory, "template")
end

def top_level_directory
File.dirname(File.dirname(File.dirname(__FILE__)))
end
register(Kickster::Install, "new", "new", "Create new folder with the Kickster template")
end
end
41 changes: 41 additions & 0 deletions lib/kickster/install.rb
@@ -0,0 +1,41 @@
require "thor"

module Kickster
class Install < Thor::Group
include Thor::Actions

argument :name
class_options force: :boolean

def self.source_root
File.expand_path("../../../template", __FILE__)
end

def name_components
@_name_components ||= name.scan(/[[:alnum:]]+/)
end

def snake_name
@_snake_name = name_components.map(&:downcase).join("_")
end

def camel_name
@_camel_name = name_components.map(&:capitalize).join("")
end

def check_if_exists?
if File.directory?(snake_name) && !options[:force]
say "Folder already exist, use --force to overwrite.", :red
exit 1
end
end

def copy_templates
directory("./", "./#{snake_name}")
end

def report_success
say "Kickster template folder successfully created!", :green
end
end
end
2 changes: 1 addition & 1 deletion lib/kickster/version.rb
@@ -1,3 +1,3 @@
module Kickster
VERSION = "0.1.3"
VERSION = "0.1.4"
end
3 changes: 1 addition & 2 deletions template/README.md → template/README.md.tt
@@ -1,5 +1,4 @@
kickster
========
# <%= camel_name %>

Jekyll starter template with GitHub Pages deploy to kickstart your project.

Expand Down
Empty file modified template/_assets/javascripts/application.js 100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion template/_config.yml → template/_config.yml.tt
@@ -1,5 +1,5 @@
permalink: pretty
name: <%= site_name %>
name: <%= snake_name %>

exclude:
- .bowerrc
Expand Down
Empty file modified template/apple-touch-icon.png 100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion template/bower.json → template/bower.json.tt
@@ -1,5 +1,5 @@
{
"name": "kickster",
"name": "<%= snake_name %>",
"dependencies": {
"jquery": "~1.11.2"
}
Expand Down
Empty file modified template/favicon.ico 100755 → 100644
Empty file.

0 comments on commit 372a410

Please sign in to comment.