desert 0.3.0 → 0.3.2

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/CHANGES CHANGED
@@ -1,6 +1,10 @@
1
+ - Fixed exception in testspec.rake when rspec is not loaded
2
+ - Fix template loading on Edge Rails and on Rails 2.1.0
3
+
4
+ 0.3.1
5
+ - Fix migration issue with Rails 2.1.0 using timestamps.
6
+
1
7
  0.3.0
2
- - Fixed bug "Desert can't override an ERB template in a plugin with another template in your app"
3
- - Fixed multipart duplication issue
4
8
  - Fixed script/destroy not removing the routes [From Jeff Dean]
5
9
  - gem includes the Rails generator files [From Jeff Dean]
6
10
  - Fixed readding the route to config/routes.rb in the script/destroy task [From Jeff Dean]
@@ -1,9 +1,9 @@
1
1
  = Desert - It doesn't get any DRYer than this
2
2
 
3
- Desert is a Rails plugin framework that makes it easy to share models, views,
3
+ Desert is a Rails plugin framework that makes it easy to share models, views,
4
4
  controllers, helpers, routes, and migrations across your applications.
5
5
 
6
- With Desert, reusability doesn't come at the cost of extensibility: it's trivial to extend
6
+ With Desert, reusability doesn't come at the cost of extensibility: it's trivial to extend
7
7
  the functionality of a plugin - both in your application _and_ in other plugins.
8
8
 
9
9
  Classes are automatically mixed in with your own or other plugins' classes.
@@ -94,7 +94,7 @@ Desert is a replacement for Appable Plugins (http://wiki.pluginaweek.org/Appable
94
94
 
95
95
  Rails::Initializer.run do |config|
96
96
  end
97
-
97
+
98
98
  NOTE: you may have to require rubygems before requiring desert.
99
99
 
100
100
  * Generate your desert plugin
@@ -115,12 +115,12 @@ Here <tt>user</tt> and <tt>will_paginate</tt> will always be loaded before <tt>b
115
115
 
116
116
  == Share Routes
117
117
 
118
- When you share controllers, you'll want to share their routes too.
118
+ When you share controllers, you'll want to share their routes too.
119
119
  If you look in your RAILS_ROOT/config/routes.rb file you will notice that the generator added a new line to the top:
120
120
 
121
121
  map.routes_from_plugin(:my_plugin_app)
122
122
 
123
- In the <tt>user</tt> plugin:
123
+ In the <tt>user</tt> plugin:
124
124
 
125
125
  # File: vendor/plugins/user/config/routes.rb
126
126
 
@@ -128,12 +128,12 @@ In the <tt>user</tt> plugin:
128
128
 
129
129
  In the <tt>blogs</tt> plugin:
130
130
 
131
- File: vendor/plugins/blogs/config/routes.rb
131
+ # File: vendor/plugins/blogs/config/routes.rb
132
132
 
133
133
  resource :blogs
134
134
 
135
135
  In the application:
136
-
136
+
137
137
  # File: config/routes.rb
138
138
 
139
139
  ActionController::Routing::Routes.draw do |map|
@@ -150,6 +150,29 @@ All standard routing methods are available in your plugin's routes file, such as
150
150
  admin.resources :posts
151
151
  end
152
152
 
153
+ Desert uses a separate table to manage migration version to maintain backwards compatibility with Rails 1.x.
154
+ Your plugin app's migration live in your_plugin/db/migrate. To run migrations, follow these steps:
155
+
156
+ * Create a new migration in your main app
157
+
158
+ script/generate migration migrate_my_plugin_to_045
159
+
160
+ * Add the custom `migrate_plugin` method
161
+
162
+ class MigrateMyPluginTo045 < ActiveRecord::Migration
163
+ def self.up
164
+ migrate_plugin(:my_plugin, 20080530223548)
165
+ end
166
+
167
+ def self.down
168
+ migrate_plugin(:my_plugin, 0)
169
+ end
170
+ end
171
+
172
+ * Run your migrations normally
173
+
174
+ rake db:migrate
175
+
153
176
  connect "/signup", :controller => "users", :action => "signup"
154
177
 
155
178
  == Share Migrations
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ task(:tag_release) do
26
26
  end
27
27
 
28
28
  PKG_NAME = "desert"
29
- PKG_VERSION = "0.3.0"
29
+ PKG_VERSION = "0.3.2"
30
30
  PKG_FILES = FileList[
31
31
  '[A-Z]*',
32
32
  '*.rb',
@@ -43,6 +43,12 @@ module Desert #:nodoc:
43
43
  end
44
44
  end
45
45
  alias_method :record_version_state_after_migrating, :set_schema_version
46
+
47
+
48
+ def migrated
49
+ current_plugin_version = self.class.current_version
50
+ (1..current_plugin_version).to_a
51
+ end
46
52
  end
47
53
  end
48
54
  end
@@ -7,4 +7,4 @@ elsif Desert::VersionChecker.rails_version_is_below_rc2?
7
7
  else
8
8
  require "#{dir}/plugin_templates/2.0.0/action_mailer"
9
9
  end
10
- require "#{dir}/plugin_templates/action_view"
10
+ require "#{dir}/plugin_templates/action_view"
@@ -0,0 +1,53 @@
1
+ module ActionView
2
+ class Base
3
+ attr_reader :view_paths
4
+ def initialize_with_desert(base_path = nil, assigns_for_first_render = {}, controller = nil)
5
+ initialize_without_desert(base_path, assigns_for_first_render, controller)
6
+
7
+ @view_paths = [base_path]
8
+ Desert::Manager.plugins_and_app.reverse.each do |plugin|
9
+ @view_paths << plugin.templates_path
10
+ end
11
+ end
12
+ alias_method_chain :initialize, :desert
13
+
14
+ private
15
+ def full_path_template_exists?(path, extension)
16
+ file_path = "#{path}.#{extension}"
17
+ @@method_names.has_key?(file_path) || FileTest.exists?(file_path)
18
+ end
19
+
20
+ def find_template_extension_for(template_path)
21
+ view_paths.each do |view_path|
22
+ full_path = "#{view_path}/#{template_path}"
23
+ if match = @@template_handlers.find { |k,| full_path_template_exists?(template_path, k) }
24
+ return match.first.to_sym
25
+ elsif full_path_template_exists?(full_path, :rhtml)
26
+ return :rhtml
27
+ elsif full_path_template_exists?(full_path, :rxml)
28
+ return :rxml
29
+ elsif full_path_template_exists?(full_path, :rjs)
30
+ return :rjs
31
+ end
32
+ end
33
+ raise ActionViewError, "No rhtml, rxml, rjs or delegate template found for #{template_path} in #{@base_path}"
34
+ end
35
+
36
+ def full_template_path_with_plugin_routing(template_path, extension)
37
+ full_template_path = full_template_path_without_plugin_routing(template_path, extension)
38
+
39
+ unless File.exist?(full_template_path)
40
+ # Look through the plugins for the template
41
+ Desert::Manager.plugins.reverse.each do |plugin|
42
+ if plugin_template_path = plugin.find_template("#{template_path}.#{extension}")
43
+ full_template_path = plugin_template_path
44
+ break
45
+ end
46
+ end
47
+ end
48
+
49
+ full_template_path
50
+ end
51
+ alias_method_chain :full_template_path, :plugin_routing
52
+ end
53
+ end
@@ -2,11 +2,15 @@ module ActionMailer #:nodoc
2
2
  class Base #:nodoc:
3
3
  private
4
4
  def template_path_with_plugin_routing
5
- template_paths = [template_path_without_plugin_routing]
6
- Desert::Manager.plugins.reverse.each do |plugin|
7
- template_paths << "#{plugin.templates_path}/#{mailer_name}"
5
+ result = nil
6
+ Desert::Manager.plugins_and_app.reverse.each do |plugin|
7
+ relative_path = "#{plugin.templates_path}/#{mailer_name}"
8
+ unless Dir["#{relative_path}/#{@template}.*"].empty?
9
+ result = relative_path
10
+ break
11
+ end
8
12
  end
9
- "{#{template_paths * ','}}"
13
+ result || template_path_without_plugin_routing
10
14
  end
11
15
  alias_method_chain :template_path, :plugin_routing
12
16
 
@@ -0,0 +1,38 @@
1
+ module ActionView #:nodoc:
2
+ class Base #:nodoc:
3
+ def initialize_with_desert_plugins(*args)
4
+ initialize_without_desert_plugins *args
5
+
6
+ Desert::Manager.plugins.reverse.each do |plugin|
7
+ view_paths << plugin.templates_path
8
+ end
9
+ end
10
+ alias_method_chain :initialize, :desert_plugins
11
+
12
+ def find_template_extension_from_handler(template_path, formatted = nil)
13
+ checked_template_path = formatted ? "#{template_path}.#{template_format}" : template_path
14
+
15
+ view_paths.each do |view_path|
16
+ template_handler_preferences.each do |template_type|
17
+ extensions =
18
+ case template_type
19
+ when :javascript
20
+ [:rjs]
21
+ when :delegate
22
+ @@template_handlers.keys
23
+ else
24
+ [template_type]
25
+ end
26
+
27
+ extensions.each do |extension|
28
+ file_path = File.join(view_path, "#{checked_template_path}.#{extension}")
29
+ if File.exist?(file_path)
30
+ return formatted ? "#{template_format}.#{extension}" : extension.to_s
31
+ end
32
+ end
33
+ end
34
+ end
35
+ nil
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ module ActionView #:nodoc:
2
+ class Base #:nodoc:
3
+ def initialize_with_desert_plugins(*args)
4
+ initialize_without_desert_plugins *args
5
+
6
+ Desert::Manager.plugins.reverse.each do |plugin|
7
+ append_view_path plugin.templates_path
8
+ end
9
+ end
10
+ alias_method_chain :initialize, :desert_plugins
11
+
12
+ def find_template_extension_from_handler(template_path, formatted = nil)
13
+ checked_template_path = formatted ? "#{template_path}.#{template_format}" : template_path
14
+
15
+ view_paths.each do |view_path|
16
+ self.class.template_handler_extensions.each do |extension|
17
+ file_path = File.join(view_path, "#{checked_template_path}.#{extension}")
18
+ if File.exist?(file_path)
19
+ return formatted ? "#{template_format}.#{extension}" : extension.to_s
20
+ end
21
+ end
22
+ end
23
+ nil
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module ActionView #:nodoc:
2
+ class TemplateFinder #:nodoc:
3
+ def initialize_with_desert_plugins(*args)
4
+ initialize_without_desert_plugins *args
5
+
6
+ Desert::Manager.plugins.reverse.each do |plugin|
7
+ append_view_path plugin.templates_path
8
+ end
9
+ end
10
+ alias_method_chain :initialize, :desert_plugins
11
+ end
12
+ end
@@ -1,125 +1,17 @@
1
+ dir = File.dirname(__FILE__)
2
+
1
3
  if ActionView.const_defined?(:TemplateFinder)
2
- module ActionView #:nodoc:
3
- class TemplateFinder #:nodoc:
4
- def initialize_with_desert_plugins(*args)
5
- initialize_without_desert_plugins *args
6
-
7
- Desert::Manager.plugins.reverse.each do |plugin|
8
- append_view_path plugin.templates_path
9
- end
10
- end
11
- alias_method_chain :initialize, :desert_plugins
12
- end
13
- end
4
+ require "#{dir}/2.1.0/action_view"
14
5
  else
15
- module ActionView #:nodoc:
16
- class Base #:nodoc:
17
- if private_instance_methods.include?('find_template_extension_from_handler')
18
- if instance_methods.include?('template_handler_preferences')
19
- # Rails 1.99.0
20
- def find_template_extension_from_handler(template_path, formatted = nil)
21
- checked_template_path = formatted ? "#{template_path}.#{template_format}" : template_path
22
-
23
- view_paths.each do |view_path|
24
- template_handler_preferences.each do |template_type|
25
- extensions =
26
- case template_type
27
- when :javascript
28
- [:rjs]
29
- when :delegate
30
- @@template_handlers.keys
31
- else
32
- [template_type]
33
- end
34
-
35
- extensions.each do |extension|
36
- file_path = File.join(view_path, "#{checked_template_path}.#{extension}")
37
- if File.exist?(file_path)
38
- return formatted ? "#{template_format}.#{extension}" : extension.to_s
39
- end
40
- end
41
- end
42
- end
43
- nil
44
- end
45
- else
46
- # Rails 2.0.2
47
- def find_template_extension_from_handler(template_path, formatted = nil)
48
- checked_template_path = formatted ? "#{template_path}.#{template_format}" : template_path
49
-
50
- view_paths.each do |view_path|
51
- self.class.template_handler_extensions.each do |extension|
52
- file_path = File.join(view_path, "#{checked_template_path}.#{extension}")
53
- if File.exist?(file_path)
54
- return formatted ? "#{template_format}.#{extension}" : extension.to_s
55
- end
56
- end
57
- end
58
- nil
59
- end
60
- end
61
- end
62
-
63
- if instance_methods.include?('view_paths')
64
- def initialize_with_desert_plugins(*args)
65
- initialize_without_desert_plugins *args
66
-
67
- Desert::Manager.plugins.reverse.each do |plugin|
68
- view_paths << plugin.templates_path
69
- end
70
- end
71
- alias_method_chain :initialize, :desert_plugins
72
- else
73
- attr_reader :view_paths
74
- def initialize_with_desert(base_path = nil, assigns_for_first_render = {}, controller = nil)
75
- initialize_without_desert(base_path, assigns_for_first_render, controller)
76
-
77
- @view_paths = [base_path]
78
- Desert::Manager.plugins_and_app.reverse.each do |plugin|
79
- @view_paths << plugin.templates_path
80
- end
81
- end
82
- alias_method_chain :initialize, :desert
83
-
84
- private
85
- def full_path_template_exists?(path, extension)
86
- file_path = "#{path}.#{extension}"
87
- @@method_names.has_key?(file_path) || FileTest.exists?(file_path)
88
- end
89
-
90
- def find_template_extension_for(template_path)
91
- view_paths.each do |view_path|
92
- full_path = "#{view_path}/#{template_path}"
93
- if match = @@template_handlers.find { |k,| full_path_template_exists?(template_path, k) }
94
- return match.first.to_sym
95
- elsif full_path_template_exists?(full_path, :rhtml)
96
- return :rhtml
97
- elsif full_path_template_exists?(full_path, :rxml)
98
- return :rxml
99
- elsif full_path_template_exists?(full_path, :rjs)
100
- return :rjs
101
- end
102
- end
103
- raise ActionViewError, "No rhtml, rxml, rjs or delegate template found for #{template_path} in #{@base_path}"
104
- end
105
-
106
- def full_template_path_with_plugin_routing(template_path, extension)
107
- full_template_path = full_template_path_without_plugin_routing(template_path, extension)
108
-
109
- unless File.exist?(full_template_path)
110
- # Look through the plugins for the template
111
- Desert::Manager.plugins.reverse.each do |plugin|
112
- if plugin_template_path = plugin.find_template("#{template_path}.#{extension}")
113
- full_template_path = plugin_template_path
114
- break
115
- end
116
- end
117
- end
118
-
119
- full_template_path
120
- end
121
- alias_method_chain :full_template_path, :plugin_routing
122
- end
6
+ if ActionView::Base.private_instance_methods.include?('find_template_extension_from_handler')
7
+ if ActionView::Base.instance_methods.include?('template_handler_preferences')
8
+ require "#{dir}/1.99.0/action_view"
9
+ else
10
+ require "#{dir}/2.0.2/action_view"
123
11
  end
12
+ elsif ActionView.const_defined?(:PathSet)
13
+ require "#{dir}/edge/action_view"
14
+ else
15
+ require "#{dir}/1.2.0/action_view"
124
16
  end
125
17
  end
@@ -0,0 +1,10 @@
1
+ ActionView::Base.class_eval do
2
+ def initialize_with_desert_plugins(*args)
3
+ initialize_without_desert_plugins *args
4
+
5
+ Desert::Manager.plugins.reverse.each do |plugin|
6
+ view_paths << plugin.templates_path
7
+ end
8
+ end
9
+ alias_method_chain :initialize, :desert_plugins
10
+ end
@@ -8,12 +8,6 @@ class ActiveRecord::Migration
8
8
  )
9
9
  end
10
10
 
11
- def schema_version_equivalent_to(plugin_name, version)
12
- plugin = find_plugin(plugin_name)
13
- Desert::PluginMigrations::Migrator.current_plugin = plugin
14
- Desert::PluginMigrations::Migrator.allocate.set_schema_version(version)
15
- end
16
-
17
11
  protected
18
12
  def find_plugin(plugin_name)
19
13
  plugin = Desert::Manager.find_plugin(plugin_name.to_s)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: desert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal Labs
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-10 00:00:00 -07:00
12
+ date: 2008-10-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,38 +28,43 @@ files:
28
28
  - Rakefile
29
29
  - README.rdoc
30
30
  - init.rb
31
- - lib/desert/rails/2.0.0/plugin.rb
32
- - lib/desert/rails/route_set.rb
33
- - lib/desert/rails/migration.rb
34
- - lib/desert/rails/1.2.0/initializer.rb
35
- - lib/desert/rails/dependencies.rb
36
31
  - lib/desert/manager.rb
37
- - lib/desert/plugin_migrations/migrator.rb
32
+ - lib/desert/plugin.rb
38
33
  - lib/desert/plugin_migrations/extensions/1.0/schema_statements.rb
39
- - lib/desert/plugin_migrations/extensions/schema_statements.rb
40
34
  - lib/desert/plugin_migrations/extensions/2.1/schema_statements.rb
41
- - lib/desert/plugin_templates.rb
42
- - lib/desert/supported_rails_versions.rb
43
- - lib/desert/ruby.rb
44
- - lib/desert/version_checker.rb
35
+ - lib/desert/plugin_migrations/extensions/schema_statements.rb
36
+ - lib/desert/plugin_migrations/migrator.rb
37
+ - lib/desert/plugin_migrations.rb
38
+ - lib/desert/plugin_templates/1.2.0/action_mailer.rb
39
+ - lib/desert/plugin_templates/1.2.0/action_view.rb
40
+ - lib/desert/plugin_templates/1.99.0/action_mailer.rb
41
+ - lib/desert/plugin_templates/1.99.0/action_view.rb
45
42
  - lib/desert/plugin_templates/2.0.0/action_mailer.rb
43
+ - lib/desert/plugin_templates/2.0.2/action_view.rb
44
+ - lib/desert/plugin_templates/2.1.0/action_view.rb
46
45
  - lib/desert/plugin_templates/action_controller.rb
47
46
  - lib/desert/plugin_templates/action_view.rb
48
- - lib/desert/plugin_templates/1.2.0/action_mailer.rb
49
- - lib/desert/plugin_templates/1.99.0/action_mailer.rb
50
- - lib/desert/ruby/object.rb
51
- - lib/desert/plugin_migrations.rb
47
+ - lib/desert/plugin_templates/edge/action_view.rb
48
+ - lib/desert/plugin_templates.rb
49
+ - lib/desert/rails/1.2.0/initializer.rb
50
+ - lib/desert/rails/2.0.0/plugin.rb
51
+ - lib/desert/rails/dependencies.rb
52
+ - lib/desert/rails/migration.rb
53
+ - lib/desert/rails/route_set.rb
52
54
  - lib/desert/rails.rb
53
- - lib/desert/plugin.rb
55
+ - lib/desert/ruby/object.rb
56
+ - lib/desert/ruby.rb
57
+ - lib/desert/supported_rails_versions.rb
58
+ - lib/desert/version_checker.rb
54
59
  - lib/desert.rb
55
60
  - generators/desert_plugin
56
- - generators/desert_plugin/USAGE
61
+ - generators/desert_plugin/desert_plugin_generator.rb
57
62
  - generators/desert_plugin/templates
58
- - generators/desert_plugin/templates/spec_helper.rb
59
- - generators/desert_plugin/templates/plugin_migration.rb
60
63
  - generators/desert_plugin/templates/empty_file
64
+ - generators/desert_plugin/templates/plugin_migration.rb
61
65
  - generators/desert_plugin/templates/routes.rb
62
- - generators/desert_plugin/desert_plugin_generator.rb
66
+ - generators/desert_plugin/templates/spec_helper.rb
67
+ - generators/desert_plugin/USAGE
63
68
  has_rdoc: true
64
69
  homepage: http://pivotallabs.com
65
70
  post_install_message:
@@ -85,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
90
  requirements: []
86
91
 
87
92
  rubyforge_project: pivotalrb
88
- rubygems_version: 1.1.1
93
+ rubygems_version: 1.2.0
89
94
  signing_key:
90
95
  specification_version: 2
91
96
  summary: Desert is a component framework for Rails that allows your plugins to be packaged as mini Rails apps.