sinatra_more 0.3.10 → 0.3.11

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/README.rdoc CHANGED
@@ -136,8 +136,8 @@ methods should be very familiar to anyone who has used rails view helpers.
136
136
  * <tt>link_to('/dashboard', :class => 'blocky') { ...content... }</tt>
137
137
  * <tt>mail_to(email, caption=nil, mail_options={})</tt>
138
138
  * Creates a mailto link tag to the specified email_address
139
- * <tt>mail_to "me@demo.com"</tt> # => <a href="mailto:me@demo.com">me@demo.com</a>
140
- * <tt>mail_to "me@demo.com", "My Email"</tt> # => <a href="mailto:me@demo.com">My Email</a>
139
+ * <tt>mail_to "me@demo.com"</tt>
140
+ * <tt>mail_to "me@demo.com", "My Email", :subject => "Feedback", :cc => 'test@demo.com'</tt>
141
141
  * <tt>image_tag(url, options={})</tt>
142
142
  * Creates an image element with given url and options
143
143
  * <tt>image_tag('icons/avatar.png')</tt>
@@ -263,7 +263,7 @@ The following are fields provided by AbstractFormBuilder that can be used within
263
263
  * <tt>submit(caption, options={})</tt>
264
264
  * <tt>f.submit "Update", :class => 'long'</tt>
265
265
  * <tt>image_submit(source, options={})</tt>
266
- * <tt>f.submit "submit.png", :class => 'long'</tt>
266
+ * <tt>f.image_submit "submit.png", :class => 'long'</tt>
267
267
 
268
268
  A form_for using these basic fields might look like:
269
269
 
@@ -595,7 +595,9 @@ The simplest possible command to generate a base application would be:
595
595
 
596
596
  This would construct a Sinatra application DemoApp (which extends from Sinatra::Application)
597
597
  inside the folder 'demo_app' at our current path. Inside the application there would be configuration and
598
- setup performed for the default components. You can also define specific components to be used:
598
+ setup performed for the default components.
599
+
600
+ You can also define specific components to be used:
599
601
 
600
602
  $ sinatra_gen demo_app . --test=rspec --renderer=haml --mock=rr --script=jquery --orm datamapper
601
603
 
@@ -610,17 +612,27 @@ The available components and their default options are listed below:
610
612
  * mock: <tt>mocha</tt> (default), <tt>rr</tt>
611
613
  * script: <tt>jquery</tt> (default), <tt>prototype</tt>, <tt>rightjs</tt>
612
614
  * orm: <tt>datamapper</tt> (default), <tt>mongomapper</tt>, <tt>activerecord</tt>, <tt>sequel</tt>
615
+
616
+ The generator uses the <tt>bundler</tt> gem to resolve any application dependencies when the application is newly created.
617
+ The necessary bundler command can be executed automatically through the generator with
618
+
619
+ $ sinatra_gen demo_app . --run_bundler # alias -b
620
+
621
+ or this can be done manually through executing command <tt>gem bundle</tt> in the terminal at the root of the generated application.
622
+ If not executed manually, the bundling will be performed automatically the first time the application attempts to boot.
623
+ Note that this command only has to be performed when the application is first generated or when the Gemfile is modified.
613
624
 
614
- The generator framework within sinatra_more is highly extensible and additional components and tools can easily be added.
625
+ The generator framework within sinatra_more is extensible and additional components and tools can be added easily.
615
626
  This would be achieved through forking our project and reading through the code in <tt>/generators/sinatra_generator.rb</tt> and
616
627
  the setup instructions inside the relevant files within <tt>/generators/components/</tt>. We are happy to accept pull requests
617
628
  for additional component types not originally included (although helping us maintain them would also be appreciated).
618
629
 
619
- We are planning to add additional generator actions such as:
630
+ We are also planning to add generator actions such as:
620
631
 
621
- * Model generator (working for any of the available orms listed)
622
- * Routes generator
623
- * Migrations generator
632
+ * Model generation (working for any of the available orms listed)
633
+ * Routes generation
634
+ * Mailer generation
635
+ * Migrations generation
624
636
 
625
637
  See the wiki article for additional information: <http://wiki.github.com/nesquena/sinatra_more/generator>
626
638
 
@@ -630,7 +642,8 @@ See the wiki article for additional information: <http://wiki.github.com/nesquen
630
642
  * Thanks to sbfaulkner for the <tt>sinatra-helpers</tt> code that I browsed through many times while starting this library.
631
643
  * Thanks to vestel for the excellent modified <tt>pony</tt> fork which in part powers the mailer_plugin (http://github.com/vestel/pony)
632
644
  * Thanks to focat and sinatra-content-for library (http://github.com/focat/sinatra-content-for) for a good content_for starting point
633
- * Thanks to wycats and all for the awesome Thor gem which made creating the sinatra generator relatively painless
645
+ * Thanks to wycats and others for the awesome Thor gem which made creating the sinatra generator relatively painless
646
+ * Thanks to wycats and others for the bundler gem which made bundling the required gems for an application easy
634
647
 
635
648
  == Contributors
636
649
 
data/ROADMAP ADDED
@@ -0,0 +1,78 @@
1
+ Working with lipsiadmin:
2
+
3
+ 1) Proof of concept for the Sinatra Framework
4
+ 2) Adding in additional features to the current sinatra_more (more generators, helpers, etc)
5
+ 3) Split plugin up into individual gems for better organization
6
+ 4) Porting of lipsiadmin over to sinatra
7
+ 5) First produciton application
8
+ 6) Build Sinatra Framework Website
9
+
10
+ Use Bundler for managing dependencies:
11
+ * http://github.com/wycats/bundler
12
+ * http://www.engineyard.com/blog/2009/using-the-rubygems-bundler-for-your-app/
13
+
14
+ Framework structure:
15
+
16
+ * sinatra-core (the existing sinatra framework) <= from Sinatra
17
+ * sinatra-helpers (adds the markup and renderer helpers) <= from MarkupPlugin, RenderPlugin
18
+ * sinatra-mailer (mail handling for sinatra applications) <= from MailerPlugin
19
+ * sinatra-gen (easy generation of and for sinatra apps) <= from Generator
20
+ * sinatra-admin (admin management dashboard for content) <= from Lipsiadmin (ported)
21
+ * sinatra-cache (page and fragment caching support)
22
+ * sinatra-mapping (sinatra route mapping system)
23
+
24
+ 'sinatra-mapping' Routing Concept:
25
+
26
+ namespace :admin do
27
+ get :show do
28
+ ...
29
+ end
30
+ end
31
+
32
+ get :accounts do
33
+ ...
34
+ end
35
+
36
+ map(:admin, :show).to("/my-admin/:id/show")
37
+ map(:accounts).to("/show-me-my/accounts")
38
+
39
+ # or
40
+
41
+ map :admin do |namespace|
42
+ namespace.map(:show).to("/my-admin/:id/show")
43
+ end
44
+
45
+ # and to use
46
+ link_to "Show Admin", admin_show_path(:id => 5)
47
+ link_to "Accounts", accounts_path
48
+ # or maybe
49
+ link_to "Show Admin", url_for(:admin, :show, :id => 5)
50
+ link_to "Accounts", url_for(:accounts)
51
+
52
+ 'sinatra-cache' Caching concept:
53
+
54
+ # in models
55
+ class Person
56
+ def something_expensive
57
+ Sinatra::Cache.get('key')
58
+ Sinatra::Cache.set('key', value)
59
+ Sinatra::Cache.fetch('key') { 'value' }
60
+ end
61
+ end
62
+
63
+ # fragment in route
64
+ get '/cache2' do
65
+ cache 'cache2', :expiry => 10 do
66
+ 'Hello Cache2'
67
+ end
68
+ end
69
+
70
+ # fragment in view
71
+ # /views/test.haml
72
+ - cache 'test', :expiry => 10 do
73
+ = partial 'item', :collection => @items
74
+
75
+ # page
76
+ get '/example', :cache => true do
77
+ haml_template 'accounts/index'
78
+ end
data/Rakefile CHANGED
@@ -16,6 +16,7 @@ begin
16
16
  gem.add_runtime_dependency "tilt", ">= 0.2"
17
17
  gem.add_runtime_dependency "thor", ">= 0.11.8"
18
18
  gem.add_runtime_dependency "activesupport", ">= 2.2.2"
19
+ gem.add_runtime_dependency "bundler"
19
20
  gem.add_development_dependency "haml", ">= 2.2.1"
20
21
  gem.add_development_dependency "shoulda", ">= 2.10.2"
21
22
  gem.add_development_dependency "mocha", ">= 0.9.7"
data/TODO CHANGED
@@ -1,12 +1,6 @@
1
- = UNFINISHED
1
+ = RESOURCES
2
2
 
3
- * Add support for model, routes, migration generator types based on components
4
- * Add support for form.fields_for (one-to-one, nested and many associations like in rails)
5
- * Add support for check_box_group, radio_button_group which create a set of checkboxes or radio buttons
6
- * Become total warden solution (basically just require warden gem installed, do everything else)
7
- * Look into removing overlapping methods and simply leverage sinatra_warden
8
- * Take advantage of shared strategies: http://github.com/hassox/warden_strategies/tree/master/lib/
9
- * Check out the following sinatra extensions:
3
+ - Check out the following sinatra extensions:
10
4
  * http://github.com/emk/sinatra-url-for/
11
5
  * http://github.com/wbzyl/sinatra-static-assets
12
6
  * http://github.com/hallison/sinatra-mapping/
@@ -14,8 +8,28 @@
14
8
  * http://github.com/giraffesoft/classy_resources
15
9
  * http://github.com/nakajima/capinatra
16
10
  * http://github.com/deadprogrammer/spork
11
+ * http://github.com/gioext/sinatra-memcache
12
+ * http://github.com/kematzy/sinatra-cache
17
13
  * http://r18n.rubyforge.org/#sinatra
18
14
 
15
+ = UNFINISHED
16
+
17
+ == Generator
18
+
19
+ * Add support for model, routes, migration generator types based on components
20
+ * Add support for bundler (http://github.com/wycats/bundler) to make setting up a generated app easy
21
+
22
+ == MarkupPlugin
23
+
24
+ * Add support for form.fields_for (one-to-one, nested and many associations like in rails)
25
+ * Add support for check_box_group, radio_button_group which create a set of checkboxes or radio buttons
26
+
27
+ == WardenPlugin
28
+
29
+ * Become total warden solution (basically just require warden gem installed, do everything) (?)
30
+ * Look into removing overlapping methods and simply leveraging sinatra_warden
31
+ * Take advantage of shared strategies: http://github.com/hassox/warden_strategies/tree/master/lib/
32
+
19
33
  = COMPLETED
20
34
 
21
35
  * Add support for button tag method, mail_to helper
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.10
1
+ 0.3.11
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ log/**/*
3
+ tmp/**/*
4
+ vendor/gems/gems
5
+ vendor/gems/specifications
6
+ vendor/gems/doc
7
+ vendor/gems/environment.rb
@@ -0,0 +1,13 @@
1
+ clear_sources
2
+ source 'http://gemcutter.org'
3
+ # Base requirements
4
+ gem 'sinatra'
5
+ gem 'sinatra_more'
6
+ gem 'rack-flash'
7
+ gem 'warden'
8
+ gem 'bcrypt-ruby', :require_as => 'bcrypt'
9
+
10
+ # Component requirements
11
+
12
+ # Testing requirements
13
+ gem 'rack-test', :require_as => 'rack/test', :only => :testing
@@ -1,6 +1,6 @@
1
1
  RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
2
2
 
3
- require File.dirname(__FILE__) + '/app.rb'
3
+ require File.dirname(__FILE__) + '/config/boot.rb'
4
4
 
5
5
  FileUtils.mkdir_p 'log' unless File.exists?('log')
6
6
  log = File.new("log/sinatra.log", "a")
@@ -1,13 +1,12 @@
1
1
  # This file is merely for beginning the boot process, check dependencies.rb for more information
2
+ require 'rubygems'
3
+ require 'sinatra/base'
2
4
 
3
5
  RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
4
6
  ROOT_DIR = File.dirname(__FILE__) + '/../' unless defined? ROOT_DIR
5
7
 
6
8
  # Helper method for file references.
7
- #
8
- # @param args [Array] Path components relative to ROOT_DIR.
9
- # @example Referencing a file in config called settings.yml:
10
- # root_path("config", "settings.yml")
9
+ # root_path("config", "settings.yml")
11
10
  def root_path(*args)
12
11
  File.join(ROOT_DIR, *args)
13
12
  end
@@ -26,6 +25,18 @@ class <%= @class_name %> < Sinatra::Application
26
25
  set :default_builder, 'StandardFormBuilder'
27
26
  set :environment, RACK_ENV if defined?(RACK_ENV)
28
27
 
28
+ # Attempts to require all dependencies with bundler, if this fails, bundle and then try again
29
+ def self.bundler_require_dependencies(environment=nil)
30
+ require 'bundler'
31
+ require File.expand_path(File.join(File.dirname(__FILE__), '/../vendor', 'gems', 'environment'))
32
+ Bundler.require_env(environment)
33
+ rescue LoadError => e
34
+ puts "Bundler must be run to resolve dependencies!"
35
+ system('gem bundle')
36
+ puts "Retrying with dependencies resolved..."
37
+ retry
38
+ end
39
+
29
40
  # Dependencies contains all required gems and core configuration
30
41
  require File.dirname(__FILE__) + '/dependencies.rb'
31
42
  end
@@ -1,7 +1,7 @@
1
1
  # Dependencies contains all required gems, helpers and core configuration
2
2
 
3
3
  class <%= @class_name %> < Sinatra::Application
4
- %w[rubygems rack-flash warden sinatra_more bcrypt].each { |gem| require gem }
4
+ bundler_require_dependencies
5
5
 
6
6
  # Required middleware
7
7
  use Rack::Session::Cookie
@@ -1,4 +1,5 @@
1
1
  RACK_ENV = 'test' unless defined?(RACK_ENV)
2
- %w[rubygems sinatra/base].each {|gem| require gem }
3
- require 'rack/test'
4
- require File.dirname(__FILE__) + "/../app"
2
+ require File.dirname(__FILE__) + "/../config/boot"
3
+ Bundler.require_env(:testing)
4
+
5
+ # Test configuration
@@ -1,27 +1,29 @@
1
1
  module SinatraMore
2
2
  module ComponentActions
3
- # Injects require statement into target file
4
- # insert_require('active_record', :path => "test/test_config.rb", :indent => 2)
5
- # options = { :path => '...', :indent => 2, :after => /.../ }
6
- def insert_require(*libs)
7
- options = libs.extract_options!
8
- options.reverse_merge!(:indent => 0, :after => /require\sgem.*?\n/)
9
- multiple_gem_require = "%w[#{libs.join(' ')}].each { |lib| require lib }\n"
10
- req = indent_spaces(options[:indent]) + (libs.size == 1 ? "require '#{libs}'\n" : multiple_gem_require)
11
- inject_into_file(options[:path], req, :after => options[:after])
3
+ # Adds all the specified gems into the Gemfile for bundler
4
+ # require_dependencies 'activerecord'
5
+ # require_dependencies 'mocha', 'bacon', :env => :testing
6
+ def require_dependencies(*gem_names)
7
+ options = gem_names.extract_options!
8
+ gem_names.each { |lib| insert_into_gemfile(lib, options) }
12
9
  end
13
10
 
14
- # Returns space characters of given count
15
- # indent_spaces(2)
16
- def indent_spaces(count)
17
- ' ' * count
11
+ # Inserts a required gem into the Gemfile to add the bundler dependency
12
+ # insert_dependency_to_gemfile(name)
13
+ # insert_dependency_to_gemfile(name, :env => :testing)
14
+ def insert_into_gemfile(name, options={})
15
+ after_pattern = "# Component requirements\n"
16
+ after_pattern = "# #{options[:env].to_s.capitalize} requirements\n" if environment = options[:env]
17
+ include_text = "gem '#{name}'" << (environment ? ", :only => #{environment.inspect}" : "") << "\n"
18
+ options.merge!(:content => include_text, :after => after_pattern)
19
+ inject_into_file('Gemfile', options[:content], :after => options[:after])
18
20
  end
19
21
 
20
22
  # Injects the test class text into the test_config file for setting up the test gen
21
23
  # insert_test_suite_setup('...CLASS_NAME...')
22
24
  # => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @class_name), :after => "set :environment, :test\n")
23
25
  def insert_test_suite_setup(suite_text, options={})
24
- options.reverse_merge!(:path => "test/test_config.rb", :after => /require.*?app.*?\n/)
26
+ options.reverse_merge!(:path => "test/test_config.rb", :after => /Test configuration\n/)
25
27
  inject_into_file(options[:path], suite_text.gsub(/CLASS_NAME/, @class_name), :after => options[:after])
26
28
  end
27
29
 
@@ -33,5 +35,11 @@ module SinatraMore
33
35
  include_text = indent_spaces(options[:indent]) + "include #{library_name}\n"
34
36
  inject_into_file(options[:path], include_text, :after => options[:after])
35
37
  end
38
+
39
+ # Returns space characters of given count
40
+ # indent_spaces(2)
41
+ def indent_spaces(count)
42
+ ' ' * count
43
+ end
36
44
  end
37
45
  end
@@ -1,7 +1,7 @@
1
1
  module SinatraMore
2
2
  module MochaMockGen
3
3
  def setup_mock
4
- insert_require 'mocha', :path => "test/test_config.rb", :after => "require 'rack/test'\n"
4
+ require_dependencies 'mocha', :env => :testing
5
5
  insert_mocking_include "Mocha::API", :path => "test/test_config.rb"
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module SinatraMore
2
2
  module RrMockGen
3
3
  def setup_mock
4
- insert_require 'rr', :path => "test/test_config.rb", :after => "require 'rack/test'\n"
4
+ require_dependencies 'rr', :env => :testing
5
5
  insert_mocking_include "RR::Adapters::RRMethods", :path => "test/test_config.rb"
6
6
  end
7
7
  end
@@ -29,8 +29,8 @@ end
29
29
  AR
30
30
 
31
31
  RAKE = <<-RAKE
32
- require 'active_record'
33
32
  require 'sinatra/base'
33
+ require 'active_record'
34
34
 
35
35
  namespace :db do
36
36
  desc "Migrate the database"
@@ -63,7 +63,16 @@ end
63
63
  MIGRATION
64
64
 
65
65
  USER = <<-USER
66
- class User < ActiveRecord::Base
66
+ class User < ActiveRecord::Base
67
+ before_save :encrypt_password
68
+
69
+ attr_accessor :password, :password_confirmation
70
+
71
+ def validate
72
+ errors.add :password, "must not be empty" if self.crypted_password.blank? && password.blank?
73
+ errors.add :password, "must match password confirmation" unless password == password_confirmation
74
+ end
75
+
67
76
  def self.authenticate(username, password)
68
77
  user = User.first(:conditions => { :username => username })
69
78
  user && user.has_password?(password) ? user : nil
@@ -80,7 +89,7 @@ end
80
89
  USER
81
90
 
82
91
  def setup_orm
83
- insert_require 'active_record', :path => "config/dependencies.rb", :indent => 2
92
+ require_dependencies 'activerecord'
84
93
  create_file("config/initializers/active_record.rb", AR)
85
94
  create_file("Rakefile", RAKE)
86
95
  create_file("db/migrate/001_create_users.rb", MIGRATION)
@@ -21,6 +21,12 @@ class User
21
21
  property :email, String
22
22
  property :crypted_password, String
23
23
 
24
+ attr_accessor :password, :password_confirmation
25
+
26
+ before :save, :encrypt_password
27
+
28
+ validates_present :password, :password_confirmation
29
+
24
30
  def self.authenticate(username, password)
25
31
  user = User.first(:username => username)
26
32
  user && user.has_password?(password) ? user : nil
@@ -38,7 +44,7 @@ User.auto_upgrade!
38
44
  USER
39
45
 
40
46
  def setup_orm
41
- insert_require 'dm-core', :path => "config/dependencies.rb", :indent => 2
47
+ require_dependencies 'dm-core'
42
48
  create_file("config/initializers/data_mapper.rb", DM)
43
49
  create_file("app/models/user.rb", USER)
44
50
  end
@@ -91,7 +91,7 @@ end
91
91
  AUTH
92
92
 
93
93
  def setup_orm
94
- insert_require 'mongo_mapper', :path => "config/dependencies.rb", :indent => 2
94
+ require_dependencies 'mongo_mapper'
95
95
  create_file("config/initializers/mongo_db.rb", MONGO)
96
96
  create_file("lib/ext/mongo_mapper.rb", CONCERNED)
97
97
  create_file("app/models/user.rb", USER)
@@ -13,35 +13,47 @@ end
13
13
  SEQUEL
14
14
 
15
15
  USER = <<-USER
16
- class User < Sequel::Model(:users)
17
- unless table_exists?
18
- set_schema do
19
- primary_key :id
20
- string :name
21
- string :username
22
- string :email
23
- string :crypted_password
16
+ class User < Sequel::Model(:users)
17
+ unless table_exists?
18
+ set_schema do
19
+ primary_key :id
20
+ string :name
21
+ string :username
22
+ string :email
23
+ string :crypted_password
24
+ end
25
+ create_table
26
+ end
27
+
28
+ attr_accessor :password, :password_confirmation
29
+
30
+ def self.authenticate(username, password)
31
+ user = User.filter(:username => username).first
32
+ user && user.has_password?(password) ? user : nil
33
+ end
34
+
35
+ def encrypt_password
36
+ return if password.blank?
37
+ self.crypted_password = BCrypt::Password.create(password)
38
+ end
39
+
40
+ def has_password?(password)
41
+ BCrypt::Password.new(crypted_password) == password
42
+ end
43
+
44
+ def before_save
45
+ encrypt_password
46
+ end
47
+
48
+ def validate
49
+ errors.add :password, "must not be empty" if self.crypted_password.blank? && password.blank?
50
+ errors.add :password, "must match password confirmation" unless password == password_confirmation
51
+ end
24
52
  end
25
- create_table
26
- end
27
-
28
- def self.authenticate(username, password)
29
- user = User.filter(:username => username).first
30
- user && user.has_password?(password) ? user : nil
31
- end
32
-
33
- def encrypt_password
34
- self.crypted_password = BCrypt::Password.create(password)
35
- end
36
-
37
- def has_password?(password)
38
- BCrypt::Password.new(crypted_password) == password
39
- end
40
- end
41
53
  USER
42
54
 
43
55
  def setup_orm
44
- insert_require 'sequel', :path => "config/dependencies.rb", :indent => 2
56
+ require_dependencies 'sequel'
45
57
  create_file("config/initializers/sequel.rb", SEQUEL)
46
58
  create_file("app/models/user.rb", USER)
47
59
  end
@@ -1,7 +1,7 @@
1
1
  module SinatraMore
2
2
  module ErbRendererGen
3
3
  def setup_renderer
4
- insert_require 'erb', :path => "config/dependencies.rb", :indent => 2
4
+ require_dependencies 'erubis'
5
5
  end
6
6
  end
7
7
  end
@@ -10,8 +10,9 @@ end
10
10
  HASSLE
11
11
 
12
12
  def setup_renderer
13
- insert_require('haml', 'sass', 'hassle', :path => 'config/dependencies.rb', :indent => 2)
13
+ require_dependencies 'haml', 'hassle'
14
14
  create_file("config/initializers/hassle.rb", HASSLE)
15
+ empty_directory('public/stylesheets/sass')
15
16
  end
16
17
  end
17
18
  end
@@ -11,7 +11,7 @@ end
11
11
  TEST
12
12
 
13
13
  def setup_test
14
- insert_require 'bacon', :path => "test/test_config.rb"
14
+ require_dependencies 'bacon', :env => :testing
15
15
  insert_test_suite_setup BACON_SETUP
16
16
  end
17
17
 
@@ -11,7 +11,7 @@ end
11
11
  TEST
12
12
 
13
13
  def setup_test
14
- insert_require 'riot', :path => "test/test_config.rb"
14
+ require_dependencies 'riot', :env => :testing
15
15
  insert_test_suite_setup RIOT_SETUP
16
16
  end
17
17
 
@@ -11,7 +11,7 @@ end
11
11
  TEST
12
12
 
13
13
  def setup_test
14
- insert_require 'spec', :path => "test/test_config.rb"
14
+ require_dependencies 'spec', :env => :testing
15
15
  insert_test_suite_setup RSPEC_SETUP
16
16
  end
17
17
 
@@ -11,7 +11,7 @@ end
11
11
  TEST
12
12
 
13
13
  def setup_test
14
- insert_require 'test/unit', 'shoulda', :path => "test/test_config.rb"
14
+ require_dependencies 'test/unit', 'shoulda', :env => :testing
15
15
  insert_test_suite_setup SHOULDA_SETUP
16
16
  end
17
17
 
@@ -11,7 +11,7 @@ end
11
11
  TEST
12
12
 
13
13
  def setup_test
14
- insert_require 'test/spec', :path => "test/test_config.rb"
14
+ require_dependencies 'test/spec', :path => "test/test_config.rb"
15
15
  insert_test_suite_setup TESTSPEC_SETUP
16
16
  end
17
17
 
@@ -12,11 +12,12 @@ module SinatraMore
12
12
  include Thor::Actions
13
13
  include SinatraMore::GeneratorActions
14
14
  include SinatraMore::ComponentActions
15
-
15
+
16
16
  desc "Description:\n\n\tsinatra_gen is the sinatra_more generators which generate or build on Sinatra applications."
17
17
 
18
18
  argument :name, :desc => "The name of your sinatra app"
19
19
  argument :path, :desc => "The path to create your app"
20
+ class_option :run_bundler, :aliases => '-b', :default => false, :type => :boolean
20
21
 
21
22
  # Definitions for the available customizable components
22
23
  component_option :orm, "database engine", :aliases => '-d', :choices => [:datamapper, :mongomapper, :activerecord, :sequel]
@@ -40,5 +41,13 @@ module SinatraMore
40
41
  execute_component_setup(comp, choice)
41
42
  end
42
43
  end
44
+
45
+ # Bundle all required components using bundler and Gemfile
46
+ def bundle_dependencies
47
+ if options[:run_bundle]
48
+ say "Bundling application dependencies using bundler..."
49
+ in_root { run 'gem bundle' }
50
+ end
51
+ end
43
52
  end
44
53
  end
data/sinatra_more.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra_more}
8
- s.version = "0.3.10"
8
+ s.version = "0.3.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Esquenazi"]
12
- s.date = %q{2009-11-11}
12
+ s.date = %q{2009-11-12}
13
13
  s.default_executable = %q{sinatra_gen}
14
14
  s.description = %q{Expands sinatra with standard helpers and tools to allow for complex applications}
15
15
  s.email = %q{nesquena@gmail.com}
@@ -23,11 +23,13 @@ Gem::Specification.new do |s|
23
23
  ".gitignore",
24
24
  "LICENSE",
25
25
  "README.rdoc",
26
+ "ROADMAP",
26
27
  "Rakefile",
27
28
  "TODO",
28
29
  "VERSION",
29
30
  "bin/sinatra_gen",
30
- "generators/base_app/app.rb.tt",
31
+ "generators/base_app/.gitignore",
32
+ "generators/base_app/Gemfile",
31
33
  "generators/base_app/app/.empty_directory",
32
34
  "generators/base_app/app/helpers/.empty_directory",
33
35
  "generators/base_app/app/helpers/view_helpers.rb",
@@ -168,6 +170,7 @@ Gem::Specification.new do |s|
168
170
  s.add_runtime_dependency(%q<tilt>, [">= 0.2"])
169
171
  s.add_runtime_dependency(%q<thor>, [">= 0.11.8"])
170
172
  s.add_runtime_dependency(%q<activesupport>, [">= 2.2.2"])
173
+ s.add_runtime_dependency(%q<bundler>, [">= 0"])
171
174
  s.add_development_dependency(%q<haml>, [">= 2.2.1"])
172
175
  s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
173
176
  s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
@@ -178,6 +181,7 @@ Gem::Specification.new do |s|
178
181
  s.add_dependency(%q<tilt>, [">= 0.2"])
179
182
  s.add_dependency(%q<thor>, [">= 0.11.8"])
180
183
  s.add_dependency(%q<activesupport>, [">= 2.2.2"])
184
+ s.add_dependency(%q<bundler>, [">= 0"])
181
185
  s.add_dependency(%q<haml>, [">= 2.2.1"])
182
186
  s.add_dependency(%q<shoulda>, [">= 2.10.2"])
183
187
  s.add_dependency(%q<mocha>, [">= 0.9.7"])
@@ -189,6 +193,7 @@ Gem::Specification.new do |s|
189
193
  s.add_dependency(%q<tilt>, [">= 0.2"])
190
194
  s.add_dependency(%q<thor>, [">= 0.11.8"])
191
195
  s.add_dependency(%q<activesupport>, [">= 2.2.2"])
196
+ s.add_dependency(%q<bundler>, [">= 0"])
192
197
  s.add_dependency(%q<haml>, [">= 2.2.1"])
193
198
  s.add_dependency(%q<shoulda>, [">= 2.10.2"])
194
199
  s.add_dependency(%q<mocha>, [">= 0.9.7"])
@@ -42,20 +42,27 @@ class TestSkeletonGenerator < Test::Unit::TestCase
42
42
  assert_match /Applying.*?prototype.*?script/, buffer
43
43
  assert_match /Applying.*?erb.*?renderer/, buffer
44
44
  end
45
+ should "output gem files for base app" do
46
+ silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--script=none']) }
47
+ assert_match_in_file(/gem 'sinatra'/, '/tmp/sample_app/Gemfile')
48
+ assert_match_in_file(/gem 'sinatra_more'/, '/tmp/sample_app/Gemfile')
49
+ assert_match_in_file(/gem 'rack-flash'/, '/tmp/sample_app/Gemfile')
50
+ assert_match_in_file(/gem 'rack-test'/, '/tmp/sample_app/Gemfile')
51
+ end
45
52
  end
46
53
 
47
- context "the generator for mock component" do
54
+ context "a generator for mock component" do
48
55
  should "properly generate for rr" do
49
56
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--mock=rr', '--script=none']) }
50
57
  assert_match /Applying.*?rr.*?mock/, buffer
51
- assert_match_in_file(/require 'rr'/, '/tmp/sample_app/test/test_config.rb')
58
+ assert_match_in_file(/gem 'rr'/, '/tmp/sample_app/Gemfile')
52
59
  assert_match_in_file(/class.*?include RR::Adapters::RRMethods/m, '/tmp/sample_app/test/test_config.rb')
53
60
  end
54
61
 
55
62
  should "properly generate default for mocha" do
56
63
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--mock=mocha', '--script=none']) }
57
64
  assert_match /Applying.*?mocha.*?mock/, buffer
58
- assert_match_in_file(/require 'mocha'/, '/tmp/sample_app/test/test_config.rb')
65
+ assert_match_in_file(/gem 'mocha'/, '/tmp/sample_app/Gemfile')
59
66
  assert_match_in_file(/class.*?include Mocha::API/m, '/tmp/sample_app/test/test_config.rb')
60
67
  end
61
68
  end
@@ -66,7 +73,7 @@ class TestSkeletonGenerator < Test::Unit::TestCase
66
73
  SinatraMore::SkeletonGenerator.instance_eval("undef setup_orm if respond_to?('setup_orm')")
67
74
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=sequel', '--script=none']) }
68
75
  assert_match /Applying.*?sequel.*?orm/, buffer
69
- assert_match_in_file(/require 'sequel'/, '/tmp/sample_app/config/dependencies.rb')
76
+ assert_match_in_file(/gem 'sequel'/, '/tmp/sample_app/Gemfile')
70
77
  assert_match_in_file(/SequelInitializer/, '/tmp/sample_app/config/initializers/sequel.rb')
71
78
  assert_match_in_file(/class User < Sequel::Model/, '/tmp/sample_app/app/models/user.rb')
72
79
  end
@@ -74,7 +81,7 @@ class TestSkeletonGenerator < Test::Unit::TestCase
74
81
  should "properly generate for activerecord" do
75
82
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=activerecord', '--script=none']) }
76
83
  assert_match /Applying.*?activerecord.*?orm/, buffer
77
- assert_match_in_file(/require 'active_record'/, '/tmp/sample_app/config/dependencies.rb')
84
+ assert_match_in_file(/gem 'activerecord'/, '/tmp/sample_app/Gemfile')
78
85
  assert_match_in_file(/ActiveRecordInitializer/, '/tmp/sample_app/config/initializers/active_record.rb')
79
86
  assert_match_in_file(/Migrate the database/, '/tmp/sample_app/Rakefile')
80
87
  assert_match_in_file(/CreateUsers < ActiveRecord::Migration/, '/tmp/sample_app/db/migrate/001_create_users.rb')
@@ -84,7 +91,7 @@ class TestSkeletonGenerator < Test::Unit::TestCase
84
91
  should "properly generate default for datamapper" do
85
92
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=datamapper', '--script=none']) }
86
93
  assert_match /Applying.*?datamapper.*?orm/, buffer
87
- assert_match_in_file(/require 'dm-core'/, '/tmp/sample_app/config/dependencies.rb')
94
+ assert_match_in_file(/gem 'dm-core'/, '/tmp/sample_app/Gemfile')
88
95
  assert_match_in_file(/DataMapperInitializer/, '/tmp/sample_app/config/initializers/data_mapper.rb')
89
96
  assert_match_in_file(/class User.*?include DataMapper::Resource/m, '/tmp/sample_app/app/models/user.rb')
90
97
  end
@@ -92,7 +99,7 @@ class TestSkeletonGenerator < Test::Unit::TestCase
92
99
  should "properly generate for mongomapper" do
93
100
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=mongomapper', '--script=none']) }
94
101
  assert_match /Applying.*?mongomapper.*?orm/, buffer
95
- assert_match_in_file(/require 'mongo_mapper'/, '/tmp/sample_app/config/dependencies.rb')
102
+ assert_match_in_file(/gem 'mongo_mapper'/, '/tmp/sample_app/Gemfile')
96
103
  assert_match_in_file(/MongoDbInitializer/, '/tmp/sample_app/config/initializers/mongo_db.rb')
97
104
  assert_match_in_file(/class User.*?include MongoMapper::Document/m, '/tmp/sample_app/app/models/user.rb')
98
105
  end
@@ -102,13 +109,14 @@ class TestSkeletonGenerator < Test::Unit::TestCase
102
109
  should "properly generate default for erb" do
103
110
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--renderer=erb', '--script=none']) }
104
111
  assert_match /Applying.*?erb.*?renderer/, buffer
105
- assert_match_in_file(/require 'erb'/, '/tmp/sample_app/config/dependencies.rb')
112
+ assert_match_in_file(/gem 'erubis'/, '/tmp/sample_app/Gemfile')
106
113
  end
107
114
 
108
115
  should "properly generate for haml" do
109
116
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--renderer=haml','--script=none']) }
110
117
  assert_match /Applying.*?haml.*?renderer/, buffer
111
- assert_match_in_file(/haml.*sass.*hassle.*require/, '/tmp/sample_app/config/dependencies.rb')
118
+ assert_match_in_file(/gem 'haml'/, '/tmp/sample_app/Gemfile')
119
+ assert_match_in_file(/gem 'hassle'/, '/tmp/sample_app/Gemfile')
112
120
  assert_match_in_file(/HassleInitializer/, '/tmp/sample_app/config/initializers/hassle.rb')
113
121
  end
114
122
  end
@@ -138,35 +146,35 @@ class TestSkeletonGenerator < Test::Unit::TestCase
138
146
  should "properly default generate for bacon" do
139
147
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=bacon', '--script=none']) }
140
148
  assert_match /Applying.*?bacon.*?test/, buffer
141
- assert_match_in_file(/require 'bacon'/, '/tmp/sample_app/test/test_config.rb')
149
+ assert_match_in_file(/gem 'bacon'/, '/tmp/sample_app/Gemfile')
142
150
  assert_match_in_file(/Bacon::Context/, '/tmp/sample_app/test/test_config.rb')
143
151
  end
144
152
 
145
153
  should "properly generate for riot" do
146
154
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=riot', '--script=none']) }
147
155
  assert_match /Applying.*?riot.*?test/, buffer
148
- assert_match_in_file(/require 'riot'/, '/tmp/sample_app/test/test_config.rb')
156
+ assert_match_in_file(/gem 'riot'/, '/tmp/sample_app/Gemfile')
149
157
  assert_match_in_file(/Riot::Situation/, '/tmp/sample_app/test/test_config.rb')
150
158
  end
151
159
 
152
160
  should "properly generate for rspec" do
153
161
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=rspec', '--script=none']) }
154
162
  assert_match /Applying.*?rspec.*?test/, buffer
155
- assert_match_in_file(/require 'spec'/, '/tmp/sample_app/test/test_config.rb')
163
+ assert_match_in_file(/gem 'spec'/, '/tmp/sample_app/Gemfile')
156
164
  assert_match_in_file(/Spec::Runner/, '/tmp/sample_app/test/test_config.rb')
157
165
  end
158
166
 
159
167
  should "properly generate for shoulda" do
160
168
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=shoulda', '--script=none']) }
161
169
  assert_match /Applying.*?shoulda.*?test/, buffer
162
- assert_match_in_file(/test\/unit.*shoulda.*require/, '/tmp/sample_app/test/test_config.rb')
170
+ assert_match_in_file(/gem 'shoulda'/, '/tmp/sample_app/Gemfile')
163
171
  assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_app/test/test_config.rb')
164
172
  end
165
173
 
166
174
  should "properly generate for testspec" do
167
175
  buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=testspec', '--script=none']) }
168
176
  assert_match /Applying.*?testspec.*?test/, buffer
169
- assert_match_in_file(/require 'test\/spec'/, '/tmp/sample_app/test/test_config.rb')
177
+ assert_match_in_file(/gem 'test\/spec'/, '/tmp/sample_app/Gemfile')
170
178
  assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_app/test/test_config.rb')
171
179
  end
172
180
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_more
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-11 00:00:00 -08:00
12
+ date: 2009-11-12 00:00:00 -08:00
13
13
  default_executable: sinatra_gen
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,16 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 2.2.2
54
54
  version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
55
65
  - !ruby/object:Gem::Dependency
56
66
  name: haml
57
67
  type: :development
@@ -116,11 +126,13 @@ files:
116
126
  - .gitignore
117
127
  - LICENSE
118
128
  - README.rdoc
129
+ - ROADMAP
119
130
  - Rakefile
120
131
  - TODO
121
132
  - VERSION
122
133
  - bin/sinatra_gen
123
- - generators/base_app/app.rb.tt
134
+ - generators/base_app/.gitignore
135
+ - generators/base_app/Gemfile
124
136
  - generators/base_app/app/.empty_directory
125
137
  - generators/base_app/app/helpers/.empty_directory
126
138
  - generators/base_app/app/helpers/view_helpers.rb
@@ -1,5 +0,0 @@
1
- %w[rubygems sinatra/base].each { |gem| require gem }
2
-
3
- class <%= @class_name %> < Sinatra::Application
4
- load(File.dirname(__FILE__) + '/config/boot.rb')
5
- end