41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/hobix/out/atom.rb', line 41
def load( file_name, vars )
= REXML::Document.new( <<EOXML )
<feed
xmlns="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xml:lang="en">
<title></title>
<link rel="alternate" type="text/html" href="" />
<link rel="self" type="application/atom+xml" href="" />
<updated></updated>
<subtitle></subtitle>
<id></id>
<generator uri="http://hobix.com/" version="#{ Hobix::VERSION }">Hobix</generator>
<rights></rights>
</feed>
EOXML
uri = vars[:weblog].link
<< REXML::XMLDecl.new
.elements['/feed/title'].text = vars[:weblog].title
alt_uri = vars[:weblog].link.to_s
REXML::XPath.first(, '/atom:feed/atom:link[@rel="alternate"]',
{ 'atom' => 'http://www.w3.org/2005/Atom' }).attributes['href'] = alt_uri
self_uri = "#{vars[:weblog].link}#{vars[:page].link}"
REXML::XPath.first(, '/atom:feed/atom:link[@rel="self"]',
{ 'atom' => 'http://www.w3.org/2005/Atom' }).attributes['href'] = self_uri
.elements['/feed'].attributes['xml:base'] = self_uri
.elements['/feed/subtitle'].text = vars[:weblog].tagline
.elements['/feed/updated'].text = vars[:page].updated.strftime( "%Y-%m-%dT%H:%M:%SZ" )
.elements['/feed/id'].text = "tag:#{ uri.host },#{ Time.now.year }:blog#{ uri.path }"
.elements['/feed/rights'].text = vars[:weblog].copyright || "None"
( vars[:entries] || [vars[:entry]] ).each do |e|
ele = REXML::Element.new 'entry'
ele.extend XmlQuick
ele.attributes['xml:base'] = e.link
ele.x( 'title', e.title )
ele.x( 'link', nil, {'rel' => 'alternate', 'type' => 'text/html', 'href' => e.link } )
ele.x( 'id', "tag:#{ uri.host },#{ Time.now.year }:blog#{ CGI.escape(uri.path) }entry#{ CGI.escape( "/#{ e.id }" ) }" )
ele.x( 'published', e.created.strftime( "%Y-%m-%dT%H:%M:%SZ" ) )
ele.x( 'updated', (e.modified || e.created).strftime( "%Y-%m-%dT%H:%M:%SZ" ) )
ele.x( 'dc:subject', e.section_id )
e.tags.find_all {|t| not (t.nil? or t == '') }.each do |t|
ele.x( 'category', '', { 'term' => t, 'scheme' => "http://hobix.com/tags" } )
end
ele.x( 'summary',
e.summary.to_html.gsub( /img src="\//, "img src=\"#{ vars[:weblog].link }/" ),
{'type' => 'html', 'mode' => 'escaped'} ) if e.respond_to? :summary and e.summary and !e.summary.empty?
author = vars[:weblog].authors[e.author]
ele_auth = REXML::Element.new 'author'
ele_auth.extend XmlQuick
ele_auth.x( 'name', author['name'] )
ele_auth.x( 'uri', author['url'] ) if author['url']
ele_auth.x( 'email', author['email'] ) if author['email']
ele << ele_auth
ele.x( 'content', e.content.to_html, {'type' => 'html'} )
.elements['/feed'].add ele
end
.to_s
end
|