Class: Hobix::Out::Atom

Inherits:
BaseOutput show all
Defined in:
lib/hobix/out/atom.rb

Instance Method Summary collapse

Methods inherited from BasePlugin

inherited, start

Constructor Details

#initialize(weblog) ⇒ Atom

Returns a new instance of Atom.



32
33
34
# File 'lib/hobix/out/atom.rb', line 32

def initialize( weblog )
    @path = weblog.skel_path
end

Instance Method Details

#extensionObject



35
36
37
# File 'lib/hobix/out/atom.rb', line 35

def extension
    "atom"
end

#load(file_name, vars) ⇒ Object



38
39
40
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
# File 'lib/hobix/out/atom.rb', line 38

def load( file_name, vars )
    rssdoc = REXML::Document.new( <<EOXML )
<feed version="0.3"
  xmlns="http://purl.org/atom/ns#"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xml:lang="en">
<title></title>
<link rel="alternate" type="text/html" href="" />
<modified></modified>
<tagline></tagline>
<id></id>
<generator url="http://hobix.com/" version="#{ Hobix::VERSION }">Hobix</generator>
<copyright></copyright>
</feed>
EOXML
    uri = vars[:weblog].link
    rssdoc << REXML::XMLDecl.new
    rssdoc.elements['/feed/title'].text = vars[:weblog].title
    rssdoc.elements['/feed/link'].attributes['href'] = vars[:weblog].link.to_s
    rssdoc.elements['/feed/tagline'].text = vars[:weblog].tagline
    rssdoc.elements['/feed/modified'].text = vars[:page].updated.strftime( "%Y-%m-%dT%H:%M:%SZ" )
    rssdoc.elements['/feed/id'].text = "tag:#{ uri.host },#{ Time.now.year }:blog#{ uri.path }"
    rssdoc.elements['/feed/copyright'].text = vars[:weblog].copyright || "None"
    ( vars[:entries] || [vars[:entry]] ).each do |e|
        ele = REXML::Element.new 'entry'
        ele.extend XmlQuick
        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( 'issued', e.created.strftime( "%Y-%m-%dT%H:%M:%SZ" ) )
        ele.x( 'modified', e.modified.strftime( "%Y-%m-%dT%H:%M:%SZ" ) )
        ele.x( 'dc:subject', e.section_id )
        e.tags.each do |t|
            ele.x( 'dc:subject', t )
        end
        ele.x( 'summary', 
            e.summary.to_html.gsub( /img src="\//, "img src=\"#{ vars[:weblog].link }/" ),
            {'type' => 'text/html', 'mode' => 'escaped'} ) if e.respond_to? :summary and e.summary
        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( 'url', author['url'] ) if author['url']
        ele_auth.x( 'email', author['email'] ) if author['email']
        ele << ele_auth
        ele.x( 'content',
            e.content.to_html.gsub( /img src="\//, "img src=\"#{ vars[:weblog].link }/" ),
            {'type' => 'text/html', 'mode' => 'escaped'} )
        rssdoc.elements['/feed'].add ele
    end
    rssdoc.to_s
end