darkhelmet-sinatra_more 0.3.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.document +5 -0
  2. data/.gitignore +23 -0
  3. data/IDEAS.md +54 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +756 -0
  6. data/ROADMAP +88 -0
  7. data/Rakefile +63 -0
  8. data/TODO +60 -0
  9. data/VERSION +1 -0
  10. data/bin/sinatra_gen +6 -0
  11. data/generators/base_app/.gitignore +7 -0
  12. data/generators/base_app/Gemfile +13 -0
  13. data/generators/base_app/app/.empty_directory +0 -0
  14. data/generators/base_app/app/helpers/.empty_directory +0 -0
  15. data/generators/base_app/app/helpers/view_helpers.rb +3 -0
  16. data/generators/base_app/app/mailers/.empty_directory +0 -0
  17. data/generators/base_app/app/models/.empty_directory +0 -0
  18. data/generators/base_app/app/routes/.empty_directory +0 -0
  19. data/generators/base_app/app/views/.empty_directory +0 -0
  20. data/generators/base_app/config.ru.tt +10 -0
  21. data/generators/base_app/config/boot.rb.tt +42 -0
  22. data/generators/base_app/config/dependencies.rb.tt +41 -0
  23. data/generators/base_app/lib/.empty_directory +0 -0
  24. data/generators/base_app/public/images/.empty_directory +0 -0
  25. data/generators/base_app/public/images/.gitignore +0 -0
  26. data/generators/base_app/public/javascripts/.empty_directory +0 -0
  27. data/generators/base_app/public/stylesheets/.empty_directory +0 -0
  28. data/generators/base_app/test/models/.empty_directory +0 -0
  29. data/generators/base_app/test/routes/.empty_directory +0 -0
  30. data/generators/base_app/test/test_config.rb.tt +5 -0
  31. data/generators/base_app/vendor/gems/.empty_directory +0 -0
  32. data/generators/components/component_actions.rb +48 -0
  33. data/generators/components/mocks/mocha_mock_gen.rb +8 -0
  34. data/generators/components/mocks/rr_mock_gen.rb +8 -0
  35. data/generators/components/orms/activerecord_orm_gen.rb +99 -0
  36. data/generators/components/orms/couchrest_orm_gen.rb +64 -0
  37. data/generators/components/orms/datamapper_orm_gen.rb +52 -0
  38. data/generators/components/orms/mongomapper_orm_gen.rb +101 -0
  39. data/generators/components/orms/sequel_orm_gen.rb +61 -0
  40. data/generators/components/renderers/erb_renderer_gen.rb +7 -0
  41. data/generators/components/renderers/haml_renderer_gen.rb +22 -0
  42. data/generators/components/scripts/jquery_script_gen.rb +9 -0
  43. data/generators/components/scripts/prototype_script_gen.rb +10 -0
  44. data/generators/components/scripts/rightjs_script_gen.rb +10 -0
  45. data/generators/components/tests/bacon_test_gen.rb +21 -0
  46. data/generators/components/tests/riot_test_gen.rb +19 -0
  47. data/generators/components/tests/rspec_test_gen.rb +19 -0
  48. data/generators/components/tests/shoulda_test_gen.rb +19 -0
  49. data/generators/components/tests/testspec_test_gen.rb +19 -0
  50. data/generators/generator_actions.rb +79 -0
  51. data/generators/skeleton_generator.rb +53 -0
  52. data/lib/sinatra/mailer_plugin.rb +14 -0
  53. data/lib/sinatra/mailer_plugin/mail_object.rb +39 -0
  54. data/lib/sinatra/mailer_plugin/mailer_base.rb +75 -0
  55. data/lib/sinatra/markup_plugin.rb +19 -0
  56. data/lib/sinatra/markup_plugin/asset_tag_helpers.rb +109 -0
  57. data/lib/sinatra/markup_plugin/form_builder/abstract_form_builder.rb +133 -0
  58. data/lib/sinatra/markup_plugin/form_builder/standard_form_builder.rb +31 -0
  59. data/lib/sinatra/markup_plugin/form_helpers.rb +194 -0
  60. data/lib/sinatra/markup_plugin/format_helpers.rb +74 -0
  61. data/lib/sinatra/markup_plugin/output_helpers.rb +98 -0
  62. data/lib/sinatra/markup_plugin/tag_helpers.rb +42 -0
  63. data/lib/sinatra/render_plugin.rb +12 -0
  64. data/lib/sinatra/render_plugin/render_helpers.rb +63 -0
  65. data/lib/sinatra/routing_plugin.rb +50 -0
  66. data/lib/sinatra/routing_plugin/named_route.rb +27 -0
  67. data/lib/sinatra/routing_plugin/routing_helpers.rb +22 -0
  68. data/lib/sinatra/support_lite.rb +19 -0
  69. data/lib/sinatra/warden_plugin.rb +51 -0
  70. data/lib/sinatra/warden_plugin/warden_helpers.rb +60 -0
  71. data/lib/sinatra_more.rb +7 -0
  72. data/sinatra_more.gemspec +215 -0
  73. data/test/active_support_helpers.rb +7 -0
  74. data/test/fixtures/mailer_app/app.rb +51 -0
  75. data/test/fixtures/mailer_app/views/demo_mailer/sample_mail.erb +1 -0
  76. data/test/fixtures/mailer_app/views/sample_mailer/anniversary_message.erb +2 -0
  77. data/test/fixtures/mailer_app/views/sample_mailer/birthday_message.erb +2 -0
  78. data/test/fixtures/markup_app/app.rb +66 -0
  79. data/test/fixtures/markup_app/views/capture_concat.erb +14 -0
  80. data/test/fixtures/markup_app/views/capture_concat.haml +13 -0
  81. data/test/fixtures/markup_app/views/content_for.erb +11 -0
  82. data/test/fixtures/markup_app/views/content_for.haml +9 -0
  83. data/test/fixtures/markup_app/views/content_tag.erb +11 -0
  84. data/test/fixtures/markup_app/views/content_tag.haml +9 -0
  85. data/test/fixtures/markup_app/views/fields_for.erb +8 -0
  86. data/test/fixtures/markup_app/views/fields_for.haml +6 -0
  87. data/test/fixtures/markup_app/views/form_for.erb +56 -0
  88. data/test/fixtures/markup_app/views/form_for.haml +47 -0
  89. data/test/fixtures/markup_app/views/form_tag.erb +57 -0
  90. data/test/fixtures/markup_app/views/form_tag.haml +45 -0
  91. data/test/fixtures/markup_app/views/link_to.erb +5 -0
  92. data/test/fixtures/markup_app/views/link_to.haml +4 -0
  93. data/test/fixtures/markup_app/views/mail_to.erb +3 -0
  94. data/test/fixtures/markup_app/views/mail_to.haml +3 -0
  95. data/test/fixtures/markup_app/views/meta_tag.erb +3 -0
  96. data/test/fixtures/markup_app/views/meta_tag.haml +3 -0
  97. data/test/fixtures/render_app/app.rb +54 -0
  98. data/test/fixtures/render_app/views/erb/test.erb +1 -0
  99. data/test/fixtures/render_app/views/haml/test.haml +1 -0
  100. data/test/fixtures/render_app/views/template/_user.haml +7 -0
  101. data/test/fixtures/render_app/views/template/haml_template.haml +1 -0
  102. data/test/fixtures/render_app/views/template/some_template.haml +2 -0
  103. data/test/fixtures/routing_app/app.rb +48 -0
  104. data/test/fixtures/routing_app/views/index.haml +7 -0
  105. data/test/fixtures/warden_app/app.rb +75 -0
  106. data/test/fixtures/warden_app/views/dashboard.haml +6 -0
  107. data/test/generators/test_skeleton_generator.rb +190 -0
  108. data/test/helper.rb +73 -0
  109. data/test/mailer_plugin/test_mail_object.rb +24 -0
  110. data/test/mailer_plugin/test_mailer_base.rb +81 -0
  111. data/test/markup_plugin/test_asset_tag_helpers.rb +171 -0
  112. data/test/markup_plugin/test_form_builder.rb +627 -0
  113. data/test/markup_plugin/test_form_helpers.rb +417 -0
  114. data/test/markup_plugin/test_format_helpers.rb +96 -0
  115. data/test/markup_plugin/test_output_helpers.rb +63 -0
  116. data/test/markup_plugin/test_tag_helpers.rb +73 -0
  117. data/test/test_mailer_plugin.rb +33 -0
  118. data/test/test_render_plugin.rb +78 -0
  119. data/test/test_routing_plugin.rb +94 -0
  120. data/test/test_warden_plugin.rb +105 -0
  121. metadata +307 -0
@@ -0,0 +1,8 @@
1
+ module Sinatra
2
+ module MochaMockGen
3
+ def setup_mock
4
+ require_dependencies 'mocha', :env => :testing
5
+ insert_mocking_include "Mocha::API", :path => "test/test_config.rb"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Sinatra
2
+ module RrMockGen
3
+ def setup_mock
4
+ require_dependencies 'rr', :env => :testing
5
+ insert_mocking_include "RR::Adapters::RRMethods", :path => "test/test_config.rb"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,99 @@
1
+ module Sinatra
2
+ module ActiverecordOrmGen
3
+
4
+ AR = <<-AR
5
+ module ActiveRecordInitializer
6
+ def self.registered(app)
7
+ app.configure :development do
8
+ ActiveRecord::Base.establish_connection(
9
+ :adapter => 'sqlite3',
10
+ :database => 'your_dev_db_here'
11
+ )
12
+ end
13
+
14
+ app.configure :production do
15
+ ActiveRecord::Base.establish_connection(
16
+ :adapter => 'sqlite3',
17
+ :database => 'your_production_db_here'
18
+ )
19
+ end
20
+
21
+ app.configure :test do
22
+ ActiveRecord::Base.establish_connection(
23
+ :adapter => 'sqlite3',
24
+ :database => 'your_test_db_here'
25
+ )
26
+ end
27
+ end
28
+ end
29
+ AR
30
+
31
+ RAKE = <<-RAKE
32
+ require 'sinatra/base'
33
+ require 'active_record'
34
+
35
+ namespace :db do
36
+ desc "Migrate the database"
37
+ task(:migrate) do
38
+ load 'config/boot.rb'
39
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
40
+ ActiveRecord::Migration.verbose = true
41
+ ActiveRecord::Migrator.migrate("db/migrate")
42
+ end
43
+ end
44
+ RAKE
45
+
46
+
47
+ MIGRATION = <<-MIGRATION
48
+ class CreateUsers < ActiveRecord::Migration
49
+ def self.up
50
+ create_table :users do |t|
51
+ t.column :name, :string
52
+ t.column :username, :string
53
+ t.column :email, :string
54
+ t.column :crypted_password, :string
55
+ t.column :created_at, :datetime
56
+ end
57
+ end
58
+
59
+ def self.down
60
+ drop_table :users
61
+ end
62
+ end
63
+ MIGRATION
64
+
65
+ USER = <<-USER
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
+
76
+ def self.authenticate(username, password)
77
+ user = User.first(:conditions => { :username => username })
78
+ user && user.has_password?(password) ? user : nil
79
+ end
80
+
81
+ def encrypt_password
82
+ self.crypted_password = BCrypt::Password.create(password)
83
+ end
84
+
85
+ def has_password?(password)
86
+ BCrypt::Password.new(crypted_password) == password
87
+ end
88
+ end
89
+ USER
90
+
91
+ def setup_orm
92
+ require_dependencies 'activerecord'
93
+ create_file("config/initializers/active_record.rb", AR)
94
+ create_file("Rakefile", RAKE)
95
+ create_file("db/migrate/001_create_users.rb", MIGRATION)
96
+ create_file("app/models/user.rb", USER)
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,64 @@
1
+ module Sinatra
2
+ module CouchrestOrmGen
3
+
4
+ COUCHREST = <<-COUCHREST
5
+ module CouchRestInitializer
6
+ def self.registered(app)
7
+ app.configure(:development) { set :couchdb, CouchRest.database!('your_dev_db_here') }
8
+ app.configure(:production) { set :couchdb, CouchRest.database!('your_production_db_here') }
9
+ app.configure(:test) { set :couchdb, CouchRest.database!('your_test_db_here') }
10
+ end
11
+ end
12
+ COUCHREST
13
+
14
+ USER = <<-USER
15
+ class User < CouchRest::ExtendedDocument
16
+ include CouchRest::Validation
17
+
18
+ use_database app { couchdb }
19
+
20
+ property :name
21
+ property :username
22
+ property :email
23
+ property :crypted_password
24
+ unique_id :id
25
+
26
+ attr_accessor :password, :password_confirmation
27
+ validates_is_confirmed :password
28
+
29
+ save_callback :before, :encrypt_password
30
+
31
+ def self.find(id)
32
+ get(id)
33
+ end
34
+
35
+ def self.id_for(username)
36
+ "user/\#{username}"
37
+ end
38
+
39
+ def self.authenticate(username, password)
40
+ user = User.get(id_for(username))
41
+ user && user.has_password?(password) ? user : nil
42
+ end
43
+
44
+ def id
45
+ self.class.id_for(username)
46
+ end
47
+
48
+ def encrypt_password
49
+ self.crypted_password = BCrypt::Password.create(password)
50
+ end
51
+
52
+ def has_password?(password)
53
+ BCrypt::Password.new(crypted_password) == password
54
+ end
55
+ end
56
+ USER
57
+
58
+ def setup_orm
59
+ require_dependencies 'couchrest'
60
+ create_file("config/initializers/couch_rest.rb", COUCHREST)
61
+ create_file("app/models/user.rb", USER)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,52 @@
1
+ module Sinatra
2
+ module DatamapperOrmGen
3
+
4
+ DM = <<-DM
5
+ module DataMapperInitializer
6
+ def self.registered(app)
7
+ app.configure(:development) { DataMapper.setup(:default, 'your_dev_db_here') }
8
+ app.configure(:production) { DataMapper.setup(:default, 'your_production_db_here') }
9
+ app.configure(:test) { DataMapper.setup(:default, 'your_test_db_here') }
10
+ end
11
+ end
12
+ DM
13
+
14
+ USER = <<-USER
15
+ class User
16
+ include DataMapper::Resource
17
+
18
+ property :id, Serial
19
+ property :name, String
20
+ property :username, String
21
+ property :email, String
22
+ property :crypted_password, String
23
+
24
+ attr_accessor :password, :password_confirmation
25
+
26
+ before :save, :encrypt_password
27
+
28
+ validates_present :password, :password_confirmation
29
+
30
+ def self.authenticate(username, password)
31
+ user = User.first(:username => username)
32
+ user && user.has_password?(password) ? user : nil
33
+ end
34
+
35
+ def encrypt_password
36
+ self.crypted_password = BCrypt::Password.create(password)
37
+ end
38
+
39
+ def has_password?(password)
40
+ BCrypt::Password.new(crypted_password) == password
41
+ end
42
+ end
43
+ User.auto_upgrade!
44
+ USER
45
+
46
+ def setup_orm
47
+ require_dependencies 'dm-core', 'dm-validations'
48
+ create_file("config/initializers/data_mapper.rb", DM)
49
+ create_file("app/models/user.rb", USER)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,101 @@
1
+ module Sinatra
2
+ module MongomapperOrmGen
3
+
4
+ MONGO = <<-MONGO
5
+ class MongoDBConnectionFailure < RuntimeError; end
6
+
7
+ module MongoDbInitializer
8
+ def self.registered(app)
9
+ app.configure :development do
10
+ MongoMapper.connection = Mongo::Connection.new('localhost')
11
+ MongoMapper.database = 'your_dev_db_here'
12
+ end
13
+
14
+ app.configure :production do
15
+ MongoMapper.connection = Mongo::Connection.new('localhost')
16
+ MongoMapper.database = 'your_production_db_here'
17
+ end
18
+
19
+ app.configure :test do
20
+ MongoMapper.connection = Mongo::Connection.new('localhost')
21
+ MongoMapper.database = 'your_test_db_here'
22
+ end
23
+ end
24
+ end
25
+ MONGO
26
+
27
+ CONCERNED = <<-CONCERN
28
+ module MongoMapper
29
+ module Document
30
+ module ClassMethods
31
+ # TODO find a cleaner way for it to know where to look for dependencies
32
+ def concerned_with(*concerns)
33
+ concerns.each { |concern| require_dependency "./app/models/\#{name.underscore}/\#{concern}" }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ CONCERN
39
+
40
+ USER = <<-USER
41
+ class User
42
+ include MongoMapper::Document
43
+ concerned_with :authentications
44
+
45
+ key :name, String, :required => true
46
+ key :username, String, :required => true
47
+ key :email, String, :required => true
48
+ key :crypted_password, String, :required => true
49
+ end
50
+ USER
51
+
52
+ AUTH = <<-AUTH
53
+ class User
54
+ attr_accessor :password, :password_confirmation
55
+ before_validation :password_checks
56
+ validate :validate_password
57
+
58
+ def password_checks
59
+ if password_required?
60
+ encrypt_password if password.present? && password == password_confirmation
61
+ end
62
+ end
63
+
64
+ def password_required?
65
+ crypted_password.blank? || !password.blank?
66
+ end
67
+
68
+ def encrypt_password
69
+ self.crypted_password = BCrypt::Password.create(password)
70
+ end
71
+
72
+ def has_password?(password)
73
+ BCrypt::Password.new(crypted_password) == password
74
+ end
75
+
76
+ def encrypt_password
77
+ return if password.blank?
78
+ self.crypted_password = BCrypt::Password.create(password)
79
+ end
80
+
81
+ def validate_password
82
+ errors.add :password, "must not be empty" if crypted_password.blank? && password.blank?
83
+ errors.add :password, "must match password confirmation" unless password == password_confirmation
84
+ end
85
+
86
+ def self.authenticate(username, password)
87
+ user = User.first(:conditions => { :username => username })
88
+ user && user.has_password?(password) ? user : nil
89
+ end
90
+ end
91
+ AUTH
92
+
93
+ def setup_orm
94
+ require_dependencies 'mongo_mapper'
95
+ create_file("config/initializers/mongo_db.rb", MONGO)
96
+ create_file("lib/ext/mongo_mapper.rb", CONCERNED)
97
+ create_file("app/models/user.rb", USER)
98
+ create_file("app/models/user/authentications.rb", AUTH)
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,61 @@
1
+ module Sinatra
2
+ module SequelOrmGen
3
+
4
+ SEQUEL = <<-SEQUEL
5
+ module SequelInitializer
6
+ def self.registered(app)
7
+ Sequel::Model.plugin(:schema)
8
+ app.configure(:development) { Sequel.connect('your_dev_db_here') }
9
+ app.configure(:production) { Sequel.connect('your_production_db_here') }
10
+ app.configure(:test) { Sequel.connect('your_test_db_here') }
11
+ end
12
+ end
13
+ SEQUEL
14
+
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
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
52
+ end
53
+ USER
54
+
55
+ def setup_orm
56
+ require_dependencies 'sequel'
57
+ create_file("config/initializers/sequel.rb", SEQUEL)
58
+ create_file("app/models/user.rb", USER)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ module Sinatra
2
+ module ErbRendererGen
3
+ def setup_renderer
4
+ require_dependencies 'erubis'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ module Sinatra
2
+ module HamlRendererGen
3
+
4
+ SASS_INIT = (<<-SASS).gsub(/^ {4}/, '')
5
+ # Enables support for SASS template reloading for rack.
6
+ # See http://nex-3.com/posts/88-sass-supports-rack for more details.
7
+
8
+ module SassInitializer
9
+ def self.registered(app)
10
+ require 'sass/plugin/rack'
11
+ app.use Sass::Plugin::Rack
12
+ end
13
+ end
14
+ SASS
15
+
16
+ def setup_renderer
17
+ require_dependencies 'haml'
18
+ create_file("config/initializers/sass.rb", SASS_INIT)
19
+ empty_directory('public/stylesheets/sass')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ module Sinatra
2
+ module JqueryScriptGen
3
+
4
+ def setup_script
5
+ get("http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js", "public/javascripts/jquery.min.js")
6
+ end
7
+
8
+ end
9
+ end