root/platform/tdiary/plugin/microsummary.rb @ 17796

Revision 17267, 1.7 kB (checked in by hb, 6 years ago)

platform/tdiary/plugin/microsummary.rb: added create_xml.

Line 
1# microsummary.rb
2#
3# Copyright (c) 2006 elytsllams <smallstyle@gmail.com>
4# Distributed under the GPL
5#
6
7add_header_proc do
8        generator_xml = @conf['generator.xml']
9       
10        if generator_xml != nil and @mode == 'latest' and !@cgi.valid?( 'date' )
11                %Q|\t<link rel="microsummary" href="#{generator_xml}" type="application/x.microsummary+xml">\n|
12        end
13end
14
15def create_xml file_name
16        xml = <<-XML
17<?xml version="1.0" encoding="UTF-8"?>
18<generator xmlns="http://www.mozilla.org/microsummaries/0.1"
19           name="tDiary Entry Title">
20  <template>
21    <transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
22      <output method="text"/>
23      <template match="/">
24        <value-of select="html/head/title"/>
25        <choose>
26          <when test="boolean(descendant::div[attribute::class='body'][1]/div[attribute::class='section'][last()]/h3)">
27            <text> - </text>
28            <value-of select="descendant::div[attribute::class='body'][1]/div[attribute::class='section'][last()]/h3"/>
29          </when>
30          <when test="boolean(descendant::div[attribute::class='day'][1]/h2)">
31            <text> - </text>
32            <value-of select="descendant::div[attribute::class='day'][1]/h2"/>
33          </when>
34        </choose>
35      </template>
36    </transform>
37  </template>
38  <update interval="240"/>
39  <pages>
40   <include>^#{@conf.base_url.gsub(/\./, '\\.')}$</include>
41  </pages>
42</generator>
43XML
44       
45        begin
46                File::open( file_name, 'w' ) do |f|
47                        f.print to_utf8( xml )
48                end
49        rescue
50        end
51end
52
53def microsummary_init
54        @conf['generator.xml'] ||= ""
55        create_xml( @conf['generator.xml'] ) unless File::exists? @conf['generator.xml']
56end
57
58if @mode == 'saveconf'
59        def saveconf_microsummary
60                @conf['generator.xml'] = @cgi.params['generator.xml'][0]
61        end
62end
Note: See TracBrowser for help on using the browser.