html-template 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d7ee8a92f5791e4ac9a898027d3815cb0f4c3619
4
+ data.tar.gz: f20c60078147da549da1495b13abb55f7aef81f8
5
+ SHA512:
6
+ metadata.gz: 49601653c67d7e9eb88813fe399e6aa738a8bb232d4048b98aaaa918335e9d22261d24f084243d545c5f6f9ae4849809ac49a30d3b210396e1ca138a47ec8455
7
+ data.tar.gz: cdbc81e61aabbac50bfd499d3ffa9efa3417d3652fe2610a32c66b39d597a17bc604431b78f1684031a055527f3618de78770e7f0394b84e5f3669972bb73bed
@@ -0,0 +1,4 @@
1
+
2
+ ### 0.0.1 / 2020-02-09
3
+
4
+ * Everything is new. First release
@@ -0,0 +1,19 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/html/template.rb
6
+ lib/html/template/version.rb
7
+ test/helper.rb
8
+ test/templates/opml.xml
9
+ test/templates/opml.xml.erb
10
+ test/templates/opml.xml.tmpl
11
+ test/templates/planet/README.md
12
+ test/templates/planet/atom.xml.tmpl
13
+ test/templates/planet/basic/index.html.tmpl
14
+ test/templates/planet/fancy/index.html.tmpl
15
+ test/templates/planet/foafroll.xml.tmpl
16
+ test/templates/planet/opml.xml.tmpl
17
+ test/templates/planet/rss10.xml.tmpl
18
+ test/templates/planet/rss20.xml.tmpl
19
+ test/test_merge.rb
@@ -0,0 +1,26 @@
1
+ # html-template - old-style classic HTML template language / engine like it's 1999 (incl. back-to-the-future ERB converter)
2
+
3
+
4
+ * home :: [github.com/feedreader/pluto](https://github.com/feedreader/pluto)
5
+ * bugs :: [github.com/feedreader/pluto/issues](https://github.com/feedreader/pluto/issues)
6
+ * gem :: [rubygems.org/gems/html-template](https://rubygems.org/gems/html-template)
7
+ * rdoc :: [rubydoc.info/gems/html-template](http://rubydoc.info/gems/html-template)
8
+ * forum :: [groups.google.com/group/wwwmake](http://groups.google.com/group/wwwmake)
9
+
10
+
11
+
12
+ ## Usage
13
+
14
+ To be done
15
+
16
+ ## License
17
+
18
+ ![](https://publicdomainworks.github.io/buttons/zero88x31.png)
19
+
20
+ The `html-template` scripts are dedicated to the public domain.
21
+ Use it as you please with no restrictions whatsoever.
22
+
23
+ ## Questions? Comments?
24
+
25
+ Send them along to the [wwwmake Forum/Mailing List](http://groups.google.com/group/wwwmake).
26
+ Thanks!
@@ -0,0 +1,28 @@
1
+ require 'hoe'
2
+ require './lib/html/template/version.rb'
3
+
4
+ Hoe.spec 'html-template' do
5
+
6
+ self.version = HtmlTemplate::VERSION
7
+
8
+ self.summary = "html-template - old-style classic HTML template language / engine like it's 1999 (incl. back-to-the-future ERB converter)"
9
+ self.description = summary
10
+
11
+ self.urls = ['https://github.com/feedreader/pluto']
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'wwwmake@googlegroups.com'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'CHANGELOG.md'
19
+
20
+ self.extra_deps = []
21
+
22
+ self.licenses = ['Public Domain']
23
+
24
+ self.spec_extras = {
25
+ required_ruby_version: '>= 2.2.2'
26
+ }
27
+
28
+ end
@@ -0,0 +1,160 @@
1
+ require 'pp'
2
+ require 'date'
3
+ require 'time'
4
+ require 'erb'
5
+ require 'cgi'
6
+ require 'ostruct'
7
+ require 'fileutils'
8
+
9
+
10
+ # our own code
11
+ require 'html/template/version' # note: let version always get first
12
+
13
+
14
+
15
+ class HtmlTemplate
16
+
17
+ attr_reader :text ## returns converted template text (with "breaking" comments!!!)
18
+
19
+ def initialize( text )
20
+ @text = convert( text ) ## note: keep a copy of the converted template text
21
+ @template = ERB.new( strip_comments( @text ) )
22
+ end
23
+
24
+
25
+ VAR_RE = %r{<TMPL_(?<tag>VAR)
26
+ \s
27
+ (?<ident>[a-zA-Z_0-9]+)
28
+ >}x
29
+
30
+ IF_OPEN_RE = %r{(?<open><)TMPL_(?<tag>IF)
31
+ \s
32
+ (?<ident>[a-zA-Z_0-9]+)
33
+ >}x
34
+
35
+ IF_CLOSE_RE = %r{(?<close></)TMPL_(?<tag>IF)
36
+ >}x
37
+
38
+ LOOP_OPEN_RE = %r{(?<open><)TMPL_(?<tag>LOOP)
39
+ \s
40
+ (?<ident>[a-zA-Z_0-9]+)
41
+ >}x
42
+
43
+ LOOP_CLOSE_RE = %r{(?<close></)TMPL_(?<tag>LOOP)
44
+ >}x
45
+
46
+ CATCH_OPEN_RE = %r{(?<open><)TMPL_(?<unknown>[^>]+?)
47
+ >}x
48
+
49
+
50
+ ALL_RE = Regexp.union( VAR_RE,
51
+ IF_OPEN_RE,
52
+ IF_CLOSE_RE,
53
+ LOOP_OPEN_RE,
54
+ LOOP_CLOSE_RE,
55
+ CATCH_OPEN_RE )
56
+
57
+
58
+ def strip_comments( text )
59
+ ## strip/remove comments lines starting with #
60
+ buf = String.new('') ## note: '' required for getting source encoding AND not ASCII-8BIT!!!
61
+ text.each_line do |line|
62
+ next if line.lstrip.start_with?( '#' )
63
+ buf << line
64
+ end
65
+ buf
66
+ end
67
+
68
+ def convert( text )
69
+ stack = []
70
+
71
+ ## note: convert line-by-line
72
+ ## allows comments and line no reporting etc.
73
+ buf = String.new('') ## note: '' required for getting source encoding AND not ASCII-8BIT!!!
74
+ lineno = 0
75
+ text.each_line do |line|
76
+ lineno += 1
77
+
78
+ if line.lstrip.start_with?( '#' ) ## or make it tripple ### - why? why not?
79
+ buf << line ## pass along as is for now!!
80
+ elsif line.strip.empty?
81
+ buf << line
82
+ else
83
+ buf << line.gsub( ALL_RE ) do |_|
84
+ m = $~ ## (global) last match object
85
+
86
+ tag = m[:tag]
87
+ tag_open = m[:open]
88
+ tag_close = m[:close]
89
+
90
+ ident = m[:ident]
91
+ unknown = m[:unknown] # catch all for unknown / unmatched tags
92
+
93
+ ## todo/fix: rename ctx to scope or __ - why? why not?
94
+ ## note: peek; get top stack item
95
+ ## if top level (stack empty) => nothing
96
+ ## otherwise => channel. or item. etc. (with trailing dot included!)
97
+ ctx = stack.empty? ? '' : "#{stack[-1]}."
98
+
99
+ code = if tag == 'VAR'
100
+ "<%= #{ctx}#{ident} %>"
101
+ elsif tag == 'LOOP' && tag_open
102
+ ## assume plural ident e.g. channels
103
+ ## cut-off last char, that is, the plural s channels => channel
104
+ ## note: ALWAYS downcase (auto-generated) loop iterator/pass name
105
+ it = ident[0..-2].downcase
106
+ stack.push( it )
107
+ "<% #{ctx}#{ident}.each do |#{it}| %>"
108
+ elsif tag == 'LOOP' && tag_close
109
+ stack.pop
110
+ "<% end %>"
111
+ elsif tag == 'IF' && tag_open
112
+ "<% if #{ctx}#{ident} %>"
113
+ elsif tag == 'IF' && tag_close
114
+ "<% end %>"
115
+ elsif unknown && tag_open
116
+ puts "!! ERROR"
117
+ "<%# !!error - unknown open tag: #{unknown} %>"
118
+ else
119
+ raise ArgumentError ## unknown tag #{tag}
120
+ end
121
+
122
+ puts " line #{lineno} - match #{m[0]} replacing with: #{code}"
123
+ code
124
+
125
+ end
126
+ end
127
+ end # each_line
128
+ buf
129
+ end # method convert
130
+
131
+
132
+ class Context < OpenStruct
133
+ ## use a different name - why? why not?
134
+ ## e.g. to_h, to_hash, vars, locals, assigns, etc.
135
+ def get_binding() binding; end
136
+
137
+ ## add builtin helpers / shortcuts
138
+ def h( text ) CGI.escapeHTML( text ); end
139
+ end # class Template::Context
140
+
141
+ def render( **kwargs )
142
+ ## todo: use locals / assigns or something instead of **kwargs - why? why not?
143
+ ## allow/support (extra) locals / assigns - why? why not?
144
+ ## note: Ruby >= 2.5 has ERB#result_with_hash - use later - why? why not?
145
+ @template.result( Context.new( **kwargs ).get_binding )
146
+ end
147
+ end
148
+
149
+
150
+ #####################
151
+ ## add convenience aliases - why? why not?
152
+ HTMLTemplate = HtmlTemplate
153
+ module HTML
154
+ Template = HtmlTemplate
155
+ end
156
+
157
+
158
+ # say hello
159
+ puts HtmlTemplate.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG)
160
+
@@ -0,0 +1,24 @@
1
+ # note: HtmlTemplate is a class (NOT a module) for now - change - why? why not?
2
+
3
+
4
+ class HtmlTemplate
5
+ MAJOR = 0
6
+ MINOR = 0
7
+ PATCH = 1
8
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
9
+
10
+ def self.version
11
+ VERSION
12
+ end
13
+
14
+ def self.banner
15
+ ### todo: add RUBY_PATCHLEVEL or RUBY_PATCH_LEVEL e.g. -p124
16
+ "html-template/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
17
+ end
18
+
19
+ def self.root
20
+ File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )
21
+ end
22
+
23
+ end # class HtmlTemplate
24
+
@@ -0,0 +1,21 @@
1
+ ## minitest setup
2
+ require 'minitest/autorun'
3
+
4
+ ## our own code
5
+ require 'html/template'
6
+
7
+
8
+
9
+ ########
10
+ ## add some "global" helpers
11
+ require 'rexml/document'
12
+
13
+ def prettify_xml( xml )
14
+ d = REXML::Document.new( xml )
15
+
16
+ formatter = REXML::Formatters::Pretty.new( 2 ) # indent=2
17
+ formatter.compact = true # This is the magic line that does what you need!
18
+ pretty_xml = formatter.write( d.root, "" ) # todo/checl: what's 2nd arg used for ??
19
+ pretty_xml
20
+ end
21
+
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0"?>
2
+ <opml version="1.1">
3
+ <head>
4
+ <title>OpenStreetMap Blogs</title>
5
+ <dateModified>Fri, 7 Feb 2020 00:00:00 +0000</dateModified>
6
+ <ownerName>OpenStreetMap</ownerName>
7
+ </head>
8
+
9
+ <body>
10
+
11
+ <outline type="rss"
12
+ text="Shaun McDonald"
13
+ xmlUrl="http://blog.shaunmcdonald.me.uk/feed/"
14
+ htmlUrl="http://blog.shaunmcdonald.me.uk/" />
15
+
16
+ <outline type="rss"
17
+ text="Mapbox"
18
+ xmlUrl="https://blog.mapbox.com/feed/tagged/openstreetmap/"
19
+ htmlUrl="https://blog.mapbox.com/" />
20
+
21
+ <outline type="rss"
22
+ text="Mapillary"
23
+ xmlUrl="https://blog.mapillary.com/rss.xml"
24
+ htmlUrl="https://blog.mapillary.com" />
25
+
26
+ <outline type="rss"
27
+ text="Richard Fairhurst"
28
+ xmlUrl="http://blog.systemed.net/rss"
29
+ htmlUrl="http://blog.systemed.net/" />
30
+
31
+ </body>
32
+ </opml>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0"?>
2
+ <opml version="1.1">
3
+ <head>
4
+ <title><%= name %></title>
5
+ <dateModified><%= date_822 %></dateModified>
6
+ <ownerName><%= owner_name %></ownerName>
7
+ </head>
8
+
9
+ <body>
10
+ <% channels.each do |channel| %>
11
+ <outline type="rss"
12
+ text="<%= channel.name %>"
13
+ xmlUrl="<%= channel.url %>"
14
+ <% if channel.channel_link %> htmlUrl="<%= channel.channel_link %>"<% end %> />
15
+ <% end %>
16
+ </body>
17
+ </opml>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0"?>
2
+ <opml version="1.1">
3
+ <head>
4
+ <title><TMPL_VAR name></title>
5
+ <dateModified><TMPL_VAR date_822></dateModified>
6
+ <ownerName><TMPL_VAR owner_name></ownerName>
7
+ </head>
8
+
9
+ <body>
10
+ <TMPL_LOOP channels>
11
+ <outline type="rss"
12
+ text="<TMPL_VAR name>"
13
+ xmlUrl="<TMPL_VAR url>"
14
+ <TMPL_IF channel_link> htmlUrl="<TMPL_VAR channel_link>"</TMPL_IF> />
15
+ </TMPL_LOOP>
16
+ </body>
17
+ </opml>
@@ -0,0 +1,7 @@
1
+ # Notes on (Original) Planet HTML Templates
2
+
3
+ see <https://people.gnome.org/~jdub/bzr/planet/devel/trunk/examples/>
4
+
5
+
6
+
7
+
@@ -0,0 +1,61 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2
+ <feed xmlns="http://www.w3.org/2005/Atom">
3
+
4
+ <title><TMPL_VAR name></title>
5
+ <link rel="self" href="<TMPL_VAR feed ESCAPE="HTML">"/>
6
+ <link href="<TMPL_VAR link ESCAPE="HTML">"/>
7
+ <id><TMPL_VAR feed ESCAPE="HTML"></id>
8
+ <updated><TMPL_VAR date_iso></updated>
9
+ <generator uri="http://www.planetplanet.org/"><TMPL_VAR generator ESCAPE="HTML"></generator>
10
+
11
+ <TMPL_LOOP Items>
12
+ <entry<TMPL_IF channel_language> xml:lang="<TMPL_VAR channel_language>"</TMPL_IF>>
13
+ <title type="html"<TMPL_IF title_language> xml:lang="<TMPL_VAR title_language>"</TMPL_IF>><TMPL_VAR title ESCAPE="HTML"></title>
14
+ <link href="<TMPL_VAR link ESCAPE="HTML">"/>
15
+ <id><TMPL_VAR id ESCAPE="HTML"></id>
16
+ <updated><TMPL_VAR date_iso></updated>
17
+ <content type="html"<TMPL_IF content_language> xml:lang="<TMPL_VAR content_language>"</TMPL_IF>><TMPL_VAR content ESCAPE="HTML"></content>
18
+ <author>
19
+ <TMPL_IF author_name>
20
+ <name><TMPL_VAR author_name ESCAPE="HTML"></name>
21
+ <TMPL_IF author_email>
22
+ <email><TMPL_VAR author_email ESCAPE="HTML"></email>
23
+ </TMPL_IF author_email>
24
+ <TMPL_ELSE>
25
+ <TMPL_IF channel_author_name>
26
+ <name><TMPL_VAR channel_author_name ESCAPE="HTML"></name>
27
+ <TMPL_IF channel_author_email>
28
+ <email><TMPL_VAR channel_author_email ESCAPE="HTML"></email>
29
+ </TMPL_IF channel_author_email>
30
+ <TMPL_ELSE>
31
+ <name><TMPL_VAR channel_name ESCAPE="HTML"></name>
32
+ </TMPL_IF>
33
+ </TMPL_IF>
34
+ <uri><TMPL_VAR channel_link ESCAPE="HTML"></uri>
35
+ </author>
36
+ <source>
37
+ <TMPL_IF channel_title>
38
+ <title type="html"><TMPL_VAR channel_title ESCAPE="HTML"></title>
39
+ <TMPL_ELSE>
40
+ <title type="html"><TMPL_VAR channel_name ESCAPE="HTML"></title>
41
+ </TMPL_IF>
42
+ <TMPL_IF channel_subtitle>
43
+ <subtitle type="html"><TMPL_VAR channel_subtitle ESCAPE="HTML"></subtitle>
44
+ </TMPL_IF>
45
+ <link rel="self" href="<TMPL_VAR channel_url ESCAPE="HTML">"/>
46
+ <TMPL_IF channel_id>
47
+ <id><TMPL_VAR channel_id ESCAPE="HTML"></id>
48
+ <TMPL_ELSE>
49
+ <id><TMPL_VAR channel_url ESCAPE="HTML"></id>
50
+ </TMPL_IF>
51
+ <TMPL_IF channel_updated_iso>
52
+ <updated><TMPL_VAR channel_updated_iso></updated>
53
+ </TMPL_IF>
54
+ <TMPL_IF channel_rights>
55
+ <rights type="html"><TMPL_VAR channel_rights ESCAPE="HTML"></rights>
56
+ </TMPL_IF>
57
+ </source>
58
+ </entry>
59
+
60
+ </TMPL_LOOP>
61
+ </feed>
@@ -0,0 +1,88 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2
+ <html>
3
+
4
+ ### Planet HTML template.
5
+ ###
6
+ ### This is intended to demonstrate and document Planet's templating
7
+ ### facilities, and at the same time provide a good base for you to
8
+ ### modify into your own design.
9
+ ###
10
+ ### The output's a bit boring though, if you're after less documentation
11
+ ### and more instant gratification, there's an example with a much
12
+ ### prettier output in the fancy-examples/ directory of the Planet source.
13
+
14
+ ### Lines like this are comments, and are automatically removed by the
15
+ ### templating engine before processing.
16
+
17
+
18
+ ### Planet makes a large number of variables available for your templates.
19
+ ### See INSTALL for the complete list. The raw value can be placed in your
20
+ ### output file using <TMPL_VAR varname>. We'll put the name of our
21
+ ### Planet in the page title and again in an h1.
22
+
23
+ <head>
24
+ <title><TMPL_VAR name></title>
25
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
26
+ <meta name="generator" content="<TMPL_VAR generator ESCAPE="HTML">">
27
+ </head>
28
+
29
+ <body>
30
+ <h1><TMPL_VAR name></h1>
31
+
32
+ ### One of the two loops available is the Channels loop. This allows you
33
+ ### to easily create a list of subscriptions, which is exactly what we'll do
34
+ ### here.
35
+
36
+ ### Note that we can also expand variables inside HTML tags, but we need
37
+ ### to be cautious and HTML-escape any illegal characters using the form
38
+ ### <TMPL_VAR varname ESCAPE="HTML">
39
+
40
+ <div style="float: right">
41
+ <h2>Subscriptions</h2>
42
+ <ul>
43
+ <TMPL_LOOP Channels>
44
+ <li><a href="<TMPL_VAR link ESCAPE="HTML">" title="<TMPL_VAR title ESCAPE="HTML">"><TMPL_VAR name></a> <a href="<TMPL_VAR url ESCAPE="HTML">">(feed)</a></li>
45
+ </TMPL_LOOP>
46
+ </ul>
47
+ </div>
48
+
49
+ ### The other loop is the Items loop, which will get iterated for each
50
+ ### news item.
51
+
52
+ <TMPL_LOOP Items>
53
+
54
+ ### Visually distinguish articles from different days by checking for
55
+ ### the new_date flag. This demonstrates the <TMPL_IF varname> ... </TMPL_IF>
56
+ ### check.
57
+
58
+ <TMPL_IF new_date>
59
+ <h2><TMPL_VAR new_date></h2>
60
+ </TMPL_IF>
61
+
62
+ ### Group consecutive articles by the same author together by checking
63
+ ### for the new_channel flag.
64
+
65
+ <TMPL_IF new_channel>
66
+ <h3><a href="<TMPL_VAR channel_link ESCAPE="HTML">" title="<TMPL_VAR channel_title ESCAPE="HTML">"><TMPL_VAR channel_name></a></h3>
67
+ </TMPL_IF>
68
+
69
+
70
+ <TMPL_IF title>
71
+ <h4><a href="<TMPL_VAR link ESCAPE="HTML">"><TMPL_VAR title></a></h4>
72
+ </TMPL_IF>
73
+ <p>
74
+ <TMPL_VAR content>
75
+ </p>
76
+ <p>
77
+ <em><a href="<TMPL_VAR link ESCAPE="HTML">"><TMPL_IF author>by <TMPL_VAR author> at </TMPL_IF><TMPL_VAR date></a></em>
78
+ </p>
79
+ </TMPL_LOOP>
80
+
81
+ <hr>
82
+ <p>
83
+ <a href="http://www.planetplanet.org/">Powered by Planet!</a><br>
84
+ <em>Last updated: <TMPL_VAR date></em>
85
+ </p>
86
+ </body>
87
+
88
+ </html>
@@ -0,0 +1,125 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2
+ <html>
3
+
4
+ ### Fancy Planet HTML template.
5
+ ###
6
+ ### When combined with the stylesheet and images in the output/ directory
7
+ ### of the Planet source, this gives you a much prettier result than the
8
+ ### default examples template and demonstrates how to use the config file
9
+ ### to support things like faces
10
+ ###
11
+ ### For documentation on the more boring template elements, see
12
+ ### examples/config.ini and examples/index.html.tmpl in the Planet source.
13
+
14
+ <head>
15
+ <title><TMPL_VAR name></title>
16
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
17
+ <meta name="generator" content="<TMPL_VAR generator ESCAPE="HTML">">
18
+ <link rel="stylesheet" href="planet.css" type="text/css">
19
+ <TMPL_IF feedtype>
20
+ <link rel="alternate" href="<TMPL_VAR feed ESCAPE="HTML">" title="<TMPL_VAR channel_title_plain ESCAPE="HTML">" type="application/<TMPL_VAR feedtype>+xml">
21
+ </TMPL_IF>
22
+ </head>
23
+
24
+ <body>
25
+ <h1><TMPL_VAR name></h1>
26
+
27
+ <TMPL_LOOP Items>
28
+ <TMPL_IF new_date>
29
+ <TMPL_UNLESS __FIRST__>
30
+ ### End <div class="channelgroup">
31
+ </div>
32
+ ### End <div class="daygroup">
33
+ </div>
34
+ </TMPL_UNLESS>
35
+ <div class="daygroup">
36
+ <h2><TMPL_VAR new_date></h2>
37
+ </TMPL_IF>
38
+
39
+ <TMPL_IF new_channel>
40
+ <TMPL_UNLESS new_date>
41
+ ### End <div class="channelgroup">
42
+ </div>
43
+ </TMPL_UNLESS>
44
+ <div class="channelgroup">
45
+
46
+ ### Planet provides template variables for *all* configuration options for
47
+ ### the channel (and defaults), even if it doesn't know about them. We
48
+ ### exploit this here to add hackergotchi faces to our channels. Planet
49
+ ### doesn't know about the "face", "facewidth" and "faceheight" configuration
50
+ ### variables, but makes them available to us anyway.
51
+
52
+ <h3><a href="<TMPL_VAR channel_link ESCAPE="HTML">" title="<TMPL_VAR channel_title_plain ESCAPE="HTML">"><TMPL_VAR channel_name></a></h3>
53
+ <TMPL_IF channel_face>
54
+ <img class="face" src="images/<TMPL_VAR channel_face ESCAPE="HTML">" width="<TMPL_VAR channel_facewidth ESCAPE="HTML">" height="<TMPL_VAR channel_faceheight ESCAPE="HTML">" alt="">
55
+ </TMPL_IF>
56
+ </TMPL_IF>
57
+
58
+
59
+ <div class="entrygroup" id="<TMPL_VAR id>"<TMPL_IF channel_language> lang="<TMPL_VAR channel_language>"</TMPL_IF>>
60
+ <TMPL_IF title>
61
+ <h4<TMPL_IF title_language> lang="<TMPL_VAR title_language>"</TMPL_IF>><a href="<TMPL_VAR link ESCAPE="HTML">"><TMPL_VAR title></a></h4>
62
+ </TMPL_IF>
63
+ <div class="entry">
64
+ <div class="content"<TMPL_IF content_language> lang="<TMPL_VAR content_language>"</TMPL_IF>>
65
+ <TMPL_VAR content>
66
+ </div>
67
+
68
+ ### Planet also makes available all of the information from the feed
69
+ ### that it can. Use the 'planet-cache' tool on the cache file for
70
+ ### a particular feed to find out what additional keys it supports.
71
+ ### Comment extra fields are 'author' and 'category' which we
72
+ ### demonstrate below.
73
+
74
+ <p class="date">
75
+ <a href="<TMPL_VAR link ESCAPE="HTML">"><TMPL_IF author>by <TMPL_VAR author> at </TMPL_IF><TMPL_VAR date><TMPL_IF category> under <TMPL_VAR category></TMPL_IF></a>
76
+ </p>
77
+ </div>
78
+ </div>
79
+
80
+ <TMPL_IF __LAST__>
81
+ ### End <div class="channelgroup">
82
+ </div>
83
+ ### End <div class="daygroup">
84
+ </div>
85
+ </TMPL_IF>
86
+ </TMPL_LOOP>
87
+
88
+
89
+ <div class="sidebar">
90
+ <img src="images/logo.png" width="136" height="136" alt="">
91
+
92
+ <h2>Subscriptions</h2>
93
+ <ul>
94
+ <TMPL_LOOP Channels>
95
+ <li>
96
+ <a href="<TMPL_VAR url ESCAPE="HTML">" title="subscribe"><img src="images/feed-icon-10x10.png" alt="(feed)"></a> <a <TMPL_IF link>href="<TMPL_VAR link ESCAPE="HTML">" </TMPL_IF><TMPL_IF message>class="message" title="<TMPL_VAR message ESCAPE="HTML">"</TMPL_IF><TMPL_UNLESS message>title="<TMPL_VAR title_plain ESCAPE="HTML">"</TMPL_UNLESS>><TMPL_VAR name></a>
97
+ </li>
98
+ </TMPL_LOOP>
99
+ </ul>
100
+
101
+ <p>
102
+ <strong>Last updated:</strong><br>
103
+ <TMPL_VAR date><br>
104
+ <em>All times are UTC.</em><br>
105
+ <br>
106
+ Powered by:<br>
107
+ <a href="http://www.planetplanet.org/"><img src="images/planet.png" width="80" height="15" alt="Planet" border="0"></a>
108
+ </p>
109
+
110
+ <p>
111
+ <h2>Planetarium:</h2>
112
+ <ul>
113
+ <li><a href="http://www.planetapache.org/">Planet Apache</a></li>
114
+ <li><a href="http://planet.debian.net/">Planet Debian</a></li>
115
+ <li><a href="http://planet.freedesktop.org/">Planet freedesktop.org</a></li>
116
+ <li><a href="http://planet.gnome.org/">Planet GNOME</a></li>
117
+ <li><a href="http://planetsun.org/">Planet Sun</a></li>
118
+ <li><a href="http://fedora.linux.duke.edu/fedorapeople/">Fedora People</a></li>
119
+ <li><a href="http://www.planetplanet.org/">more...</a></li>
120
+ </ul>
121
+ </p>
122
+ </div>
123
+ </body>
124
+
125
+ </html>
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0"?>
2
+ <rdf:RDF
3
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
4
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
5
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
6
+ xmlns:rss="http://purl.org/rss/1.0/"
7
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
8
+ >
9
+ <foaf:Group>
10
+ <foaf:name><TMPL_VAR name ESCAPE="HTML"></foaf:name>
11
+ <foaf:homepage><TMPL_VAR link ESCAPE="HTML"></foaf:homepage>
12
+ <rdfs:seeAlso rdf:resource="<TMPL_VAR url ESCAPE="HTML">" />
13
+
14
+ <TMPL_LOOP Channels>
15
+ <foaf:member>
16
+ <foaf:Agent>
17
+ <foaf:name><TMPL_VAR name ESCAPE="HTML"></foaf:name>
18
+ <foaf:weblog>
19
+ <foaf:Document rdf:about="<TMPL_VAR link ESCAPE="HTML">">
20
+ <dc:title><TMPL_VAR title_plain ESCAPE="HTML"></dc:title>
21
+ <rdfs:seeAlso>
22
+ <rss:channel rdf:about="<TMPL_VAR url ESCAPE="HTML">" />
23
+ </rdfs:seeAlso>
24
+ </foaf:Document>
25
+ </foaf:weblog>
26
+ </foaf:Agent>
27
+ </foaf:member>
28
+ </TMPL_LOOP>
29
+
30
+ </foaf:Group>
31
+ </rdf:RDF>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0"?>
2
+ <opml version="1.1">
3
+ <head>
4
+ <title><TMPL_VAR name ESCAPE="HTML"></title>
5
+ <dateModified><TMPL_VAR date_822></dateModified>
6
+ <ownerName><TMPL_VAR owner_name></ownerName>
7
+ <ownerEmail><TMPL_VAR owner_email></ownerEmail>
8
+ </head>
9
+
10
+ <body>
11
+ <TMPL_LOOP Channels>
12
+ <outline type="rss" text="<TMPL_VAR name ESCAPE="HTML">" xmlUrl="<TMPL_VAR url ESCAPE="HTML">" title="<TMPL_IF title><TMPL_VAR title ESCAPE="HTML"></TMPL_IF><TMPL_UNLESS title><TMPL_VAR name ESCAPE="HTML"></TMPL_UNLESS>"<TMPL_IF channel_link> htmlUrl="<TMPL_VAR channel_link ESCAPE="HTML">"</TMPL_IF> />
13
+ </TMPL_LOOP>
14
+ </body>
15
+ </opml>
@@ -0,0 +1,37 @@
1
+ <?xml version="1.0"?>
2
+ <rdf:RDF
3
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
4
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
5
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
6
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
7
+ xmlns="http://purl.org/rss/1.0/"
8
+ >
9
+ <channel rdf:about="<TMPL_VAR link ESCAPE="HTML">">
10
+ <title><TMPL_VAR name ESCAPE="HTML"></title>
11
+ <link><TMPL_VAR link ESCAPE="HTML"></link>
12
+ <description><TMPL_VAR name ESCAPE="HTML"> - <TMPL_VAR link ESCAPE="HTML"></description>
13
+
14
+ <items>
15
+ <rdf:Seq>
16
+ <TMPL_LOOP Items>
17
+ <rdf:li rdf:resource="<TMPL_VAR id ESCAPE="HTML">" />
18
+ </TMPL_LOOP>
19
+ </rdf:Seq>
20
+ </items>
21
+ </channel>
22
+
23
+ <TMPL_LOOP Items>
24
+ <item rdf:about="<TMPL_VAR id ESCAPE="HTML">">
25
+ <title><TMPL_VAR channel_name ESCAPE="HTML"><TMPL_IF title>: <TMPL_VAR title_plain ESCAPE="HTML"></TMPL_IF></title>
26
+ <link><TMPL_VAR link ESCAPE="HTML"></link>
27
+ <TMPL_IF content>
28
+ <content:encoded><TMPL_VAR content ESCAPE="HTML"></content:encoded>
29
+ </TMPL_IF>
30
+ <dc:date><TMPL_VAR date_iso></dc:date>
31
+ <TMPL_IF author_name>
32
+ <dc:creator><TMPL_VAR author_name></dc:creator>
33
+ </TMPL_IF>
34
+ </item>
35
+ </TMPL_LOOP>
36
+
37
+ </rdf:RDF>
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0"?>
2
+ <rss version="2.0">
3
+
4
+ <channel>
5
+ <title><TMPL_VAR name></title>
6
+ <link><TMPL_VAR link ESCAPE="HTML"></link>
7
+ <language>en</language>
8
+ <description><TMPL_VAR name ESCAPE="HTML"> - <TMPL_VAR link ESCAPE="HTML"></description>
9
+
10
+ <TMPL_LOOP Items>
11
+ <item>
12
+ <title><TMPL_VAR channel_name ESCAPE="HTML"><TMPL_IF title>: <TMPL_VAR title_plain ESCAPE="HTML"></TMPL_IF></title>
13
+ <guid><TMPL_VAR id ESCAPE="HTML"></guid>
14
+ <link><TMPL_VAR link ESCAPE="HTML"></link>
15
+ <TMPL_IF content>
16
+ <description><TMPL_VAR content ESCAPE="HTML"></description>
17
+ </TMPL_IF>
18
+ <pubDate><TMPL_VAR date_822></pubDate>
19
+ <TMPL_IF author_email>
20
+ <TMPL_IF author_name>
21
+ <author><TMPL_VAR author_email> (<TMPL_VAR author_name>)</author>
22
+ <TMPL_ELSE>
23
+ <author><TMPL_VAR author_email></author>
24
+ </TMPL_IF>
25
+ </TMPL_IF>
26
+ </item>
27
+ </TMPL_LOOP>
28
+
29
+ </channel>
30
+ </rss>
@@ -0,0 +1,103 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_merge.rb
4
+
5
+ require 'helper'
6
+
7
+
8
+
9
+ class TestMerge < MiniTest::Test
10
+
11
+ Site = Struct.new( :name, :owner_name, :date_822, :channels )
12
+ Channel = Struct.new( :name, :url, :channel_link )
13
+
14
+ def sample1
15
+ Site.new( 'OpenStreetMap Blogs',
16
+ 'OpenStreetMap',
17
+ Date.new( 2020, 2, 7 ).rfc2822,
18
+ [Channel.new( 'Shaun McDonald',
19
+ 'http://blog.shaunmcdonald.me.uk/feed/',
20
+ 'http://blog.shaunmcdonald.me.uk/' ),
21
+ Channel.new( 'Mapbox',
22
+ 'https://blog.mapbox.com/feed/tagged/openstreetmap/',
23
+ 'https://blog.mapbox.com/' ),
24
+ Channel.new( 'Mapillary',
25
+ 'https://blog.mapillary.com/rss.xml',
26
+ 'https://blog.mapillary.com' ),
27
+ Channel.new( 'Richard Fairhurst',
28
+ 'http://blog.systemed.net/rss',
29
+ 'http://blog.systemed.net/' )]
30
+ )
31
+ end
32
+
33
+ def test_merge
34
+ site = sample1
35
+ pp site
36
+
37
+ xml = File.open( "#{HtmlTemplate.root}/test/templates/opml.xml", "r:utf-8" ).read
38
+ template = File.open( "#{HtmlTemplate.root}/test/templates/opml.xml.tmpl", "r:utf-8" ).read
39
+
40
+ t = HtmlTemplate.new( template )
41
+
42
+ assert_equal prettify_xml( xml ),
43
+ prettify_xml( t.render( name: site.name,
44
+ owner_name: site.owner_name,
45
+ date_822: site.date_822,
46
+ channels: site.channels ))
47
+ end
48
+
49
+
50
+ def test_convert
51
+ text = File.open( "#{HtmlTemplate.root}/test/templates/opml.xml.erb", "r:utf-8" ).read
52
+ template = File.open( "#{HtmlTemplate.root}/test/templates/opml.xml.tmpl", "r:utf-8" ).read
53
+
54
+ t = HtmlTemplate.new( template )
55
+
56
+ assert_equal text, t.text
57
+ end
58
+
59
+ =begin
60
+ <!-- students.tmpl -->
61
+ <TMPL_LOOP NAME=STUDENT>
62
+ <p>
63
+ Name: <TMPL_VAR NAME=NAME><br/>
64
+ GPA: <TMPL_VAR NAME=GPA>
65
+ </p>
66
+ </TMPL_LOOP>
67
+
68
+ # students.pl
69
+ my $template = HTML::Template->new(filename => 'students.tmpl');
70
+
71
+ $template->param(
72
+ STUDENT => [
73
+ { NAME => 'Bluto Blutarsky', GPA => '0.0' },
74
+ { NAME => 'Tracey Flick' , GPA => '4.0' },
75
+ ]
76
+ );
77
+ print $template->output;
78
+ =end
79
+
80
+ Student = Struct.new( :name, :gpa )
81
+
82
+ def test_students_example
83
+
84
+ tmpl =<<TXT
85
+ <TMPL_LOOP students>
86
+ <p>
87
+ Name: <TMPL_VAR name><br/>
88
+ GPA: <TMPL_VAR gpa>
89
+ </p>
90
+ </TMPL_LOOP>
91
+ TXT
92
+
93
+ t = HtmlTemplate.new( tmpl )
94
+ puts t.text
95
+ puts "---"
96
+ puts t.render( students: [ Student.new( 'Bluto Blutarsky', 0.0 ),
97
+ Student.new( 'Tracey Flick', 4.0 ) ])
98
+
99
+
100
+ assert true # assume it's alright if we get here
101
+ end
102
+ end
103
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html-template
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.16'
41
+ description: html-template - old-style classic HTML template language / engine like
42
+ it's 1999 (incl. back-to-the-future ERB converter)
43
+ email: wwwmake@googlegroups.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - CHANGELOG.md
48
+ - Manifest.txt
49
+ - README.md
50
+ files:
51
+ - CHANGELOG.md
52
+ - Manifest.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/html/template.rb
56
+ - lib/html/template/version.rb
57
+ - test/helper.rb
58
+ - test/templates/opml.xml
59
+ - test/templates/opml.xml.erb
60
+ - test/templates/opml.xml.tmpl
61
+ - test/templates/planet/README.md
62
+ - test/templates/planet/atom.xml.tmpl
63
+ - test/templates/planet/basic/index.html.tmpl
64
+ - test/templates/planet/fancy/index.html.tmpl
65
+ - test/templates/planet/foafroll.xml.tmpl
66
+ - test/templates/planet/opml.xml.tmpl
67
+ - test/templates/planet/rss10.xml.tmpl
68
+ - test/templates/planet/rss20.xml.tmpl
69
+ - test/test_merge.rb
70
+ homepage: https://github.com/feedreader/pluto
71
+ licenses:
72
+ - Public Domain
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options:
76
+ - "--main"
77
+ - README.md
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.2.2
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: html-template - old-style classic HTML template language / engine like it's
96
+ 1999 (incl. back-to-the-future ERB converter)
97
+ test_files: []