hisyo 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes +15 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +9 -0
- data/README.mkd +5 -1
- data/Rakefile +1 -0
- data/data/generators/assistance/sprockets/Gemfile.erubis +4 -0
- data/data/generators/assistance/sprockets/Rakefile.erubis +8 -0
- data/data/generators/assistance/sprockets/app/assets/javascripts/app.js +2 -0
- data/data/generators/assistance/sprockets/app/assets/javascripts/foo.js +1 -0
- data/data/generators/assistance/sprockets/app/sprockets.rb +47 -0
- data/data/generators/assistance/test/foo.txt +2 -0
- data/data/generators/assistance/test/test.txt.erubis +2 -0
- data/data/generators/assistance/travis/.travis.yml.erubis +10 -0
- data/data/generators/assistance/travis/Rakefile.erubis +7 -0
- data/data/generators/project/Gemfile +1 -0
- data/data/generators/project/Rakefile +5 -0
- data/data/generators/project/app/app.rb +13 -3
- data/data/generators/project/app/controllers.rb +11 -3
- data/lib/hisyo.rb +17 -3
- data/lib/hisyo/cli.rb +2 -14
- data/lib/hisyo/generator.rb +77 -22
- data/lib/hisyo/generator/sprockets.rb +13 -0
- data/lib/hisyo/generator/test.rb +10 -0
- data/lib/hisyo/generator/travis.rb +18 -0
- data/lib/hisyo/util.rb +84 -0
- data/lib/hisyo/version.rb +1 -1
- data/spec/cli_spec.rb +5 -6
- data/spec/generate_app_spec.rb +15 -0
- data/spec/generate_assistance_spec.rb +36 -0
- data/spec/generator_spec.rb +62 -15
- data/spec/spec_helper.rb +53 -4
- data/spec/support/assistance_context.rb +17 -0
- data/spec/support/rackup.rb +26 -0
- metadata +24 -4
- data/spec/generated_app_spec.rb +0 -49
data/Changes
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
= 0.2.0 / 2012-06-09
|
2
|
+
|
3
|
+
* Added: `-k sprockets` generator
|
4
|
+
|
5
|
+
* Changed: Rakefile will be generated by default
|
6
|
+
|
7
|
+
* Changed: Generated app is extend Sinatra::Base instead Sinatra::Application
|
8
|
+
|
9
|
+
* Changed: MyApp.controllers is deprecated,
|
10
|
+
use MyApp.namespace (Sinatra::Namespace at sinatra-contrib)
|
11
|
+
|
12
|
+
* Added: `-h` or `--help` will be display about assistance(e.g. travis, sprockets)
|
13
|
+
|
14
|
+
* Changed: if generated file path is exist, Hisyo try merging it
|
15
|
+
|
1
16
|
= 0.1.0 / 2012-05-30
|
2
17
|
|
3
18
|
* Generated app has no dependency on `hisyo`
|
data/Gemfile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
3
|
gem "sinatra", :require => "sinatra/base"
|
4
|
+
gem "erubis"
|
4
5
|
gem "tilt"
|
5
6
|
gem "sinatra-contrib", :require => "sinatra/contrib"
|
6
7
|
|
@@ -9,4 +10,7 @@ group :test do
|
|
9
10
|
gem "rack-test", :require => "rack/test"
|
10
11
|
gem "simplecov", :require => false
|
11
12
|
gem "rake" # for Travis CI
|
13
|
+
|
14
|
+
# for sprockets generator
|
15
|
+
gem "sprockets"
|
12
16
|
end
|
data/Gemfile.lock
CHANGED
@@ -3,7 +3,9 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
backports (2.5.3)
|
5
5
|
diff-lcs (1.1.3)
|
6
|
+
erubis (2.7.0)
|
6
7
|
eventmachine (0.12.10)
|
8
|
+
hike (1.2.1)
|
7
9
|
multi_json (1.3.5)
|
8
10
|
rack (1.4.1)
|
9
11
|
rack-protection (1.2.0)
|
@@ -34,16 +36,23 @@ GEM
|
|
34
36
|
rack-test
|
35
37
|
sinatra (~> 1.3.0)
|
36
38
|
tilt (~> 1.3)
|
39
|
+
sprockets (2.4.3)
|
40
|
+
hike (~> 1.2)
|
41
|
+
multi_json (~> 1.0)
|
42
|
+
rack (~> 1.0)
|
43
|
+
tilt (~> 1.1, != 1.3.0)
|
37
44
|
tilt (1.3.3)
|
38
45
|
|
39
46
|
PLATFORMS
|
40
47
|
ruby
|
41
48
|
|
42
49
|
DEPENDENCIES
|
50
|
+
erubis
|
43
51
|
rack-test
|
44
52
|
rake
|
45
53
|
rspec
|
46
54
|
simplecov
|
47
55
|
sinatra
|
48
56
|
sinatra-contrib
|
57
|
+
sprockets
|
49
58
|
tilt
|
data/README.mkd
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[![Travis CI Build Status](https://secure.travis-ci.org/uu59/hisyo.png?branch=master)](http://travis-ci.org/uu59/hisyo)
|
2
2
|
|
3
|
-
Hisyo is a generator that for your Sinatra project to play.
|
3
|
+
Hisyo is a generator that for your pure Sinatra project to play.
|
4
4
|
|
5
5
|
$ gem install hisyo
|
6
6
|
$ rbenv rehash; rehash; # if necessary
|
@@ -39,6 +39,10 @@ Hisyo is a generator that for your Sinatra project to play.
|
|
39
39
|
[2012-05-28 02:24:32] INFO WEBrick 1.3.1
|
40
40
|
[2012-05-28 02:24:32] INFO ruby 1.9.3 (2012-02-16) [x86_64-linux]
|
41
41
|
[2012-05-28 02:24:32] INFO WEBrick::HTTPServer#start: pid=11232 port=9292
|
42
|
+
^C
|
43
|
+
$ hisyo -r . -k travis
|
44
|
+
create: ./.travis.yml
|
45
|
+
create: ./Rakefile
|
42
46
|
|
43
47
|
Generated project(as below) is a purely Sinatra application.
|
44
48
|
That means you can `gem uninstall hisyo` after generation.
|
data/Rakefile
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
"hello sprockets";
|
@@ -0,0 +1,47 @@
|
|
1
|
+
MyApp.class_eval do
|
2
|
+
set :sprockets, Sprockets::Environment.new(root)
|
3
|
+
set :assets_prefix, '/assets'
|
4
|
+
set :assets_digest, true
|
5
|
+
|
6
|
+
configure do
|
7
|
+
sprockets.append_path File.join(root, 'app', 'assets', 'stylesheets')
|
8
|
+
sprockets.append_path File.join(root, 'app', 'assets', 'javascripts')
|
9
|
+
|
10
|
+
#sample config for compression
|
11
|
+
#sprockets.js_compressor = Uglifier.new
|
12
|
+
#sprockets.css_compressor = YUI::CssCompressor.new
|
13
|
+
end
|
14
|
+
|
15
|
+
helpers do
|
16
|
+
def javascript_path(path)
|
17
|
+
path << ".js" if File.extname(path).empty?
|
18
|
+
asset_path(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def stylesheet_path(path)
|
22
|
+
path << ".css" if File.extname(path).empty?
|
23
|
+
asset_path(path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def asset_path(path)
|
27
|
+
return path if path.match %r!^(?:https?:)//!
|
28
|
+
|
29
|
+
asset = settings.sprockets.find_asset(path)
|
30
|
+
raise "asset not found for '#{path}'" unless asset
|
31
|
+
basename = settings.assets_digest ? asset.digest_path : asset.logical_path
|
32
|
+
File.join(settings.assets_prefix, basename)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
get "#{settings.assets_prefix}/*" do
|
37
|
+
path = params[:splat].last.sub(%r!^/!, "")
|
38
|
+
if digest = path[/-[0-9a-f]+\./]
|
39
|
+
path.sub!(digest, ".")
|
40
|
+
expires 8640000, :public
|
41
|
+
end
|
42
|
+
asset = settings.sprockets.index.find_asset path
|
43
|
+
halt 404, "asset not found '#{path}'" unless asset
|
44
|
+
content_type File.extname(path)
|
45
|
+
asset
|
46
|
+
end
|
47
|
+
end
|
@@ -1,12 +1,22 @@
|
|
1
1
|
# Feel free to rename from "MyApp" to anything
|
2
2
|
# if so, remember changing config.ru, config/boot.rb
|
3
|
-
class MyApp < Sinatra::
|
3
|
+
class MyApp < Sinatra::Base
|
4
4
|
set :root, File.expand_path("../../", __FILE__)
|
5
5
|
set :views, File.join(root, "app/views")
|
6
6
|
set :public_folder, File.join(root, "public")
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
register Sinatra::RespondWith
|
9
|
+
register Sinatra::Namespace
|
10
|
+
|
11
|
+
helpers do
|
12
|
+
include Sinatra::Streaming
|
13
|
+
include Sinatra::ContentFor
|
14
|
+
include Sinatra::JSON
|
15
|
+
end
|
16
|
+
|
17
|
+
configure :development do
|
18
|
+
MyApp.reset!
|
19
|
+
use Rack::Reloader
|
10
20
|
end
|
11
21
|
|
12
22
|
def self.setup
|
@@ -1,11 +1,19 @@
|
|
1
|
-
MyApp.
|
2
|
-
get
|
1
|
+
MyApp.namespace "/" do
|
2
|
+
get do
|
3
3
|
# render "index.str" at app/views/index.str
|
4
4
|
render :str, :index
|
5
5
|
end
|
6
6
|
|
7
|
-
get "
|
7
|
+
get "hi/:name" do
|
8
8
|
# `hi` is helper at app/helpers.rb
|
9
9
|
hi(params[:name] || "joe")
|
10
10
|
end
|
11
|
+
|
12
|
+
# /admin/*
|
13
|
+
namespace "admin" do
|
14
|
+
before { halt 403, "Secret zone" }
|
15
|
+
get "/secret" do
|
16
|
+
"foobar"
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
data/lib/hisyo.rb
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require "fileutils"
|
2
|
+
require "optparse"
|
3
|
+
require "find"
|
4
4
|
|
5
5
|
module Hisyo
|
6
|
+
DIR = File.expand_path("../../data/generators", __FILE__)
|
7
|
+
HELP = []
|
8
|
+
|
9
|
+
def self.help(str)
|
10
|
+
HELP << str
|
11
|
+
end
|
12
|
+
|
13
|
+
dir = File.dirname(__FILE__)
|
14
|
+
$LOAD_PATH.unshift(dir) if $LOAD_PATH.grep(dir).empty?
|
6
15
|
end
|
16
|
+
|
17
|
+
require "hisyo/util"
|
18
|
+
require "hisyo/generator"
|
19
|
+
require "hisyo/cli"
|
20
|
+
require "hisyo/version"
|
data/lib/hisyo/cli.rb
CHANGED
@@ -1,20 +1,8 @@
|
|
1
|
-
require "optparse"
|
2
|
-
|
3
1
|
module Hisyo
|
4
2
|
module CLI
|
5
3
|
def self.run(argv)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def self.parse_options(argv)
|
10
|
-
options = {}
|
11
|
-
OptionParser.new do |opts|
|
12
|
-
opts.on('-n', '--dry-run', 'Do not actually run'){|v| options[:dryrun] = true}
|
13
|
-
opts.on('-v', '--verbose', 'Verbose mode'){|v| options[:verbose] = true}
|
14
|
-
opts.on('-r VAL', '--root=VAL', 'Application root directory'){|v| options[:root] = v}
|
15
|
-
opts.parse!(argv)
|
16
|
-
end
|
17
|
-
options
|
4
|
+
gen = Generator.new(argv)
|
5
|
+
gen.run
|
18
6
|
end
|
19
7
|
end
|
20
8
|
end
|
data/lib/hisyo/generator.rb
CHANGED
@@ -1,34 +1,89 @@
|
|
1
|
-
|
1
|
+
Dir.glob("#{File.dirname(__FILE__)}/generator/*.rb") do |file|
|
2
|
+
require file
|
3
|
+
end
|
2
4
|
|
3
5
|
module Hisyo
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
class Generator
|
7
|
+
include Hisyo::Util
|
8
|
+
|
9
|
+
attr_reader :params, :options
|
10
|
+
|
11
|
+
def initialize(argv = [])
|
12
|
+
@params = {}
|
13
|
+
@argv = argv
|
14
|
+
parse
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse
|
18
|
+
@options = begin
|
19
|
+
options = {
|
20
|
+
:dryrun => false,
|
21
|
+
:color => false,
|
22
|
+
:verbose => true,
|
23
|
+
:root => Dir.pwd,
|
24
|
+
}
|
25
|
+
OptionParser.new do |opts|
|
26
|
+
opts.on('-n', '--dryrun', 'Do not actually run'){|v| options[:dryrun] = true}
|
27
|
+
opts.on('-v', '--verbose', 'Verbose mode'){|v| options[:verbose] = true}
|
28
|
+
opts.on('-q', '--quite', 'Non-verbose mode'){|v| options[:verbose] = false}
|
29
|
+
opts.on('-c', '--color', 'Colorise'){|v| options[:color] = true}
|
30
|
+
opts.on('-r VAL', '--root=VAL', 'Application root directory'){|v| options[:root] = v}
|
31
|
+
|
32
|
+
opts.on('-k VAL', '--kind=VAL', 'What to generate'){|v| options[:kind] = v}
|
33
|
+
|
34
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
35
|
+
puts opts
|
36
|
+
puts
|
37
|
+
puts "Hisyo assistance help e.g. `hisyo -k foo bar=baz`"
|
38
|
+
puts HELP.join("\n")
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
begin
|
43
|
+
opts.parse!(@argv)
|
44
|
+
rescue OptionParser::InvalidOption => e
|
45
|
+
$stderr.puts e
|
46
|
+
$stderr.puts opts.help
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
options
|
51
|
+
end
|
52
|
+
|
53
|
+
@argv.each do |kv|
|
54
|
+
k,v = kv.split("=")
|
55
|
+
@params[k] = v
|
14
56
|
end
|
15
57
|
end
|
16
58
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
path = File.join(root, file.gsub(skelton, ""))
|
21
|
-
if File.file?(path)
|
22
|
-
puts "\e[31mskip: \e[0m#{path.gsub(root + "/", "")}/" if options[:verbose]
|
59
|
+
def run
|
60
|
+
if options[:kind]
|
61
|
+
gen_assistance
|
23
62
|
else
|
24
|
-
|
25
|
-
klass.cp(file, path)
|
63
|
+
gen_project
|
26
64
|
end
|
27
65
|
end
|
28
66
|
|
29
|
-
|
30
|
-
|
31
|
-
|
67
|
+
def gen_project
|
68
|
+
root = options[:root]
|
69
|
+
src_dir = File.expand_path("project", DIR)
|
70
|
+
copy(src_dir)
|
71
|
+
|
72
|
+
puts "Complete."
|
73
|
+
puts " $ cd #{root}/"
|
74
|
+
puts ' $ rackup (or `rspec spec/`, `vim app/helpers.rb`, etc)'
|
75
|
+
end
|
76
|
+
|
77
|
+
def generators
|
78
|
+
methods.grep(/^generate_/)
|
79
|
+
end
|
80
|
+
|
81
|
+
def gen_assistance
|
82
|
+
unless method = generators.find{|g| g.to_s == "generate_#{options[:kind]}"}
|
83
|
+
raise "unknown"
|
84
|
+
end
|
85
|
+
__send__(method)
|
86
|
+
end
|
32
87
|
end
|
33
88
|
end
|
34
89
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Hisyo
|
2
|
+
class Generator
|
3
|
+
def generate_travis
|
4
|
+
src = File.expand_path("assistance/travis", DIR)
|
5
|
+
root = options[:root]
|
6
|
+
@params = {
|
7
|
+
"email" => command("git config user.email") || "foo@example.com"
|
8
|
+
}.merge(@params)
|
9
|
+
copy(src)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
help <<-TEXT
|
14
|
+
-k travis: for Travis CI files
|
15
|
+
* email=foo@example.com
|
16
|
+
Notification email address (default is `git config user.email`)
|
17
|
+
TEXT
|
18
|
+
end
|
data/lib/hisyo/util.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module Hisyo
|
2
|
+
module Util
|
3
|
+
COLORS = {
|
4
|
+
:black => 30,
|
5
|
+
:red => 31,
|
6
|
+
:green => 32,
|
7
|
+
:yellow => 33,
|
8
|
+
:blue => 34,
|
9
|
+
:magenta => 35,
|
10
|
+
:cyan => 36,
|
11
|
+
:while => 37,
|
12
|
+
}
|
13
|
+
|
14
|
+
def copy(src)
|
15
|
+
Find.find(src) do |file|
|
16
|
+
next if file == src
|
17
|
+
is_dir = File.directory?(file)
|
18
|
+
dest = File.join(options[:root], file.gsub(src, ""))
|
19
|
+
dir = is_dir ? dest : File.dirname(dest)
|
20
|
+
if File.exists?(dest)
|
21
|
+
skip(dest)
|
22
|
+
next
|
23
|
+
end
|
24
|
+
FileUtils.mkdir_p(dir) unless options[:dryrun]
|
25
|
+
next if is_dir
|
26
|
+
|
27
|
+
if file.match(/\.erubis$/)
|
28
|
+
dest.gsub!(/\.erubis$/, "")
|
29
|
+
template = Tilt.new(file)
|
30
|
+
content = template.render(Object.new, @params) do
|
31
|
+
File.exist?(dest) ? File.read(dest) : ""
|
32
|
+
end
|
33
|
+
if File.exist?(dest) && File.file?(dest)
|
34
|
+
tmp = template.render(Object.new, @params) { "" }.strip
|
35
|
+
if File.read(dest)[tmp]
|
36
|
+
skip(dest)
|
37
|
+
next
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else
|
41
|
+
content = File.read(file)
|
42
|
+
if File.exist?(dest) && File.read(dest)[content]
|
43
|
+
skip(dest)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
if File.exist?(dest)
|
48
|
+
merge(dest)
|
49
|
+
else
|
50
|
+
create(dest)
|
51
|
+
end
|
52
|
+
|
53
|
+
unless options[:dryrun]
|
54
|
+
File.open(dest, "w"){|f| f.write content}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def command(cmd)
|
60
|
+
begin
|
61
|
+
ret = %x!#{cmd}!
|
62
|
+
return ret if $?.exitstatus == 0
|
63
|
+
rescue Errno::ENOENT
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def color(text, color = :green)
|
69
|
+
options[:color] ? "\e[1m\e[#{COLORS[color] || "33"}m#{text}\e[0m" : text
|
70
|
+
end
|
71
|
+
|
72
|
+
def create(dest)
|
73
|
+
puts color("create: ", :green) + dest if @options[:verbose]
|
74
|
+
end
|
75
|
+
|
76
|
+
def skip(dest)
|
77
|
+
puts color("skip: ", :yellow) + dest if @options[:verbose]
|
78
|
+
end
|
79
|
+
|
80
|
+
def merge(dest)
|
81
|
+
puts color("merge: ", :magenta) + dest if @options[:verbose]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/hisyo/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Hisyo
|
4
|
-
it "should
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
options[:root].should == "/tmp"
|
3
|
+
describe "Hisyo::CLI options" do
|
4
|
+
it "should run Generator.new.run" do
|
5
|
+
capture_io do
|
6
|
+
lambda { Hisyo::CLI.run(%w!--help!) }.should raise_error(SystemExit)
|
7
|
+
end
|
9
8
|
end
|
10
9
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Hisyo::Generator assistance" do
|
4
|
+
context "travis" do
|
5
|
+
let(:kind) { "travis" }
|
6
|
+
include_context "assistance"
|
7
|
+
|
8
|
+
it "should create .travis.yml " do
|
9
|
+
File.exists?("#{@approot}/.travis.yml").should be_true
|
10
|
+
yml = YAML.load File.read("#{@approot}/.travis.yml")
|
11
|
+
yml["notifications"]["email"].should_not be_empty
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "sprockets" do
|
16
|
+
let(:kind) { "sprockets" }
|
17
|
+
include_context "assistance"
|
18
|
+
|
19
|
+
it "should get under the /assets" do
|
20
|
+
genapp do
|
21
|
+
get "/assets/app.js"
|
22
|
+
last_response.body.should =~ /sprockets/
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should compile by Rake" do
|
27
|
+
approot = @approot
|
28
|
+
capture_io do
|
29
|
+
rake do
|
30
|
+
tasks.find{|t| t.name == "assets"}.execute
|
31
|
+
end
|
32
|
+
end
|
33
|
+
Dir.entries("#{approot}/public/assets").should_not be_empty
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/generator_spec.rb
CHANGED
@@ -1,41 +1,88 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Hisyo
|
3
|
+
describe "Hisyo::Generator basic" do
|
4
4
|
after(:each) do
|
5
5
|
FileUtils.rm_rf @approot
|
6
6
|
end
|
7
7
|
|
8
|
-
it "should
|
9
|
-
|
8
|
+
it "should parse options" do
|
9
|
+
gen = Hisyo::Generator.new(%w!-k travis -n -v --root=/tmp!)
|
10
|
+
options = gen.options
|
11
|
+
options[:dryrun].should be_true
|
12
|
+
options[:verbose].should be_true
|
13
|
+
options[:color].should be_false
|
14
|
+
options[:root].should == "/tmp"
|
15
|
+
options[:kind].should == "travis"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse params" do
|
19
|
+
gen = Hisyo::Generator.new(%w!-k travis -n -v --root=/tmp foo=bar!)
|
20
|
+
gen.params["foo"].should == "bar"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should exit invalid option given" do
|
24
|
+
out, err = capture_io do
|
25
|
+
lambda { Hisyo::Generator.new(%w!--invalid-option!) }.should raise_error(SystemExit)
|
26
|
+
end
|
27
|
+
err["Usage"].should_not be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should run command" do
|
31
|
+
gen = Hisyo::Generator.new
|
32
|
+
gen.command("/bin/true").should == ""
|
33
|
+
gen.command("does_not_exists_command").should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should same data/project/ and approot/" do
|
37
|
+
# https://github.com/rubinius/rubinius/blob/17aa445116/lib/find.rb#L39
|
38
|
+
pending "Rubinius's Find.find raise LocalJumpError if no block given" if defined?(Rubinius)
|
39
|
+
generate(
|
10
40
|
:root => @approot,
|
11
41
|
)
|
12
|
-
dest=
|
42
|
+
dest = Find.find(@approot).map{|f| f.gsub(@approot, "")}.sort
|
13
43
|
src_dir = "#{@root}/data/generators/project"
|
14
|
-
src =
|
44
|
+
src = Find.find(src_dir).map{|f| f.gsub(src_dir, "")}.sort
|
15
45
|
dest.should == src
|
16
46
|
end
|
17
47
|
|
18
48
|
it "should not create files when :dryrun option given" do
|
19
|
-
|
49
|
+
# https://github.com/rubinius/rubinius/blob/17aa445116/lib/find.rb#L39
|
50
|
+
pending "Rubinius's Find.find raise LocalJumpError if no block given" if defined?(Rubinius)
|
51
|
+
generate(
|
20
52
|
:root => @approot,
|
21
53
|
:dryrun => true,
|
22
54
|
)
|
23
|
-
|
55
|
+
lambda { Find.find(@approot).to_a }.should raise_error(Errno::ENOENT)
|
24
56
|
end
|
25
57
|
|
26
58
|
it "should skip if file exists" do
|
27
|
-
|
59
|
+
generate(
|
28
60
|
:root => @approot,
|
29
|
-
:verbose => true,
|
30
61
|
)
|
31
62
|
|
32
|
-
out, err =
|
63
|
+
out, err = generate(
|
33
64
|
:root => @approot,
|
34
|
-
:
|
65
|
+
:color => false,
|
35
66
|
)
|
36
|
-
messages = out.split("\n").
|
37
|
-
messages.
|
38
|
-
messages.
|
39
|
-
|
67
|
+
messages = out.split("\n").grep(/^[a-z]+:/i)
|
68
|
+
messages.grep(/^create/).should be_empty
|
69
|
+
messages.grep(/^skip/).length.should == messages.length
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should merge exists content" do
|
73
|
+
generate(:root => @approot)
|
74
|
+
File.open("#{@approot}/test.txt", "w"){|f| f.write "original"}
|
75
|
+
generate(:root => @approot, :kind => "test")
|
76
|
+
File.read("#{@approot}/test.txt").rstrip.should == "original\ntemplate"
|
77
|
+
File.read("#{@approot}/foo.txt").rstrip.should == "foo"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should dedup merge" do
|
81
|
+
generate(:root => @approot)
|
82
|
+
generate(:root => @approot, :kind => "test")
|
83
|
+
File.read("#{@approot}/foo.txt").rstrip.should == "foo"
|
84
|
+
|
85
|
+
generate(:root => @approot, :kind => "test")
|
86
|
+
File.read("#{@approot}/foo.txt").rstrip.should == "foo"
|
40
87
|
end
|
41
88
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,10 +3,10 @@ require "bundler/setup"
|
|
3
3
|
Bundler.require(:default, :test)
|
4
4
|
if ENV["COVERAGE"]
|
5
5
|
require "simplecov"
|
6
|
-
SimpleCov.start
|
6
|
+
SimpleCov.start "test_frameworks"
|
7
7
|
end
|
8
8
|
require File.expand_path("../../lib/hisyo.rb", __FILE__)
|
9
|
-
|
9
|
+
Dir["./spec/support/**/*.rb"].each{|f| require f}
|
10
10
|
|
11
11
|
RSpec.configure do |conf|
|
12
12
|
conf.before(:all) do
|
@@ -38,10 +38,59 @@ RSpec.configure do |conf|
|
|
38
38
|
$stderr = orig_stderr
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def generate(options = {}, params = {})
|
42
42
|
capture_io do
|
43
|
-
Hisyo.
|
43
|
+
gen = Hisyo::Generator.new
|
44
|
+
gen.instance_variable_set(:@options, options)
|
45
|
+
gen.instance_variable_set(:@params, params)
|
46
|
+
gen.run
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def genapp(&block)
|
51
|
+
pending "jruby does not support fork" if defined? JRUBY_VERSION
|
52
|
+
generate(
|
53
|
+
:root => @approot,
|
54
|
+
)
|
55
|
+
pid = fork do
|
56
|
+
@mock = Class.new
|
57
|
+
configru = "#{@approot}/config.ru"
|
58
|
+
bootrb = "#{@approot}/config/boot.rb"
|
59
|
+
@mock.class_eval do
|
60
|
+
require bootrb
|
61
|
+
|
62
|
+
include Rack::Test::Methods
|
63
|
+
@configru = configru
|
64
|
+
|
65
|
+
def self.configru
|
66
|
+
@configru
|
67
|
+
end
|
68
|
+
|
69
|
+
def app
|
70
|
+
Rack::Builder.parse_file(self.class.configru).first
|
71
|
+
end
|
72
|
+
end
|
73
|
+
@mock.new.instance_eval &block
|
74
|
+
end
|
75
|
+
Process.wait pid
|
76
|
+
end
|
77
|
+
|
78
|
+
def rake(rakefile = nil, &block)
|
79
|
+
pending "jruby does not support fork" if defined? JRUBY_VERSION
|
80
|
+
rakefile ||= File.join(@approot, "Rakefile")
|
81
|
+
pid = fork do
|
82
|
+
Dir.chdir(File.dirname(rakefile))
|
83
|
+
app = Rake::Application.new
|
84
|
+
Rake.application = app
|
85
|
+
app.instance_eval do
|
86
|
+
@rakefiles.clear
|
87
|
+
@rakefiles << rakefile
|
88
|
+
init
|
89
|
+
load_rakefile
|
90
|
+
self.instance_eval &block
|
91
|
+
end
|
44
92
|
end
|
93
|
+
Process.waitpid pid
|
45
94
|
end
|
46
95
|
|
47
96
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples_for "rackapp" do
|
4
|
+
after(:each) do
|
5
|
+
FileUtils.rm_rf @approot
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should rackup" do
|
9
|
+
genapp do
|
10
|
+
get "/"
|
11
|
+
last_response.body.rstrip.should == "Hello, MyApp!"
|
12
|
+
|
13
|
+
get "/hi/uu59"
|
14
|
+
last_response.body.should == "Hi, uu59!"
|
15
|
+
|
16
|
+
get "/admin/secret"
|
17
|
+
last_response.status.should == 403
|
18
|
+
last_response.body.should == "Secret zone"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should rake run" do
|
23
|
+
pending "jruby does not support fork" if defined? JRUBY_VERSION
|
24
|
+
lambda { rake{} }.should_not raise_error
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hisyo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Create simple Sinatra project template
|
15
15
|
email:
|
@@ -28,8 +28,18 @@ files:
|
|
28
28
|
- README.mkd
|
29
29
|
- Rakefile
|
30
30
|
- bin/hisyo
|
31
|
+
- data/generators/assistance/sprockets/Gemfile.erubis
|
32
|
+
- data/generators/assistance/sprockets/Rakefile.erubis
|
33
|
+
- data/generators/assistance/sprockets/app/assets/javascripts/app.js
|
34
|
+
- data/generators/assistance/sprockets/app/assets/javascripts/foo.js
|
35
|
+
- data/generators/assistance/sprockets/app/sprockets.rb
|
36
|
+
- data/generators/assistance/test/foo.txt
|
37
|
+
- data/generators/assistance/test/test.txt.erubis
|
38
|
+
- data/generators/assistance/travis/.travis.yml.erubis
|
39
|
+
- data/generators/assistance/travis/Rakefile.erubis
|
31
40
|
- data/generators/project/.gitignore
|
32
41
|
- data/generators/project/Gemfile
|
42
|
+
- data/generators/project/Rakefile
|
33
43
|
- data/generators/project/app/app.rb
|
34
44
|
- data/generators/project/app/controllers.rb
|
35
45
|
- data/generators/project/app/helpers.rb
|
@@ -42,11 +52,18 @@ files:
|
|
42
52
|
- lib/hisyo.rb
|
43
53
|
- lib/hisyo/cli.rb
|
44
54
|
- lib/hisyo/generator.rb
|
55
|
+
- lib/hisyo/generator/sprockets.rb
|
56
|
+
- lib/hisyo/generator/test.rb
|
57
|
+
- lib/hisyo/generator/travis.rb
|
58
|
+
- lib/hisyo/util.rb
|
45
59
|
- lib/hisyo/version.rb
|
46
60
|
- spec/cli_spec.rb
|
47
|
-
- spec/
|
61
|
+
- spec/generate_app_spec.rb
|
62
|
+
- spec/generate_assistance_spec.rb
|
48
63
|
- spec/generator_spec.rb
|
49
64
|
- spec/spec_helper.rb
|
65
|
+
- spec/support/assistance_context.rb
|
66
|
+
- spec/support/rackup.rb
|
50
67
|
homepage: https://github.com/uu59/hisyo
|
51
68
|
licenses: []
|
52
69
|
post_install_message:
|
@@ -73,6 +90,9 @@ specification_version: 3
|
|
73
90
|
summary: Create simple Sinatra project template
|
74
91
|
test_files:
|
75
92
|
- spec/cli_spec.rb
|
76
|
-
- spec/
|
93
|
+
- spec/generate_app_spec.rb
|
94
|
+
- spec/generate_assistance_spec.rb
|
77
95
|
- spec/generator_spec.rb
|
78
96
|
- spec/spec_helper.rb
|
97
|
+
- spec/support/assistance_context.rb
|
98
|
+
- spec/support/rackup.rb
|
data/spec/generated_app_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Hisyo generated app" do
|
4
|
-
def genapp(&block)
|
5
|
-
pending "jruby does not support fork" if defined? JRUBY_VERSION
|
6
|
-
pid = fork do
|
7
|
-
generate_app(
|
8
|
-
:root => @approot,
|
9
|
-
)
|
10
|
-
@mock = Class.new
|
11
|
-
configru = "#{@approot}/config.ru"
|
12
|
-
bootrb = "#{@approot}/config/boot.rb"
|
13
|
-
@mock.class_eval do
|
14
|
-
require bootrb
|
15
|
-
|
16
|
-
include Rack::Test::Methods
|
17
|
-
@configru = configru
|
18
|
-
|
19
|
-
def self.configru
|
20
|
-
@configru
|
21
|
-
end
|
22
|
-
|
23
|
-
def app
|
24
|
-
Rack::Builder.parse_file(self.class.configru).first
|
25
|
-
end
|
26
|
-
end
|
27
|
-
@mock.new.instance_eval &block
|
28
|
-
end
|
29
|
-
Process.wait pid
|
30
|
-
end
|
31
|
-
|
32
|
-
after(:each) do
|
33
|
-
FileUtils.rm_rf @approot
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should rackup" do
|
37
|
-
genapp do
|
38
|
-
get "/"
|
39
|
-
last_response.body.rstrip.should == "Hello, MyApp!"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it "controllers" do
|
44
|
-
genapp do
|
45
|
-
get "/hi/uu59"
|
46
|
-
last_response.body.should == "Hi, uu59!"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|