genki-merb_component 0.2.0.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/lib/merb_component/controller_ext.rb +24 -2
- data/lib/merb_component/router_ext.rb +1 -1
- data/spec/fixture/app/controllers/comments.rb +1 -0
- data/spec/fixture/app/views/comments/index.atom.builder +21 -0
- data/spec/fixture/app/views/comments/index.html.erb +4 -0
- data/spec/fixture/app/views/posts/show.html.erb +2 -0
- data/spec/posts_spec.rb +14 -0
- data/spec/spec_helper.rb +3 -0
- metadata +11 -1
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'merb-core'
|
|
5
5
|
require 'merb-core/tasks/merb'
|
6
6
|
|
7
7
|
GEM_NAME = "merb_component"
|
8
|
-
GEM_VERSION = "0.2.
|
8
|
+
GEM_VERSION = "0.2.1"
|
9
9
|
AUTHOR = "Genki Takiuchi"
|
10
10
|
EMAIL = "genki@s21g.com"
|
11
11
|
HOMEPAGE = "http://blog.s21g.com/genki"
|
@@ -24,6 +24,7 @@ spec = Gem::Specification.new do |s|
|
|
24
24
|
s.email = EMAIL
|
25
25
|
s.homepage = HOMEPAGE
|
26
26
|
s.add_dependency('merb', '>= 1.0.7.1')
|
27
|
+
s.add_development_dependency('merb_full_url', '>= 0.0.2')
|
27
28
|
s.require_path = 'lib'
|
28
29
|
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
29
30
|
|
@@ -53,7 +53,7 @@ class Merb::Controller
|
|
53
53
|
begin
|
54
54
|
layout = cc.class.default_layout
|
55
55
|
cc.class.layout(options[:layout])
|
56
|
-
|
56
|
+
cc._abstract_dispatch(action)
|
57
57
|
ensure
|
58
58
|
cc.class.layout(layout)
|
59
59
|
end
|
@@ -69,6 +69,9 @@ class Merb::Controller
|
|
69
69
|
# GET with component id
|
70
70
|
object = model.get(params[:id])
|
71
71
|
c.instance_variable_set(var, object)
|
72
|
+
elsif params[:format]
|
73
|
+
@component_format = params.delete(:format)
|
74
|
+
#c._abstract_dispatch(action)
|
72
75
|
end
|
73
76
|
c.instance_variable_set("#{var}_component", object)
|
74
77
|
|
@@ -76,6 +79,20 @@ class Merb::Controller
|
|
76
79
|
c.params[:id] = id if id
|
77
80
|
c.params[:action] = c.action_name = agg_action.to_s
|
78
81
|
}, :only => arg)
|
82
|
+
|
83
|
+
add_filter(_after_filters, proc{|c|
|
84
|
+
# setup request
|
85
|
+
request.reset_params!
|
86
|
+
request.instance_variable_set(:@params, params.merge(
|
87
|
+
:controller => arg, :action => :index,
|
88
|
+
:format => @component_format))
|
89
|
+
|
90
|
+
# call index action of subsidiary controller with scope
|
91
|
+
cc = Object.full_const_get(arg.to_s.camel_case).new(request)
|
92
|
+
@body = Aggregator.new(c, cc.class) do
|
93
|
+
cc._abstract_dispatch(:index)
|
94
|
+
end.result
|
95
|
+
}, :only => agg_action, :if => proc{@component_format})
|
79
96
|
end
|
80
97
|
end
|
81
98
|
end
|
@@ -150,13 +167,18 @@ private
|
|
150
167
|
req.reset_params!
|
151
168
|
req.instance_variable_set :@params, params
|
152
169
|
|
153
|
-
Aggregator.new(self, controller) do
|
170
|
+
Aggregator.new(this = self, controller) do
|
154
171
|
controller.new(req)._dispatch(action).instance_eval do
|
155
172
|
if object
|
156
173
|
original = instance_variable_get(var)
|
157
174
|
object.attributes = original.attributes if original
|
158
175
|
instance_variable_set(var, object)
|
159
176
|
end
|
177
|
+
cc = this.instance_variable_get(:@_caught_content)
|
178
|
+
instance_variable_get(:@_caught_content).each do |k, v|
|
179
|
+
next if k == :for_layout
|
180
|
+
cc[k].nil? ? this.throw_content(k, v) : this.append_content(k, v)
|
181
|
+
end
|
160
182
|
render :layout => false
|
161
183
|
end
|
162
184
|
end.result
|
@@ -0,0 +1,21 @@
|
|
1
|
+
xml.instruct! :xml, :version=>"1.0"
|
2
|
+
xml.feed(:xmlns => "http://www.w3.org/2005/Atom") do |feed|
|
3
|
+
feed.title @title
|
4
|
+
feed.link :type => 'text/html', :rel => 'alternate',
|
5
|
+
:href => full_resource(:comments)
|
6
|
+
|
7
|
+
@comments.each do |comment|
|
8
|
+
feed.entry do |entry|
|
9
|
+
entry.id comment.id
|
10
|
+
entry.title "Comment to post#%s" % comment.post.id
|
11
|
+
entry.content comment.body, :type => 'text'
|
12
|
+
#entry.issued comment.created_at
|
13
|
+
#entry.modified comment.updated_at
|
14
|
+
entry.link :type => "text/html", :rel => "alternate",
|
15
|
+
:href => full_resource(comment)
|
16
|
+
#entry.author do |author|
|
17
|
+
# author.name comment.user.login
|
18
|
+
#end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/posts_spec.rb
CHANGED
@@ -36,6 +36,7 @@ describe "Posts controller" do
|
|
36
36
|
res.should_not have_xpath("//input[@value='put']")
|
37
37
|
res.should have_xpath("//input[@value='new']")
|
38
38
|
res.should have_xpath("//a[@href='/posts/#{@post.id}/comments?page=1']")
|
39
|
+
res.should contain("test_content")
|
39
40
|
end
|
40
41
|
|
41
42
|
it "should show html for pagination params" do
|
@@ -156,4 +157,17 @@ describe "Posts controller" do
|
|
156
157
|
|
157
158
|
pending "should check pagination"
|
158
159
|
end
|
160
|
+
|
161
|
+
it "should provide atom feed for comments" do
|
162
|
+
comment = @post.comments.create(:body => "test")
|
163
|
+
comment.should_not be_new_record
|
164
|
+
res = request(resource(@post, :comments, :format => :atom))
|
165
|
+
res.should be_successful
|
166
|
+
res.should have_xpath("//feed/title")
|
167
|
+
url = "http://example.org/posts/#{@post.id}/comments"
|
168
|
+
res.should have_xpath("//feed/link[@href='#{url}']")
|
169
|
+
res.should have_xpath("//entry/title")
|
170
|
+
url = "http://example.org/posts/#{@post.id}/comments/#{comment.id}"
|
171
|
+
res.should have_xpath("//entry/link[@href='#{url}']")
|
172
|
+
end
|
159
173
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,8 @@ dependency "merb-action-args"
|
|
12
12
|
dependency "merb-helpers"
|
13
13
|
dependency "merb-assets"
|
14
14
|
dependency "dm-validations"
|
15
|
+
dependency "merb-builder"
|
16
|
+
dependency "merb_full_url"
|
15
17
|
|
16
18
|
use_orm :datamapper
|
17
19
|
use_test :rspec
|
@@ -28,6 +30,7 @@ Merb.start_environment(
|
|
28
30
|
:log_file => File.dirname(__FILE__) / '..' / "merb_test.log"
|
29
31
|
)
|
30
32
|
DataMapper.setup(:default, "sqlite3::memory:")
|
33
|
+
Merb.add_mime_type(:atom, :to_atom, %w[application/atom+xml])
|
31
34
|
|
32
35
|
Spec::Runner.configure do |config|
|
33
36
|
config.include(Merb::Test::ViewHelper)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genki-merb_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Takiuchi
|
@@ -21,6 +21,15 @@ dependencies:
|
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.0.7.1
|
23
23
|
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: merb_full_url
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 0.0.2
|
32
|
+
version:
|
24
33
|
description: Merb plugin that provides composition of controllers.
|
25
34
|
email: genki@s21g.com
|
26
35
|
executables: []
|
@@ -58,6 +67,7 @@ files:
|
|
58
67
|
- spec/fixture/app/views/admin/show.html.erb
|
59
68
|
- spec/fixture/app/views/comments
|
60
69
|
- spec/fixture/app/views/comments/edit.html.erb
|
70
|
+
- spec/fixture/app/views/comments/index.atom.builder
|
61
71
|
- spec/fixture/app/views/comments/index.html.erb
|
62
72
|
- spec/fixture/app/views/comments/new.html.erb
|
63
73
|
- spec/fixture/app/views/layout
|