cauta-desert 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +46 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +316 -0
- data/Rakefile +77 -0
- data/VERSION.yml +2 -0
- data/generators/desert_plugin/USAGE +14 -0
- data/generators/desert_plugin/desert_plugin_generator.rb +73 -0
- data/generators/desert_plugin/templates/desert_routes.rb +4 -0
- data/generators/desert_plugin/templates/empty_file +0 -0
- data/generators/desert_plugin/templates/plugin_migration.rb +11 -0
- data/generators/desert_plugin/templates/spec_helper.rb +8 -0
- data/init.rb +0 -0
- data/lib/desert/manager.rb +129 -0
- data/lib/desert/plugin.rb +74 -0
- data/lib/desert/plugin_migrations/1.2/extensions/schema_statements.rb +34 -0
- data/lib/desert/plugin_migrations/1.2/migrator.rb +33 -0
- data/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb +33 -0
- data/lib/desert/plugin_migrations/2.1/migrator.rb +35 -0
- data/lib/desert/plugin_migrations/migrator.rb +29 -0
- data/lib/desert/plugin_migrations.rb +11 -0
- data/lib/desert/plugin_templates/1.2.0/action_mailer.rb +21 -0
- data/lib/desert/plugin_templates/1.2.0/action_view.rb +53 -0
- data/lib/desert/plugin_templates/1.99.0/action_mailer.rb +25 -0
- data/lib/desert/plugin_templates/1.99.0/action_view.rb +38 -0
- data/lib/desert/plugin_templates/2.0.0/action_mailer.rb +23 -0
- data/lib/desert/plugin_templates/2.0.2/action_view.rb +26 -0
- data/lib/desert/plugin_templates/2.1.0/action_view.rb +12 -0
- data/lib/desert/plugin_templates/action_controller.rb +12 -0
- data/lib/desert/plugin_templates/action_view.rb +17 -0
- data/lib/desert/plugin_templates.rb +10 -0
- data/lib/desert/rails/1.2.0/initializer.rb +20 -0
- data/lib/desert/rails/2.0.0/plugin.rb +22 -0
- data/lib/desert/rails/dependencies.rb +87 -0
- data/lib/desert/rails/migration.rb +36 -0
- data/lib/desert/rails/route_set.rb +23 -0
- data/lib/desert/rails.rb +10 -0
- data/lib/desert/ruby/object.rb +34 -0
- data/lib/desert/ruby.rb +2 -0
- data/lib/desert/supported_rails_versions.rb +12 -0
- data/lib/desert/tasks.rb +4 -0
- data/lib/desert/version_checker.rb +26 -0
- data/lib/desert.rb +14 -0
- metadata +102 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
module Desert
|
2
|
+
class Manager # nodoc
|
3
|
+
class << self
|
4
|
+
def instance
|
5
|
+
@instance ||= new
|
6
|
+
end
|
7
|
+
attr_writer :instance
|
8
|
+
|
9
|
+
protected
|
10
|
+
def method_missing(method_name, *args, &block)
|
11
|
+
instance.__send__(method_name, *args, &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :loading_plugin, :plugins_in_registration
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@plugins = []
|
19
|
+
@plugins_in_registration = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def plugins
|
23
|
+
@plugins.dup
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_paths
|
27
|
+
paths = []
|
28
|
+
plugin_paths.each do |component_root|
|
29
|
+
paths << File.join(component_root, 'app')
|
30
|
+
paths << File.join(component_root, 'app','models')
|
31
|
+
paths << File.join(component_root, 'app','controllers')
|
32
|
+
paths << File.join(component_root, 'app','helpers')
|
33
|
+
paths << File.join(component_root, 'lib')
|
34
|
+
end
|
35
|
+
dependencies.load_paths.reverse.each do |path|
|
36
|
+
paths << File.expand_path(path) unless paths.include?(File.expand_path(path))
|
37
|
+
end
|
38
|
+
paths
|
39
|
+
end
|
40
|
+
|
41
|
+
def register_plugin(plugin_path)
|
42
|
+
plugin = Plugin.new(plugin_path)
|
43
|
+
@plugins_in_registration << plugin
|
44
|
+
|
45
|
+
yield if block_given?
|
46
|
+
|
47
|
+
dependencies.load_paths << plugin.models_path
|
48
|
+
dependencies.load_paths << plugin.controllers_path
|
49
|
+
dependencies.load_paths << plugin.helpers_path
|
50
|
+
|
51
|
+
@plugins_in_registration.pop
|
52
|
+
|
53
|
+
if existing_plugin = find_plugin(plugin.name)
|
54
|
+
return existing_plugin
|
55
|
+
end
|
56
|
+
|
57
|
+
@plugins << plugin
|
58
|
+
plugin
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_plugin(name_or_directory)
|
62
|
+
name = File.basename(File.expand_path(name_or_directory))
|
63
|
+
plugins.find do |plugin|
|
64
|
+
plugin.name == name
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def plugin_exists?(name_or_directory)
|
69
|
+
!find_plugin(name_or_directory).nil?
|
70
|
+
end
|
71
|
+
|
72
|
+
def plugin_path(name)
|
73
|
+
plugin = find_plugin(name)
|
74
|
+
return nil unless plugin
|
75
|
+
plugin.path
|
76
|
+
end
|
77
|
+
|
78
|
+
def files_on_load_path(file)
|
79
|
+
desert_file_exists = false
|
80
|
+
files = []
|
81
|
+
load_paths.each do |path|
|
82
|
+
full_path = File.join(path, file)
|
83
|
+
full_path << '.rb' unless File.extname(full_path) == '.rb'
|
84
|
+
files << full_path if File.exists?(full_path)
|
85
|
+
end
|
86
|
+
files
|
87
|
+
end
|
88
|
+
|
89
|
+
def directory_on_load_path?(dir_suffix)
|
90
|
+
Desert::Manager.load_paths.each do |path|
|
91
|
+
return true if File.directory?(File.join(path, dir_suffix))
|
92
|
+
end
|
93
|
+
return false
|
94
|
+
end
|
95
|
+
|
96
|
+
def layout_paths
|
97
|
+
layout_paths = plugins.reverse.collect do |plugin|
|
98
|
+
plugin.layouts_path
|
99
|
+
end
|
100
|
+
layout_paths
|
101
|
+
end
|
102
|
+
|
103
|
+
def require_all_files
|
104
|
+
all_files.each do |file|
|
105
|
+
require file
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def all_files
|
110
|
+
Desert::Manager.load_paths.inject([]) do |all, load_path|
|
111
|
+
all |= Dir["#{load_path}/**/*.rb"]
|
112
|
+
all
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
protected
|
117
|
+
def dependencies
|
118
|
+
@dependencies ||= ActiveSupport.const_defined?(:Dependencies) ? ActiveSupport::Dependencies : Dependencies
|
119
|
+
end
|
120
|
+
|
121
|
+
def plugin_paths
|
122
|
+
plugins_and_app.collect { |plugin| plugin.path }
|
123
|
+
end
|
124
|
+
|
125
|
+
def plugins_and_app
|
126
|
+
plugins + @plugins_in_registration + [Plugin.new(RAILS_ROOT)]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Desert
|
2
|
+
class Plugin # nodoc
|
3
|
+
attr_reader :name, :path
|
4
|
+
def initialize(path)
|
5
|
+
@path = File.expand_path(path)
|
6
|
+
@name = File.basename(@path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def migration_path
|
10
|
+
"#{@path}/db/migrate"
|
11
|
+
end
|
12
|
+
|
13
|
+
# The path to the views for this plugin
|
14
|
+
def templates_path
|
15
|
+
"#{@path}/app/views"
|
16
|
+
end
|
17
|
+
|
18
|
+
def controllers_path
|
19
|
+
"#{@path}/app/controllers"
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO: Test me
|
23
|
+
def models_path
|
24
|
+
"#{@path}/app/models"
|
25
|
+
end
|
26
|
+
|
27
|
+
# TODO: Test me
|
28
|
+
def helpers_path
|
29
|
+
"#{@path}/app/helpers"
|
30
|
+
end
|
31
|
+
|
32
|
+
# The path to the layout for this plugin
|
33
|
+
def layouts_path
|
34
|
+
"#{templates_path}/layouts"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Finds a template with the specified path
|
38
|
+
def find_template(template)
|
39
|
+
template_path = "#{templates_path}/#{template}"
|
40
|
+
File.exists?(template_path) ? template_path : nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def framework_paths
|
44
|
+
# TODO: Don't include dirs for frameworks that are not used
|
45
|
+
%w(
|
46
|
+
railties
|
47
|
+
railties/lib
|
48
|
+
actionpack/lib
|
49
|
+
activesupport/lib
|
50
|
+
activerecord/lib
|
51
|
+
actionmailer/lib
|
52
|
+
actionwebservice/lib
|
53
|
+
).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def ==(other)
|
57
|
+
self.path == other.path
|
58
|
+
end
|
59
|
+
|
60
|
+
def migration
|
61
|
+
@migration ||= PluginMigrations::Migrator.new(:up, migration_path)
|
62
|
+
end
|
63
|
+
|
64
|
+
def with_current_plugin
|
65
|
+
old_plugin = PluginMigrations::Migrator.current_plugin
|
66
|
+
begin
|
67
|
+
PluginMigrations::Migrator.current_plugin = self
|
68
|
+
yield
|
69
|
+
ensure
|
70
|
+
PluginMigrations::Migrator.current_plugin = old_plugin
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
|
2
|
+
def initialize_schema_information_with_plugins
|
3
|
+
initialize_schema_information_without_plugins
|
4
|
+
|
5
|
+
begin
|
6
|
+
execute "CREATE TABLE #{Desert::PluginMigrations::Migrator.schema_info_table_name} (plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:integer)})"
|
7
|
+
rescue ActiveRecord::StatementInvalid
|
8
|
+
# Schema has been initialized
|
9
|
+
end
|
10
|
+
end
|
11
|
+
alias_method_chain :initialize_schema_information, :plugins
|
12
|
+
|
13
|
+
def dump_schema_information_with_plugins
|
14
|
+
schema_information = []
|
15
|
+
|
16
|
+
dump = dump_schema_information_without_plugins
|
17
|
+
schema_information << dump if dump
|
18
|
+
|
19
|
+
begin
|
20
|
+
plugins = ActiveRecord::Base.connection.select_all("SELECT * FROM #{Desert::PluginMigrations::Migrator.schema_info_table_name}")
|
21
|
+
plugins.each do |plugin|
|
22
|
+
if (version = plugin['version'].to_i) > 0
|
23
|
+
plugin_name = ActiveRecord::Base.quote_value(plugin['plugin_name'])
|
24
|
+
schema_information << "INSERT INTO #{Desert::PluginMigrations::Migrator.schema_info_table_name} (plugin_name, version) VALUES (#{plugin_name}, #{version})"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
rescue ActiveRecord::StatementInvalid
|
28
|
+
# No Schema Info
|
29
|
+
end
|
30
|
+
|
31
|
+
schema_information.join(";\n")
|
32
|
+
end
|
33
|
+
alias_method_chain :dump_schema_information, :plugins
|
34
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Desert #:nodoc:
|
2
|
+
module PluginMigrations
|
3
|
+
class Migrator < ActiveRecord::Migrator
|
4
|
+
class << self
|
5
|
+
def current_version #:nodoc:
|
6
|
+
result = ActiveRecord::Base.connection.select_one("SELECT version FROM #{schema_info_table_name} WHERE plugin_name = '#{current_plugin.name}'")
|
7
|
+
if result
|
8
|
+
result['version'].to_i
|
9
|
+
else
|
10
|
+
# There probably isn't an entry for this plugin in the migration info table.
|
11
|
+
0
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_schema_version(version)
|
17
|
+
version = down? ? version.to_i - 1 : version.to_i
|
18
|
+
|
19
|
+
if ActiveRecord::Base.connection.select_one("SELECT version FROM #{self.class.schema_info_table_name} WHERE plugin_name = '#{current_plugin.name}'").nil?
|
20
|
+
# We need to create the entry since it doesn't exist
|
21
|
+
ActiveRecord::Base.connection.execute("INSERT INTO #{self.class.schema_info_table_name} (version, plugin_name) VALUES (#{version},'#{current_plugin.name}')")
|
22
|
+
else
|
23
|
+
ActiveRecord::Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{version} WHERE plugin_name = '#{current_plugin.name}'")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def migrated
|
28
|
+
current_plugin_version = self.class.current_version
|
29
|
+
(1..current_plugin_version).to_a
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
|
2
|
+
def initialize_schema_migrations_table_with_plugins
|
3
|
+
initialize_schema_migrations_table_without_plugins
|
4
|
+
|
5
|
+
begin
|
6
|
+
execute "CREATE TABLE #{Desert::PluginMigrations::Migrator.schema_migrations_table_name} (plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:string)})"
|
7
|
+
plugins_and_versions = select_all("SELECT plugin_name, version from #{Desert::PluginMigrations::Migrator.schema_migrations_table_name}")
|
8
|
+
plugins_and_versions.each do |plugin_data|
|
9
|
+
plugin_name, version = plugin_data["plugin_name"], plugin_data["version"]
|
10
|
+
plugin = Desert::Manager.find_plugin(plugin_name)
|
11
|
+
migration_versions = Dir["#{plugin.migration_path}/*.rb"].map do |path|
|
12
|
+
File.basename(path, ".rb")
|
13
|
+
end.select do |migration|
|
14
|
+
# Make sure versions don't start with zero, or Integer will interpret them as octal
|
15
|
+
version_from_table_stripped = version.sub(/^0*/, '')
|
16
|
+
migration_version_stripped = migration.split("_").first.sub(/^0*/, '')
|
17
|
+
Integer(migration_version_stripped) <= Integer(version_from_table_stripped)
|
18
|
+
end
|
19
|
+
migration_versions.each do |migration_version|
|
20
|
+
insert_sql = ActiveRecord::Base.send(:sanitize_sql, [
|
21
|
+
"INSERT INTO #{Desert::PluginMigrations::Migrator.schema_migrations_table_name}(plugin_name, version) VALUES(?, ?)",
|
22
|
+
plugin_name,
|
23
|
+
Integer(migration_version.split("_").first.sub(/^0*/, ''))
|
24
|
+
])
|
25
|
+
execute insert_sql
|
26
|
+
end
|
27
|
+
end
|
28
|
+
rescue ActiveRecord::StatementInvalid
|
29
|
+
# Schema has been initialized
|
30
|
+
end
|
31
|
+
end
|
32
|
+
alias_method_chain :initialize_schema_migrations_table, :plugins
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Desert #:nodoc:
|
2
|
+
module PluginMigrations
|
3
|
+
class Migrator < ActiveRecord::Migrator
|
4
|
+
class << self
|
5
|
+
def current_version #:nodoc:
|
6
|
+
result = ActiveRecord::Base.connection.select_one("SELECT version FROM #{schema_migrations_table_name} WHERE plugin_name = '#{current_plugin.name}' order by version desc")
|
7
|
+
if result
|
8
|
+
result['version'].to_i
|
9
|
+
else
|
10
|
+
# There probably isn't an entry for this plugin in the migration info table.
|
11
|
+
0
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_all_versions
|
16
|
+
ActiveRecord::Base.connection.select_values("SELECT version FROM #{schema_migrations_table_name} where plugin_name='#{current_plugin.name}'").map(&:to_i).sort
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def record_version_state_after_migrating(version)
|
21
|
+
sm_table = self.class.schema_migrations_table_name
|
22
|
+
|
23
|
+
if down?
|
24
|
+
ActiveRecord::Base.connection.update("DELETE FROM #{sm_table} WHERE version = '#{version}' WHERE plugin_name = '#{current_plugin.name}'")
|
25
|
+
else
|
26
|
+
ActiveRecord::Base.connection.insert("INSERT INTO #{sm_table} (plugin_name, version) VALUES ('#{current_plugin.name}', '#{version}')")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def migrated
|
31
|
+
self.class.get_all_versions
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Desert #:nodoc:
|
2
|
+
module PluginMigrations
|
3
|
+
# Responsible for migrating plugins. PluginMigrations.Migrator.current_plugin
|
4
|
+
# indicates which plugin is currently being migrated
|
5
|
+
class Migrator < ActiveRecord::Migrator
|
6
|
+
# We need to be able to set the current plugin being migrated.
|
7
|
+
cattr_accessor :current_plugin
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# Runs the migrations from a plugin, up (or down) to the version given
|
11
|
+
def migrate_plugin(plugin, version = nil)
|
12
|
+
self.current_plugin = plugin
|
13
|
+
if ActiveRecord::Base.connection.respond_to?(:initialize_schema_migrations_table)
|
14
|
+
ActiveRecord::Base.connection.initialize_schema_migrations_table
|
15
|
+
end
|
16
|
+
migrate(plugin.migration_path, version)
|
17
|
+
end
|
18
|
+
|
19
|
+
def schema_info_table_name #:nodoc:
|
20
|
+
ActiveRecord::Base.table_name_prefix + 'plugin_schema_info' + ActiveRecord::Base.table_name_suffix
|
21
|
+
end
|
22
|
+
|
23
|
+
def schema_migrations_table_name
|
24
|
+
ActiveRecord::Base.table_name_prefix + 'plugin_schema_migrations' + ActiveRecord::Base.table_name_suffix
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
dir = File.dirname(__FILE__)
|
4
|
+
require "#{dir}/plugin_migrations/migrator"
|
5
|
+
if ActiveRecord::ConnectionAdapters::SchemaStatements.instance_methods.include?('initialize_schema_information')
|
6
|
+
require "#{dir}/plugin_migrations/1.2/migrator"
|
7
|
+
require "#{dir}/plugin_migrations/1.2/extensions/schema_statements"
|
8
|
+
else
|
9
|
+
require "#{dir}/plugin_migrations/2.1/migrator"
|
10
|
+
require "#{dir}/plugin_migrations/2.1/extensions/schema_statements"
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActionMailer #:nodoc
|
2
|
+
class Base #:nodoc:
|
3
|
+
private
|
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}"
|
8
|
+
end
|
9
|
+
"{#{template_paths * ','}}"
|
10
|
+
end
|
11
|
+
alias_method_chain :template_path, :plugin_routing
|
12
|
+
|
13
|
+
def initialize_template_class(assigns)
|
14
|
+
view_path = File.dirname(Dir["#{template_path}/#{@template}.*"].first)
|
15
|
+
returning(template = ActionView::Base.new(view_path, assigns, self)) do
|
16
|
+
template.extend ApplicationHelper
|
17
|
+
template.extend self.class.master_helper_module
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActionMailer #:nodoc
|
2
|
+
class Base #:nodoc:
|
3
|
+
private
|
4
|
+
def template_path_with_plugin_routing
|
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
|
12
|
+
end
|
13
|
+
result || template_path_without_plugin_routing
|
14
|
+
end
|
15
|
+
alias_method_chain :template_path, :plugin_routing
|
16
|
+
|
17
|
+
def initialize_template_class(assigns)
|
18
|
+
view_path = File.dirname(Dir["#{template_path}/#{@template}.*"].first)
|
19
|
+
returning(template = ActionView::Base.new([view_path], assigns, self)) do
|
20
|
+
template.extend ApplicationHelper
|
21
|
+
template.extend self.class.master_helper_module
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -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,23 @@
|
|
1
|
+
module ActionMailer #:nodoc
|
2
|
+
class Base #:nodoc:
|
3
|
+
private
|
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}"
|
8
|
+
end
|
9
|
+
"{#{template_paths * ','}}"
|
10
|
+
end
|
11
|
+
alias_method_chain :template_path, :plugin_routing
|
12
|
+
|
13
|
+
def initialize_template_class(assigns)
|
14
|
+
view_paths = Dir[template_path].collect do |path|
|
15
|
+
File.dirname(path)
|
16
|
+
end
|
17
|
+
returning(template = ActionView::Base.new(view_paths, assigns, self)) do
|
18
|
+
template.extend ApplicationHelper
|
19
|
+
template.extend self.class.master_helper_module
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
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
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActionController #:nodoc:
|
2
|
+
module Layout #:nodoc:
|
3
|
+
module ClassMethods #:nodoc:
|
4
|
+
private
|
5
|
+
def layout_list_with_plugin_routing
|
6
|
+
plugin_layouts = Desert::Manager.layout_paths.join(",")
|
7
|
+
layout_list_without_plugin_routing + Dir["{#{plugin_layouts}}/**/*"]
|
8
|
+
end
|
9
|
+
alias_method_chain :layout_list, :plugin_routing
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
if ActionView.const_defined?(:TemplateFinder)
|
4
|
+
require "#{dir}/2.1.0/action_view"
|
5
|
+
else
|
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"
|
11
|
+
end
|
12
|
+
elsif ActionView.const_defined?(:PathSet)
|
13
|
+
require "#{dir}/2.2.0/action_view"
|
14
|
+
else
|
15
|
+
require "#{dir}/1.2.0/action_view"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require "#{dir}/plugin_templates/action_controller"
|
3
|
+
if Desert::VersionChecker.rails_version_is_below_1990?
|
4
|
+
require "#{dir}/plugin_templates/1.2.0/action_mailer"
|
5
|
+
elsif Desert::VersionChecker.rails_version_is_below_rc2?
|
6
|
+
require "#{dir}/plugin_templates/1.99.0/action_mailer"
|
7
|
+
else
|
8
|
+
require "#{dir}/plugin_templates/2.0.0/action_mailer"
|
9
|
+
end
|
10
|
+
require "#{dir}/plugin_templates/action_view"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rails
|
2
|
+
class Initializer
|
3
|
+
def load_plugin_with_desert(directory)
|
4
|
+
return if Desert::Manager.plugin_exists?(directory)
|
5
|
+
plugin = Desert::Manager.register_plugin(directory) do
|
6
|
+
load_plugin_without_desert(directory)
|
7
|
+
end
|
8
|
+
# TODO: Can we use Initializer::Configuration#default_load_paths to do this?
|
9
|
+
configuration.controller_paths << plugin.controllers_path
|
10
|
+
end
|
11
|
+
alias_method_chain :load_plugin, :desert
|
12
|
+
|
13
|
+
def require_plugin(plugin_name)
|
14
|
+
find_plugins(configuration.plugin_paths).sort.each do |path|
|
15
|
+
return load_plugin(path) if File.basename(path) == plugin_name
|
16
|
+
end
|
17
|
+
raise "Plugin '#{plugin_name}' does not exist"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Rails::Plugin
|
2
|
+
attr_accessor :initializer
|
3
|
+
def require_plugin(plugin_name)
|
4
|
+
initializer.configuration.plugin_locators.each do |locator|
|
5
|
+
locator.new(initializer).each do |plugin_loader|
|
6
|
+
return plugin_loader.load(initializer) if plugin_loader.name.to_s == plugin_name.to_s
|
7
|
+
end
|
8
|
+
end
|
9
|
+
raise "Plugin '#{plugin_name}' does not exist"
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_with_desert(initializer)
|
13
|
+
@initializer = initializer
|
14
|
+
return if Desert::Manager.plugin_exists?(directory)
|
15
|
+
plugin = Desert::Manager.register_plugin(directory) do
|
16
|
+
load_without_desert(initializer)
|
17
|
+
end
|
18
|
+
# TODO: Can we use Initializer::Configuration#default_load_paths to do this?
|
19
|
+
initializer.configuration.controller_paths << plugin.controllers_path
|
20
|
+
end
|
21
|
+
alias_method_chain :load, :desert
|
22
|
+
end
|