merb_parts 0.9.9
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 +77 -0
- data/TODO +5 -0
- data/lib/merb-parts/merbtasks.rb +6 -0
- data/lib/merb-parts/mixins/parts_mixin.rb +42 -0
- data/lib/merb-parts/mixins/web_controller.rb +53 -0
- data/lib/merb-parts/part_controller.rb +114 -0
- data/lib/merb-parts.rb +4 -0
- metadata +74 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Daniel Neighman
|
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,77 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require "extlib"
|
4
|
+
require 'merb-core/tasks/merb_rake_helper'
|
5
|
+
require "spec/rake/spectask"
|
6
|
+
|
7
|
+
##############################################################################
|
8
|
+
# Package && release
|
9
|
+
##############################################################################
|
10
|
+
RUBY_FORGE_PROJECT = "merb"
|
11
|
+
PROJECT_URL = "http://merbivore.com"
|
12
|
+
PROJECT_SUMMARY = "Merb plugin that provides Part Controllers."
|
13
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY
|
14
|
+
|
15
|
+
GEM_AUTHOR = "Daniel Neighman"
|
16
|
+
GEM_EMAIL = "has.sox@gmail.com"
|
17
|
+
|
18
|
+
GEM_NAME = "merb_parts"
|
19
|
+
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
20
|
+
GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.9") + PKG_BUILD
|
21
|
+
|
22
|
+
RELEASE_NAME = "REL #{GEM_VERSION}"
|
23
|
+
|
24
|
+
require "extlib/tasks/release"
|
25
|
+
|
26
|
+
spec = Gem::Specification.new do |s|
|
27
|
+
s.rubyforge_project = RUBY_FORGE_PROJECT
|
28
|
+
s.name = GEM_NAME
|
29
|
+
s.version = GEM_VERSION
|
30
|
+
s.platform = Gem::Platform::RUBY
|
31
|
+
s.has_rdoc = true
|
32
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
33
|
+
s.summary = PROJECT_SUMMARY
|
34
|
+
s.description = PROJECT_DESCRIPTION
|
35
|
+
s.author = GEM_AUTHOR
|
36
|
+
s.email = GEM_EMAIL
|
37
|
+
s.homepage = PROJECT_URL
|
38
|
+
s.add_dependency('merb-core', '>= 0.9.9')
|
39
|
+
s.require_path = 'lib'
|
40
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib}/**/*")
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
44
|
+
pkg.gem_spec = spec
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Install the gem"
|
48
|
+
task :install do
|
49
|
+
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Uninstall the gem"
|
53
|
+
task :uninstall do
|
54
|
+
Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "Create a gemspec file"
|
58
|
+
task :gemspec do
|
59
|
+
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
60
|
+
file.puts spec.to_ruby
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Run all examples (or a specific spec with TASK=xxxx)"
|
65
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
66
|
+
t.spec_opts = ["-cfs"]
|
67
|
+
t.spec_files = begin
|
68
|
+
if ENV["TASK"]
|
69
|
+
ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
|
70
|
+
else
|
71
|
+
FileList['spec/**/*_spec.rb']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
desc 'Default: run spec examples'
|
77
|
+
task :default => 'spec'
|
data/TODO
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Merb
|
2
|
+
module PartsMixin
|
3
|
+
|
4
|
+
# Dispatches a PartController.
|
5
|
+
# ==== Parameters
|
6
|
+
# opts<Hash>:: A Hash of Options. (see below)
|
7
|
+
#
|
8
|
+
# ==== Options
|
9
|
+
# An option hash has two parts.
|
10
|
+
# 1. keys that are Merb::PartControllers with values that are action names (as symbols)
|
11
|
+
# 2. key value pairs that will become available in the PartController as params merged
|
12
|
+
# with the web controllers params
|
13
|
+
#
|
14
|
+
# ==== Example
|
15
|
+
# Calling a part controller
|
16
|
+
# {{{
|
17
|
+
# part TodoPart => :list
|
18
|
+
# }}}
|
19
|
+
#
|
20
|
+
# Calling a part with additional options
|
21
|
+
# {{{
|
22
|
+
# part TodoPart => :list, :limit => 20, :user => current_user
|
23
|
+
# }}}
|
24
|
+
#
|
25
|
+
# ==== Returns
|
26
|
+
# Returns the result of the PartControllers action, which is a string.
|
27
|
+
def part(opts = {})
|
28
|
+
# Extract any params out that may have been specified
|
29
|
+
klasses, opts = opts.partition do |k,v|
|
30
|
+
k.respond_to?(:ancestors) && k.ancestors.include?(Merb::PartController)
|
31
|
+
end
|
32
|
+
|
33
|
+
opts = opts.empty? ? {} : Hash[*(opts.first)]
|
34
|
+
|
35
|
+
res = klasses.inject([]) do |memo,(klass,action)|
|
36
|
+
memo << klass.new(self, opts)._dispatch(action)
|
37
|
+
end
|
38
|
+
res.size == 1 ? res[0] : res
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Includes files into the class to allow it to minimally delegates to a web controller
|
2
|
+
module Merb
|
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, *args)
|
40
|
+
@web_controller.url(name, *args)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
module ClassMethods
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
end # WebController
|
52
|
+
end # Mixins
|
53
|
+
end # Merb
|
@@ -0,0 +1,114 @@
|
|
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 html.
|
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 = :html, controller = controller_name)
|
34
|
+
"#{controller}/#{action}.#{type}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# The location to look for a template and mime-type. This is overridden
|
38
|
+
# from AbstractController, which defines a version of this that does not
|
39
|
+
# involve mime-types.
|
40
|
+
#
|
41
|
+
# ==== Parameters
|
42
|
+
# template<String>::
|
43
|
+
# The absolute path to a template - without mime and template extension.
|
44
|
+
# The mime-type extension is optional - it will be appended from the
|
45
|
+
# current content type if it hasn't been added already.
|
46
|
+
# type<~to_s>::
|
47
|
+
# The mime-type of the template that will be rendered. Defaults to nil.
|
48
|
+
#
|
49
|
+
# @public
|
50
|
+
def _absolute_template_location(template, type)
|
51
|
+
template.match(/\.#{type.to_s.escape_regexp}$/) ? template : "#{template}.#{type}"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Sets the template root to the default parts view directory.
|
55
|
+
#
|
56
|
+
# ==== Parameters
|
57
|
+
# klass<Class>::
|
58
|
+
# The Merb::PartController inheriting from the base class.
|
59
|
+
def self.inherited(klass)
|
60
|
+
_subclasses << klass.to_s
|
61
|
+
super
|
62
|
+
klass._template_root = Merb.dir_for(:part) / "views" unless self._template_root
|
63
|
+
end
|
64
|
+
|
65
|
+
# ==== Parameters
|
66
|
+
# web_controller<Merb::Controller>:: The controller calling this part.
|
67
|
+
# opts<Hash>:: Additional options for this part.
|
68
|
+
def initialize(web_controller, opts = {})
|
69
|
+
@web_controller = web_controller
|
70
|
+
@params = @web_controller.params.dup
|
71
|
+
@params.merge!(opts) unless opts.empty?
|
72
|
+
super
|
73
|
+
@content_type = @web_controller.content_type
|
74
|
+
end
|
75
|
+
|
76
|
+
# ==== Parameters
|
77
|
+
# name<~to_sym, Hash>:: The name of the URL to generate.
|
78
|
+
# rparams<Hash>:: Parameters for the route generation.
|
79
|
+
#
|
80
|
+
# ==== Returns
|
81
|
+
# String:: The generated URL.
|
82
|
+
#
|
83
|
+
# ==== Alternatives
|
84
|
+
# If a hash is used as the first argument, a default route will be
|
85
|
+
# generated based on it and rparams.
|
86
|
+
# ====
|
87
|
+
# TODO: Update this documentation
|
88
|
+
def url(name, *args)
|
89
|
+
args << params
|
90
|
+
Merb::Router.url(name, *args)
|
91
|
+
end
|
92
|
+
|
93
|
+
alias_method :relative_url, :url
|
94
|
+
|
95
|
+
# ==== Parameters
|
96
|
+
# action<~to_s>:: An action to dispatch to. Defaults to :to_s.
|
97
|
+
#
|
98
|
+
# ==== Returns
|
99
|
+
# String:: The part body.
|
100
|
+
def _dispatch(action=:to_s)
|
101
|
+
action = action.to_s
|
102
|
+
self.action_name = action
|
103
|
+
super(action)
|
104
|
+
@body
|
105
|
+
end
|
106
|
+
|
107
|
+
# Send any methods that are missing back up to the web controller
|
108
|
+
# Patched to set partial locals on the web controller
|
109
|
+
def method_missing(sym, *args, &blk)
|
110
|
+
@web_controller.instance_variable_set(:@_merb_partial_locals, @_merb_partial_locals) if @_merb_partial_locals
|
111
|
+
@web_controller.send(sym, *args, &blk)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/merb-parts.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb_parts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Neighman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-14 00:00:00 +03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.9
|
24
|
+
version:
|
25
|
+
description: Merb plugin that provides Part Controllers.
|
26
|
+
email: has.sox@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
- LICENSE
|
34
|
+
- TODO
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README
|
38
|
+
- Rakefile
|
39
|
+
- TODO
|
40
|
+
- lib/merb-parts
|
41
|
+
- lib/merb-parts/merbtasks.rb
|
42
|
+
- lib/merb-parts/mixins
|
43
|
+
- lib/merb-parts/mixins/parts_mixin.rb
|
44
|
+
- lib/merb-parts/mixins/web_controller.rb
|
45
|
+
- lib/merb-parts/part_controller.rb
|
46
|
+
- lib/merb-parts.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://merbivore.com
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: merb
|
69
|
+
rubygems_version: 1.2.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: Merb plugin that provides Part Controllers.
|
73
|
+
test_files: []
|
74
|
+
|