vivlio_pack 0.1.2 → 0.2.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/lib/vivlio_pack/generator.rb +4 -1
- data/lib/vivlio_pack/renderer.rb +41 -31
- data/lib/vivlio_pack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c192a73dccc79b483c36d698edc87c15e8e6c3b20633e9b59a75823b1af78998
|
|
4
|
+
data.tar.gz: 00d4917ecfb439bb3f1880a09b814a0350539c0705c196c0f76a664703237b4c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52fa7963778da69f69bbd0c3e89306e2bcca33aae8d886b461f2bc549ddacbddf7979ba9f2b3c221517fdae1513a665feef72740e91fbf69d453ec8fbc8d4b3f
|
|
7
|
+
data.tar.gz: c29e2523dd8fc0733aacceaad5b98438540fc8aaa9f045e6a48d3d1f19329c08af0069c4b4d40609800dc7da120f5de6872003bbc35839067e1f50d677f8b898
|
|
@@ -8,7 +8,10 @@ module VivlioPack
|
|
|
8
8
|
class Generator
|
|
9
9
|
def initialize(workdir)
|
|
10
10
|
@workdir = File.expand_path(workdir)
|
|
11
|
-
@names = Psych.load_file("articles.yaml")
|
|
11
|
+
@names = Psych.load_file("#{@workdir}/articles.yaml")
|
|
12
|
+
if File.exist?("#{@workdir}/plugin.rb")
|
|
13
|
+
load "#{@workdir}/plugin.rb"
|
|
14
|
+
end
|
|
12
15
|
@markdown = Redcarpet::Markdown.new(Renderer, autolink: true, tables: true, fenced_code_blocks: true)
|
|
13
16
|
end
|
|
14
17
|
|
data/lib/vivlio_pack/renderer.rb
CHANGED
|
@@ -6,11 +6,21 @@ module VivlioPack
|
|
|
6
6
|
class Renderer < Redcarpet::Render::HTML
|
|
7
7
|
include Rouge::Plugins::Redcarpet
|
|
8
8
|
|
|
9
|
+
def self.add_plugin(name, mod)
|
|
10
|
+
(@plugins ||= {})[name] = mod
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.plugin(name)
|
|
14
|
+
@plugins[name]
|
|
15
|
+
end
|
|
16
|
+
|
|
9
17
|
def initialize
|
|
10
18
|
super
|
|
11
19
|
@sec = 0
|
|
12
20
|
@ch = 0
|
|
13
21
|
@para = 0
|
|
22
|
+
@state = []
|
|
23
|
+
@ring_buffer = []
|
|
14
24
|
end
|
|
15
25
|
|
|
16
26
|
def header(c, level)
|
|
@@ -33,13 +43,9 @@ module VivlioPack
|
|
|
33
43
|
end
|
|
34
44
|
|
|
35
45
|
def paragraph(text)
|
|
46
|
+
@ring_buffer.push text
|
|
47
|
+
@ring_buffer.shift if @ring_buffer.length > 5
|
|
36
48
|
case text.strip
|
|
37
|
-
when "[begin dialog]"
|
|
38
|
-
@in_dialog = true
|
|
39
|
-
return "<div class='dialog'>\n"
|
|
40
|
-
when "[end dialog]"
|
|
41
|
-
@in_dialog = false
|
|
42
|
-
return "</div>\n"
|
|
43
49
|
when /\A\[file (?<filename>(\w+\/)*(\w+)\.(\w+))(:(?<lineno>\d+))?\]$/
|
|
44
50
|
@in_file = true
|
|
45
51
|
filename = $~[:filename]
|
|
@@ -48,34 +54,38 @@ module VivlioPack
|
|
|
48
54
|
return ""
|
|
49
55
|
when "[page break]"
|
|
50
56
|
return "<div class='page-break'></div>\n"
|
|
51
|
-
when "[begin one-point]"
|
|
52
|
-
return "<div><img src='images/onepoint_before.png' class='one-point'>\n"
|
|
53
|
-
when "[end one-point]"
|
|
54
|
-
return "<img src='images/onepoint_after.png' class='one-point'></div>\n"
|
|
55
57
|
when /\A%([a-z][a-z0-9\-]*):(.*)/m
|
|
56
58
|
return "<div class='#{$1}'>#{$2}</div>\n"
|
|
59
|
+
when /\A\[begin (\w+)\]\z/
|
|
60
|
+
plugin_name = $~[1]
|
|
61
|
+
plugin = Renderer.plugin(plugin_name)
|
|
62
|
+
if plugin
|
|
63
|
+
@state.push plugin_name
|
|
64
|
+
result = plugin.process_begin
|
|
65
|
+
return result if result
|
|
66
|
+
end
|
|
67
|
+
when /\A\[end (\w+)\]\z/
|
|
68
|
+
plugin_name = $~[1]
|
|
69
|
+
plugin = Renderer.plugin(plugin_name)
|
|
70
|
+
if plugin
|
|
71
|
+
if @state.last == plugin_name
|
|
72
|
+
@state.pop
|
|
73
|
+
else
|
|
74
|
+
@ring_buffer.each do |line|
|
|
75
|
+
puts line
|
|
76
|
+
end
|
|
77
|
+
raise RuntimeError.new("plugin: #{plugin_name} の対応が合っていません")
|
|
78
|
+
end
|
|
79
|
+
result = plugin.process_end
|
|
80
|
+
return result if result
|
|
81
|
+
end
|
|
57
82
|
end
|
|
58
83
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
<div class="icon"></div>
|
|
65
|
-
<div class="baloon">
|
|
66
|
-
<p>#{$1}</p>
|
|
67
|
-
</div>
|
|
68
|
-
</div>
|
|
69
|
-
HTML
|
|
70
|
-
when /^黒猫先生「(.+)」$/
|
|
71
|
-
return <<~HTML
|
|
72
|
-
<div class="speech kuroneko">
|
|
73
|
-
<div class="icon"></div>
|
|
74
|
-
<div class="baloon">
|
|
75
|
-
<p>#{$1}</p>
|
|
76
|
-
</div>
|
|
77
|
-
</div>
|
|
78
|
-
HTML
|
|
84
|
+
@state.reverse.each do |plugin_name|
|
|
85
|
+
plugin = Renderer.plugin(plugin_name)
|
|
86
|
+
if plugin
|
|
87
|
+
result = plugin.process_inner(text)
|
|
88
|
+
return result if result
|
|
79
89
|
end
|
|
80
90
|
end
|
|
81
91
|
|
|
@@ -111,7 +121,7 @@ module VivlioPack
|
|
|
111
121
|
figure_attr = size_class.empty? ? "" : " class=\"#{size_class}\""
|
|
112
122
|
<<~HTML
|
|
113
123
|
<figure#{figure_attr}>
|
|
114
|
-
<img src="
|
|
124
|
+
<img src="contents/images/#{link}" alt="#{caption}" />
|
|
115
125
|
<figcaption id="#{name}">#{caption}</figcaption>
|
|
116
126
|
</figure>
|
|
117
127
|
HTML
|
data/lib/vivlio_pack/version.rb
CHANGED