hisyo 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +22 -0
- data/README.mkd +51 -0
- data/bin/hisyo +8 -0
- data/data/generators/project/.gitignore +2 -0
- data/data/generators/project/Gemfile +10 -0
- data/data/generators/project/app/app.rb +5 -0
- data/data/generators/project/app/helpers.rb +6 -0
- data/data/generators/project/config.ru +9 -0
- data/data/generators/project/config/boot.rb +7 -0
- data/data/generators/project/spec/hello_spec.rb +7 -0
- data/data/generators/project/spec/spec_helper.rb +15 -0
- data/hisyo.gemspec +17 -0
- data/lib/hisyo.rb +6 -0
- data/lib/hisyo/application.rb +24 -0
- data/lib/hisyo/cli.rb +20 -0
- data/lib/hisyo/generator.rb +30 -0
- data/lib/hisyo/version.rb +3 -0
- data/spec/cli_spec.rb +10 -0
- data/spec/generated_app_spec.rb +29 -0
- data/spec/generator_spec.rb +43 -0
- data/spec/spec_helper.rb +38 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
backports (2.5.3)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
eventmachine (0.12.10)
|
7
|
+
multi_json (1.3.5)
|
8
|
+
rack (1.4.1)
|
9
|
+
rack-protection (1.2.0)
|
10
|
+
rack
|
11
|
+
rack-test (0.6.1)
|
12
|
+
rack (>= 1.0)
|
13
|
+
rspec (2.10.0)
|
14
|
+
rspec-core (~> 2.10.0)
|
15
|
+
rspec-expectations (~> 2.10.0)
|
16
|
+
rspec-mocks (~> 2.10.0)
|
17
|
+
rspec-core (2.10.1)
|
18
|
+
rspec-expectations (2.10.0)
|
19
|
+
diff-lcs (~> 1.1.3)
|
20
|
+
rspec-mocks (2.10.1)
|
21
|
+
simplecov (0.6.4)
|
22
|
+
multi_json (~> 1.0)
|
23
|
+
simplecov-html (~> 0.5.3)
|
24
|
+
simplecov-html (0.5.3)
|
25
|
+
sinatra (1.3.2)
|
26
|
+
rack (~> 1.3, >= 1.3.6)
|
27
|
+
rack-protection (~> 1.2)
|
28
|
+
tilt (~> 1.3, >= 1.3.3)
|
29
|
+
sinatra-contrib (1.3.1)
|
30
|
+
backports (>= 2.0)
|
31
|
+
eventmachine
|
32
|
+
rack-protection
|
33
|
+
rack-test
|
34
|
+
sinatra (~> 1.3.0)
|
35
|
+
tilt (~> 1.3)
|
36
|
+
tilt (1.3.3)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
rack-test
|
43
|
+
rspec
|
44
|
+
simplecov
|
45
|
+
sinatra
|
46
|
+
sinatra-contrib
|
47
|
+
tilt
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 uu59
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.mkd
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
Hisyo is a thin wrapper for your Sinatra project
|
2
|
+
|
3
|
+
$ gem install hisyo
|
4
|
+
$ rbenv rehash; rehash; # if necessary
|
5
|
+
$ hisyo -v -r ~/myapp
|
6
|
+
create: lib/
|
7
|
+
create: config/
|
8
|
+
create: views/
|
9
|
+
create: public/
|
10
|
+
create: spec/
|
11
|
+
create: app/views/
|
12
|
+
create: app/assets/
|
13
|
+
create: db/
|
14
|
+
create: tmp/
|
15
|
+
create: log/
|
16
|
+
copy to: spec/spec_helper.rb
|
17
|
+
copy to: spec/hello_spec.rb
|
18
|
+
copy to: config.ru
|
19
|
+
copy to: config/boot.rb
|
20
|
+
copy to: Gemfile
|
21
|
+
copy to: app/helpers.rb
|
22
|
+
copy to: app/app.rb
|
23
|
+
$ cd ~/myapp
|
24
|
+
$ tree -F
|
25
|
+
.
|
26
|
+
├── Gemfile
|
27
|
+
├── app/
|
28
|
+
│ ├── app.rb
|
29
|
+
│ ├── assets/
|
30
|
+
│ ├── helpers.rb
|
31
|
+
│ └── views/
|
32
|
+
├── config/
|
33
|
+
│ └── boot.rb
|
34
|
+
├── config.ru
|
35
|
+
├── db/
|
36
|
+
├── lib/
|
37
|
+
├── log/
|
38
|
+
├── public/
|
39
|
+
├── spec/
|
40
|
+
│ ├── hello_spec.rb
|
41
|
+
│ └── spec_helper.rb
|
42
|
+
├── tmp/
|
43
|
+
└── views/
|
44
|
+
|
45
|
+
11 directories, 7 files
|
46
|
+
$ rackup
|
47
|
+
[2012-05-28 02:24:32] INFO WEBrick 1.3.1
|
48
|
+
[2012-05-28 02:24:32] INFO ruby 1.9.3 (2012-02-16) [x86_64-linux]
|
49
|
+
[2012-05-28 02:24:32] INFO WEBrick::HTTPServer#start: pid=11232 port=9292
|
50
|
+
|
51
|
+
|
data/bin/hisyo
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
ENV["RACK_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
|
3
|
+
|
4
|
+
RSpec.configure do |conf|
|
5
|
+
#conf.mock_with :rr
|
6
|
+
#conf.include Rack::Test::Methods
|
7
|
+
#conf.include Capybara::DSL
|
8
|
+
end
|
9
|
+
|
10
|
+
def app
|
11
|
+
##
|
12
|
+
# You can handle all padrino applications using instead:
|
13
|
+
# Padrino.application
|
14
|
+
Dara.tap { |app| p app }
|
15
|
+
end
|
data/hisyo.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/hisyo/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["uu59"]
|
6
|
+
gem.email = ["k@uu59.org"]
|
7
|
+
gem.description = %q{Create simple Sinatra project template}
|
8
|
+
gem.summary = %q{Create simple Sinatra project template}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "hisyo"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Hisyo::VERSION
|
17
|
+
end
|
data/lib/hisyo.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Hisyo
|
2
|
+
class Application < Sinatra::Base
|
3
|
+
end
|
4
|
+
|
5
|
+
def self.env
|
6
|
+
@env ||= ENV["RACK_ENV"] ||= "development"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.setup
|
10
|
+
bootrb = caller.first.split(/:[0-9]+:/).first
|
11
|
+
approot = bootrb.gsub("/config/boot.rb", "")
|
12
|
+
%w!config lib app!.each do |dir|
|
13
|
+
Dir.glob("#{approot}/#{dir}/**/*.rb") do |file|
|
14
|
+
require file
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Hisyo::Application.instance_eval do
|
19
|
+
set :root, approot
|
20
|
+
set :views, File.join(approot, "app/views")
|
21
|
+
set :public_folder, File.join(approot, "public")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/hisyo/cli.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module Hisyo
|
4
|
+
module CLI
|
5
|
+
def self.run(argv)
|
6
|
+
Hisyo.generate_project parse_options(argv)
|
7
|
+
end
|
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'){|v| options[:verbose] = true}
|
14
|
+
opts.on('-r VAL', '--root=VAL', 'copy to files dir'){|v| options[:root] = v}
|
15
|
+
opts.parse!(argv)
|
16
|
+
end
|
17
|
+
options
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module Hisyo
|
4
|
+
def self.generate_project(options = {})
|
5
|
+
root = options[:root] || Dir.pwd
|
6
|
+
klass = options[:dryrun] ? FileUtils::NoWrite : FileUtils
|
7
|
+
%w!lib config views public spec app/views app/assets db tmp log!.each do |dir|
|
8
|
+
dir = File.join(root, dir)
|
9
|
+
if File.directory?(dir)
|
10
|
+
puts "\e[31mskip: \e[0m#{dir.gsub(root + "/", "")}/" if options[:verbose]
|
11
|
+
else
|
12
|
+
puts "\e[1m\e[32mcreate: \e[0m#{dir.gsub(root + "/", "")}/" if options[:verbose]
|
13
|
+
klass.mkdir_p dir
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
skelton = File.expand_path("../../../data/generators/project", __FILE__)
|
18
|
+
Dir.glob("#{skelton}/**/*", File::FNM_DOTMATCH) do |file|
|
19
|
+
next if File.directory?(file)
|
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]
|
23
|
+
else
|
24
|
+
puts "\e[1m\e[32mcopy to: \e[0m#{path.gsub(root + "/", "")}" if options[:verbose]
|
25
|
+
klass.cp(file, path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Hisyo.parse_options" do
|
4
|
+
it "should parse options" do
|
5
|
+
options = Hisyo::CLI.parse_options(%w!-n -v --root=/tmp!)
|
6
|
+
options[:dryrun].should be_true
|
7
|
+
options[:verbose].should be_true
|
8
|
+
options[:root].should == "/tmp"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Hisyo.generate_project" do
|
4
|
+
before(:each) do
|
5
|
+
Hisyo.generate_project(
|
6
|
+
:root => @approot,
|
7
|
+
)
|
8
|
+
@mock = Class.new
|
9
|
+
configru = "#{@approot}/config.ru"
|
10
|
+
@mock.class_eval do
|
11
|
+
include Rack::Test::Methods
|
12
|
+
RU = configru
|
13
|
+
def app
|
14
|
+
Rack::Builder.parse_file(RU).first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:each) do
|
20
|
+
system("rm -rf #{@approot}")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should rackup" do
|
24
|
+
@mock.new.instance_eval do
|
25
|
+
get "/"
|
26
|
+
last_response.body.should == "Hello, MyApp!"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Hisyo.generate_project" do
|
4
|
+
after(:each) do
|
5
|
+
system("rm -rf #{@approot}")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should same data/ and approot/" do
|
9
|
+
Hisyo.generate_project(
|
10
|
+
:root => @approot,
|
11
|
+
)
|
12
|
+
dest= Dir.glob("#{@approot}/**/*", File::FNM_DOTMATCH).find_all{|f| File.file?(f)}.map{|f| f.gsub(@approot, "")}
|
13
|
+
src_dir = "#{@root}/data/generators/project"
|
14
|
+
src = Dir.glob("#{src_dir}/**/*", File::FNM_DOTMATCH).find_all{|f| File.file?(f)}.map{|f| f.gsub(src_dir, "")}
|
15
|
+
dest.should == src
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not create files when :dryrun option given" do
|
19
|
+
Hisyo.generate_project(
|
20
|
+
:root => @approot,
|
21
|
+
:dryrun => true,
|
22
|
+
)
|
23
|
+
Dir.glob("#{@approot}/**/*", File::FNM_DOTMATCH).to_a.should == []
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should skip if file exists" do
|
27
|
+
out,err = capture_io do
|
28
|
+
Hisyo.generate_project(
|
29
|
+
:root => @approot,
|
30
|
+
:verbose => true,
|
31
|
+
)
|
32
|
+
end
|
33
|
+
out.split("\n").map{|line| line.gsub(/\e\[\d+m/, "")}.map{|line| line.split(": ").first}.uniq.should == ["create", "copy to"]
|
34
|
+
|
35
|
+
out,err = capture_io do
|
36
|
+
Hisyo.generate_project(
|
37
|
+
:root => @approot,
|
38
|
+
:verbose => true,
|
39
|
+
)
|
40
|
+
end
|
41
|
+
out.split("\n").map{|line| line.gsub(/\e\[\d+m/, "")}.map{|line| line.split(": ").first}.uniq.should == ["skip"]
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
Bundler.require(:default, :test)
|
4
|
+
SimpleCov.start if ENV["COVERAGE"]
|
5
|
+
require File.expand_path("../../lib/hisyo.rb", __FILE__)
|
6
|
+
|
7
|
+
|
8
|
+
RSpec.configure do |conf|
|
9
|
+
conf.before(:all) do
|
10
|
+
@root = File.expand_path("../../", __FILE__)
|
11
|
+
@approot = File.expand_path("../testapp", __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
# https://github.com/seattlerb/minitest/blob/master/lib/minitest/unit.rb#L431
|
15
|
+
##
|
16
|
+
# Captures $stdout and $stderr into strings:
|
17
|
+
#
|
18
|
+
# out, err = capture_io do
|
19
|
+
# warn "You did a bad thing"
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# assert_match %r%bad%, err
|
23
|
+
def capture_io
|
24
|
+
require 'stringio'
|
25
|
+
|
26
|
+
orig_stdout, orig_stderr = $stdout, $stderr
|
27
|
+
captured_stdout, captured_stderr = StringIO.new, StringIO.new
|
28
|
+
$stdout, $stderr = captured_stdout, captured_stderr
|
29
|
+
|
30
|
+
yield
|
31
|
+
|
32
|
+
return captured_stdout.string, captured_stderr.string
|
33
|
+
ensure
|
34
|
+
$stdout = orig_stdout
|
35
|
+
$stderr = orig_stderr
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hisyo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- uu59
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-27 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Create simple Sinatra project template
|
15
|
+
email:
|
16
|
+
- k@uu59.org
|
17
|
+
executables:
|
18
|
+
- hisyo
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE
|
26
|
+
- README.mkd
|
27
|
+
- bin/hisyo
|
28
|
+
- data/generators/project/.gitignore
|
29
|
+
- data/generators/project/Gemfile
|
30
|
+
- data/generators/project/app/app.rb
|
31
|
+
- data/generators/project/app/helpers.rb
|
32
|
+
- data/generators/project/config.ru
|
33
|
+
- data/generators/project/config/boot.rb
|
34
|
+
- data/generators/project/spec/hello_spec.rb
|
35
|
+
- data/generators/project/spec/spec_helper.rb
|
36
|
+
- hisyo.gemspec
|
37
|
+
- lib/hisyo.rb
|
38
|
+
- lib/hisyo/application.rb
|
39
|
+
- lib/hisyo/cli.rb
|
40
|
+
- lib/hisyo/generator.rb
|
41
|
+
- lib/hisyo/version.rb
|
42
|
+
- spec/cli_spec.rb
|
43
|
+
- spec/generated_app_spec.rb
|
44
|
+
- spec/generator_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.11
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Create simple Sinatra project template
|
70
|
+
test_files:
|
71
|
+
- spec/cli_spec.rb
|
72
|
+
- spec/generated_app_spec.rb
|
73
|
+
- spec/generator_spec.rb
|
74
|
+
- spec/spec_helper.rb
|