vivlio_pack 0.1.2 → 0.2.0
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 +38 -30
- 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: f3f7e8cb39772caa7b6b7540b0d27803f073754df8665fc3d20e582e213a9ec1
|
|
4
|
+
data.tar.gz: c044a43ce69b0647d33d0e5ebf04cb4fcdd1ca3e0835295c56286c16df92620d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5fab41d5e18430f80abd15794f6273d7b9f3eec9df8926dcb7688f540007d8989070e119331f92e33f5dd4523af87786c7659442b1746b321271cd4a093bcea0
|
|
7
|
+
data.tar.gz: da9c1312aa215c2f3ee9b0c6e278c264ab4ac43a96517f3520ac1c52816d0e500fd602278935e1ac2342be5bd8d16674a1fd063a1ded69db40b3a5e3dd35d28e
|
|
@@ -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,36 @@ 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
|
+
end
|
|
57
80
|
end
|
|
58
81
|
|
|
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
|
|
82
|
+
@state.reverse.each do |plugin_name|
|
|
83
|
+
plugin = Renderer.plugin(plugin_name)
|
|
84
|
+
if plugin
|
|
85
|
+
result = plugin.process_inner(text)
|
|
86
|
+
return result if result
|
|
79
87
|
end
|
|
80
88
|
end
|
|
81
89
|
|
data/lib/vivlio_pack/version.rb
CHANGED