hisyo 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - rbx-19mode
5
+ - jruby-19mode
6
+ - ruby-head
7
+ notifications:
8
+ email:
9
+ - k@uu59.org
data/Changes ADDED
@@ -0,0 +1,4 @@
1
+ = 0.1.0 / 2012-05-30
2
+
3
+ * Generated app has no dependency on `hisyo`
4
+ You can remove `hisyo` gem after generation.
data/Gemfile CHANGED
@@ -7,5 +7,6 @@ gem "sinatra-contrib", :require => "sinatra/contrib"
7
7
  group :test do
8
8
  gem "rspec"
9
9
  gem "rack-test", :require => "rack/test"
10
- gem "simplecov"
10
+ gem "simplecov", :require => false
11
+ gem "rake" # for Travis CI
11
12
  end
data/Gemfile.lock CHANGED
@@ -10,6 +10,7 @@ GEM
10
10
  rack
11
11
  rack-test (0.6.1)
12
12
  rack (>= 1.0)
13
+ rake (0.9.2.2)
13
14
  rspec (2.10.0)
14
15
  rspec-core (~> 2.10.0)
15
16
  rspec-expectations (~> 2.10.0)
@@ -40,6 +41,7 @@ PLATFORMS
40
41
 
41
42
  DEPENDENCIES
42
43
  rack-test
44
+ rake
43
45
  rspec
44
46
  simplecov
45
47
  sinatra
data/README.mkd CHANGED
@@ -1,34 +1,25 @@
1
- Hisyo is a thin wrapper for your Sinatra project
1
+ [![Travis CI Build Status](https://secure.travis-ci.org/uu59/hisyo.png?branch=master)](http://travis-ci.org/uu59/hisyo)
2
+
3
+ Hisyo is a generator that for your Sinatra project to play.
2
4
 
3
5
  $ gem install hisyo
4
6
  $ 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
7
+ $ hisyo -r ~/myapp
8
+ Complete.
9
+ $ cd ~/myapp
10
+ $ rackup (or `rspec spec/`, `vim app/helpers.rb`, etc)
23
11
  $ cd ~/myapp
24
- $ tree -F
12
+ $ tree -Fa
25
13
  .
14
+ ├── .gitignore
26
15
  ├── Gemfile
27
16
  ├── app/
28
17
  │   ├── app.rb
29
18
  │   ├── assets/
19
+ │   ├── controllers.rb
30
20
  │   ├── helpers.rb
31
21
  │   └── views/
22
+ │   └── index.str
32
23
  ├── config/
33
24
  │   └── boot.rb
34
25
  ├── config.ru
@@ -42,10 +33,12 @@ Hisyo is a thin wrapper for your Sinatra project
42
33
  ├── tmp/
43
34
  └── views/
44
35
 
45
- 11 directories, 7 files
36
+ 11 directories, 10 files
37
+
46
38
  $ rackup
47
39
  [2012-05-28 02:24:32] INFO WEBrick 1.3.1
48
40
  [2012-05-28 02:24:32] INFO ruby 1.9.3 (2012-02-16) [x86_64-linux]
49
41
  [2012-05-28 02:24:32] INFO WEBrick::HTTPServer#start: pid=11232 port=9292
50
42
 
51
-
43
+ Generated project(as below) is a purely Sinatra application.
44
+ That means you can `gem uninstall hisyo` after generation.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require File.expand_path("../spec/spec_helper.rb", __FILE__)
2
+
3
+ require "rspec/core/rake_task"
4
+ require "rspec/core/version"
5
+
6
+ task :default => :spec
7
+
8
+ desc "Run all examples"
9
+ RSpec::Core::RakeTask.new(:spec) do |t|
10
+ #t.ruby_opts = %w[-w]
11
+ end
@@ -3,7 +3,6 @@ source :rubygems
3
3
  gem "sinatra"
4
4
  gem "sinatra-contrib", :require => "sinatra/contrib"
5
5
  gem "tilt"
6
- gem "hisyo"
7
6
 
8
7
  group :test do
9
8
  gem "rspec"
@@ -1,5 +1,19 @@
1
- class MyApp < Hisyo::Application
2
- get "/" do
3
- hello("MyApp")
1
+ # Feel free to rename from "MyApp" to anything
2
+ # if so, remember changing config.ru, config/boot.rb
3
+ class MyApp < Sinatra::Application
4
+ set :root, File.expand_path("../../", __FILE__)
5
+ set :views, File.join(root, "app/views")
6
+ set :public_folder, File.join(root, "public")
7
+
8
+ def self.controllers(&block)
9
+ instance_eval &block
10
+ end
11
+
12
+ def self.setup
13
+ %w!config lib app!.each do |dir|
14
+ Dir.glob("#{root}/#{dir}/**/*.rb") do |file|
15
+ require file
16
+ end
17
+ end
4
18
  end
5
19
  end
@@ -0,0 +1,11 @@
1
+ MyApp.controllers do
2
+ get "/" do
3
+ # render "index.str" at app/views/index.str
4
+ render :str, :index
5
+ end
6
+
7
+ get "/hi/:name" do
8
+ # `hi` is helper at app/helpers.rb
9
+ hi(params[:name] || "joe")
10
+ end
11
+ end
@@ -1,6 +1,6 @@
1
- Hisyo::Application.helpers do
2
- def hello(word)
3
- "Hello, #{word}!"
1
+ MyApp.helpers do
2
+ def hi(word)
3
+ "Hi, #{word}!"
4
4
  end
5
5
  end
6
6
 
@@ -0,0 +1 @@
1
+ Hello, MyApp!
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env rackup
2
2
  # encoding: utf-8
3
3
 
4
- # This file can be used to start Padrino,
5
- # just execute it from the command line.
6
-
7
4
  require File.expand_path("../config/boot.rb", __FILE__)
8
5
 
6
+ # app/app.rb
9
7
  run MyApp
@@ -4,4 +4,5 @@ require "bundler/setup"
4
4
  Bundler.require(:default, ENV["RACK_ENV"] || "development")
5
5
 
6
6
  # load .rb files at lib/**, config/**, app/**
7
- Hisyo.setup
7
+ require File.expand_path("../../app/app.rb", __FILE__)
8
+ MyApp.setup
@@ -6,10 +6,3 @@ RSpec.configure do |conf|
6
6
  #conf.include Rack::Test::Methods
7
7
  #conf.include Capybara::DSL
8
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 CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["k@uu59.org"]
7
7
  gem.description = %q{Create simple Sinatra project template}
8
8
  gem.summary = %q{Create simple Sinatra project template}
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/uu59/hisyo"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/lib/hisyo/cli.rb CHANGED
@@ -9,9 +9,9 @@ module Hisyo
9
9
  def self.parse_options(argv)
10
10
  options = {}
11
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}
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
15
  opts.parse!(argv)
16
16
  end
17
17
  options
@@ -25,6 +25,10 @@ module Hisyo
25
25
  klass.cp(file, path)
26
26
  end
27
27
  end
28
+
29
+ puts "Complete."
30
+ puts " $ cd #{root}/"
31
+ puts ' $ rackup (or `rspec spec/`, `vim app/helpers.rb`, etc)'
28
32
  end
29
33
  end
30
34
 
data/lib/hisyo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hisyo
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,29 +1,49 @@
1
1
  require "spec_helper"
2
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
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
15
26
  end
27
+ @mock.new.instance_eval &block
16
28
  end
29
+ Process.wait pid
17
30
  end
18
31
 
19
32
  after(:each) do
20
- system("rm -rf #{@approot}")
33
+ FileUtils.rm_rf @approot
21
34
  end
22
35
 
23
36
  it "should rackup" do
24
- @mock.new.instance_eval do
37
+ genapp do
25
38
  get "/"
26
- last_response.body.should == "Hello, MyApp!"
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!"
27
47
  end
28
48
  end
29
49
  end
@@ -2,11 +2,11 @@ require "spec_helper"
2
2
 
3
3
  describe "Hisyo.generate_project" do
4
4
  after(:each) do
5
- system("rm -rf #{@approot}")
5
+ FileUtils.rm_rf @approot
6
6
  end
7
7
 
8
8
  it "should same data/ and approot/" do
9
- Hisyo.generate_project(
9
+ generate_app(
10
10
  :root => @approot,
11
11
  )
12
12
  dest= Dir.glob("#{@approot}/**/*", File::FNM_DOTMATCH).find_all{|f| File.file?(f)}.map{|f| f.gsub(@approot, "")}
@@ -16,7 +16,7 @@ describe "Hisyo.generate_project" do
16
16
  end
17
17
 
18
18
  it "should not create files when :dryrun option given" do
19
- Hisyo.generate_project(
19
+ generate_app(
20
20
  :root => @approot,
21
21
  :dryrun => true,
22
22
  )
@@ -24,20 +24,18 @@ describe "Hisyo.generate_project" do
24
24
  end
25
25
 
26
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"]
27
+ generate_app(
28
+ :root => @approot,
29
+ :verbose => true,
30
+ )
34
31
 
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"]
32
+ out, err = generate_app(
33
+ :root => @approot,
34
+ :verbose => true,
35
+ )
36
+ messages = out.split("\n").map{|line| line.gsub(/\e\[\d+m/, "")}.map{|line| line.split(": ").first}.uniq
37
+ messages.include?("copy to").should be_false
38
+ messages.include?("create").should be_false
39
+ messages.include?("skip").should be_true
42
40
  end
43
41
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
3
  Bundler.require(:default, :test)
4
- SimpleCov.start if ENV["COVERAGE"]
4
+ if ENV["COVERAGE"]
5
+ require "simplecov"
6
+ SimpleCov.start
7
+ end
5
8
  require File.expand_path("../../lib/hisyo.rb", __FILE__)
6
9
 
7
10
 
@@ -35,4 +38,10 @@ RSpec.configure do |conf|
35
38
  $stderr = orig_stderr
36
39
  end
37
40
 
41
+ def generate_app(options = {})
42
+ capture_io do
43
+ Hisyo.generate_project(options)
44
+ end
45
+ end
46
+
38
47
  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.0.3
4
+ version: 0.1.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-05-27 00:00:00.000000000 Z
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Create simple Sinatra project template
15
15
  email:
@@ -20,22 +20,26 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - .gitignore
23
+ - .travis.yml
24
+ - Changes
23
25
  - Gemfile
24
26
  - Gemfile.lock
25
27
  - LICENSE
26
28
  - README.mkd
29
+ - Rakefile
27
30
  - bin/hisyo
28
31
  - data/generators/project/.gitignore
29
32
  - data/generators/project/Gemfile
30
33
  - data/generators/project/app/app.rb
34
+ - data/generators/project/app/controllers.rb
31
35
  - data/generators/project/app/helpers.rb
36
+ - data/generators/project/app/views/index.str
32
37
  - data/generators/project/config.ru
33
38
  - data/generators/project/config/boot.rb
34
39
  - data/generators/project/spec/hello_spec.rb
35
40
  - data/generators/project/spec/spec_helper.rb
36
41
  - hisyo.gemspec
37
42
  - lib/hisyo.rb
38
- - lib/hisyo/application.rb
39
43
  - lib/hisyo/cli.rb
40
44
  - lib/hisyo/generator.rb
41
45
  - lib/hisyo/version.rb
@@ -43,7 +47,7 @@ files:
43
47
  - spec/generated_app_spec.rb
44
48
  - spec/generator_spec.rb
45
49
  - spec/spec_helper.rb
46
- homepage: ''
50
+ homepage: https://github.com/uu59/hisyo
47
51
  licenses: []
48
52
  post_install_message:
49
53
  rdoc_options: []
@@ -1,24 +0,0 @@
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