quirkey-sinatra-gen 0.1.1

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.
Files changed (31) hide show
  1. data/History.txt +12 -0
  2. data/Manifest.txt +27 -0
  3. data/PostInstall.txt +2 -0
  4. data/README.rdoc +50 -0
  5. data/Rakefile +28 -0
  6. data/app_generators/sinatra_app/USAGE +8 -0
  7. data/app_generators/sinatra_app/sinatra_app_generator.rb +114 -0
  8. data/app_generators/sinatra_app/templates/Capfile +3 -0
  9. data/app_generators/sinatra_app/templates/Rakefile.erb +4 -0
  10. data/app_generators/sinatra_app/templates/app.rb.erb +17 -0
  11. data/app_generators/sinatra_app/templates/config/deploy.rb.erb +13 -0
  12. data/app_generators/sinatra_app/templates/config.ru.erb +8 -0
  13. data/app_generators/sinatra_app/templates/config.yml +1 -0
  14. data/app_generators/sinatra_app/templates/lib/module.rb.erb +3 -0
  15. data/app_generators/sinatra_app/templates/test/test_app_rspec.rb.erb +10 -0
  16. data/app_generators/sinatra_app/templates/test/test_app_shoulda.rb.erb +17 -0
  17. data/app_generators/sinatra_app/templates/test/test_app_spec.rb.erb +10 -0
  18. data/app_generators/sinatra_app/templates/test/test_app_unit.rb.erb +9 -0
  19. data/app_generators/sinatra_app/templates/test/test_helper.rb.erb +20 -0
  20. data/app_generators/sinatra_app/templates/views/builder_index.erb +4 -0
  21. data/app_generators/sinatra_app/templates/views/erb_index.erb +2 -0
  22. data/app_generators/sinatra_app/templates/views/erb_layout.erb +15 -0
  23. data/app_generators/sinatra_app/templates/views/haml_index.erb +2 -0
  24. data/app_generators/sinatra_app/templates/views/haml_layout.erb +6 -0
  25. data/bin/sinatra-gen +17 -0
  26. data/lib/sinatra-gen.rb +6 -0
  27. data/sinatra-gen.gemspec +44 -0
  28. data/test/test_generator_helper.rb +29 -0
  29. data/test/test_helper.rb +3 -0
  30. data/test/test_sinatra_app_generator.rb +174 -0
  31. metadata +115 -0
data/History.txt ADDED
@@ -0,0 +1,12 @@
1
+ == 0.1.1 2008-12-16
2
+
3
+ * 1 major enhancement
4
+ * added --cap option for generating capistrano recipe
5
+ * 1 minor enhancement
6
+ * added empty config.yml on generation
7
+
8
+ == 0.1.0 2008-12-13
9
+
10
+ * 1 major enhancement:
11
+ * Initial release
12
+ * See README.rdoc for more info
data/Manifest.txt ADDED
@@ -0,0 +1,27 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ app_generators/sinatra_app/USAGE
7
+ app_generators/sinatra_app/sinatra_app_generator.rb
8
+ app_generators/sinatra_app/templates/Capfile
9
+ app_generators/sinatra_app/templates/Rakefile.erb
10
+ app_generators/sinatra_app/templates/app.rb.erb
11
+ app_generators/sinatra_app/templates/config.ru.erb
12
+ app_generators/sinatra_app/templates/config.yml
13
+ app_generators/sinatra_app/templates/config/deploy.rb.erb
14
+ app_generators/sinatra_app/templates/lib/module.rb.erb
15
+ app_generators/sinatra_app/templates/test/test_app_rspec.rb.erb
16
+ app_generators/sinatra_app/templates/test/test_app_shoulda.rb.erb
17
+ app_generators/sinatra_app/templates/test/test_app_spec.rb.erb
18
+ app_generators/sinatra_app/templates/test/test_app_unit.rb.erb
19
+ app_generators/sinatra_app/templates/test/test_helper.rb.erb
20
+ app_generators/sinatra_app/templates/views/builder_index.erb
21
+ app_generators/sinatra_app/templates/views/erb_index.erb
22
+ app_generators/sinatra_app/templates/views/erb_layout.erb
23
+ app_generators/sinatra_app/templates/views/haml_index.erb
24
+ app_generators/sinatra_app/templates/views/haml_layout.erb
25
+ bin/sinatra-gen
26
+ lib/sinatra-gen.rb
27
+ sinatra-gen.gemspec
data/PostInstall.txt ADDED
@@ -0,0 +1,2 @@
1
+ For information about sinatra-gen and its options run:
2
+ sinatra-gen
data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = sinatra-gen
2
+
3
+ http://github.com/quirkey/sinatra-gen
4
+
5
+ == DESCRIPTION:
6
+
7
+ sinatra-gen generates a common file structure and basic app files for a web app utilizing the sinatra framework.
8
+ For more information on sinatra, check out http://sinatra.rubyforge.org
9
+
10
+ == SYNOPSIS:
11
+
12
+ sinatra-gen has a bunch of different options (based loosley on merb-gen) to try to not lock the
13
+ user into any specific frameworks/dev practices.
14
+
15
+ Run:
16
+
17
+ sinatra-gen [appname] [options]
18
+
19
+ e.g.
20
+
21
+ sinatra-gen mysinatrapp --vendor --init --test=shoulda --views=haml
22
+
23
+ Options (can also be obtained by running sinatra-gen with no arguments):
24
+
25
+ -v, --version Show the sinatra-gen version number and quit.
26
+ -d, --vendor Extract the latest sinatra to vendor/sinatra
27
+ --tiny Only create the minimal files.
28
+ --init Initialize a git repository
29
+ --cap Adds config directory with basic capistrano deploy.rb
30
+ --scripts Install the rubigen scripts (script/generate, script/destroy)
31
+ --git /path/to/git Specify a different path for 'git'
32
+ --test=test_framework Specify your testing framework (unit (default)/rspec/spec/shoulda)
33
+ --views=view_framework Specify your view framework (erb (default)/haml/builder)
34
+
35
+
36
+ The --tiny option will create no directories. Just an app.rb, a Rakefile, and a config.ru (Rackup file)
37
+
38
+ == ACKNOWLEDGEMENTS:
39
+
40
+ Big props to the Sinatra developers (http://github.com/bmizerany/sinatra/).
41
+ Also, thanks to Dr. Nic (http://github.com/drnic) for the Rubigen and Newgem libraries
42
+
43
+ == REQUIREMENTS:
44
+
45
+ To use the --vendor option, git must be installed.
46
+ To run the app without using the vendor option, the sinatra gem must be installed.
47
+
48
+ == INSTALL:
49
+
50
+ sudo gem install sintra-gen
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/sinatra-gen'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('sinatra-gen', SinatraGen::VERSION) do |p|
7
+ p.developer('Aaron Quint', 'aaron@quirkey.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+ p.extra_deps = [
12
+ ['rubigen','>= 1.3.3'],
13
+ ]
14
+ p.extra_dev_deps = [
15
+ ['newgem', ">= #{::Newgem::VERSION}"]
16
+ ]
17
+
18
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
+ p.rsync_args = '-av --delete --ignore-errors'
22
+ end
23
+
24
+ require 'newgem/tasks' # load /tasks/*.rake
25
+ Dir['tasks/**/*.rake'].each { |t| load t }
26
+
27
+ # TODO - want other tests/tasks run by default? Add them to the list
28
+ # task :default => [:spec, :features]
@@ -0,0 +1,8 @@
1
+ Description:
2
+
3
+ sinatra-gen generates a common file structure and basic app files for a web app utilizing the sinatra framework.
4
+ For more information on sinatra, check out http://sinatra.rubyforge.org
5
+
6
+ Usage:
7
+
8
+ sinatra-gen [appname] [options]
@@ -0,0 +1,114 @@
1
+ class SinatraAppGenerator < RubiGen::Base
2
+
3
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
+ Config::CONFIG['ruby_install_name'])
5
+
6
+ default_options :author => nil
7
+
8
+ attr_accessor :app_name, :vendor, :tiny, :git, :git_init, :test_framework, :view_framework, :install_scripts, :cap
9
+
10
+ def initialize(runtime_args, runtime_options = {})
11
+ super
12
+ usage if args.empty?
13
+ @destination_root = File.expand_path(args.shift)
14
+ self.app_name = base_name
15
+ extract_options
16
+ end
17
+
18
+ def manifest
19
+ record do |m|
20
+ # Ensure appropriate folder(s) exists
21
+ m.directory ''
22
+
23
+ if git_init
24
+ `cd #{@destination_root} && #{git} init`
25
+ end
26
+
27
+ m.template 'config.ru.erb', 'config.ru'
28
+ m.template 'app.rb.erb' , 'app.rb'
29
+ m.template 'Rakefile.erb' , 'Rakefile'
30
+
31
+ unless tiny
32
+ BASEDIRS.each { |path| m.directory path }
33
+ m.file 'config.yml', 'config.yml'
34
+ m.template 'lib/module.rb.erb', "lib/#{app_name}.rb"
35
+ m.template 'test/test_helper.rb.erb', 'test/test_helper.rb'
36
+ m.template "test/test_app_#{test_framework}.rb.erb", "test/test_#{app_name}.rb"
37
+ m.template "views/#{view_framework}_index.erb", "views/index.#{view_framework}"
38
+ m.template "views/#{view_framework}_layout.erb", "views/layout.#{view_framework}" unless view_framework == 'builder'
39
+ end
40
+
41
+ if vendor
42
+ m.directory 'vendor'
43
+ if git_init || File.exists?(File.join(@destination_root, '.git'))
44
+ command = "cd #{@destination_root} && #{git} submodule add git://github.com/bmizerany/sinatra.git vendor/sinatra"
45
+ else
46
+ command = "cd #{@destination_root} && #{git} clone git://github.com/bmizerany/sinatra.git vendor/sinatra"
47
+ end
48
+ `#{command}`
49
+ end
50
+
51
+ if cap
52
+ m.directory 'config'
53
+ m.file 'Capfile', 'Capfile'
54
+ m.template 'config/deploy.rb.erb', 'config/deploy.rb'
55
+ end
56
+
57
+ if install_scripts
58
+ m.dependency "install_rubigen_scripts", [destination_root, 'sinatra-gen'], :shebang => options[:shebang], :collision => :force
59
+ end
60
+ end
61
+ end
62
+
63
+ protected
64
+ def banner
65
+ <<-EOS
66
+ Creates the skeleton for a new sinatra app
67
+
68
+ USAGE: #{spec.name} app_name
69
+ EOS
70
+ end
71
+
72
+ def add_options!(opts)
73
+ opts.separator ''
74
+ opts.separator 'Options:'
75
+
76
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
77
+ opts.on("-d", "--vendor", "Extract the latest sinatra to vendor/sinatra") {|o| options[:vendor] = o }
78
+ opts.on("--tiny", "Only create the minimal files.") {|o| options[:tiny] = o }
79
+ opts.on("--init", "Initialize a git repository") {|o| options[:init] = o }
80
+ opts.on("--cap", "Adds config directory with basic capistrano deploy.rb") {|o| options[:cap] = o }
81
+ opts.on("--scripts", "Install the rubigen scripts (script/generate, script/destroy)") {|o| options[:scripts] = o }
82
+ opts.on("--git /path/to/git", "Specify a different path for 'git'") {|o| options[:git] = o }
83
+ opts.on("--test=test_framework", String, "Specify your testing framework (unit (default)/rspec/spec/shoulda)") {|o| options[:test_framework] = o }
84
+ opts.on("--views=view_framework", "Specify your view framework (erb (default)/haml/builder)") {|o| options[:view_framework] = o }
85
+ end
86
+
87
+ def extract_options
88
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
89
+ # Templates can access these value via the attr_reader-generated methods, but not the
90
+ # raw instance variable value.
91
+ self.vendor = options[:vendor]
92
+ self.tiny = options[:tiny]
93
+ self.cap = options[:cap]
94
+ self.git = options[:git] || `which git`.strip
95
+ self.git_init = options[:init]
96
+ self.test_framework = options[:test_framework] || 'unit'
97
+ self.view_framework = options[:view_framework] || 'erb'
98
+ self.install_scripts = options[:scripts] || false
99
+ end
100
+
101
+ def klass_name
102
+ app_name.classify
103
+ end
104
+
105
+
106
+ # Installation skeleton. Intermediate directories are automatically
107
+ # created so don't sweat their absence here.
108
+ BASEDIRS = %w(
109
+ lib
110
+ test
111
+ public
112
+ views
113
+ )
114
+ end
@@ -0,0 +1,3 @@
1
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
2
+ Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
3
+ load 'config/deploy'
@@ -0,0 +1,4 @@
1
+ namespace :<%= app_name %> do
2
+
3
+
4
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ <%- if vendor -%>
3
+ $:.unshift File.join(File.dirname(__FILE__), 'vendor', 'sinatra', 'lib')
4
+ require 'sinatra'
5
+ <%- else -%>
6
+ require 'sinatra'
7
+ <%- end -%>
8
+ <%- unless tiny -%>
9
+ require File.join(File.dirname(__FILE__), 'lib', '<%= app_name %>')
10
+
11
+ set :public, 'public'
12
+ set :views, 'views'
13
+ <%- end -%>
14
+
15
+ get '/' do
16
+ <%= view_framework -%> :index
17
+ end
@@ -0,0 +1,13 @@
1
+ set :application, "<%= app_name %>"
2
+ set :deploy_via, :remote_cache
3
+ set :user, 'SERVER_USER_NAME'
4
+ set :runner, user
5
+
6
+ set :scm, :git
7
+ set :repository, "git@github.com:GITHUB_USER_NAME/#{application}.git"
8
+ set :branch, 'master'
9
+ set :git_enable_submodules, 1
10
+ set :keep_releases, 3
11
+ set :deploy_to, "/var/www/apps/#{application}"
12
+
13
+ server "YOUR_DOMAIN", :web, :app, :db, :primary => true
@@ -0,0 +1,8 @@
1
+ # To use with thin
2
+ # thin start -p PORT -R config.ru
3
+
4
+ require File.join(File.dirname(__FILE__), 'app.rb')
5
+
6
+ disable :run
7
+ set :env, :production
8
+ run Sinatra.application
@@ -0,0 +1,3 @@
1
+ module <%= klass_name %>
2
+
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ describe '<%= klass_name %>' do
4
+
5
+ it 'should load the index' do
6
+ get_it '/'
7
+ @response.should be_ok
8
+ end
9
+
10
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class <%= klass_name -%>Test < Test::Unit::TestCase
4
+
5
+ context "<%= klass_name -%>" do
6
+ context "getting the index" do
7
+ setup do
8
+ get_it '/'
9
+ end
10
+
11
+ should "respond" do
12
+ assert @response.body
13
+ end
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ describe '<%= klass_name %>' do
4
+
5
+ it 'should load the index' do
6
+ get_it '/'
7
+ should.be.ok
8
+ end
9
+
10
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class <%= klass_name -%>Test < Test::Unit::TestCase
4
+
5
+ def test_my_default
6
+ get_it '/'
7
+ end
8
+
9
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ <%- if vendor -%>
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'vendor', 'sinatra', 'lib')
4
+ require 'sinatra'
5
+ <%- else -%>
6
+ require 'sinatra'
7
+ <%- end -%>
8
+ <%- case test_framework -%>
9
+ <%- when 'rspec' -%>
10
+ require 'spec'
11
+ require 'sinatra/test/rspec'
12
+ <%- when 'spec' -%>
13
+ require 'sinatra/test/spec'
14
+ <%- when 'shoulda' -%>
15
+ require 'sinatra/test/unit'
16
+ require 'shoulda'
17
+ <%- when 'unit' -%>
18
+ require 'sinatra/test/unit'
19
+ <%- end -%>
20
+ require File.join(File.dirname(__FILE__), '..', 'app.rb')
@@ -0,0 +1,4 @@
1
+ xml.instruct!
2
+ xml.app do
3
+ xml.data { xml.cdata! "Default sinatra-gen index. Generated at <%= Time.now %>" }
4
+ end
@@ -0,0 +1,2 @@
1
+ <p>Hello!</p>
2
+ <p>Default sinatra-gen index (generated at <%= Time.now %>)</p>
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+
8
+ <title><%= app_name %></title>
9
+
10
+ </head>
11
+
12
+ <body>
13
+ <%%= yield %>
14
+ </body>
15
+ </html>
@@ -0,0 +1,2 @@
1
+ %p Hello!
2
+ %p Default sinatra-gen index (generated at <%= Time.now %>)
@@ -0,0 +1,6 @@
1
+ %html{:xmlns=> "http://www.w3.org/1999/xhtml", 'xml:lang' => "en", :lang => "en"}
2
+ %head
3
+ %meta{'http-equiv' => "Content-Type", 'content' => "text/html; charset=utf-8"}
4
+ %title <%= app_name %>
5
+ %body
6
+ = yield
data/bin/sinatra-gen ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rubigen'
5
+
6
+ if %w(-v --version).include? ARGV.first
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'sinatra-gen')
8
+ puts "#{File.basename($0)} #{SinatraGen::VERSION}"
9
+ exit(0)
10
+ end
11
+
12
+ require 'rubigen/scripts/generate'
13
+ source = RubiGen::PathSource.new(:application,
14
+ File.join(File.dirname(__FILE__), "../app_generators"))
15
+ RubiGen::Base.reset_sources
16
+ RubiGen::Base.append_sources source
17
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'sinatra_app')
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module SinatraGen
5
+ VERSION = '0.1.1'
6
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{sinatra-gen}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Aaron Quint"]
9
+ s.date = %q{2008-12-16}
10
+ s.default_executable = %q{sinatra-gen}
11
+ s.description = %q{sinatra-gen generates a common file structure and basic app files for a web app utilizing the sinatra framework. For more information on sinatra, check out http://sinatra.rubyforge.org}
12
+ s.email = ["aaron@quirkey.com"]
13
+ s.executables = ["sinatra-gen"]
14
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
15
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "app_generators/sinatra_app/USAGE", "app_generators/sinatra_app/sinatra_app_generator.rb", "app_generators/sinatra_app/templates/Capfile", "app_generators/sinatra_app/templates/Rakefile.erb", "app_generators/sinatra_app/templates/app.rb.erb", "app_generators/sinatra_app/templates/config.ru.erb", "app_generators/sinatra_app/templates/config.yml", "app_generators/sinatra_app/templates/config/deploy.rb.erb", "app_generators/sinatra_app/templates/lib/module.rb.erb", "app_generators/sinatra_app/templates/test/test_app_rspec.rb.erb", "app_generators/sinatra_app/templates/test/test_app_shoulda.rb.erb", "app_generators/sinatra_app/templates/test/test_app_spec.rb.erb", "app_generators/sinatra_app/templates/test/test_app_unit.rb.erb", "app_generators/sinatra_app/templates/test/test_helper.rb.erb", "app_generators/sinatra_app/templates/views/builder_index.erb", "app_generators/sinatra_app/templates/views/erb_index.erb", "app_generators/sinatra_app/templates/views/erb_layout.erb", "app_generators/sinatra_app/templates/views/haml_index.erb", "app_generators/sinatra_app/templates/views/haml_layout.erb", "bin/sinatra-gen", "lib/sinatra-gen.rb", "sinatra-gen.gemspec", "test/test_generator_helper.rb", "test/test_helper.rb", "test/test_sinatra_app_generator.rb"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://github.com/quirkey/sinatra-gen}
18
+ s.post_install_message = %q{PostInstall.txt}
19
+ s.rdoc_options = ["--main", "README.rdoc"]
20
+ s.require_paths = ["lib"]
21
+ s.rubyforge_project = %q{sinatra-gen}
22
+ s.rubygems_version = %q{1.3.1}
23
+ s.summary = %q{sinatra-gen generates a common file structure and basic app files for a web app utilizing the sinatra framework}
24
+ s.test_files = ["test/test_generator_helper.rb", "test/test_helper.rb", "test/test_sinatra_app_generator.rb"]
25
+
26
+ if s.respond_to? :specification_version then
27
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
28
+ s.specification_version = 2
29
+
30
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
31
+ s.add_runtime_dependency(%q<rubigen>, [">= 1.3.3"])
32
+ s.add_development_dependency(%q<newgem>, [">= 1.2.1"])
33
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
34
+ else
35
+ s.add_dependency(%q<rubigen>, [">= 1.3.3"])
36
+ s.add_dependency(%q<newgem>, [">= 1.2.1"])
37
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
38
+ end
39
+ else
40
+ s.add_dependency(%q<rubigen>, [">= 1.3.3"])
41
+ s.add_dependency(%q<newgem>, [">= 1.2.1"])
42
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ begin
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+ rescue LoadError
4
+ require 'test/unit'
5
+ end
6
+ require 'fileutils'
7
+
8
+ # Must set before requiring generator libs.
9
+ TMP_ROOT = File.dirname(__FILE__) + "/tmp" unless defined?(TMP_ROOT)
10
+ PROJECT_NAME = "myproject" unless defined?(PROJECT_NAME)
11
+ app_root = File.join(TMP_ROOT, PROJECT_NAME)
12
+ if defined?(APP_ROOT)
13
+ APP_ROOT.replace(app_root)
14
+ else
15
+ APP_ROOT = app_root
16
+ end
17
+ if defined?(RAILS_ROOT)
18
+ RAILS_ROOT.replace(app_root)
19
+ else
20
+ RAILS_ROOT = app_root
21
+ end
22
+
23
+ begin
24
+ require 'rubigen'
25
+ rescue LoadError
26
+ require 'rubygems'
27
+ require 'rubigen'
28
+ end
29
+ require 'rubigen/helpers/generator_test_helper'
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/sinatra-gen'
@@ -0,0 +1,174 @@
1
+ require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
+
3
+ class TestSinatraAppGenerator < Test::Unit::TestCase
4
+ include RubiGen::GeneratorTestHelper
5
+
6
+ def setup
7
+ bare_setup
8
+ end
9
+
10
+ def teardown
11
+ bare_teardown
12
+ end
13
+
14
+ # Some generator-related assertions:
15
+ # assert_generated_file(name, &block) # block passed the file contents
16
+ # assert_directory_exists(name)
17
+ # assert_generated_class(name, &block)
18
+ # assert_generated_module(name, &block)
19
+ # assert_generated_test_for(name, &block)
20
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
21
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
22
+ #
23
+ # Other helper methods are:
24
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
25
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
26
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
27
+
28
+ def test_generate_app_without_options
29
+ run_generator('sinatra_app', [APP_ROOT], sources)
30
+ assert_basic_paths_and_files
31
+ assert_generated_file 'views/layout.erb'
32
+ assert_generated_file 'views/index.erb'
33
+ assert_generated_file "test/test_#{app_name}.rb" do |test_contents|
34
+ assert_match(/def test/, test_contents)
35
+ end
36
+ end
37
+
38
+ def test_generate_app_with_vendor_option
39
+ run_generator('sinatra_app', [APP_ROOT, '--vendor'], sources)
40
+ assert_basic_paths_and_files
41
+ assert_directory_exists 'vendor/sinatra/lib'
42
+ end
43
+
44
+ def test_generate_app_with_tiny_option
45
+ run_generator('sinatra_app', [APP_ROOT, '--tiny'], sources)
46
+ assert_generated_file 'config.ru'
47
+ assert_generated_file 'app.rb'
48
+ assert_generated_file 'Rakefile'
49
+ end
50
+
51
+ def test_generate_app_with_init_option
52
+ run_generator('sinatra_app', [APP_ROOT, '-i'], sources)
53
+ assert_basic_paths_and_files
54
+ assert_directory_exists '.git'
55
+ end
56
+
57
+ def test_generate_app_with_cap_option
58
+ run_generator('sinatra_app', [APP_ROOT, '--cap'], sources)
59
+ assert_basic_paths_and_files
60
+ assert_directory_exists 'config'
61
+ assert_generated_file 'Capfile'
62
+ assert_generated_file 'config/deploy.rb' do |deploy_contents|
63
+ assert_match(/set \:application, "#{app_name}"/, deploy_contents)
64
+ end
65
+ end
66
+
67
+ def test_generate_app_with_rspect_test_option
68
+ run_generator('sinatra_app', [APP_ROOT, '--test=rspec'], sources)
69
+ assert_basic_paths_and_files
70
+ assert_generated_file 'test/test_helper.rb' do |helper_contents|
71
+ assert_match(/sinatra\/test\/rspec/, helper_contents)
72
+ end
73
+ assert_generated_file "test/test_#{app_name}.rb" do |test_contents|
74
+ assert_match(/describe/, test_contents)
75
+ end
76
+ end
77
+
78
+ def test_generate_app_with_spec_test_option
79
+ run_generator('sinatra_app', [APP_ROOT, '--test=spec'], sources)
80
+ assert_basic_paths_and_files
81
+ assert_generated_file 'test/test_helper.rb' do |helper_contents|
82
+ assert_match(/sinatra\/test\/spec/, helper_contents)
83
+ end
84
+ assert_generated_file "test/test_#{app_name}.rb" do |test_contents|
85
+ assert_match(/describe/, test_contents)
86
+ end
87
+ end
88
+
89
+ def test_generate_app_with_shoulda_test_option
90
+ run_generator('sinatra_app', [APP_ROOT, '--test=shoulda'], sources)
91
+ assert_basic_paths_and_files
92
+ assert_generated_file 'test/test_helper.rb' do |helper_contents|
93
+ assert_match(/sinatra\/test\/unit/, helper_contents)
94
+ assert_match(/shoulda/, helper_contents)
95
+ end
96
+ assert_generated_file "test/test_#{app_name}.rb" do |test_contents|
97
+ assert_match(/context/, test_contents)
98
+ end
99
+ end
100
+
101
+ def test_generate_app_with_test_unit_option
102
+ run_generator('sinatra_app', [APP_ROOT, '--test=unit'], sources)
103
+ assert_basic_paths_and_files
104
+ assert_generated_file 'test/test_helper.rb' do |helper_contents|
105
+ assert_match(/sinatra\/test\/unit/, helper_contents)
106
+ end
107
+ assert_generated_file "test/test_#{app_name}.rb" do |test_contents|
108
+ assert_match(/def test/, test_contents)
109
+ end
110
+ end
111
+
112
+ def test_generate_app_with_views_haml_option
113
+ run_generator('sinatra_app', [APP_ROOT, '--views=erb'], sources)
114
+ assert_basic_paths_and_files
115
+ assert_generated_file 'app.rb' do |app_contents|
116
+ assert_match(/erb \:index/, app_contents)
117
+ end
118
+ assert_generated_file 'views/layout.erb'
119
+ assert_generated_file 'views/index.erb'
120
+ end
121
+
122
+ def test_generate_app_with_views_haml_option
123
+ run_generator('sinatra_app', [APP_ROOT, '--views=haml'], sources)
124
+ assert_basic_paths_and_files
125
+ assert_generated_file 'app.rb' do |app_contents|
126
+ assert_match(/haml \:index/, app_contents)
127
+ end
128
+ assert_generated_file 'views/layout.haml'
129
+ assert_generated_file 'views/index.haml'
130
+ end
131
+
132
+ def test_generate_app_with_views_builder_option
133
+ run_generator('sinatra_app', [APP_ROOT, '--views=builder'], sources)
134
+ assert_basic_paths_and_files
135
+ assert_generated_file 'app.rb' do |app_contents|
136
+ assert_match(/builder \:index/, app_contents)
137
+ end
138
+ assert_generated_file 'views/index.builder'
139
+ end
140
+
141
+ def test_generate_app_with_scripts_option
142
+ run_generator('sinatra_app', [APP_ROOT, '--scripts'], sources)
143
+ assert_basic_paths_and_files
144
+ assert_directory_exists 'script'
145
+ assert_generated_file 'script/destroy'
146
+ assert_generated_file 'script/generate'
147
+ end
148
+
149
+ private
150
+ def assert_basic_paths_and_files
151
+ assert_directory_exists 'lib'
152
+ assert_directory_exists 'test'
153
+ assert_directory_exists 'public'
154
+ assert_directory_exists 'views'
155
+ assert_generated_file 'config.ru'
156
+ assert_generated_file 'app.rb'
157
+ assert_generated_file 'Rakefile'
158
+ assert_generated_file 'config.yml'
159
+ assert_generated_module "lib/#{app_name}"
160
+ end
161
+
162
+
163
+ def sources
164
+ [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))]
165
+ end
166
+
167
+ def app_name
168
+ File.basename(APP_ROOT)
169
+ end
170
+
171
+ def generator_path
172
+ "app_generators"
173
+ end
174
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quirkey-sinatra-gen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Quint
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-16 00:00:00 -08:00
13
+ default_executable: sinatra-gen
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubigen
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.3.3
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: newgem
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.2.1
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: hoe
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.0
41
+ version:
42
+ description: sinatra-gen generates a common file structure and basic app files for a web app utilizing the sinatra framework. For more information on sinatra, check out http://sinatra.rubyforge.org
43
+ email:
44
+ - aaron@quirkey.com
45
+ executables:
46
+ - sinatra-gen
47
+ extensions: []
48
+
49
+ extra_rdoc_files:
50
+ - History.txt
51
+ - Manifest.txt
52
+ - PostInstall.txt
53
+ - README.rdoc
54
+ files:
55
+ - History.txt
56
+ - Manifest.txt
57
+ - PostInstall.txt
58
+ - README.rdoc
59
+ - Rakefile
60
+ - app_generators/sinatra_app/USAGE
61
+ - app_generators/sinatra_app/sinatra_app_generator.rb
62
+ - app_generators/sinatra_app/templates/Capfile
63
+ - app_generators/sinatra_app/templates/Rakefile.erb
64
+ - app_generators/sinatra_app/templates/app.rb.erb
65
+ - app_generators/sinatra_app/templates/config.ru.erb
66
+ - app_generators/sinatra_app/templates/config.yml
67
+ - app_generators/sinatra_app/templates/config/deploy.rb.erb
68
+ - app_generators/sinatra_app/templates/lib/module.rb.erb
69
+ - app_generators/sinatra_app/templates/test/test_app_rspec.rb.erb
70
+ - app_generators/sinatra_app/templates/test/test_app_shoulda.rb.erb
71
+ - app_generators/sinatra_app/templates/test/test_app_spec.rb.erb
72
+ - app_generators/sinatra_app/templates/test/test_app_unit.rb.erb
73
+ - app_generators/sinatra_app/templates/test/test_helper.rb.erb
74
+ - app_generators/sinatra_app/templates/views/builder_index.erb
75
+ - app_generators/sinatra_app/templates/views/erb_index.erb
76
+ - app_generators/sinatra_app/templates/views/erb_layout.erb
77
+ - app_generators/sinatra_app/templates/views/haml_index.erb
78
+ - app_generators/sinatra_app/templates/views/haml_layout.erb
79
+ - bin/sinatra-gen
80
+ - lib/sinatra-gen.rb
81
+ - sinatra-gen.gemspec
82
+ - test/test_generator_helper.rb
83
+ - test/test_helper.rb
84
+ - test/test_sinatra_app_generator.rb
85
+ has_rdoc: true
86
+ homepage: http://github.com/quirkey/sinatra-gen
87
+ post_install_message: PostInstall.txt
88
+ rdoc_options:
89
+ - --main
90
+ - README.rdoc
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ requirements: []
106
+
107
+ rubyforge_project: sinatra-gen
108
+ rubygems_version: 1.2.0
109
+ signing_key:
110
+ specification_version: 2
111
+ summary: sinatra-gen generates a common file structure and basic app files for a web app utilizing the sinatra framework
112
+ test_files:
113
+ - test/test_generator_helper.rb
114
+ - test/test_helper.rb
115
+ - test/test_sinatra_app_generator.rb