Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nesquena/sinatra_more
Browse files Browse the repository at this point in the history
  • Loading branch information
nesquena committed Nov 16, 2009
2 parents 38d2f05 + 6605c8a commit 33a46ed
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.rdoc
Expand Up @@ -691,7 +691,7 @@ The available components and their default options are listed below:
* renderer: <tt>erb</tt> (default), <tt>haml</tt>
* mock: <tt>mocha</tt> (default), <tt>rr</tt>
* script: <tt>jquery</tt> (default), <tt>prototype</tt>, <tt>rightjs</tt>
* orm: <tt>datamapper</tt> (default), <tt>mongomapper</tt>, <tt>activerecord</tt>, <tt>sequel</tt>
* orm: <tt>datamapper</tt> (default), <tt>mongomapper</tt>, <tt>activerecord</tt>, <tt>sequel</tt>, <tt>couchrest</tt>

The generator uses the <tt>bundler</tt> gem to resolve any application dependencies when the application is newly created.
The necessary bundler command can be executed automatically through the generator with
Expand Down Expand Up @@ -730,6 +730,7 @@ See the wiki article for additional information: <http://wiki.github.com/nesquen

* Nathan Esquenazi - Project creator and code maintainer
* Arthur Chiu - Forming the idea and various code contributions
* Rob Holland - Added couchrest ORM component to generator

== Known Issues

Expand Down
9 changes: 7 additions & 2 deletions ROADMAP
Expand Up @@ -27,7 +27,7 @@ Additional wish-list features (integrate existing plugin) (?)
* Internationalization - http://r18n.rubyforge.org/#sinatra
* Asynchronous Commands - http://github.com/deadprogrammer/spork
* Capistrano Deployment - http://github.com/nakajima/capinatra (?)
* Job Queue - http://github.com/adamcooke/resque (or http://github.com/bmizerany/sinatra-dj)
* Job Queue - http://github.com/adamcooke/resque (or http://github.com/bmizerany/sinatra-dj)

'sinatra-cache' Caching concept:

Expand Down Expand Up @@ -80,4 +80,9 @@ Additional wish-list features (integrate existing plugin) (?)

# and to use
link_to "Show Admin", url_for(:admin, :show, :id => 5)
link_to "Accounts", url_for(:accounts)
link_to "Accounts", url_for(:accounts)

'commands' Concept: (console (?) http://github.com/sickill/racksh)

$ sinatra_more console # loads console for sinatra
$ sinatra_more test # runs all test using specified testing framework
4 changes: 4 additions & 0 deletions generators/base_app/config/dependencies.rb.tt
@@ -1,5 +1,9 @@
# Dependencies contains all required gems, helpers and core configuration

def app(&block)
<%= @class_name %>.class_eval(&block)
end

class <%= @class_name %> < Sinatra::Application
bundler_require_dependencies

Expand Down
64 changes: 64 additions & 0 deletions generators/components/orms/couchrest_orm_gen.rb
@@ -0,0 +1,64 @@
module SinatraMore
module CouchrestOrmGen

COUCHREST = <<-COUCHREST
module CouchRestInitializer
def self.registered(app)
app.configure(:development) { set :couchdb, CouchRest.database!('your_dev_db_here') }
app.configure(:production) { set :couchdb, CouchRest.database!('your_production_db_here') }
app.configure(:test) { set :couchdb, CouchRest.database!('your_test_db_here') }
end
end
COUCHREST

USER = <<-USER
class User < CouchRest::ExtendedDocument
include CouchRest::Validation
use_database app { couchdb }
property :name
property :username
property :email
property :crypted_password
unique_id :id
attr_accessor :password, :password_confirmation
validates_is_confirmed :password
save_callback :before, :encrypt_password
def self.find(id)
get(id)
end
def self.id_for(username)
"user/\#{username}"
end
def self.authenticate(username, password)
user = User.get(id_for(username))
user && user.has_password?(password) ? user : nil
end
def id
self.class.id_for(username)
end
def encrypt_password
self.crypted_password = BCrypt::Password.create(password)
end
def has_password?(password)
BCrypt::Password.new(crypted_password) == password
end
end
USER

def setup_orm
require_dependencies 'couchrest'
create_file("config/initializers/couch_rest.rb", COUCHREST)
create_file("app/models/user.rb", USER)
end
end
end
2 changes: 1 addition & 1 deletion generators/skeleton_generator.rb
Expand Up @@ -20,7 +20,7 @@ def self.banner; "sinatra_gen [app_name] [path] [options]"; end
class_option :run_bundler, :aliases => '-b', :default => false, :type => :boolean

# Definitions for the available customizable components
component_option :orm, "database engine", :aliases => '-d', :choices => [:datamapper, :mongomapper, :activerecord, :sequel]
component_option :orm, "database engine", :aliases => '-d', :choices => [:datamapper, :mongomapper, :activerecord, :sequel, :couchrest]
component_option :test, "testing framework", :aliases => '-t', :choices => [:bacon, :shoulda, :rspec, :testspec, :riot]
component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr]
component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs]
Expand Down
1 change: 1 addition & 0 deletions sinatra_more.gemspec
Expand Up @@ -55,6 +55,7 @@ Gem::Specification.new do |s|
"generators/components/mocks/mocha_mock_gen.rb",
"generators/components/mocks/rr_mock_gen.rb",
"generators/components/orms/activerecord_orm_gen.rb",
"generators/components/orms/couchrest_orm_gen.rb",
"generators/components/orms/datamapper_orm_gen.rb",
"generators/components/orms/mongomapper_orm_gen.rb",
"generators/components/orms/sequel_orm_gen.rb",
Expand Down
8 changes: 8 additions & 0 deletions test/generators/test_skeleton_generator.rb
Expand Up @@ -103,6 +103,14 @@ def setup
assert_match_in_file(/MongoDbInitializer/, '/tmp/sample_app/config/initializers/mongo_db.rb')
assert_match_in_file(/class User.*?include MongoMapper::Document/m, '/tmp/sample_app/app/models/user.rb')
end

should "properly generate for couchrest" do
buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=couchrest', '--script=none']) }
assert_match /Applying.*?couchrest.*?orm/, buffer
assert_match_in_file(/gem 'couchrest'/, '/tmp/sample_app/Gemfile')
assert_match_in_file(/CouchRestInitializer/, '/tmp/sample_app/config/initializers/couch_rest.rb')
assert_match_in_file(/class User < CouchRest::ExtendedDocument/m, '/tmp/sample_app/app/models/user.rb')
end
end

context "the generator for renderer component" do
Expand Down

0 comments on commit 33a46ed

Please sign in to comment.