merb-parts 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +4 -0
- data/Rakefile +51 -0
- data/TODO +5 -0
- data/lib/merb-parts.rb +44 -0
- data/lib/merb-parts/merbtasks.rb +6 -0
- data/lib/merb-parts/mixins/web_controller.rb +67 -0
- data/lib/merb-parts/part_controller.rb +75 -0
- metadata +72 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 YOUR NAME
|
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
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require "spec/rake/spectask"
|
4
|
+
|
5
|
+
PLUGIN = "merb-parts"
|
6
|
+
NAME = "merb-parts"
|
7
|
+
VERSION = "0.9.2"
|
8
|
+
AUTHOR = "Hassox"
|
9
|
+
EMAIL = ""
|
10
|
+
HOMEPAGE = "http://merb-plugins.rubyforge.org/merb-parts/"
|
11
|
+
SUMMARY = "Merb More: Merb plugin that provides Part Controllers."
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
s.name = NAME
|
15
|
+
s.version = VERSION
|
16
|
+
s.platform = Gem::Platform::RUBY
|
17
|
+
s.has_rdoc = true
|
18
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
19
|
+
s.summary = SUMMARY
|
20
|
+
s.description = s.summary
|
21
|
+
s.author = AUTHOR
|
22
|
+
s.email = EMAIL
|
23
|
+
s.homepage = HOMEPAGE
|
24
|
+
s.add_dependency('merb-core', '>= 0.9.2')
|
25
|
+
s.require_path = 'lib'
|
26
|
+
s.autorequire = PLUGIN
|
27
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*")
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
31
|
+
pkg.gem_spec = spec
|
32
|
+
end
|
33
|
+
|
34
|
+
task :install => [:package] do
|
35
|
+
sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
|
36
|
+
end
|
37
|
+
|
38
|
+
namespace :jruby do
|
39
|
+
|
40
|
+
desc "Run :package and install the resulting .gem with jruby"
|
41
|
+
task :install => :package do
|
42
|
+
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Run all specs"
|
48
|
+
Spec::Rake::SpecTask.new("specs") do |t|
|
49
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
50
|
+
t.spec_files = Dir["spec/**/*_spec.rb"].sort
|
51
|
+
end
|
data/TODO
ADDED
data/lib/merb-parts.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'merb-parts','part_controller')
|
2
|
+
|
3
|
+
module Merb
|
4
|
+
class Controller
|
5
|
+
# Dispatches a PartController.
|
6
|
+
# ==== Parameters
|
7
|
+
# opts<Hash>:: A Hash of Options. (see below)
|
8
|
+
#
|
9
|
+
# ==== Options
|
10
|
+
# An option hash has two parts.
|
11
|
+
# 1. keys that are Merb::PartControllers with values that are action names (as symbols)
|
12
|
+
# 2. key value pairs that will become available in the PartController as params merged
|
13
|
+
# with the web controllers params
|
14
|
+
#
|
15
|
+
# ==== Example
|
16
|
+
# Calling a part controller
|
17
|
+
# {{{
|
18
|
+
# part TodoPart => :list
|
19
|
+
# }}}
|
20
|
+
#
|
21
|
+
# Calling a part with additional options
|
22
|
+
# {{{
|
23
|
+
# part TodoPart => :list, :limit => 20, :user => current_user
|
24
|
+
# }}}
|
25
|
+
#
|
26
|
+
# ==== Returns
|
27
|
+
# Returns the result of the PartControllers action, which is a string.
|
28
|
+
def part(opts = {})
|
29
|
+
# Extract any params out that may have been specified
|
30
|
+
klasses, opts = opts.partition do |k,v|
|
31
|
+
k.respond_to?(:ancestors) && k.ancestors.include?(Merb::PartController)
|
32
|
+
end
|
33
|
+
|
34
|
+
opts = Hash[*(opts.flatten)]
|
35
|
+
|
36
|
+
res = klasses.inject([]) do |memo,(klass,action)|
|
37
|
+
memo << klass.new(self, opts)._dispatch(action)
|
38
|
+
end
|
39
|
+
res.size == 1 ? res[0] : res
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Includes files into the class to allow it to minimally delegates to a web controller
|
2
|
+
module Merb #:nodoc:
|
3
|
+
module Mixins
|
4
|
+
module WebController
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
[:content_type, :web_controller].each do |attr|
|
8
|
+
base.send(:attr_accessor, attr)
|
9
|
+
end
|
10
|
+
base.send(:include, InstanceMethods)
|
11
|
+
base.send(:extend, ClassMethods)
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
def request
|
16
|
+
@web_controller.request
|
17
|
+
end
|
18
|
+
|
19
|
+
def cookies
|
20
|
+
@web_controller.cookies
|
21
|
+
end
|
22
|
+
|
23
|
+
def headers
|
24
|
+
@web_controller.headers
|
25
|
+
end
|
26
|
+
|
27
|
+
def session
|
28
|
+
@web_controller.session
|
29
|
+
end
|
30
|
+
|
31
|
+
def response
|
32
|
+
@web_controller.response
|
33
|
+
end
|
34
|
+
|
35
|
+
def route
|
36
|
+
request.route
|
37
|
+
end
|
38
|
+
|
39
|
+
def url(name, rparams={})
|
40
|
+
Merb::Router.generate(name, rparams,
|
41
|
+
{ :controller => @web_controller.controller_name,
|
42
|
+
:action => @web_controller.action_name,
|
43
|
+
:format => params[:format]
|
44
|
+
}
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
# This method is here to overwrite the one in the general_controller mixin
|
50
|
+
# The method ensures that when a url is generated with a hash, it contains a controller
|
51
|
+
def get_controller_for_url_generation(opts)
|
52
|
+
controller = opts[:controller] || @web_controller.params[:controller]
|
53
|
+
raise "No Controller Specified for url()" unless controller
|
54
|
+
controller
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
module ClassMethods
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
end # WebController
|
66
|
+
end # Mixins
|
67
|
+
end # Merb
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "mixins", "web_controller")
|
2
|
+
module Merb
|
3
|
+
|
4
|
+
# A Merb::PartController is a light weight way to share logic and templates
|
5
|
+
# amongst controllers.
|
6
|
+
# Merb::PartControllers work just like Merb::controller.
|
7
|
+
# There is a filter stack, layouts (if needed) all the render functions,
|
8
|
+
# and url generation.
|
9
|
+
#
|
10
|
+
# Cookies, params, and even the request object are shared with the web controller
|
11
|
+
class PartController < AbstractController
|
12
|
+
include Merb::Mixins::WebController
|
13
|
+
|
14
|
+
attr_reader :params
|
15
|
+
|
16
|
+
cattr_accessor :_subclasses
|
17
|
+
self._subclasses = Set.new
|
18
|
+
|
19
|
+
# ==== Returns
|
20
|
+
# Array[Class]:: Classes that inherit from Merb::PartController.
|
21
|
+
def self.subclasses_list() _subclasses end
|
22
|
+
|
23
|
+
# ==== Parameters
|
24
|
+
# action<~to_s>:: The name of the action that will be rendered.
|
25
|
+
# type<~to_s>::
|
26
|
+
# The mime-type of the template that will be rendered. Defaults to nil.
|
27
|
+
# controller<~to_s>::
|
28
|
+
# The name of the controller that will be rendered. Defaults to
|
29
|
+
# controller_name.
|
30
|
+
#
|
31
|
+
# ==== Returns
|
32
|
+
# String:: The template location, i.e. ":controller/:action.:type".
|
33
|
+
def _template_location(action, type = nil, controller = controller_name)
|
34
|
+
"#{controller}/#{action}.#{type}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sets the template root to the default parts view directory.
|
38
|
+
#
|
39
|
+
# ==== Parameters
|
40
|
+
# klass<Class>::
|
41
|
+
# The Merb::PartController inheriting from the base class.
|
42
|
+
def self.inherited(klass)
|
43
|
+
_subclasses << klass.to_s
|
44
|
+
super
|
45
|
+
klass.class_eval %{self._template_root = Merb.dir_for(:part) / "views"}
|
46
|
+
end
|
47
|
+
|
48
|
+
# ==== Parameters
|
49
|
+
# web_controller<Merb::Controller>:: The controller calling this part.
|
50
|
+
# opts<Hash>:: Additional options for this part.
|
51
|
+
def initialize(web_controller, opts = {})
|
52
|
+
@web_controller = web_controller
|
53
|
+
@params = @web_controller.params
|
54
|
+
@params.merge!(opts) unless opts.empty?
|
55
|
+
super
|
56
|
+
@content_type = @web_controller.content_type
|
57
|
+
end
|
58
|
+
|
59
|
+
# ==== Parameters
|
60
|
+
# action<~to_s>:: An action to dispatch to. Defaults to :to_s.
|
61
|
+
#
|
62
|
+
# ==== Returns
|
63
|
+
# String:: The part body.
|
64
|
+
def _dispatch(action=:to_s)
|
65
|
+
self.action_name = action
|
66
|
+
super(action)
|
67
|
+
@body
|
68
|
+
end
|
69
|
+
|
70
|
+
# Send any methods that are missing back up to the web controller
|
71
|
+
def method_missing(sym, *args, &blk)
|
72
|
+
@web_controller.send(sym, *args, &blk)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb-parts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hassox
|
8
|
+
autorequire: merb-parts
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-24 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-core
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.2
|
23
|
+
version:
|
24
|
+
description: "Merb More: Merb plugin that provides Part Controllers."
|
25
|
+
email: ""
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- LICENSE
|
33
|
+
- TODO
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README
|
37
|
+
- Rakefile
|
38
|
+
- TODO
|
39
|
+
- lib/merb-parts
|
40
|
+
- lib/merb-parts/merbtasks.rb
|
41
|
+
- lib/merb-parts/mixins
|
42
|
+
- lib/merb-parts/mixins/web_controller.rb
|
43
|
+
- lib/merb-parts/part_controller.rb
|
44
|
+
- lib/merb-parts.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://merb-plugins.rubyforge.org/merb-parts/
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.0.1
|
68
|
+
signing_key:
|
69
|
+
specification_version: 2
|
70
|
+
summary: "Merb More: Merb plugin that provides Part Controllers."
|
71
|
+
test_files: []
|
72
|
+
|