opml2html 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/opml2html/outline.rb +66 -0
- data/lib/opml2html/renderer.rb +15 -0
- data/lib/opml2html/traverser.rb +31 -35
- data/lib/opml2html/version.rb +1 -1
- data/lib/opml2html.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35579ffe32849ad4716759cbf23028cf33333768292a1634ea1724f4726a98e6
|
4
|
+
data.tar.gz: 6446148749519f5ef707c30084b67fb69c9aa614962824d1aa40b9ec4355d87f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47f39adaa1897478f24e20aee16beed46b397c5b511b2f43c97533620a0e3788259a5f9de19dbf90889496a1de559ef5fc6d63a33a3a94613eb742fd9c8cb044
|
7
|
+
data.tar.gz: a582bfd488188023495ee13686686ce0ccae958fe3025be51f6a20a001aaef2f80d92777086a114320f46a103a737b8a5b71bdca61e13d8a50b08dd3efad37ac
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
module OPML2HTML
|
2
|
+
class Outline
|
3
|
+
def initialize(node)
|
4
|
+
node => Element[name: "outline"]
|
5
|
+
@node = node
|
6
|
+
end
|
7
|
+
|
8
|
+
def deconstruct_keys(*keys)
|
9
|
+
result = {}
|
10
|
+
keys => [keys]
|
11
|
+
keys.each do |key|
|
12
|
+
case key
|
13
|
+
in :text
|
14
|
+
result[:text] = text
|
15
|
+
in :created
|
16
|
+
result[:created] = created
|
17
|
+
in :children
|
18
|
+
result[:children] = children
|
19
|
+
in :xml_url
|
20
|
+
result[:xml_url] = xml_url
|
21
|
+
end
|
22
|
+
end
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def text
|
29
|
+
@text and return @text
|
30
|
+
attributes => [*, Attr[name: "text", value:], *]
|
31
|
+
@text = value
|
32
|
+
end
|
33
|
+
|
34
|
+
def created
|
35
|
+
@created || @empty_created and return @created
|
36
|
+
if attributes in [*, Attr[name: "created", value:], *]
|
37
|
+
@created = value
|
38
|
+
else
|
39
|
+
@empty_created = true
|
40
|
+
return
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def xml_url
|
45
|
+
@xml_url || @empty_xml_url and return @xml_url
|
46
|
+
if attributes in [*, Attr[name: "xmlUrl", value:], *]
|
47
|
+
@xml_url = value
|
48
|
+
else
|
49
|
+
@empty_xml_url = true
|
50
|
+
return
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def attributes
|
55
|
+
@attributes and return @attributes
|
56
|
+
@node => Element[attributes:]
|
57
|
+
@attributes = attributes
|
58
|
+
end
|
59
|
+
|
60
|
+
def children
|
61
|
+
@children and return @children
|
62
|
+
@node => Element[children:]
|
63
|
+
@children = children
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/opml2html/renderer.rb
CHANGED
@@ -31,6 +31,12 @@ module OPML2HTML
|
|
31
31
|
@document.metadata.add_child("modified: #{time}<br/>")
|
32
32
|
end
|
33
33
|
|
34
|
+
def head_owner_email(content)
|
35
|
+
@document.metadata.add_child("owner email: #{content}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def head_docs(*); end
|
39
|
+
|
34
40
|
def head_end
|
35
41
|
@document.head.add_child("<link rel=\"stylesheet\" href=\"#{ @css }\"/>")
|
36
42
|
@document.main.add_child(@document.metadata)
|
@@ -48,6 +54,15 @@ module OPML2HTML
|
|
48
54
|
@document.main.add_child(par)
|
49
55
|
end
|
50
56
|
|
57
|
+
def body_outline_rss(fragment, xml_url)
|
58
|
+
anchor = @document.create_element("a")
|
59
|
+
anchor.add_child(fragment)
|
60
|
+
anchor["href"] = xml_url
|
61
|
+
par = @document.create_element("p")
|
62
|
+
par.add_child(anchor)
|
63
|
+
@document.main.add_child(par)
|
64
|
+
end
|
65
|
+
|
51
66
|
def body_outline_created(time)
|
52
67
|
# @document.body.add_child("<p style='text-align: right'><small>#{time}</small></p>")
|
53
68
|
end
|
data/lib/opml2html/traverser.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "nokogiri"
|
2
2
|
require "time"
|
3
|
+
require_relative "outline"
|
3
4
|
|
4
5
|
module OPML2HTML
|
5
6
|
class Traverser
|
@@ -20,27 +21,31 @@ module OPML2HTML
|
|
20
21
|
private
|
21
22
|
|
22
23
|
def parse_document(node)
|
23
|
-
node =>
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
node => Document[root: Element[name: "opml",
|
25
|
+
attributes: [Attr[name: "version",
|
26
|
+
value: "2.0"]],
|
27
|
+
children:]]
|
27
28
|
children.each { |child| parse_under_document(child) }
|
28
29
|
end
|
29
30
|
|
30
31
|
def parse_under_document(node)
|
32
|
+
(node in Text) and return
|
31
33
|
case node
|
32
|
-
in Text # nop
|
33
34
|
in Element[name: "head", children:]
|
34
35
|
children.each { |child| parse_under_head(child) }
|
35
36
|
@hook.head_end
|
36
37
|
in Element[name: "body", children:]
|
37
|
-
children.each
|
38
|
+
children.each do |child|
|
39
|
+
(child in Text) and next
|
40
|
+
parse_outline(child, level: 1)
|
41
|
+
end
|
38
42
|
else
|
39
43
|
raise Error, node.inspect
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
47
|
def parse_under_head(node)
|
48
|
+
(node in Text) and return
|
44
49
|
case node
|
45
50
|
in Element[name: "title", children: [Text[content:]]]
|
46
51
|
@hook.head_title(content)
|
@@ -55,43 +60,34 @@ module OPML2HTML
|
|
55
60
|
in Element[name: "dateModified", children: [Text[content:]]]
|
56
61
|
time = Time.parse(content)
|
57
62
|
@hook.head_date_modified(time)
|
58
|
-
in Text
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
def parse_body_outline_attribute(node)
|
69
|
-
case node
|
70
|
-
in Attr[name: "text", value:]
|
71
|
-
value = DocumentFragment.parse(value)
|
72
|
-
@hook.body_outline_text(value)
|
73
|
-
in Attr[name: "created", value:]
|
74
|
-
time = Time.parse(value)
|
75
|
-
@hook.body_outline_created(time)
|
76
|
-
in Attr[name: "flNumberedSubs"] # nop
|
63
|
+
in Element[name: "ownerEmail", children: [Text[content:]]]
|
64
|
+
@hook.head_owner_email(content)
|
65
|
+
in Element[name: "docs", children: [Text[content:]]]
|
66
|
+
@hook.head_docs(content)
|
67
|
+
in Element[name: "ownerId" |
|
68
|
+
"urlUpdateSocket" |
|
69
|
+
"expansionState" |
|
70
|
+
"lastCursor"] # nop
|
77
71
|
else
|
78
72
|
raise Error, node.inspect
|
79
73
|
end
|
80
74
|
end
|
81
75
|
|
82
76
|
def parse_outline(node, level:)
|
83
|
-
case
|
84
|
-
in
|
85
|
-
|
86
|
-
|
77
|
+
case Outline.new(node)
|
78
|
+
in text:, xml_url:, children: []
|
79
|
+
value = DocumentFragment.parse(text)
|
80
|
+
@hook.body_outline_rss(value, xml_url)
|
81
|
+
in text:, children: []
|
82
|
+
value = DocumentFragment.parse(text)
|
87
83
|
@hook.body_outline_text(value)
|
88
|
-
in
|
89
|
-
value = DocumentFragment.parse(
|
84
|
+
in text:, children:
|
85
|
+
value = DocumentFragment.parse(text)
|
90
86
|
@hook.body_outline_heading(value)
|
91
|
-
children.each
|
92
|
-
|
93
|
-
|
94
|
-
|
87
|
+
children.each do |child|
|
88
|
+
(child in Text) and next
|
89
|
+
parse_outline(child, level: level + 1)
|
90
|
+
end
|
95
91
|
end
|
96
92
|
end
|
97
93
|
end
|
data/lib/opml2html/version.rb
CHANGED
data/lib/opml2html.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opml2html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gemmaro
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/opml2html.rb
|
86
86
|
- lib/opml2html/dumper.rb
|
87
87
|
- lib/opml2html/html_document.rb
|
88
|
+
- lib/opml2html/outline.rb
|
88
89
|
- lib/opml2html/renderer.rb
|
89
90
|
- lib/opml2html/traverser.rb
|
90
91
|
- lib/opml2html/version.rb
|