natlownes-desert 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/CHANGES +46 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +316 -0
  4. data/Rakefile +77 -0
  5. data/VERSION.yml +2 -0
  6. data/generators/desert_plugin/USAGE +14 -0
  7. data/generators/desert_plugin/desert_plugin_generator.rb +73 -0
  8. data/generators/desert_plugin/templates/desert_routes.rb +4 -0
  9. data/generators/desert_plugin/templates/empty_file +0 -0
  10. data/generators/desert_plugin/templates/plugin_migration.rb +11 -0
  11. data/generators/desert_plugin/templates/spec_helper.rb +8 -0
  12. data/init.rb +0 -0
  13. data/lib/desert.rb +14 -0
  14. data/lib/desert/manager.rb +130 -0
  15. data/lib/desert/plugin.rb +74 -0
  16. data/lib/desert/plugin_migrations.rb +11 -0
  17. data/lib/desert/plugin_migrations/1.2/extensions/schema_statements.rb +34 -0
  18. data/lib/desert/plugin_migrations/1.2/migrator.rb +33 -0
  19. data/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb +36 -0
  20. data/lib/desert/plugin_migrations/2.1/migrator.rb +35 -0
  21. data/lib/desert/plugin_migrations/migrator.rb +29 -0
  22. data/lib/desert/plugin_templates.rb +13 -0
  23. data/lib/desert/plugin_templates/1.2.0/action_mailer.rb +21 -0
  24. data/lib/desert/plugin_templates/1.2.0/action_view.rb +53 -0
  25. data/lib/desert/plugin_templates/1.99.0/action_mailer.rb +25 -0
  26. data/lib/desert/plugin_templates/1.99.0/action_view.rb +38 -0
  27. data/lib/desert/plugin_templates/2.0.0/action_mailer.rb +23 -0
  28. data/lib/desert/plugin_templates/2.0.2/action_view.rb +26 -0
  29. data/lib/desert/plugin_templates/2.1.0/action_view.rb +15 -0
  30. data/lib/desert/plugin_templates/2.2.0/action_mailer.rb +23 -0
  31. data/lib/desert/plugin_templates/2.2.0/action_view.rb +10 -0
  32. data/lib/desert/plugin_templates/action_controller.rb +12 -0
  33. data/lib/desert/plugin_templates/action_view.rb +17 -0
  34. data/lib/desert/rails.rb +10 -0
  35. data/lib/desert/rails/1.2.0/initializer.rb +20 -0
  36. data/lib/desert/rails/2.0.0/plugin.rb +22 -0
  37. data/lib/desert/rails/dependencies.rb +87 -0
  38. data/lib/desert/rails/migration.rb +36 -0
  39. data/lib/desert/rails/route_set.rb +23 -0
  40. data/lib/desert/ruby.rb +2 -0
  41. data/lib/desert/ruby/object.rb +34 -0
  42. data/lib/desert/supported_rails_versions.rb +12 -0
  43. data/lib/desert/tasks.rb +4 -0
  44. data/lib/desert/version_checker.rb +34 -0
  45. metadata +104 -0
data/CHANGES ADDED
@@ -0,0 +1,46 @@
1
+ 0.5.0
2
+ - Rails 2.2.3 support
3
+ - routes.rb becomes desert_routes.rb
4
+ - Added Desert::Manager.require_all_files and Desert::Manager.all_files
5
+
6
+ 0.3.4
7
+ - Fix problems with plugin migrations numbered higher than 7
8
+ - Cleanups to specs: cruise rake task, improved docs, and specs run on OSX
9
+
10
+ 0.3.3
11
+ - Fixed [#20770] Can't get specs to run for desert-based plugin bug (http://rubyforge.org/tracker/index.php?func=detail&aid=20770&group_id=6426&atid=24920)
12
+ - Fixed [#21564] Can't see desert rake tasks (http://rubyforge.org/tracker/index.php?func=detail&aid=21564&group_id=6426&atid=24920)
13
+ - Renamed plugin_schema_info to plugin_schema_migrations when using Rails >= 2.1
14
+ - Migrater#migrated are now properly implemented for plugin_schema_migrations for Rails >= 2.1.0
15
+
16
+ 0.3.2
17
+ - Fixed exception in testspec.rake when rspec is not loaded
18
+ - Fix template loading on Edge Rails and on Rails 2.1.0
19
+
20
+ 0.3.1
21
+ - Fix migration issue with Rails 2.1.0 using timestamps.
22
+
23
+ 0.3.0
24
+ - Fixed script/destroy not removing the routes [From Jeff Dean]
25
+ - gem includes the Rails generator files [From Jeff Dean]
26
+ - Fixed readding the route to config/routes.rb in the script/destroy task [From Jeff Dean]
27
+ - Github now properly formats readme [From Jeff Dean]
28
+ - Updated the gemspec so rdoc includes it and updated it to add installation and setup instructions [From Jeff Dean]
29
+ - Removed sample route from generator [From Jeff Dean]
30
+
31
+ 0.2.1
32
+ - Fixed ActionMailer rendering in Rails 1.99.0
33
+
34
+ 0.2.0
35
+ - Works with edge Rails
36
+ - Removed Desert::Plugin#up_to_date?
37
+ - Removed Migrator#latest_version
38
+
39
+ 0.1.1
40
+ - Works with edge Rails
41
+ - Fixed double loading issue with not fully expanded load_paths.
42
+
43
+ 0.1.0
44
+ - Fixed [#13346] ActionController::Base.helper raises error when helper is only in plugin
45
+ - Desert does not require files that have been required before Desert was loaded
46
+
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Pivotal Labs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,316 @@
1
+ = Desert - It doesn't get any DRYer than this
2
+
3
+ Desert is a Rails plugin framework that makes it easy to share models, views,
4
+ controllers, helpers, routes, and migrations across your applications.
5
+
6
+ With Desert, reusability doesn't come at the cost of extensibility: it's trivial to extend
7
+ the functionality of a plugin - both in your application _and_ in other plugins.
8
+
9
+ Classes are automatically mixed in with your own or other plugins' classes.
10
+ This allows you to make full featured composable components.
11
+
12
+ Desert is a replacement for Appable Plugins (http://wiki.pluginaweek.org/Appable_plugins).
13
+
14
+ == Bug/Feature Tracker
15
+
16
+ Pivotal Tracker: http://www.pivotaltracker.com/projects/358
17
+
18
+ == Anatomy of a desert plugin
19
+
20
+ |-- app
21
+ | |-- controllers
22
+ | | |-- application.rb
23
+ | | `-- blogs_controller.rb
24
+ | |-- helpers
25
+ | | |-- application_helper.rb
26
+ | | `-- blogs_helper.rb
27
+ | |-- models
28
+ | | `-- user.rb
29
+ | `-- views
30
+ | |-- blogs
31
+ | |-- layouts
32
+ | | `-- users.html.erb
33
+ | `-- users
34
+ | |-- index.html.erb
35
+ | `-- show.html.erb
36
+ |-- db
37
+ | `-- migrate
38
+ | `-- 001_migrate_users_to_001.rb
39
+ |-- lib
40
+ | `-- current_user.rb
41
+ |-- spec
42
+ | |-- controllers
43
+ | | `-- blogs_controller_spec.rb
44
+ | |-- fixtures
45
+ | |-- models
46
+ | |-- spec_helper.rb
47
+ | `-- views
48
+ | `-- blogs
49
+ `-- vendor
50
+ `-- plugins
51
+ `-- user
52
+ |-- app
53
+ | |-- controllers
54
+ | | `-- users_controller.rb
55
+ | |-- helpers
56
+ | | `-- users_helper.rb
57
+ | |-- models
58
+ | | `-- user.rb
59
+ | `-- views
60
+ | `-- users
61
+ | |-- edit.html.erb
62
+ | |-- index.html.erb
63
+ | |-- new.html.erb
64
+ | `-- show.html.erb
65
+ |-- config
66
+ | `-- desert_routes.rb
67
+ |-- db
68
+ | `-- migrate
69
+ | `-- 001_create_users.rb
70
+ |-- init.rb
71
+ |-- lib
72
+ | `-- current_user.rb
73
+ |-- spec
74
+ | |-- controllers
75
+ | | `-- user_controller_spec.rb
76
+ | |-- fixtures
77
+ | | `-- users.yml
78
+ | |-- models
79
+ | | `-- user.rb
80
+ | |-- spec_helper.rb
81
+ | `-- views
82
+ | `-- users
83
+ `-- tasks
84
+
85
+ == Installation and Usage
86
+
87
+ * Install the gem
88
+
89
+ sudo gem install desert
90
+
91
+ * Require 'desert' between 'boot' and Rails::Initializer.run in environment.rb
92
+
93
+ # File: config/environment.rb
94
+
95
+ require File.join(File.dirname(__FILE__), 'boot')
96
+
97
+ require 'desert'
98
+
99
+ Rails::Initializer.run do |config|
100
+ end
101
+
102
+ NOTE: you may have to require rubygems before requiring desert.
103
+
104
+ * Generate your desert plugin
105
+
106
+ script/generate desert_plugin my_plugin_app
107
+
108
+ == Manage Plugin Dependencies
109
+
110
+ By default, Rails loads plugins in alphabetical order, making it tedious to manage dependencies.
111
+ Desert will automatically load plugins in the proper order when you declare their dependencies like this:
112
+
113
+ # File: vendor/plugins/blogs/init.rb
114
+
115
+ require_plugin 'user'
116
+ require_plugin 'will_paginate'
117
+
118
+ Here <tt>user</tt> and <tt>will_paginate</tt> will always be loaded before <tt>blogs<tt>. Note that any plugin can be declared as a dependency.
119
+
120
+ == Share Routes
121
+
122
+ When you share controllers, you'll want to share their routes too.
123
+ If you look in your RAILS_ROOT/config/routes.rb file you will notice that the generator added a new line to the top:
124
+
125
+ map.routes_from_plugin(:my_plugin_app)
126
+
127
+ In the <tt>user</tt> plugin:
128
+
129
+ # File: vendor/plugins/user/config/desert_routes.rb
130
+
131
+ resource :users
132
+
133
+ In the <tt>blogs</tt> plugin:
134
+
135
+ # File: vendor/plugins/blogs/config/desert_routes.rb
136
+
137
+ resource :blogs
138
+
139
+ In the application:
140
+
141
+ # File: config/desert_routes.rb
142
+
143
+ ActionController::Routing::Routes.draw do |map|
144
+ map.routes_from_plugin :blogs
145
+ map.routes_from_plugin :user
146
+ end
147
+
148
+ Here the application adds the <tt>users</tt> resource from the <tt>user</tt> plugin and the <tt>blogs</tt> resource from the <tt>blogs</tt> plugin.
149
+ Notice that there is no need to call methods on map in the plugin route files, because they are instance eval'd in the map object.
150
+
151
+ All standard routing methods are available in your plugin's routes file, such as:
152
+
153
+ namespace :admin do |admin|
154
+ admin.resources :posts
155
+ end
156
+
157
+ Desert uses a separate table to manage migration version to maintain backwards compatibility with Rails 1.x.
158
+ Your plugin app's migration live in your_plugin/db/migrate. To run migrations, follow these steps:
159
+
160
+ * Create a new migration in your main app
161
+
162
+ script/generate migration migrate_my_plugin_to_045
163
+
164
+ * Add the custom `migrate_plugin` method
165
+
166
+ class MigrateMyPluginTo045 < ActiveRecord::Migration
167
+ def self.up
168
+ migrate_plugin(:my_plugin, 20080530223548)
169
+ end
170
+
171
+ def self.down
172
+ migrate_plugin(:my_plugin, 0)
173
+ end
174
+ end
175
+
176
+ * Run your migrations normally
177
+
178
+ rake db:migrate
179
+
180
+ connect "/signup", :controller => "users", :action => "signup"
181
+
182
+ == Share Migrations
183
+
184
+ Sharing models means sharing schema fragments, and that means sharing migrations:
185
+
186
+ In the <tt>user</tt> plugin:
187
+
188
+ vendor/plugins/user/db/migrate/
189
+ 001_create_user_table.rb
190
+
191
+ In the <tt>blogs</tt> plugin:
192
+
193
+ vendor/plugins/blogs/db/migrate/
194
+ 001_create_user_table.rb
195
+ 002_add_became_a_blogger_at_to_user.rb
196
+
197
+ Here the <tt>blogs</tt> plugin needs to add a column to the <tt>users</tt> table. No problem!
198
+ It just includes a migration in its <tt>db/migrate</tt> directory, just like a regular Rails application.
199
+ When the application developer installs the plugin, he migrates the plugin in his own migration:
200
+
201
+ <tt>application_root/db/migrate/009_install_user_and_blogs_plugins.rb</tt>
202
+
203
+ class InstallUserAndBlogsPlugins < ActiveRecord::Migration
204
+ def self.up
205
+ migrate_plugin 'user', 1
206
+ migrate_plugin :blogs, 2
207
+ end
208
+
209
+ def self.down
210
+ migrate_plugin 'user', 0
211
+ migrate_plugin :blogs, 0
212
+ end
213
+ end
214
+
215
+ Here the application migrates the <tt>user</tt> plugin to version 1 and the <tt>blogs</tt> plugin to version 2.
216
+ If a subsequent version of the plugin introduces new migrations, the application developer has full control over when to apply them to his schema.
217
+
218
+ == Share Views
219
+
220
+ To share views, just create templates and partials in the plugin's <tt>app/views</tt> directory, just as you would with a Rails application.
221
+
222
+ <tt>application_root/app/views/blogs/index.html.erb</tt>
223
+
224
+ <%= @blog.posts.each do |post| %>
225
+ ...
226
+ <% end %>
227
+
228
+ == Customize / extend behavior in each installation
229
+
230
+ Say you want to create a plugin named acts_as_spiffy.
231
+ Desert allows Spiffy to have a set of features that can be reused and extended in several projects.
232
+
233
+ The Spiffy project has a:
234
+
235
+ * SpiffyController
236
+ * Spiffy model
237
+ * SpiffyHelper
238
+ * spiffy.html.erb
239
+ * SpiffyLib library class
240
+
241
+ The Spiffy plugin acts as its own mini Rails application. Here is the directory structure:
242
+
243
+ RAILS_ROOT/vendor/plugins/spiffy/app/controllers/spiffy_controller.rb
244
+ RAILS_ROOT/vendor/plugins/spiffy/app/models/spiffy.rb
245
+ RAILS_ROOT/vendor/plugins/spiffy/app/helpers/spiffy_helper.rb
246
+ RAILS_ROOT/vendor/plugins/spiffy/app/views/spiffy/spiffy.rhtml
247
+ RAILS_ROOT/vendor/plugins/spiffy/lib/spiffy_lib.rb
248
+
249
+ Now, say there is a Spiffy Store rails application that uses acts_as_spiffy. The Rails app can open up any of the Spiffy classes and override any of the methods.
250
+
251
+ Say spiffy.rb in the Spiffy plugin is defined as:
252
+
253
+ class Spiffy < ActiveRecord::Base
254
+ def why?
255
+ "I just am Spiffy"
256
+ end
257
+ end
258
+
259
+ The Spiffy#why method can be overridden in RAILS_ROOT/app/models/spiffy.rb
260
+
261
+ class Spiffy < ActiveRecord::Base
262
+ def why?
263
+ "I sell Spiffy stuff"
264
+ end
265
+ end
266
+
267
+ == Running plugin tests
268
+
269
+ You can run your plugin tests/specs like so:
270
+
271
+ rake desert:testspec:plugins PLUGIN=spiffy
272
+
273
+ Leaving off the PLUGIN environment variable will cause it to run all the
274
+ test/specs for all installed plugins, which may not be what you want.
275
+
276
+ == Running Desert Specs
277
+
278
+ To run specs, you need to:
279
+
280
+ * Make sure you have the necessary gems installed:
281
+
282
+ sudo geminstaller
283
+
284
+ * On OSX, you may have to manually install sqlite3-ruby gem
285
+
286
+ sudo env ARCHFLAGS="-arch i386" gem install sqlite3-ruby
287
+
288
+ * If sqlite3-ruby fails to compile, install it.
289
+
290
+ OSX: sudo port install sqlite3
291
+ Debian: sudo aptitude install sqlite sqlite3 libsqlite-dev libsqlite3-dev
292
+
293
+ * Install git http://git.or.cz/
294
+ * Install the dependencies
295
+
296
+ rake install_dependencies
297
+
298
+ * Run the specs
299
+
300
+ rake
301
+
302
+ == Notes on Rails version dependencies
303
+
304
+ Desert is a library that heavily monkey patches Rails. To ensure that Desert works with
305
+ multiple versions of Rails, its tests are run against the supported versions of Rails.
306
+
307
+ To set up the different supported versions of Rails, run
308
+
309
+ rake install_dependencies
310
+
311
+ This will clone the Rails git repo and export the supported versions of rails into the
312
+ respective directories.
313
+
314
+ rake update_dependencies
315
+
316
+ will update the clones repo on your machine.
@@ -0,0 +1,77 @@
1
+ require "rake"
2
+ require 'rake/contrib/rubyforgepublisher'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+
7
+ desc "Runs the Rspec suite"
8
+ task :default do
9
+ run_suite
10
+ end
11
+
12
+ desc "Runs the Rspec suite"
13
+ task :spec do
14
+ run_suite
15
+ end
16
+
17
+ def run_suite
18
+ dir = File.dirname(__FILE__)
19
+ system("ruby #{dir}/spec/spec_suite.rb") || raise("Example Suite failed")
20
+ end
21
+
22
+ begin
23
+ gem "pivotal-jeweler"
24
+ require 'jeweler'
25
+ Jeweler::Tasks.new do |s|
26
+ s.name = "desert"
27
+ s.summary = "Desert is a component framework for Rails that allows your plugins to be packaged as mini Rails apps."
28
+ s.email = "opensource@pivotallabs.com"
29
+ s.homepage = "http://pivotallabs.com"
30
+ s.description = "Desert is a component framework for Rails that allows your plugins to be packaged as mini Rails apps."
31
+ s.authors = ["Pivotal Labs", "Brian Takita", "Parker Thompson", "Adam Milligan, Joe Moore"]
32
+ s.files = FileList[
33
+ '[A-Z]*',
34
+ '*.rb',
35
+ 'lib/**/*.rb',
36
+ 'generators/**/*',
37
+ 'generators/**/templates/*',
38
+ 'examples/**/*.rb'
39
+ ].to_a
40
+ s.extra_rdoc_files = [ "README.rdoc", "CHANGES" ]
41
+ s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
42
+ s.test_files = Dir.glob('spec/*_spec.rb')
43
+ s.rubyforge_project = "desert"
44
+ end
45
+ rescue LoadError
46
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
47
+ end
48
+
49
+
50
+ desc "Install dependencies to run the build. This task uses Git."
51
+ task :install_dependencies do
52
+ require "lib/desert/supported_rails_versions"
53
+ system("git clone git://github.com/rails/rails.git /Users/pivotal/workspace/desert/spec/rails_root/vendor/rails_versions/edge")
54
+ Dir.chdir("spec/rails_root/vendor/rails_versions/edge") do
55
+ begin
56
+ Desert::SUPPORTED_RAILS_VERSIONS.each do |version, data|
57
+ unless version == 'edge'
58
+ system("git checkout #{data['git_tag']}")
59
+ system("cp -R ../edge ../#{version}")
60
+ end
61
+ end
62
+ ensure
63
+ system("git checkout master")
64
+ end
65
+ end
66
+ end
67
+
68
+ desc "Updates the dependencies to run the build. This task uses Git."
69
+ task :update_dependencies do
70
+ system "cd spec/rails_root/vendor/rails_versions/edge; git pull origin"
71
+ end
72
+
73
+ desc "Runs the CI build"
74
+ task :cruise => :install_dependencies do
75
+ run_suite
76
+ end
77
+