ulysses 0.4.0 → 0.4.1
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/README.md +3 -3
- data/lib/ulysses.rb +0 -1
- data/lib/ulysses/printer.rb +54 -4
- data/lib/ulysses/version.rb +1 -1
- metadata +1 -2
- data/lib/ulysses/printer/elements.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94a96891b11b517de41e2a090402f02e12404b96
|
4
|
+
data.tar.gz: 894df84f95414f2b8e328439e05fc7c57447bd73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa083c9df77861877daeb0b5fa3967de65dc3c2799fe57aaa40a2e1fdd6cfbf7f21fc70d051996536e079bb044fa539e597d15a0bbc661a088efaebccc631f5
|
7
|
+
data.tar.gz: ff82e2446f4dbe38300af87dd0a5509e4522c72d2d67899a6d72966576dc8ffc420b6e36ffbc1f82f5cc479fa297d79bffe47946ee5913e4754dd8038bb2ab9a
|
data/README.md
CHANGED
@@ -39,10 +39,10 @@ Get Sheets:
|
|
39
39
|
|
40
40
|
group.sheets
|
41
41
|
|
42
|
-
|
42
|
+
Print sheet to HTML:
|
43
43
|
|
44
|
-
|
45
|
-
html
|
44
|
+
printer = Ulysses::Printer.new(library) # also applies to group or sheet
|
45
|
+
html = printer.print
|
46
46
|
|
47
47
|
## Development
|
48
48
|
|
data/lib/ulysses.rb
CHANGED
data/lib/ulysses/printer.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Ulysses
|
2
2
|
class Printer
|
3
3
|
|
4
|
+
INLINE_MARKUPS = %w(strong emph mark delete inlineComment code inlineNative)
|
4
5
|
SHEET_CONTENT_XPATH = '/sheet/string[@xml:space="preserve"]'
|
5
6
|
|
6
7
|
def initialize(target)
|
@@ -55,8 +56,12 @@ module Ulysses
|
|
55
56
|
tags.delete('tab')
|
56
57
|
tags << "tabs_#{tabs}"
|
57
58
|
end
|
58
|
-
|
59
|
-
|
59
|
+
if tags.any?
|
60
|
+
tags = tags.uniq.map{|t| snake_case(t)}.join(' ')
|
61
|
+
"<p class=\"#{tags}\">#{content}</p>"
|
62
|
+
else
|
63
|
+
"<p>#{content}</p>"
|
64
|
+
end
|
60
65
|
end
|
61
66
|
|
62
67
|
def parse_content(nodes)
|
@@ -92,10 +97,55 @@ module Ulysses
|
|
92
97
|
end
|
93
98
|
|
94
99
|
def parse_element(node)
|
95
|
-
|
100
|
+
kind = node.attributes['kind'].value
|
101
|
+
if INLINE_MARKUPS.include?(kind)
|
102
|
+
parse_inline_style(kind, node)
|
103
|
+
else
|
104
|
+
send "parse_element_#{node.attributes['kind'].value}", node
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def parse_inline_style(markup, node)
|
109
|
+
'<span class="' + snake_case(markup) + '">' + parse_content(node.children) + '</span>'
|
110
|
+
end
|
111
|
+
|
112
|
+
def parse_element_link(node)
|
113
|
+
attrs = parse_element_attributes(node)
|
114
|
+
content = parse_content(node.children.select{ |child| !child.element? || child.name != 'attribute' })
|
115
|
+
'<a href="' + attrs.fetch('URL', '') + '" title="' + attrs.fetch('title', '') + '">' + content + '</a>'
|
116
|
+
end
|
117
|
+
|
118
|
+
def parse_element_image(node)
|
119
|
+
attrs = parse_element_attributes(node)
|
120
|
+
'<img src="' + attrs.fetch('URL', '') + '" alt="' + attrs.fetch('title', '') + '" />'
|
121
|
+
end
|
122
|
+
|
123
|
+
def parse_element_video(node)
|
124
|
+
attrs = parse_element_attributes(node)
|
125
|
+
'<video><source src="' + attrs['URL'] + '" /></video>'
|
126
|
+
end
|
127
|
+
|
128
|
+
def parse_element_footnote(node)
|
129
|
+
attrs = parse_element_attributes(node)
|
130
|
+
@footnotes << attrs['text']
|
131
|
+
'<sup class="footnote-ref"><a href="#fn' + @footnotes.size.to_s + '">' + @footnotes.size.to_s + '</a></sup>'
|
132
|
+
end
|
133
|
+
|
134
|
+
def parse_element_annotation(node)
|
135
|
+
attrs = parse_element_attributes(node)
|
136
|
+
@annotations << attrs['text']
|
137
|
+
'<span class="annotation" data-id="' + @annotations.size.to_s + '">' + @annotations.size.to_s + '</span>'
|
138
|
+
end
|
139
|
+
|
140
|
+
def parse_element_attributes(element)
|
141
|
+
attributes = element.children.select { |child| child.element? && child.name === 'attribute' }
|
142
|
+
attributes.map! do |attr|
|
143
|
+
[attr.attributes['identifier'].value, parse_content(attr.children)]
|
144
|
+
end
|
145
|
+
Hash[attributes]
|
96
146
|
end
|
97
147
|
|
98
|
-
def
|
148
|
+
def snake_case(tag)
|
99
149
|
tag.gsub(/::/, '/')
|
100
150
|
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
101
151
|
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
data/lib/ulysses/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ulysses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaodong Zhao
|
@@ -115,7 +115,6 @@ files:
|
|
115
115
|
- lib/ulysses/group.rb
|
116
116
|
- lib/ulysses/library.rb
|
117
117
|
- lib/ulysses/printer.rb
|
118
|
-
- lib/ulysses/printer/elements.rb
|
119
118
|
- lib/ulysses/sheet.rb
|
120
119
|
- lib/ulysses/version.rb
|
121
120
|
- ulysses.gemspec
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Ulysses
|
2
|
-
class Printer
|
3
|
-
|
4
|
-
def parse_element_strong(node)
|
5
|
-
'<strong>' + node.content + '</strong>'
|
6
|
-
end
|
7
|
-
|
8
|
-
def parse_element_emph(node)
|
9
|
-
'<em>' + node.content + '</em>'
|
10
|
-
end
|
11
|
-
|
12
|
-
def parse_element_mark(node)
|
13
|
-
'<span class="marked">' + node.content + '</span>'
|
14
|
-
end
|
15
|
-
|
16
|
-
def parse_element_delete(node)
|
17
|
-
'<del>' + node.content + '</del>'
|
18
|
-
end
|
19
|
-
|
20
|
-
def parse_element_inlineComment(node)
|
21
|
-
'<span class="inline-comment">' + node.content + '</span>'
|
22
|
-
end
|
23
|
-
|
24
|
-
def parse_element_code(node)
|
25
|
-
'<code>' + node.content + '</code>'
|
26
|
-
end
|
27
|
-
|
28
|
-
def parse_element_inlineNative(node)
|
29
|
-
'<span class="inline-native">' + node.content + '</span>'
|
30
|
-
end
|
31
|
-
|
32
|
-
def parse_element_link(node)
|
33
|
-
attrs = parse_element_attributes(node)
|
34
|
-
content = parse_content(node.children.select{ |child| !child.element? || child.name != 'attribute' })
|
35
|
-
'<a href="' + attrs.fetch('URL', '') + '" title="' + attrs.fetch('title', '') + '">' + content + '</a>'
|
36
|
-
end
|
37
|
-
|
38
|
-
def parse_element_image(node)
|
39
|
-
attrs = parse_element_attributes(node)
|
40
|
-
'<img src="' + attrs.fetch('URL', '') + '" alt="' + attrs.fetch('title', '') + '" />'
|
41
|
-
end
|
42
|
-
|
43
|
-
def parse_element_video(node)
|
44
|
-
attrs = parse_element_attributes(node)
|
45
|
-
'<video><source src="' + attrs['URL'] + '" /></video>'
|
46
|
-
end
|
47
|
-
|
48
|
-
def parse_element_footnote(node)
|
49
|
-
attrs = parse_element_attributes(node)
|
50
|
-
@footnotes << attrs['text']
|
51
|
-
'<sup class="footnote-ref"><a href="#fn' + @footnotes.size.to_s + '">' + @footnotes.size.to_s + '</a></sup>'
|
52
|
-
end
|
53
|
-
|
54
|
-
def parse_element_annotation(node)
|
55
|
-
attrs = parse_element_attributes(node)
|
56
|
-
@annotations << attrs['text']
|
57
|
-
'<span class="annotation" data-id="' + @annotations.size.to_s + '">' + @annotations.size.to_s + '</span>'
|
58
|
-
end
|
59
|
-
|
60
|
-
def parse_element_attributes(element)
|
61
|
-
attributes = element.children.select { |child| child.element? && child.name === 'attribute' }
|
62
|
-
attributes.map! do |attr|
|
63
|
-
[attr.attributes['identifier'].value, parse_content(attr.children)]
|
64
|
-
end
|
65
|
-
Hash[attributes]
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|