joshnabbott-desert 0.3.5.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 +36 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +316 -0
- data/Rakefile +106 -0
- data/generators/desert_plugin/USAGE +14 -0
- data/generators/desert_plugin/desert_plugin_generator.rb +73 -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/routes.rb +4 -0
- data/generators/desert_plugin/templates/spec_helper.rb +8 -0
- data/init.rb +0 -0
- data/lib/desert/manager.rb +116 -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/2.1/extensions/schema_statements.rb +30 -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 +13 -0
- data/lib/desert/plugin_templates/action_controller.rb +14 -0
- data/lib/desert/plugin_templates/action_view.rb +17 -0
- data/lib/desert/plugin_templates/edge/action_view.rb +10 -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/observer.rb +22 -0
- data/lib/desert/rails/route_set.rb +23 -0
- data/lib/desert/rails.rb +11 -0
- data/lib/desert/ruby/object.rb +34 -0
- data/lib/desert/ruby.rb +2 -0
- data/lib/desert/supported_rails_versions.rb +11 -0
- data/lib/desert/version_checker.rb +26 -0
- data/lib/desert.rb +14 -0
- metadata +95 -0
@@ -0,0 +1,116 @@
|
|
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
|
+
protected
|
104
|
+
def dependencies
|
105
|
+
@dependencies ||= ActiveSupport.const_defined?(:Dependencies) ? ActiveSupport::Dependencies : Dependencies
|
106
|
+
end
|
107
|
+
|
108
|
+
def plugin_paths
|
109
|
+
plugins_and_app.collect { |plugin| plugin.path }
|
110
|
+
end
|
111
|
+
|
112
|
+
def plugins_and_app
|
113
|
+
plugins + @plugins_in_registration + [Plugin.new(RAILS_ROOT)]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
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,30 @@
|
|
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_info_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
|
+
Integer(migration.split("_").first) <= Integer(version)
|
15
|
+
end
|
16
|
+
migration_versions.each do |migration_version|
|
17
|
+
insert_sql = ActiveRecord::Base.send(:sanitize_sql, [
|
18
|
+
"INSERT INTO #{Desert::PluginMigrations::Migrator.schema_migrations_table_name}(plugin_name, version) VALUES(?, ?)",
|
19
|
+
plugin_name,
|
20
|
+
Integer(migration_version.split("_").first)
|
21
|
+
])
|
22
|
+
execute insert_sql
|
23
|
+
end
|
24
|
+
end
|
25
|
+
rescue ActiveRecord::StatementInvalid
|
26
|
+
# Schema has been initialized
|
27
|
+
end
|
28
|
+
end
|
29
|
+
alias_method_chain :initialize_schema_migrations_table, :plugins
|
30
|
+
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,13 @@
|
|
1
|
+
module ActionView #:nodoc:
|
2
|
+
class TemplateFinder #:nodoc:
|
3
|
+
def initialize_with_desert_plugins(base, *paths)
|
4
|
+
self.class.process_view_paths(*paths)
|
5
|
+
initialize_without_desert_plugins base, *paths
|
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
|
@@ -0,0 +1,14 @@
|
|
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
|
+
plugin_layouts.empty? ?
|
8
|
+
layout_list_without_plugin_routing :
|
9
|
+
layout_list_without_plugin_routing + Dir["{#{plugin_layouts}}/**/*"]
|
10
|
+
end
|
11
|
+
alias_method_chain :layout_list, :plugin_routing
|
12
|
+
end
|
13
|
+
end
|
14
|
+
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}/edge/action_view"
|
14
|
+
else
|
15
|
+
require "#{dir}/1.2.0/action_view"
|
16
|
+
end
|
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
|
@@ -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
|