mizuho 0.9.8 → 0.9.9
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.
- data/LICENSE.txt +1 -1
- data/README.markdown +14 -25
- data/asciidoc/stylesheets/flask.css +25 -11
- data/bin/mizuho +27 -11
- data/lib/mizuho.rb +25 -4
- data/lib/mizuho/fuzzystringmatch.rb +100 -0
- data/lib/mizuho/generator.rb +185 -83
- data/lib/mizuho/id_map.rb +224 -0
- data/lib/mizuho/source_highlight.rb +20 -0
- data/templates/arrow-up.png +0 -0
- data/templates/balloon.png +0 -0
- data/templates/balloon.svg +177 -0
- data/templates/jquery-1.6.1.min.js +18 -0
- data/templates/jquery-1.7.1.min.js +4 -0
- data/templates/jquery.hashchange-1.0.0.js +121 -0
- data/templates/juvia.js +140 -0
- data/templates/mizuho.css +122 -0
- data/templates/mizuho.js +199 -0
- data/templates/topbar.css +116 -0
- data/templates/topbar.html +7 -0
- data/templates/topbar.js +175 -0
- data/test/id_map_spec.rb +188 -0
- metadata +22 -16
- data/lib/mizuho/chapter.rb +0 -54
- data/lib/mizuho/heading.rb +0 -46
- data/lib/mizuho/parser.rb +0 -103
- data/lib/mizuho/template.rb +0 -50
- data/templates/asciidoc.css +0 -358
- data/templates/asciidoc.html.erb +0 -86
- data/templates/manualsonrails.css +0 -165
- data/templates/manualsonrails.html.erb +0 -97
data/LICENSE.txt
CHANGED
data/README.markdown
CHANGED
|
@@ -4,29 +4,23 @@ Mizuho is a documentation formatting tool, best suited for small to
|
|
|
4
4
|
medium-sized documentation. One writes documentation in plain text
|
|
5
5
|
files, which Mizuho then converts to nicely formatted HTML.
|
|
6
6
|
|
|
7
|
-
Mizuho
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
options.
|
|
7
|
+
Mizuho wraps [Asciidoc](http://www.methods.co.nz/asciidoc/), the text
|
|
8
|
+
formatting tool used by e.g. Git and Phusion Passenger for its manuals.
|
|
9
|
+
Mizuho adds the following functionality on top of Asciidoc:
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
* Commenting via [Juvia](https://github.com/FooBarWidget/juvia).
|
|
13
12
|
|
|
14
|
-
Mizuho
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
XHTML files (one per chapter).
|
|
22
|
-
* Output is fully customizable via ERB templates.
|
|
23
|
-
* Based on Asciidoc and supports all Asciidoc formatting commands.
|
|
24
|
-
* Comes bundled with Asciidoc so you don't have to install it yourself. Mizuho
|
|
25
|
-
Just Works(tm) out-of-the-box.
|
|
13
|
+
Mizuho bundles Asciidoc so you don't have to install it yourself. Mizuho
|
|
14
|
+
should Just Work(tm) out-of-the-box. Asciidoc uses GNU source-highlight
|
|
15
|
+
for highlighting source code. GNU source-highlight depends on Boost and
|
|
16
|
+
so is notorious for being difficult to install on systems without a
|
|
17
|
+
decent package manager (e.g. OS X). Mizuho comes prebundled with an OS
|
|
18
|
+
X binary for GNU source-highlight so that you don't have to worry about
|
|
19
|
+
that.
|
|
26
20
|
|
|
27
21
|
## Requirements
|
|
28
22
|
|
|
29
|
-
*
|
|
23
|
+
* Nokogiri (`gem install nokogiri`)
|
|
30
24
|
* Python (because Asciidoc is written in Python)
|
|
31
25
|
* [GNU Source-highlight](http://www.gnu.org/software/src-highlite/), if you
|
|
32
26
|
want syntax highlighting support. If you're on OS X then it's not necessary
|
|
@@ -46,17 +40,12 @@ http://www.methods.co.nz/asciidoc/userguide.html
|
|
|
46
40
|
|
|
47
41
|
Next, write an input file and save it in a .txt file.
|
|
48
42
|
|
|
49
|
-
Finally, convert the .txt file to a single
|
|
43
|
+
Finally, convert the .txt file to a single HTML file with Mizuho, with the
|
|
50
44
|
default template:
|
|
51
45
|
|
|
52
46
|
mizuho input.txt
|
|
53
47
|
|
|
54
|
-
This will generate 'input.html'.
|
|
55
|
-
that also have a different look:
|
|
56
|
-
|
|
57
|
-
mizuho input.txt --template manualsonrails --multi-page
|
|
58
|
-
|
|
59
|
-
Take a look at the 'templates' directory for available templates.
|
|
48
|
+
This will generate 'input.html'.
|
|
60
49
|
|
|
61
50
|
## Credits
|
|
62
51
|
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* AsciiDoc 'flask' theme for xhtml11 and html5 backends. A shameless knock-off
|
|
3
|
-
* of the Flask website styling (http://flask.pocoo.org/docs/).
|
|
4
|
-
*
|
|
5
|
-
* The implementation is straight-forward, consisting of the asciidoc.css file
|
|
6
|
-
* followed by theme specific overrides.
|
|
7
|
-
*
|
|
8
|
-
* */
|
|
9
|
-
|
|
10
|
-
|
|
11
1
|
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */
|
|
12
2
|
|
|
13
3
|
/* Default font. */
|
|
@@ -92,6 +82,7 @@ ul > li > * { color: black; }
|
|
|
92
82
|
pre {
|
|
93
83
|
padding: 0;
|
|
94
84
|
margin: 0;
|
|
85
|
+
overflow: auto;
|
|
95
86
|
}
|
|
96
87
|
|
|
97
88
|
#author {
|
|
@@ -518,6 +509,29 @@ th.tableblock.valign-bottom, td.tableblock.valign-bottom {
|
|
|
518
509
|
}
|
|
519
510
|
|
|
520
511
|
|
|
512
|
+
/*
|
|
513
|
+
* manpage specific
|
|
514
|
+
*
|
|
515
|
+
* */
|
|
516
|
+
|
|
517
|
+
body.manpage h1 {
|
|
518
|
+
padding-top: 0.5em;
|
|
519
|
+
padding-bottom: 0.5em;
|
|
520
|
+
border-top: 2px solid silver;
|
|
521
|
+
border-bottom: 2px solid silver;
|
|
522
|
+
}
|
|
523
|
+
body.manpage h2 {
|
|
524
|
+
border-style: none;
|
|
525
|
+
}
|
|
526
|
+
body.manpage div.sectionbody {
|
|
527
|
+
margin-left: 3em;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
@media print {
|
|
531
|
+
body.manpage div#toc { display: none; }
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
|
|
521
535
|
/*
|
|
522
536
|
* Theme specific overrides of the preceding (asciidoc.css) CSS.
|
|
523
537
|
*
|
|
@@ -544,7 +558,7 @@ h1 { font-size: 240%; }
|
|
|
544
558
|
h2 { font-size: 180%; }
|
|
545
559
|
h3 { font-size: 150%; }
|
|
546
560
|
h4 { font-size: 130%; }
|
|
547
|
-
h5 { font-size:
|
|
561
|
+
h5 { font-size: 115%; }
|
|
548
562
|
h6 { font-size: 100%; }
|
|
549
563
|
#header h1 { margin-top: 0; }
|
|
550
564
|
#toc {
|
data/bin/mizuho
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + "/../lib/mizuho")
|
|
3
3
|
require 'optparse'
|
|
4
|
+
require 'rubygems'
|
|
4
5
|
require 'mizuho/generator'
|
|
5
6
|
|
|
6
7
|
$KCODE = 'UTF-8'
|
|
7
|
-
options = {}
|
|
8
|
+
options = { :topbar => true }
|
|
8
9
|
parser = OptionParser.new do |opts|
|
|
10
|
+
nl = "\n" + ' ' * 37
|
|
9
11
|
opts.banner = "Usage: mizuho [options] INPUT"
|
|
10
12
|
opts.separator ""
|
|
11
13
|
|
|
12
14
|
opts.separator "Options:"
|
|
13
|
-
opts.on("-
|
|
14
|
-
|
|
15
|
+
opts.on("-c", "--comments SYSTEM",
|
|
16
|
+
"Use a commenting system. The only#{nl}" +
|
|
17
|
+
"supported commenting system right now is#{nl}" +
|
|
18
|
+
"'juvia'.") do |value|
|
|
19
|
+
if value != 'juvia'
|
|
20
|
+
abort "The only supported commenting system right now is 'juvia'."
|
|
21
|
+
end
|
|
22
|
+
options[:commenting_system] = value
|
|
15
23
|
end
|
|
16
|
-
opts.on("-
|
|
17
|
-
|
|
24
|
+
opts.on("--juvia-url URL", "When using Juvia as the commenting system,#{nl}" +
|
|
25
|
+
"specify the Juvia base URL here.") do |value|
|
|
26
|
+
options[:juvia_url] = value
|
|
18
27
|
end
|
|
19
|
-
opts.on("--
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
opts.on("--juvia-site-key KEY", "When using Juvia as the commenting system,#{nl}" +
|
|
29
|
+
"specify the Juvia site key here.") do |value|
|
|
30
|
+
options[:juvia_site_key] = value
|
|
31
|
+
end
|
|
32
|
+
#opts.on("-m", "--multi-page", "Generate one file per chapter.") do |value|
|
|
33
|
+
# options[:multi_page] = value
|
|
34
|
+
#end
|
|
35
|
+
opts.on("--icons-dir DIR", "Specify the directory in which icons#{nl}" <<
|
|
36
|
+
"should be searched. Defaults to#{nl}" <<
|
|
37
|
+
"'images/icons'.") do |value|
|
|
22
38
|
options[:icons_dir] = value
|
|
23
39
|
end
|
|
24
40
|
opts.on("-o", "--output FILE", String, "Specify the output filename.") do |value|
|
|
@@ -28,9 +44,9 @@ end
|
|
|
28
44
|
begin
|
|
29
45
|
parser.parse!
|
|
30
46
|
rescue OptionParser::ParseError => e
|
|
31
|
-
puts e
|
|
32
|
-
puts
|
|
33
|
-
puts "Please see '--help' for valid options."
|
|
47
|
+
STDERR.puts e
|
|
48
|
+
STDERR.puts
|
|
49
|
+
STDERR.puts "Please see '--help' for valid options."
|
|
34
50
|
exit 1
|
|
35
51
|
end
|
|
36
52
|
|
data/lib/mizuho.rb
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
|
+
# Copyright (c) 2008-2012 Hongli Lai
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
1
21
|
module Mizuho
|
|
2
|
-
SOURCE_ROOT
|
|
3
|
-
LIBDIR
|
|
4
|
-
|
|
22
|
+
SOURCE_ROOT = File.expand_path(File.dirname(__FILE__) + "/..")
|
|
23
|
+
LIBDIR = "#{SOURCE_ROOT}/lib"
|
|
24
|
+
TEMPLATES_DIR = "#{SOURCE_ROOT}/templates"
|
|
25
|
+
ASCIIDOC = "#{SOURCE_ROOT}/asciidoc/asciidoc.py"
|
|
5
26
|
|
|
6
|
-
VERSION_STRING = "0.9.
|
|
27
|
+
VERSION_STRING = "0.9.9"
|
|
7
28
|
|
|
8
29
|
if $LOAD_PATH.first != LIBDIR
|
|
9
30
|
$LOAD_PATH.unshift(LIBDIR)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Extracted from https://github.com/kiyoka/fuzzy-string-match
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Fuzzy String Match
|
|
5
|
+
#
|
|
6
|
+
# Copyright 2010 Kiyoka Nishiyama
|
|
7
|
+
#
|
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
# you may not use this file except in compliance with the License.
|
|
10
|
+
# You may obtain a copy of the License at
|
|
11
|
+
#
|
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
#
|
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
# See the License for the specific language governing permissions and
|
|
18
|
+
# limitations under the License.
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
module Mizuho
|
|
22
|
+
class JaroWinklerPure
|
|
23
|
+
THRESHOLD = 0.7
|
|
24
|
+
|
|
25
|
+
def getDistance( s1, s2 )
|
|
26
|
+
a1 = s1.split( // )
|
|
27
|
+
a2 = s2.split( // )
|
|
28
|
+
|
|
29
|
+
if s1.size > s2.size
|
|
30
|
+
(max,min) = a1,a2
|
|
31
|
+
else
|
|
32
|
+
(max,min) = a2,a1
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
range = [ (max.size / 2 - 1), 0 ].max
|
|
36
|
+
indexes = Array.new( min.size, -1 )
|
|
37
|
+
flags = Array.new( max.size, false )
|
|
38
|
+
|
|
39
|
+
matches = 0;
|
|
40
|
+
(0 ... min.size).each { |mi|
|
|
41
|
+
c1 = min[mi]
|
|
42
|
+
xi = [mi - range, 0].max
|
|
43
|
+
xn = [mi + range + 1, max.size].min
|
|
44
|
+
|
|
45
|
+
(xi ... xn).each { |i|
|
|
46
|
+
if (not flags[i]) && ( c1 == max[i] )
|
|
47
|
+
indexes[mi] = i
|
|
48
|
+
flags[i] = true
|
|
49
|
+
matches += 1
|
|
50
|
+
break
|
|
51
|
+
end
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
ms1 = Array.new( matches, nil )
|
|
56
|
+
ms2 = Array.new( matches, nil )
|
|
57
|
+
|
|
58
|
+
si = 0
|
|
59
|
+
(0 ... min.size).each { |i|
|
|
60
|
+
if (indexes[i] != -1)
|
|
61
|
+
ms1[si] = min[i]
|
|
62
|
+
si += 1
|
|
63
|
+
end
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
si = 0
|
|
67
|
+
(0 ... max.size).each { |i|
|
|
68
|
+
if flags[i]
|
|
69
|
+
ms2[si] = max[i]
|
|
70
|
+
si += 1
|
|
71
|
+
end
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
transpositions = 0
|
|
75
|
+
(0 ... ms1.size).each { |mi|
|
|
76
|
+
if ms1[mi] != ms2[mi]
|
|
77
|
+
transpositions += 1
|
|
78
|
+
end
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
prefix = 0
|
|
82
|
+
(0 ... min.size).each { |mi|
|
|
83
|
+
if s1[mi] == s2[mi]
|
|
84
|
+
prefix += 1
|
|
85
|
+
else
|
|
86
|
+
break
|
|
87
|
+
end
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if 0 == matches
|
|
91
|
+
0.0
|
|
92
|
+
else
|
|
93
|
+
m = matches.to_f
|
|
94
|
+
t = (transpositions/ 2)
|
|
95
|
+
j = ((m / s1.size) + (m / s2.size) + ((m - t) / m)) / 3.0;
|
|
96
|
+
return j < THRESHOLD ? j : j + [0.1, 1.0 / max.size].min * prefix * (1 - j)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
data/lib/mizuho/generator.rb
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# Copyright (c) 2008-2012 Hongli Lai
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
require 'nokogiri'
|
|
3
22
|
require 'mizuho'
|
|
4
|
-
require 'mizuho/parser'
|
|
5
|
-
require 'mizuho/template'
|
|
6
23
|
require 'mizuho/source_highlight'
|
|
24
|
+
require 'mizuho/id_map'
|
|
7
25
|
|
|
8
26
|
module Mizuho
|
|
9
27
|
|
|
@@ -12,24 +30,52 @@ end
|
|
|
12
30
|
|
|
13
31
|
class Generator
|
|
14
32
|
def initialize(input, options = {})
|
|
15
|
-
@
|
|
16
|
-
@
|
|
17
|
-
@
|
|
18
|
-
@
|
|
19
|
-
@icons_dir
|
|
20
|
-
@conf_file
|
|
33
|
+
@options = options
|
|
34
|
+
@input_file = input
|
|
35
|
+
@output_file = options[:output] || default_output_filename(input)
|
|
36
|
+
@id_map_file = options[:id_map] || default_id_map_filename(input)
|
|
37
|
+
@icons_dir = options[:icons_dir]
|
|
38
|
+
@conf_file = options[:conf_file]
|
|
39
|
+
@enable_topbar = options[:topbar]
|
|
40
|
+
@commenting_system = options[:commenting_system]
|
|
41
|
+
if @commenting_system == 'juvia'
|
|
42
|
+
require_options(options, :juvia_url, :juvia_site_key)
|
|
43
|
+
end
|
|
21
44
|
end
|
|
22
45
|
|
|
23
46
|
def start
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
if @commenting_system
|
|
48
|
+
@id_map = IdMap.new
|
|
49
|
+
if File.exist?(@id_map_file)
|
|
50
|
+
@id_map.load(@id_map_file)
|
|
51
|
+
else
|
|
52
|
+
warn "No ID map file, generating one (#{@id_map_file})..."
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
self.class.run_asciidoc(@input_file, @output_file, @icons_dir, @conf_file)
|
|
56
|
+
transform(@output_file)
|
|
57
|
+
if @commenting_system
|
|
58
|
+
@id_map.save(@id_map_file)
|
|
59
|
+
stats = @id_map.stats
|
|
60
|
+
if stats[:fuzzy] > 0
|
|
61
|
+
warn "Warning: #{stats[:fuzzy]} fuzzy ID(s)"
|
|
62
|
+
end
|
|
63
|
+
if stats[:orphaned] > 0
|
|
64
|
+
warn "Warning: #{stats[:orphaned]} unused ID(s)"
|
|
65
|
+
end
|
|
28
66
|
end
|
|
29
67
|
end
|
|
30
68
|
|
|
31
69
|
def self.run_asciidoc(input, output, icons_dir = nil, conf_file = nil)
|
|
32
|
-
args = [
|
|
70
|
+
args = [
|
|
71
|
+
"python", ASCIIDOC,
|
|
72
|
+
"-b", "html5",
|
|
73
|
+
"-a", "toc",
|
|
74
|
+
"-a", "theme=flask",
|
|
75
|
+
"-a", "toclevels=3",
|
|
76
|
+
"-a", "icons",
|
|
77
|
+
"-n"
|
|
78
|
+
]
|
|
33
79
|
if icons_dir
|
|
34
80
|
args << "-a"
|
|
35
81
|
args << "iconsdir=#{icons_dir}"
|
|
@@ -41,93 +87,149 @@ class Generator
|
|
|
41
87
|
args << cf
|
|
42
88
|
end
|
|
43
89
|
end
|
|
44
|
-
args += ["-
|
|
90
|
+
args += ["-o", output, input]
|
|
45
91
|
if !system(*args)
|
|
46
92
|
raise GenerationError, "Asciidoc failed."
|
|
47
93
|
end
|
|
48
94
|
end
|
|
49
95
|
|
|
50
96
|
private
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return template_name
|
|
57
|
-
else
|
|
58
|
-
return "#{SOURCE_ROOT}/templates/#{template_name}.html.erb"
|
|
59
|
-
end
|
|
97
|
+
def default_output_filename(input)
|
|
98
|
+
return File.dirname(input) +
|
|
99
|
+
"/" +
|
|
100
|
+
File.basename(input, File.extname(input)) +
|
|
101
|
+
".html"
|
|
60
102
|
end
|
|
61
103
|
|
|
62
|
-
def
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
104
|
+
def default_id_map_filename(input)
|
|
105
|
+
return File.dirname(input) +
|
|
106
|
+
"/" +
|
|
107
|
+
File.basename(input, File.extname(input)) +
|
|
108
|
+
".idmap.txt"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def warn(message)
|
|
112
|
+
STDERR.puts(message)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def transform(filename)
|
|
116
|
+
File.open(filename, 'r+') do |f|
|
|
117
|
+
doc = Nokogiri.HTML(f)
|
|
118
|
+
head = (doc / "head")[0]
|
|
119
|
+
body = (doc / "body")[0]
|
|
120
|
+
title = (doc / "title")[0].text
|
|
121
|
+
preamble = (doc / "#preamble")[0]
|
|
122
|
+
toctitle = (doc / "#toctitle")[0]
|
|
123
|
+
|
|
124
|
+
head.add_child(stylesheet_tag)
|
|
125
|
+
|
|
126
|
+
if @commenting_system
|
|
127
|
+
headers = (doc / "#content h2, #content h3, #content h4")
|
|
128
|
+
headers.each do |header|
|
|
129
|
+
header['data-comment-topic'] = @id_map.associate(header.text)
|
|
130
|
+
header.add_previous_sibling(create_comment_balloon)
|
|
131
|
+
end
|
|
73
132
|
end
|
|
74
|
-
|
|
75
|
-
if
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
133
|
+
|
|
134
|
+
if @enable_topbar
|
|
135
|
+
body.children.first.add_previous_sibling(topbar(title))
|
|
136
|
+
end
|
|
137
|
+
body.add_child(javascript_tag)
|
|
138
|
+
|
|
139
|
+
if preamble
|
|
140
|
+
preamble.remove
|
|
141
|
+
preamble_copy = (doc / "#header > h1")[0].add_next_sibling(preamble.to_s)[0]
|
|
142
|
+
preamble_copy['id'] = 'preamble'
|
|
81
143
|
end
|
|
144
|
+
|
|
145
|
+
toctitle.add_previous_sibling(create_comment_balloon)
|
|
146
|
+
|
|
147
|
+
f.rewind
|
|
148
|
+
f.truncate(0)
|
|
149
|
+
f.puts(doc.to_html)
|
|
82
150
|
end
|
|
83
|
-
return File.expand_path(filename)
|
|
84
151
|
end
|
|
85
152
|
|
|
86
|
-
def
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
:multi_page? => true,
|
|
94
|
-
:title => parser.title,
|
|
95
|
-
:table_of_contents => parser.table_of_contents,
|
|
96
|
-
:contents => chapter.contents,
|
|
97
|
-
:is_preamble? => chapter.heading.nil?,
|
|
98
|
-
:chapters => parser.chapters,
|
|
99
|
-
:prev_chapter => (i <= 1) ? nil : parser.chapters[i - 1],
|
|
100
|
-
:current_chapter => chapter,
|
|
101
|
-
:next_chapter => parser.chapters[i + 1])
|
|
102
|
-
template.save(chapter.filename)
|
|
153
|
+
def stylesheet_tag
|
|
154
|
+
content = %Q{<style type="text/css">\n}
|
|
155
|
+
|
|
156
|
+
css = File.read("#{TEMPLATES_DIR}/mizuho.css")
|
|
157
|
+
css.gsub!(/url\('(.*?)\.png'\)/) do
|
|
158
|
+
data = File.open("#{TEMPLATES_DIR}/#{$1}.png", "rb") do |f|
|
|
159
|
+
f.read
|
|
103
160
|
end
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
:title => parser.title,
|
|
108
|
-
:table_of_contents => parser.table_of_contents,
|
|
109
|
-
:contents => parser.contents)
|
|
110
|
-
template.save(asciidoc_file)
|
|
161
|
+
data = [data].pack('m')
|
|
162
|
+
data.gsub!("\n", "")
|
|
163
|
+
"url('data:image/png;base64,#{data}')"
|
|
111
164
|
end
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
165
|
+
content << css << "\n"
|
|
166
|
+
|
|
167
|
+
if @enable_topbar
|
|
168
|
+
content << File.read("#{TEMPLATES_DIR}/topbar.css") << "\n"
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
if @commenting_system == 'disqus'
|
|
172
|
+
content << File.read("#{TEMPLATES_DIR}/disqus.css") << "\n"
|
|
173
|
+
elsif @commenting_system == 'intensedebate'
|
|
174
|
+
content << File.read("#{TEMPLATES_DIR}/intensedebate.css") << "\n"
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
content << %Q{</style>\n}
|
|
178
|
+
return content
|
|
115
179
|
end
|
|
116
180
|
|
|
117
|
-
def
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
181
|
+
def topbar(title)
|
|
182
|
+
content = render_template("topbar.html")
|
|
183
|
+
content.gsub!(/\{TITLE\}/, title)
|
|
184
|
+
return content
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def javascript_tag
|
|
188
|
+
content = %Q{<script>}
|
|
189
|
+
content << File.read("#{TEMPLATES_DIR}/jquery-1.7.1.min.js") << "\n"
|
|
190
|
+
content << File.read("#{TEMPLATES_DIR}/jquery.hashchange-1.0.0.js") << "\n"
|
|
191
|
+
content << File.read("#{TEMPLATES_DIR}/mizuho.js") << "\n"
|
|
192
|
+
if @enable_topbar
|
|
193
|
+
content << File.read("#{TEMPLATES_DIR}/topbar.js") << "\n"
|
|
194
|
+
end
|
|
195
|
+
if @commenting_system == 'juvia'
|
|
196
|
+
content << %Q{
|
|
197
|
+
var JUVIA_URL = '#{@options[:juvia_url]}';
|
|
198
|
+
var JUVIA_SITE_KEY = '#{@options[:juvia_site_key]}';
|
|
199
|
+
}
|
|
200
|
+
content << File.read("#{TEMPLATES_DIR}/juvia.js") << "\n"
|
|
201
|
+
end
|
|
202
|
+
content << %Q{</script>}
|
|
203
|
+
return content
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def create_comment_balloon
|
|
207
|
+
return %Q{<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a>}
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def render_template(name)
|
|
211
|
+
content = File.read("#{TEMPLATES_DIR}/#{name}")
|
|
212
|
+
content.gsub!(/\{INLINE_IMAGE:(.*?)\.png\}/) do
|
|
213
|
+
data = File.open("#{TEMPLATES_DIR}/#{$1}.png", "rb") do |f|
|
|
214
|
+
f.read
|
|
215
|
+
end
|
|
216
|
+
data = [data].pack('m')
|
|
217
|
+
data.gsub!("\n", "")
|
|
218
|
+
"data:image/png;base64,#{data}"
|
|
219
|
+
end
|
|
220
|
+
return content
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def require_options(options, *required_keys)
|
|
224
|
+
fail = false
|
|
225
|
+
required_keys.each do |key|
|
|
226
|
+
if !options.has_key?(key)
|
|
227
|
+
fail = true
|
|
228
|
+
argument_name = '--' + key.to_s.gsub('_', '-')
|
|
229
|
+
STDERR.puts "You must also specify #{argument_name}!"
|
|
129
230
|
end
|
|
130
231
|
end
|
|
232
|
+
exit 1 if fail
|
|
131
233
|
end
|
|
132
234
|
end
|
|
133
235
|
|