rails3_plugin_toolbox 0.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/.document +5 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/LICENSE +20 -0
- data/README.markdown +78 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/plugin_toolbox/extender.rb +45 -0
- data/lib/plugin_toolbox/loader.rb +31 -0
- data/lib/plugin_toolbox/util.rb +24 -0
- data/lib/plugin_toolbox/validator/hook_validator.rb +11 -0
- data/lib/plugin_toolbox/validator/type_validator.rb +11 -0
- data/lib/rails3_plugin_toolbox.rb +6 -0
- data/rails3_plugin_toolbox.gemspec +70 -0
- data/spec/plugin_toolbox/extender_spec.rb +0 -0
- data/spec/plugin_toolbox/loader_spec.rb +0 -0
- data/spec/plugin_toolbox/util_spec.rb +0 -0
- data/spec/spec_helper.rb +7 -0
- metadata +132 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format nested --color
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kristian Mandrup
|
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.markdown
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Rails3 plugin toolbox
|
2
|
+
|
3
|
+
A toolbox to facilitate creating Plugins for Rails 3 without having to necessarily know a lot about the Rails 3 internals and Plugin architecture.
|
4
|
+
|
5
|
+
## Status
|
6
|
+
|
7
|
+
This gem needs to be tested. I 'hope' it works as is... I will soon make sure of it and add an RSpec 2 test suite ;)
|
8
|
+
|
9
|
+
## Inspiration
|
10
|
+
|
11
|
+
This project was inspired by the Yehuda Katz article at http://www.railsdispatch.com/, titled "How Rails enables more choices".
|
12
|
+
|
13
|
+
## Install
|
14
|
+
|
15
|
+
<code>gem install rails3_plugin_toolbox</code>
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
<pre>
|
20
|
+
# my_plugin/lib/load.rb
|
21
|
+
module MyPlugin
|
22
|
+
include Rails::Plugin::Toolbox::Extender
|
23
|
+
|
24
|
+
# do some actions after Application has been initialized using registered initializers
|
25
|
+
after(:initialize) do
|
26
|
+
include MyViewModule
|
27
|
+
end
|
28
|
+
|
29
|
+
# extend action_view with methods from some modules
|
30
|
+
extend_rails(:view) do
|
31
|
+
with UltraFix
|
32
|
+
with PowerTools
|
33
|
+
end
|
34
|
+
|
35
|
+
extend_rails(:controller) do
|
36
|
+
extend_from_module Ultra::Power, :util, :logging, :monitor
|
37
|
+
extend_from_module Ultra::Power::More, :extra, :stuff
|
38
|
+
end
|
39
|
+
end
|
40
|
+
</pre>
|
41
|
+
|
42
|
+
The following are some general tips for adding custom rake tasks and generators to your Rails 3 plugin.
|
43
|
+
|
44
|
+
## Custom rake tasks
|
45
|
+
|
46
|
+
<pre>
|
47
|
+
# my_plugin/lib/railtie.rb
|
48
|
+
module MyPlugin
|
49
|
+
class Railtie < ::Rails::Railtie
|
50
|
+
rake_tasks do
|
51
|
+
load "my_plugin/railties/tasks.rake"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
</pre>
|
56
|
+
|
57
|
+
<pre>
|
58
|
+
# my_plugin/lib/railties/tasks.rake
|
59
|
+
desc "Talk about being in my_gem"
|
60
|
+
task :my_gem do
|
61
|
+
puts "You're in my_gem"
|
62
|
+
end
|
63
|
+
</pre>
|
64
|
+
|
65
|
+
|
66
|
+
## Note on Patches/Pull Requests
|
67
|
+
|
68
|
+
* Fork the project.
|
69
|
+
* Make your feature addition or bug fix.
|
70
|
+
* Add tests for it. This is important so I don't break it in a
|
71
|
+
future version unintentionally.
|
72
|
+
* Commit, do not mess with rakefile, version, or history.
|
73
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
74
|
+
* Send me a pull request. Bonus points for topic branches.
|
75
|
+
|
76
|
+
## Copyright
|
77
|
+
|
78
|
+
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "rails3_plugin_toolbox"
|
5
|
+
gem.summary = %Q{Toolbox to facilitate Rails 3 plugin development}
|
6
|
+
gem.description = %Q{Toolbox to facilitate Rails 3 plugin development}
|
7
|
+
gem.email = "kmandrup@gmail.com"
|
8
|
+
gem.homepage = "http://github.com/kristianmandrup/rails3_plugin_toolbox"
|
9
|
+
gem.authors = ["Kristian Mandrup"]
|
10
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
|
11
|
+
gem.add_dependency "rails", ">= 3.0.0.rc"
|
12
|
+
gem.add_dependency "require_all", ">= 1.1.0"
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
# require 'spec/rake/spectask'
|
21
|
+
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
22
|
+
# spec.libs << 'lib' << 'spec'
|
23
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
27
|
+
# spec.libs << 'lib' << 'spec'
|
28
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
29
|
+
# spec.rcov = true
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# task :spec => :check_dependencies
|
33
|
+
#
|
34
|
+
# task :default => :spec
|
35
|
+
#
|
36
|
+
# require 'rake/rdoctask'
|
37
|
+
# Rake::RDocTask.new do |rdoc|
|
38
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
#
|
40
|
+
# rdoc.rdoc_dir = 'rdoc'
|
41
|
+
# rdoc.title = "rails3_plugin_toolbox #{version}"
|
42
|
+
# rdoc.rdoc_files.include('README*')
|
43
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
# end
|
45
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'plugin_toolbox/util'
|
2
|
+
|
3
|
+
module Rails::PluginToolbox
|
4
|
+
class Extender
|
5
|
+
include Rails::PluginToolbox::Util
|
6
|
+
|
7
|
+
attr_reader :loader
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@loader = Loader.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def extend_rails(type, &block)
|
14
|
+
loader.load_after(type, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def extend! module_name, type
|
18
|
+
do_extend! get_module(module_name), get_type(type.to_sym)
|
19
|
+
end
|
20
|
+
|
21
|
+
def extend_with module_name
|
22
|
+
type = options[:in] || options
|
23
|
+
extend! module_name, type
|
24
|
+
end
|
25
|
+
alias_method :with, :extend_with
|
26
|
+
|
27
|
+
# convenience method to extend with multiple modules all within the same base module
|
28
|
+
def extend_from_module base_name, *module_names
|
29
|
+
module_names.each do |name|
|
30
|
+
extend_with "#{base_name.camelize}::#{name.to_s.camelize}".constantize
|
31
|
+
end
|
32
|
+
type = options[:in] || options
|
33
|
+
extend! module_name, type
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def do_extend! module_name, type
|
39
|
+
ActiveSupport.on_load(type) do
|
40
|
+
include module_name
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_all File.dirname(__FILE__) + '/validator'
|
2
|
+
|
3
|
+
module Rails::PluginToolbox
|
4
|
+
class Loader
|
5
|
+
include Rails::PluginToolbox::HookValidator
|
6
|
+
|
7
|
+
def load_before type, &block
|
8
|
+
raise ArgumentError "#{type} is not a valid before hook" if !valid_before_hook?
|
9
|
+
ActiveSupport.on_load(:"before_#{type}") do |loader|
|
10
|
+
do_loader loader, &block
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_after type, &block
|
15
|
+
type = valid_after_hook? ? type : :"action_#{type}"
|
16
|
+
raise ArgumentError "#{type} is not a valid after hook" if !valid_after_hook? type
|
17
|
+
ActiveSupport.on_load(type) do |loader|
|
18
|
+
do_loader loader, &block
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def do_loader loader, &block
|
25
|
+
loader.extend(Loader)
|
26
|
+
if block
|
27
|
+
block.arity < 1 ? loader.instance_eval(&block) : block.call(loader)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_all File.dirname(__FILE__) + '/validator'
|
2
|
+
|
3
|
+
module Rails::PluginToolbox
|
4
|
+
module Util
|
5
|
+
include Rails::PluginToolbox::TypeValidator
|
6
|
+
|
7
|
+
def get_type category
|
8
|
+
return :"action_#{type}" if action_type?(type)
|
9
|
+
return type if valid_type?(type)
|
10
|
+
raise ArgumentError, "The type #{type} was not recognized"
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_module module_name
|
14
|
+
case module_name
|
15
|
+
when Constant
|
16
|
+
module_name
|
17
|
+
when String
|
18
|
+
module_name.to_s.constantize
|
19
|
+
else
|
20
|
+
raise ArgumentError, "#{module_name} could not be converted into a loaded module"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Rails::PluginToolbox
|
2
|
+
module HookValidator
|
3
|
+
def valid_before_hook?
|
4
|
+
[:initialize, :configuration, :eager_load].include?(type)
|
5
|
+
end
|
6
|
+
|
7
|
+
def valid_after_hook?
|
8
|
+
[:initialize, :i18n, :active_record, :action_view, :action_controller, :action_mailer].include?(type)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rails3_plugin_toolbox}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = %q{2010-08-21}
|
13
|
+
s.description = %q{Toolbox to facilitate Rails 3 plugin development}
|
14
|
+
s.email = %q{kmandrup@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
".rspec",
|
23
|
+
"LICENSE",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/plugin_toolbox/extender.rb",
|
28
|
+
"lib/plugin_toolbox/loader.rb",
|
29
|
+
"lib/plugin_toolbox/util.rb",
|
30
|
+
"lib/plugin_toolbox/validator/hook_validator.rb",
|
31
|
+
"lib/plugin_toolbox/validator/type_validator.rb",
|
32
|
+
"lib/rails3_plugin_toolbox.rb",
|
33
|
+
"rails3_plugin_toolbox.gemspec",
|
34
|
+
"spec/plugin_toolbox/extender_spec.rb",
|
35
|
+
"spec/plugin_toolbox/loader_spec.rb",
|
36
|
+
"spec/plugin_toolbox/util_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/kristianmandrup/rails3_plugin_toolbox}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.7}
|
43
|
+
s.summary = %q{Toolbox to facilitate Rails 3 plugin development}
|
44
|
+
s.test_files = [
|
45
|
+
"spec/plugin_toolbox/extender_spec.rb",
|
46
|
+
"spec/plugin_toolbox/loader_spec.rb",
|
47
|
+
"spec/plugin_toolbox/util_spec.rb",
|
48
|
+
"spec/spec_helper.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
57
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.0.0.rc"])
|
58
|
+
s.add_runtime_dependency(%q<require_all>, [">= 1.1.0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
61
|
+
s.add_dependency(%q<rails>, [">= 3.0.0.rc"])
|
62
|
+
s.add_dependency(%q<require_all>, [">= 1.1.0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
66
|
+
s.add_dependency(%q<rails>, [">= 3.0.0.rc"])
|
67
|
+
s.add_dependency(%q<require_all>, [">= 1.1.0"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
File without changes
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails3_plugin_toolbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kristian Mandrup
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-21 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- beta
|
33
|
+
- 19
|
34
|
+
version: 2.0.0.beta.19
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rails
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 3
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
- rc
|
50
|
+
version: 3.0.0.rc
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: require_all
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 1
|
64
|
+
- 0
|
65
|
+
version: 1.1.0
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id003
|
68
|
+
description: Toolbox to facilitate Rails 3 plugin development
|
69
|
+
email: kmandrup@gmail.com
|
70
|
+
executables: []
|
71
|
+
|
72
|
+
extensions: []
|
73
|
+
|
74
|
+
extra_rdoc_files:
|
75
|
+
- LICENSE
|
76
|
+
- README.markdown
|
77
|
+
files:
|
78
|
+
- .document
|
79
|
+
- .gitignore
|
80
|
+
- .rspec
|
81
|
+
- LICENSE
|
82
|
+
- README.markdown
|
83
|
+
- Rakefile
|
84
|
+
- VERSION
|
85
|
+
- lib/plugin_toolbox/extender.rb
|
86
|
+
- lib/plugin_toolbox/loader.rb
|
87
|
+
- lib/plugin_toolbox/util.rb
|
88
|
+
- lib/plugin_toolbox/validator/hook_validator.rb
|
89
|
+
- lib/plugin_toolbox/validator/type_validator.rb
|
90
|
+
- lib/rails3_plugin_toolbox.rb
|
91
|
+
- rails3_plugin_toolbox.gemspec
|
92
|
+
- spec/plugin_toolbox/extender_spec.rb
|
93
|
+
- spec/plugin_toolbox/loader_spec.rb
|
94
|
+
- spec/plugin_toolbox/util_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
has_rdoc: true
|
97
|
+
homepage: http://github.com/kristianmandrup/rails3_plugin_toolbox
|
98
|
+
licenses: []
|
99
|
+
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options:
|
102
|
+
- --charset=UTF-8
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
requirements: []
|
122
|
+
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.3.7
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Toolbox to facilitate Rails 3 plugin development
|
128
|
+
test_files:
|
129
|
+
- spec/plugin_toolbox/extender_spec.rb
|
130
|
+
- spec/plugin_toolbox/loader_spec.rb
|
131
|
+
- spec/plugin_toolbox/util_spec.rb
|
132
|
+
- spec/spec_helper.rb
|