|
Revision 17267, 1.7 kB
(checked in by hb, 4 months 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 | |
|---|
| 7 | add_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 |
|---|
| 13 | end |
|---|
| 14 | |
|---|
| 15 | def 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> |
|---|
| 43 | XML |
|---|
| 44 | |
|---|
| 45 | begin |
|---|
| 46 | File::open( file_name, 'w' ) do |f| |
|---|
| 47 | f.print to_utf8( xml ) |
|---|
| 48 | end |
|---|
| 49 | rescue |
|---|
| 50 | end |
|---|
| 51 | end |
|---|
| 52 | |
|---|
| 53 | def microsummary_init |
|---|
| 54 | @conf['generator.xml'] ||= "" |
|---|
| 55 | create_xml( @conf['generator.xml'] ) unless File::exists? @conf['generator.xml'] |
|---|
| 56 | end |
|---|
| 57 | |
|---|
| 58 | if @mode == 'saveconf' |
|---|
| 59 | def saveconf_microsummary |
|---|
| 60 | @conf['generator.xml'] = @cgi.params['generator.xml'][0] |
|---|
| 61 | end |
|---|
| 62 | end |
|---|