Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7e4ea5f4
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7e4ea5f4
编写于
6月 25, 2008
作者:
D
Darragh Curran
提交者:
Pratik Naik
8月 21, 2008
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow overriding id for feed and entry with atom_feed_builder. [#485 state:resolved]
Signed-off-by:
N
Pratik Naik
<
pratiknaik@gmail.com
>
上级
24156526
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
16 deletion
+45
-16
actionpack/lib/action_view/helpers/atom_feed_helper.rb
actionpack/lib/action_view/helpers/atom_feed_helper.rb
+13
-11
actionpack/test/template/atom_feed_helper_test.rb
actionpack/test/template/atom_feed_helper_test.rb
+32
-5
未找到文件。
actionpack/lib/action_view/helpers/atom_feed_helper.rb
浏览文件 @
7e4ea5f4
...
...
@@ -17,7 +17,7 @@ module AtomFeedHelper
# # GET /posts.atom
# def index
# @posts = Post.find(:all)
#
#
# respond_to do |format|
# format.html
# format.atom
...
...
@@ -29,12 +29,12 @@ module AtomFeedHelper
# atom_feed do |feed|
# feed.title("My great blog!")
# feed.updated((@posts.first.created_at))
#
#
# for post in @posts
# feed.entry(post) do |entry|
# entry.title(post.title)
# entry.content(post.body, :type => 'html')
#
#
# entry.author do |author|
# author.name("DHH")
# end
...
...
@@ -47,8 +47,9 @@ module AtomFeedHelper
# * <tt>:language</tt>: Defaults to "en-US".
# * <tt>:root_url</tt>: The HTML alternative that this feed is doubling for. Defaults to / on the current host.
# * <tt>:url</tt>: The URL for this feed. Defaults to the current URL.
# * <tt>:schema_date</tt>: The date at which the tag scheme for the feed was first used. A good default is the year you
# created the feed. See http://feedvalidator.org/docs/error/InvalidTAG.html for more information. If not specified,
# * <tt>:id</tt>: The id for this feed. Defaults to "tag:#{request.host},#{options[:schema_date]}:#{request.request_uri.split(".")[0]}"
# * <tt>:schema_date</tt>: The date at which the tag scheme for the feed was first used. A good default is the year you
# created the feed. See http://feedvalidator.org/docs/error/InvalidTAG.html for more information. If not specified,
# 2005 is used (as an "I don't care" value).
#
# Other namespaces can be added to the root element:
...
...
@@ -81,7 +82,7 @@ def atom_feed(options = {}, &block)
else
options
[
:schema_date
]
=
"2005"
# The Atom spec copyright date
end
xml
=
options
[
:xml
]
||
eval
(
"xml"
,
block
.
binding
)
xml
.
instruct!
...
...
@@ -89,10 +90,10 @@ def atom_feed(options = {}, &block)
feed_opts
.
merge!
(
options
).
reject!
{
|
k
,
v
|
!
k
.
to_s
.
match
(
/^xml/
)}
xml
.
feed
(
feed_opts
)
do
xml
.
id
(
"tag:
#{
request
.
host
}
,
#{
options
[
:schema_date
]
}
:
#{
request
.
request_uri
.
split
(
"."
)[
0
]
}
"
)
xml
.
id
(
options
[
:id
]
||
"tag:
#{
request
.
host
}
,
#{
options
[
:schema_date
]
}
:
#{
request
.
request_uri
.
split
(
"."
)[
0
]
}
"
)
xml
.
link
(
:rel
=>
'alternate'
,
:type
=>
'text/html'
,
:href
=>
options
[
:root_url
]
||
(
request
.
protocol
+
request
.
host_with_port
))
xml
.
link
(
:rel
=>
'self'
,
:type
=>
'application/atom+xml'
,
:href
=>
options
[
:url
]
||
request
.
url
)
yield
AtomFeedBuilder
.
new
(
xml
,
self
,
options
)
end
end
...
...
@@ -102,7 +103,7 @@ class AtomFeedBuilder
def
initialize
(
xml
,
view
,
feed_options
=
{})
@xml
,
@view
,
@feed_options
=
xml
,
view
,
feed_options
end
# Accepts a Date or Time object and inserts it in the proper format. If nil is passed, current time in UTC is used.
def
updated
(
date_or_time
=
nil
)
@xml
.
updated
((
date_or_time
||
Time
.
now
.
utc
).
xmlschema
)
...
...
@@ -115,9 +116,10 @@ def updated(date_or_time = nil)
# * <tt>:published</tt>: Time first published. Defaults to the created_at attribute on the record if one such exists.
# * <tt>:updated</tt>: Time of update. Defaults to the updated_at attribute on the record if one such exists.
# * <tt>:url</tt>: The URL for this entry. Defaults to the polymorphic_url for the record.
# * <tt>:id</tt>: The ID for this entry. Defaults to "tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}"
def
entry
(
record
,
options
=
{})
@xml
.
entry
do
@xml
.
id
(
"tag:
#{
@view
.
request
.
host
}
,
#{
@feed_options
[
:schema_date
]
}
:
#{
record
.
class
}
/
#{
record
.
id
}
"
)
@xml
.
entry
do
@xml
.
id
(
options
[
:id
]
||
"tag:
#{
@view
.
request
.
host
}
,
#{
@feed_options
[
:schema_date
]
}
:
#{
record
.
class
}
/
#{
record
.
id
}
"
)
if
options
[
:published
]
||
(
record
.
respond_to?
(
:created_at
)
&&
record
.
created_at
)
@xml
.
published
((
options
[
:published
]
||
record
.
created_at
).
xmlschema
)
...
...
actionpack/test/template/atom_feed_helper_test.rb
浏览文件 @
7e4ea5f4
...
...
@@ -67,6 +67,24 @@ class ScrollsController < ActionController::Base
entry.content(scroll.body, :type => 'html')
entry.tag!('app:edited', Time.now)
entry.author do |author|
author.name("DHH")
end
end
end
end
EOT
FEEDS
[
"feed_with_overridden_ids"
]
=
<<-
EOT
atom_feed({:id => 'tag:test.rubyonrails.org,2008:test/'}) do |feed|
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
for scroll in @scrolls
feed.entry(scroll, :id => "tag:test.rubyonrails.org,2008:"+scroll.id.to_s) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
entry.tag!('app:edited', Time.now)
entry.author do |author|
author.name("DHH")
end
...
...
@@ -79,7 +97,7 @@ def index
Scroll
.
new
(
1
,
"1"
,
"Hello One"
,
"Something <i>COOL!</i>"
,
Time
.
utc
(
2007
,
12
,
12
,
15
),
Time
.
utc
(
2007
,
12
,
12
,
15
)),
Scroll
.
new
(
2
,
"2"
,
"Hello Two"
,
"Something Boring"
,
Time
.
utc
(
2007
,
12
,
12
,
15
)),
]
render
:inline
=>
FEEDS
[
params
[
:id
]],
:type
=>
:builder
end
...
...
@@ -98,21 +116,21 @@ def setup
@request
.
host
=
"www.nextangle.com"
end
def
test_feed_should_use_default_language_if_none_is_given
with_restful_routing
(
:scrolls
)
do
get
:index
,
:id
=>
"defaults"
assert_match
%r{xml:lang="en-US"}
,
@response
.
body
end
end
def
test_feed_should_include_two_entries
with_restful_routing
(
:scrolls
)
do
get
:index
,
:id
=>
"defaults"
assert_select
"entry"
,
2
end
end
def
test_entry_should_only_use_published_if_created_at_is_present
with_restful_routing
(
:scrolls
)
do
get
:index
,
:id
=>
"defaults"
...
...
@@ -167,7 +185,16 @@ def test_feed_should_include_atomPub_namespace
end
end
private
def
test_feed_should_allow_overriding_ids
with_restful_routing
(
:scrolls
)
do
get
:index
,
:id
=>
"feed_with_overridden_ids"
assert_select
"id"
,
:text
=>
"tag:test.rubyonrails.org,2008:test/"
assert_select
"entry id"
,
:text
=>
"tag:test.rubyonrails.org,2008:1"
assert_select
"entry id"
,
:text
=>
"tag:test.rubyonrails.org,2008:2"
end
end
private
def
with_restful_routing
(
resources
)
with_routing
do
|
set
|
set
.
draw
do
|
map
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录