merb-parts 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +34 -22
- data/lib/merb-parts.rb +3 -43
- data/lib/merb-parts/mixins/parts_mixin.rb +42 -0
- data/lib/merb-parts/mixins/web_controller.rb +1 -1
- data/lib/merb-parts/part_controller.rb +32 -15
- data/spec/fixtures/controllers/main.rb +4 -0
- data/spec/fixtures/parts/done_part.rb +4 -0
- data/spec/fixtures/parts/todo_part.rb +4 -0
- data/spec/merb-parts_spec.rb +14 -1
- metadata +14 -11
data/Rakefile
CHANGED
@@ -1,49 +1,61 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake/gempackagetask'
|
3
|
+
require "extlib"
|
4
|
+
require 'merb-core/tasks/merb_rake_helper'
|
3
5
|
require "spec/rake/spectask"
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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.4") + PKG_BUILD
|
21
|
+
|
22
|
+
RELEASE_NAME = "REL #{GEM_VERSION}"
|
23
|
+
|
24
|
+
require "extlib/tasks/release"
|
12
25
|
|
13
26
|
spec = Gem::Specification.new do |s|
|
14
|
-
s.
|
15
|
-
s.
|
27
|
+
s.rubyforge_project = RUBY_FORGE_PROJECT
|
28
|
+
s.name = GEM_NAME
|
29
|
+
s.version = GEM_VERSION
|
16
30
|
s.platform = Gem::Platform::RUBY
|
17
31
|
s.has_rdoc = true
|
18
32
|
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
19
|
-
s.summary =
|
20
|
-
s.description =
|
21
|
-
s.author =
|
22
|
-
s.email =
|
23
|
-
s.homepage =
|
24
|
-
s.add_dependency('merb-core', '>= 0.9.
|
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.4')
|
25
39
|
s.require_path = 'lib'
|
26
|
-
s.
|
27
|
-
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
40
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,merb_generators}/**/*")
|
28
41
|
end
|
29
42
|
|
30
43
|
Rake::GemPackageTask.new(spec) do |pkg|
|
31
44
|
pkg.gem_spec = spec
|
32
45
|
end
|
33
46
|
|
34
|
-
|
35
|
-
|
47
|
+
desc "Install the gem"
|
36
48
|
task :install => [:package] do
|
37
|
-
sh %{sudo gem install #{install_home} pkg/#{
|
49
|
+
sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
|
38
50
|
end
|
39
51
|
|
40
52
|
namespace :jruby do
|
41
53
|
|
42
54
|
desc "Run :package and install the resulting .gem with jruby"
|
43
55
|
task :install => :package do
|
44
|
-
sh %{#{
|
56
|
+
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
|
45
57
|
end
|
46
|
-
|
58
|
+
|
47
59
|
end
|
48
60
|
|
49
61
|
desc "Run all specs"
|
data/lib/merb-parts.rb
CHANGED
@@ -1,44 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),
|
1
|
+
require File.join(File.dirname(__FILE__), "merb-parts", "part_controller")
|
2
|
+
require File.join(File.dirname(__FILE__), "merb-parts", "mixins", "parts_mixin")
|
2
3
|
|
3
|
-
|
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
|
4
|
+
Merb::Controller.send(:include, Merb::PartsMixin)
|
@@ -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 = Hash[*(opts.flatten)]
|
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
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "mixins", "web_controller")
|
2
2
|
module Merb
|
3
|
-
|
3
|
+
|
4
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.
|
5
|
+
# amongst controllers.
|
6
|
+
# Merb::PartControllers work just like Merb::controller.
|
7
7
|
# There is a filter stack, layouts (if needed) all the render functions,
|
8
|
-
# and url generation.
|
8
|
+
# and url generation.
|
9
9
|
#
|
10
|
-
# Cookies, params, and even the request object are shared with the web controller
|
10
|
+
# Cookies, params, and even the request object are shared with the web controller
|
11
11
|
class PartController < AbstractController
|
12
12
|
include Merb::Mixins::WebController
|
13
|
-
|
13
|
+
|
14
14
|
attr_reader :params
|
15
15
|
|
16
16
|
cattr_accessor :_subclasses
|
17
17
|
self._subclasses = Set.new
|
18
|
-
|
18
|
+
|
19
19
|
# ==== Returns
|
20
20
|
# Array[Class]:: Classes that inherit from Merb::PartController.
|
21
21
|
def self.subclasses_list() _subclasses end
|
@@ -23,26 +23,43 @@ module Merb
|
|
23
23
|
# ==== Parameters
|
24
24
|
# action<~to_s>:: The name of the action that will be rendered.
|
25
25
|
# type<~to_s>::
|
26
|
-
# The mime-type of the template that will be rendered. Defaults to
|
26
|
+
# The mime-type of the template that will be rendered. Defaults to html.
|
27
27
|
# controller<~to_s>::
|
28
28
|
# The name of the controller that will be rendered. Defaults to
|
29
29
|
# controller_name.
|
30
30
|
#
|
31
31
|
# ==== Returns
|
32
32
|
# String:: The template location, i.e. ":controller/:action.:type".
|
33
|
-
def _template_location(action, type =
|
33
|
+
def _template_location(action, type = :html, controller = controller_name)
|
34
34
|
"#{controller}/#{action}.#{type}"
|
35
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
|
36
53
|
|
37
54
|
# Sets the template root to the default parts view directory.
|
38
55
|
#
|
39
56
|
# ==== Parameters
|
40
57
|
# klass<Class>::
|
41
|
-
# The Merb::PartController inheriting from the base class.
|
58
|
+
# The Merb::PartController inheriting from the base class.
|
42
59
|
def self.inherited(klass)
|
43
60
|
_subclasses << klass.to_s
|
44
61
|
super
|
45
|
-
klass.
|
62
|
+
klass._template_root = Merb.dir_for(:part) / "views" unless self._template_root
|
46
63
|
end
|
47
64
|
|
48
65
|
# ==== Parameters
|
@@ -50,7 +67,7 @@ module Merb
|
|
50
67
|
# opts<Hash>:: Additional options for this part.
|
51
68
|
def initialize(web_controller, opts = {})
|
52
69
|
@web_controller = web_controller
|
53
|
-
@params = @web_controller.params
|
70
|
+
@params = @web_controller.params.dup
|
54
71
|
@params.merge!(opts) unless opts.empty?
|
55
72
|
super
|
56
73
|
@content_type = @web_controller.content_type
|
@@ -65,8 +82,8 @@ module Merb
|
|
65
82
|
self.action_name = action
|
66
83
|
super(action)
|
67
84
|
@body
|
68
|
-
end
|
69
|
-
|
85
|
+
end
|
86
|
+
|
70
87
|
# Send any methods that are missing back up to the web controller
|
71
88
|
# Patched to set partial locals on the web controller
|
72
89
|
def method_missing(sym, *args, &blk)
|
@@ -74,4 +91,4 @@ module Merb
|
|
74
91
|
@web_controller.send(sym, *args, &blk)
|
75
92
|
end
|
76
93
|
end
|
77
|
-
end
|
94
|
+
end
|
data/spec/merb-parts_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe "A Merb PartController" do
|
|
29
29
|
|
30
30
|
it "should render the html format by default to the controller that set it" do
|
31
31
|
controller = dispatch_to(Main, :index4)
|
32
|
-
controller.body.should match(/part_html_format/m)
|
32
|
+
controller.body.should match(/part_html_format/m)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should render the xml format according to the controller" do
|
@@ -52,6 +52,10 @@ describe "A Merb PartController" do
|
|
52
52
|
controller.body.should match( /Do this/)
|
53
53
|
end
|
54
54
|
|
55
|
+
it "should render a template from an absolute path" do
|
56
|
+
controller = dispatch_to(Main, :parth_with_absolute_template)
|
57
|
+
controller.body.should match(/part_html_format/m)
|
58
|
+
end
|
55
59
|
|
56
60
|
end
|
57
61
|
|
@@ -68,4 +72,13 @@ describe "A Merb Part Controller with urls" do
|
|
68
72
|
the_url.should == "/main/bar"
|
69
73
|
end
|
70
74
|
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "A Merb Part Controller inheriting from another Part Controller" do
|
78
|
+
|
79
|
+
it "should inherit the _template_root" do
|
80
|
+
TodoPart._template_root.should == File.expand_path(File.dirname(__FILE__) / 'fixtures' / 'parts' / 'views')
|
81
|
+
TodoPart._template_root.should == DonePart._template_root
|
82
|
+
end
|
83
|
+
|
71
84
|
end
|
metadata
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-parts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Daniel Neighman
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-13 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: merb-core
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
20
21
|
- - ">="
|
21
22
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.9.
|
23
|
+
version: 0.9.4
|
23
24
|
version:
|
24
|
-
description:
|
25
|
-
email:
|
25
|
+
description: Merb plugin that provides Part Controllers.
|
26
|
+
email: has.sox@gmail.com
|
26
27
|
executables: []
|
27
28
|
|
28
29
|
extensions: []
|
@@ -39,6 +40,7 @@ files:
|
|
39
40
|
- lib/merb-parts
|
40
41
|
- lib/merb-parts/merbtasks.rb
|
41
42
|
- lib/merb-parts/mixins
|
43
|
+
- lib/merb-parts/mixins/parts_mixin.rb
|
42
44
|
- lib/merb-parts/mixins/web_controller.rb
|
43
45
|
- lib/merb-parts/part_controller.rb
|
44
46
|
- lib/merb-parts.rb
|
@@ -46,6 +48,7 @@ files:
|
|
46
48
|
- spec/fixtures/controllers
|
47
49
|
- spec/fixtures/controllers/main.rb
|
48
50
|
- spec/fixtures/parts
|
51
|
+
- spec/fixtures/parts/done_part.rb
|
49
52
|
- spec/fixtures/parts/todo_part.rb
|
50
53
|
- spec/fixtures/parts/views
|
51
54
|
- spec/fixtures/parts/views/layout
|
@@ -63,7 +66,7 @@ files:
|
|
63
66
|
- spec/merb-parts_spec.rb
|
64
67
|
- spec/spec_helper.rb
|
65
68
|
has_rdoc: true
|
66
|
-
homepage: http://
|
69
|
+
homepage: http://merbivore.com
|
67
70
|
post_install_message:
|
68
71
|
rdoc_options: []
|
69
72
|
|
@@ -83,10 +86,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
86
|
version:
|
84
87
|
requirements: []
|
85
88
|
|
86
|
-
rubyforge_project:
|
87
|
-
rubygems_version: 1.0
|
89
|
+
rubyforge_project: merb
|
90
|
+
rubygems_version: 1.2.0
|
88
91
|
signing_key:
|
89
92
|
specification_version: 2
|
90
|
-
summary:
|
93
|
+
summary: Merb plugin that provides Part Controllers.
|
91
94
|
test_files: []
|
92
95
|
|