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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86f8b4072a12bf95e2bc5432d08f89810703425938d2ad537a3e0460eb34972a
4
- data.tar.gz: cd58c06735451231cd56708c0cc144e27737573b24d363d57ec45f10fdfec8e5
3
+ metadata.gz: 35579ffe32849ad4716759cbf23028cf33333768292a1634ea1724f4726a98e6
4
+ data.tar.gz: 6446148749519f5ef707c30084b67fb69c9aa614962824d1aa40b9ec4355d87f
5
5
  SHA512:
6
- metadata.gz: 50da65a32f37b59868dec3c76514a5e826c2533045fd4b1cfd8c517bc33ec17046160339296dca5e55cd20af7ec3756f89f43bb5b121196cdb0999138578e182
7
- data.tar.gz: 6008a560211d1253f7c34947cba17658b44561fe98cacd7b5f404f0791d818d12c2d0b30469f58b7af7f95c127524f38f0af4b1bdacc112aed6b17b715ab81f4
6
+ metadata.gz: 47f39adaa1897478f24e20aee16beed46b397c5b511b2f43c97533620a0e3788259a5f9de19dbf90889496a1de559ef5fc6d63a33a3a94613eb742fd9c8cb044
7
+ data.tar.gz: a582bfd488188023495ee13686686ce0ccae958fe3025be51f6a20a001aaef2f80d92777086a114320f46a103a737b8a5b71bdca61e13d8a50b08dd3efad37ac
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.0.2 - 2025-02-05
6
+
7
+ * Render XML URI hyperlinks.
8
+ * Add more head elements for metadata; owner email and docs.
9
+
5
10
  ## 0.0.1 - 2025-01-05
6
11
 
7
12
  * Initial release
@@ -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
@@ -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
@@ -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 => Nokogiri::XML::Document[root: Element[name: "opml",
24
- attributes: [Attr[name: "version",
25
- value: "2.0"]],
26
- children:]]
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 { |child| parse_outline(child, level: 1) }
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
- Element[name: "ownerId" |
60
- "urlUpdateSocket" |
61
- "expansionState" |
62
- "lastCursor"] # nop
63
- else
64
- raise Error, node.inspect
65
- end
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 [node, level]
84
- in [Text, _] # nop
85
- in [Element[name: "outline", attributes: [Attr[name: "text", value:], Attr[name: "created", value: _]], children: []], _]
86
- value = DocumentFragment.parse(value)
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 [Element[name: "outline", attributes: [Attr[name: "text", value:], Attr[name: "created", value: _]], children:], 1]
89
- value = DocumentFragment.parse(value)
84
+ in text:, children:
85
+ value = DocumentFragment.parse(text)
90
86
  @hook.body_outline_heading(value)
91
- children.each { |child| parse_outline(child, level: level + 1) }
92
- in [Element[name: "outline", attributes:, children:], _]
93
- attributes.each { |attribute| parse_body_outline_attribute(attribute) }
94
- children.each { |child| parse_outline(child, level: level + 1) }
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OPML2HTML
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
data/lib/opml2html.rb CHANGED
@@ -12,4 +12,5 @@ module OPML2HTML
12
12
  Attr = Nokogiri::XML::Attr
13
13
  Text = Nokogiri::XML::Text
14
14
  DocumentFragment = Nokogiri::XML::DocumentFragment
15
+ Document = Nokogiri::XML::Document
15
16
  end
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.1
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