plugems 1.1.0
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/MIT-LICENSE +20 -0
- data/README +0 -0
- data/config/manifest.yml +5 -0
- data/init.rb +1 -0
- data/lib/plugems.rb +44 -0
- data/lib/plugems/loader.rb +153 -0
- data/lib/plugems/manifest.rb +57 -0
- data/lib/plugems/plugem_view_support.rb +75 -0
- data/lib/plugems/tasks/loader.rb +19 -0
- data/lib/tasks/rails.rb +25 -0
- metadata +59 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Revolution Health Group LLC. All rights reserved.
|
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.
|
data/README
ADDED
File without changes
|
data/config/manifest.yml
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'plugems'
|
data/lib/plugems.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Rails 1.1.16 is not very extensible in how it loads rake tasks.
|
2
|
+
# There is a file called tasks/rails.rb, required from the default RAILS_ROOT/Rakefile,
|
3
|
+
# that has 3 lines of Dir['foo'].each {|a| load a}, which is not very extensible
|
4
|
+
# Therefore, plugems unshifts the current lib directory in order to include a plugem
|
5
|
+
# copy of tasks/rails.rb.
|
6
|
+
$:.unshift File.dirname(__FILE__)
|
7
|
+
|
8
|
+
if defined?(RAILS_ROOT)
|
9
|
+
require 'plugems/loader'
|
10
|
+
|
11
|
+
module Rails
|
12
|
+
class Initializer
|
13
|
+
|
14
|
+
def load_plugins_with_plugems
|
15
|
+
Plugems::Loader.load(configuration)
|
16
|
+
load_plugins_without_plugems
|
17
|
+
end
|
18
|
+
|
19
|
+
# TODO replace with alias_method_chain on Rails 1.2
|
20
|
+
# alias_method_chain :load_plugins, :plugems
|
21
|
+
alias_method :load_plugins_without_plugems, :load_plugins
|
22
|
+
alias_method :load_plugins, :load_plugins_with_plugems
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Gem
|
28
|
+
|
29
|
+
class << self
|
30
|
+
|
31
|
+
def activate_plugin_or_gem(gem, autorequire, *version_requirements)
|
32
|
+
if Plugems::Loader.plugin?(gem)
|
33
|
+
Plugems::Loader.load_as_plugin(gem)
|
34
|
+
else
|
35
|
+
activate_gem(gem, autorequire, *version_requirements)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
alias_method :activate_gem, :activate
|
40
|
+
alias_method :activate, :activate_plugin_or_gem
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'plugems/manifest'
|
2
|
+
require 'plugems/tasks/loader'
|
3
|
+
|
4
|
+
# load monkey patch for finding views in plugins + gems too
|
5
|
+
require 'plugems/plugem_view_support.rb'
|
6
|
+
|
7
|
+
module Plugems
|
8
|
+
class Loader
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def load(configuration)
|
13
|
+
# TODO find a way to get the plugin_paths defined in the Rails::Initializer block, if any
|
14
|
+
#@@configuration = configuration
|
15
|
+
@@loaded_plugems = {} # hash of all loaded plugems, to prevent loading duplicates
|
16
|
+
|
17
|
+
manifest = Plugems::Manifest.load("#{RAILS_ROOT}/config/manifest.yml")
|
18
|
+
load_plugems(manifest)
|
19
|
+
set_dependencies_loaded_flag
|
20
|
+
end
|
21
|
+
|
22
|
+
def gem_rake_tasks
|
23
|
+
(@@gem_rake_tasks ||= []).flatten.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
def gem_views
|
27
|
+
(@@gem_views ||= []).flatten.uniq
|
28
|
+
end
|
29
|
+
|
30
|
+
def plugin_views
|
31
|
+
plugin_lib_paths.collect do |plugin_path|
|
32
|
+
Dir["#{plugin_path}/views/**/*.*"]
|
33
|
+
end.flatten.uniq
|
34
|
+
end
|
35
|
+
|
36
|
+
def plugin?(name)
|
37
|
+
(path = plugin_path(name)) && File.directory?(path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_as_plugin(name)
|
41
|
+
path = plugin_path(name)
|
42
|
+
plugin_lib = File.join(path, "lib")
|
43
|
+
$: << plugin_lib if File.exist?(plugin_lib)
|
44
|
+
process_plugin_manifest(path)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def plugin_lib_paths
|
50
|
+
# TODO determine if the configuration object is already configured by this point
|
51
|
+
Rails::Configuration.new.plugin_paths.collect do |plugin_path|
|
52
|
+
# Cant use Dir["foo/**/lib"] because symlinks are not followed with Dir
|
53
|
+
Dir["#{plugin_path}/*"].collect { |plugin_lib| plugin_lib}
|
54
|
+
end.flatten.uniq
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_plugems(manifest)
|
58
|
+
# after loading the gem specific dependencies require
|
59
|
+
# each file picking up gems and plugins. This is loaded outside the above loop
|
60
|
+
# incase of a dependency cycle...
|
61
|
+
manifest.dependencies.each do |name, version|
|
62
|
+
load_plugem(name, version || ">= 0.0.0")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def load_plugem(name, version)
|
67
|
+
return if @@loaded_plugems.include?(name)
|
68
|
+
debug "Loading #{name}..."
|
69
|
+
if plugin?(name)
|
70
|
+
load_as_plugin(name)
|
71
|
+
else
|
72
|
+
load_as_gem(name,version)
|
73
|
+
end
|
74
|
+
debug "Loaded #{name}!"
|
75
|
+
@@loaded_plugems[name] = true
|
76
|
+
end
|
77
|
+
|
78
|
+
def plugin_path(gem_or_plugin)
|
79
|
+
name = gem_or_plugin.respond_to?(:name) ? gem_or_plugin.name : gem_or_plugin
|
80
|
+
plugin_lib_paths.grep(/\/#{name}$/).first
|
81
|
+
end
|
82
|
+
|
83
|
+
def process_plugin_manifest(path)
|
84
|
+
plugin_manifest_file = File.join(path, "config", "manifest.yml")
|
85
|
+
if File.exists?(plugin_manifest_file)
|
86
|
+
plugin_manifest = Plugems::Manifest.load(plugin_manifest_file)
|
87
|
+
load_plugems(plugin_manifest)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def load_as_gem(name, version)
|
92
|
+
|
93
|
+
begin
|
94
|
+
|
95
|
+
require_gem name, version
|
96
|
+
|
97
|
+
path = gem_path(name)
|
98
|
+
append_rake_tasks!(path)
|
99
|
+
append_gem_views!(path)
|
100
|
+
|
101
|
+
debug "#{name} - Found: (#{loaded_version(name)})"
|
102
|
+
rescue Gem::LoadError, Gem::Exception => gem_load_error
|
103
|
+
error "#{gem_load_error}"
|
104
|
+
error "#{name} - Searching: (#{version}), but found: (#{loaded_version(name)})"
|
105
|
+
error "use BOOT_DEBUG=true to show more information."
|
106
|
+
exit(1)
|
107
|
+
rescue Exception => error
|
108
|
+
error "#{error}"
|
109
|
+
error.backtrace.each do |stacktrace|
|
110
|
+
error " #{stacktrace}"
|
111
|
+
end
|
112
|
+
exit(1)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
def loaded_version(gem_name)
|
118
|
+
gem_path(gem_name).split('/').grep(/#{gem_name}/).first[/[\d\.]+$/] rescue "Not Found"
|
119
|
+
end
|
120
|
+
|
121
|
+
def gem_path(gem_name)
|
122
|
+
File.dirname($:.grep(%r{/gems/#{gem_name}-\d}).first)
|
123
|
+
end
|
124
|
+
|
125
|
+
def debug(msg)
|
126
|
+
puts "[Plugems Debug]: #{msg}" if ENV['BOOT_DEBUG']
|
127
|
+
end
|
128
|
+
|
129
|
+
def error(msg)
|
130
|
+
puts "[Plugems Error]: #{msg}"
|
131
|
+
end
|
132
|
+
|
133
|
+
def set_dependencies_loaded_flag
|
134
|
+
# TODO: fix rhg_configuration to use Rails::Initializer.all_dependencies_loaded?
|
135
|
+
Object.const_set('DEPENDENCIES_LOADED', true) unless defined?(DEPENDENCIES_LOADED)
|
136
|
+
end
|
137
|
+
|
138
|
+
def append_gem_views!(path)
|
139
|
+
views = Dir["#{path}/views/**/*.*"]
|
140
|
+
(@@gem_views ||= []) << views unless views.blank?
|
141
|
+
end
|
142
|
+
|
143
|
+
def append_rake_tasks!(path)
|
144
|
+
tasks = Dir["#{path}/tasks/**/*.rake"].reject {|tsk| tsk=~/bootstrap|rails/}
|
145
|
+
(@@gem_rake_tasks ||= []) << tasks unless tasks.blank?
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
extend ClassMethods
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
module Plugems
|
4
|
+
class Manifest
|
5
|
+
|
6
|
+
attr_accessor :manifest
|
7
|
+
|
8
|
+
[:name, :version, :description, :author, :executables].each do |property|
|
9
|
+
define_method(property) { manifest[property] }
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(file_name = nil)
|
13
|
+
begin
|
14
|
+
@manifest = load_file(file_name || self.class.manifest_file)
|
15
|
+
rescue Exception => e
|
16
|
+
puts "#{e}. Manifest file is not set? (via Plugems::Manifest.manifest_file =)"
|
17
|
+
puts e
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def dependencies
|
22
|
+
manifest[:dependencies] || []
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
|
27
|
+
@@manifest_file = nil
|
28
|
+
|
29
|
+
def manifest_file
|
30
|
+
@@manifest_file || default_manifest_file
|
31
|
+
end
|
32
|
+
|
33
|
+
def load(file_name)
|
34
|
+
new(file_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_manifest_file
|
38
|
+
"#{RAILS_ROOT}/config/manifest.yml"
|
39
|
+
end
|
40
|
+
|
41
|
+
def manifest_file=(file)
|
42
|
+
@@manifest_file = file
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
extend ClassMethods
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def load_file(file)
|
52
|
+
YAML.load(ERB.new(IO.read(file)).result)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class TemplateCache
|
2
|
+
|
3
|
+
@@cache = {}
|
4
|
+
@@caching = true
|
5
|
+
|
6
|
+
def self.cache
|
7
|
+
@@caching ? @@cache : {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.caching=(arg)
|
11
|
+
@@caching = arg
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
# Plugems requires that views be loaded from gems defined in application manifest
|
17
|
+
module ActionView
|
18
|
+
class Base
|
19
|
+
def full_template_path(template_path, extension)
|
20
|
+
TemplateCache.cache[ [template_path, extension] ] ||= lookup_full_template_path(template_path, extension)
|
21
|
+
end
|
22
|
+
|
23
|
+
def lookup_full_template_path(template_path, extension)
|
24
|
+
default_template = "#{@base_path}/#{template_path}.#{extension}"
|
25
|
+
return default_template if File.exist?(default_template)
|
26
|
+
|
27
|
+
plugin_views = self.class.plugin_template("#{template_path}.#{extension}")
|
28
|
+
return plugin_views.first || default_template
|
29
|
+
end
|
30
|
+
|
31
|
+
# This is cached, and maybe should not be cached in development mode.
|
32
|
+
def self.plugin_templates
|
33
|
+
# Note: This does support symlinks (top-level) vendor/plugins/acts_as_funky_chicken,
|
34
|
+
# but not vendor/plugins/acts/acts_as_funky_bacon
|
35
|
+
(Plugems::Loader.gem_views + Plugems::Loader.plugin_views).flatten.uniq
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.plugin_template(file_name)
|
39
|
+
plugin_templates.select {|dir| dir =~ /#{file_name}/ }
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.plugin_layouts
|
43
|
+
plugin_templates.select {|dir| dir =~ /views\/layouts/ }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# action_pack/lib/action_controller/layout.rb
|
49
|
+
module ActionController
|
50
|
+
module Layout
|
51
|
+
module ClassMethods
|
52
|
+
|
53
|
+
# Allow layouts to also exist in plugems
|
54
|
+
def layout_list
|
55
|
+
TemplateCache.cache[:layout_list_cache] ||= Dir.glob("#{template_root}/layouts/**/*") + ActionView::Base.plugin_layouts
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def layout_directory?(layout_name)
|
61
|
+
TemplateCache.cache[layout_name] ||= begin
|
62
|
+
template_path = File.join(self.class.view_root, 'layouts', layout_name)
|
63
|
+
dirname = File.dirname(template_path)
|
64
|
+
|
65
|
+
# if the layout requested was not found in the application view root, look in plugem view paths
|
66
|
+
unless File.directory? dirname
|
67
|
+
plugin_layout_list = ActionView::Base.plugin_template("\/views\/layouts\/#{layout_name}.*")
|
68
|
+
dirname = File.dirname(plugin_layout_list.first) if plugin_layout_list.first
|
69
|
+
end
|
70
|
+
|
71
|
+
self.class.send(:layout_directory_exists_cache)[dirname]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Plugems
|
2
|
+
module Tasks
|
3
|
+
class Loader
|
4
|
+
def self.find_and_load
|
5
|
+
Plugems::Loader.gem_rake_tasks.each do |ext|
|
6
|
+
begin
|
7
|
+
load ext
|
8
|
+
rescue => e
|
9
|
+
puts "[Plugems Error]: Error (#{e}) loading rake tasks in gems #{ext}"
|
10
|
+
e.backtrace.each do |err|
|
11
|
+
puts "[Plugems Error]: #{err}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
puts "[plugems] - Loaded rake tasks from gem dependencies"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/tasks/rails.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# The original source of this file is here:
|
2
|
+
# gems/rails-1.1.6/lib/tasks/rails.rb
|
3
|
+
# See comments in ../plugems.rb
|
4
|
+
require "#{RAILS_ROOT}/config/environment"
|
5
|
+
|
6
|
+
$VERBOSE = nil
|
7
|
+
# Need to require environment rb from rake tasks so that plugems are initialized with plugin paths
|
8
|
+
|
9
|
+
if File.directory?("#{RAILS_ROOT}/vendor/rails")
|
10
|
+
rails_path = "#{RAILS_ROOT}/vendor/rails/railties/lib"
|
11
|
+
else
|
12
|
+
rails_path = $:.grep(/gems\/rails-.*\/lib/)
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir["#{rails_path}/tasks/*.rake"].each { |ext| load ext }
|
16
|
+
|
17
|
+
# Load any custom rakefile extensions
|
18
|
+
Dir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
|
19
|
+
Dir["#{RAILS_ROOT}/vendor/plugins/*/tasks/**/*.rake"].sort.each { |ext| load ext }
|
20
|
+
|
21
|
+
#Definitely load plugems own rake tasks
|
22
|
+
Dir["#{__FILE__}/../../tasks/**/*.rake"].sort.each {|ext| load ext}
|
23
|
+
|
24
|
+
# Load rake tasks from all plugems defined in application manifest
|
25
|
+
Plugems::Tasks::Loader.find_and_load
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: plugems
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2007-05-01 00:00:00 -04:00
|
8
|
+
summary: Dependency-management framework built on top of Ruby On Rails
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: rails-trunk@revolution.com
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: plugems
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- RHG Team
|
31
|
+
files:
|
32
|
+
- init.rb
|
33
|
+
- lib/plugems
|
34
|
+
- lib/plugems.rb
|
35
|
+
- lib/tasks
|
36
|
+
- lib/plugems/loader.rb
|
37
|
+
- lib/plugems/manifest.rb
|
38
|
+
- lib/plugems/plugem_view_support.rb
|
39
|
+
- lib/plugems/tasks
|
40
|
+
- lib/plugems/tasks/loader.rb
|
41
|
+
- lib/tasks/rails.rb
|
42
|
+
- config/manifest.yml
|
43
|
+
- README
|
44
|
+
- MIT-LICENSE
|
45
|
+
test_files: []
|
46
|
+
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
extra_rdoc_files:
|
50
|
+
- README
|
51
|
+
- MIT-LICENSE
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
dependencies: []
|
59
|
+
|