review 2.5.0 → 3.0.0.preview1
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/.rubocop.yml +28 -10
- data/.travis.yml +11 -2
- data/NEWS.ja.md +89 -17
- data/NEWS.md +92 -0
- data/README.md +1 -1
- data/Rakefile +0 -13
- data/bin/review-catalog-converter +83 -37
- data/bin/review-check +17 -5
- data/bin/review-compile +1 -1
- data/bin/review-index +6 -0
- data/bin/review-init +3 -155
- data/bin/review-preproc +0 -5
- data/bin/review-validate +21 -7
- data/bin/review-vol +13 -5
- data/doc/config.yml.sample +12 -7
- data/doc/config.yml.sample-simple +1 -1
- data/doc/format.ja.md +39 -3
- data/doc/format.md +39 -3
- data/doc/format_idg.ja.md +0 -4
- data/doc/pdfmaker.ja.md +1 -1
- data/doc/pdfmaker.md +1 -1
- data/doc/sample.css +7 -0
- data/lib/epubmaker/content.rb +31 -12
- data/lib/epubmaker/epubcommon.rb +10 -3
- data/lib/epubmaker/epubv2.rb +11 -3
- data/lib/epubmaker/epubv3.rb +11 -3
- data/lib/epubmaker/producer.rb +55 -20
- data/lib/review/book/base.rb +63 -48
- data/lib/review/book/chapter.rb +19 -7
- data/lib/review/book/compilable.rb +5 -20
- data/lib/review/book/image_finder.rb +10 -3
- data/lib/review/book/index.rb +30 -9
- data/lib/review/book/part.rb +9 -6
- data/lib/review/book.rb +0 -14
- data/lib/review/builder.rb +110 -18
- data/lib/review/catalog.rb +24 -4
- data/lib/review/compiler.rb +3 -1
- data/lib/review/configure.rb +43 -9
- data/lib/review/epubmaker/reviewheaderlistener.rb +57 -0
- data/lib/review/epubmaker.rb +129 -85
- data/lib/review/htmlbuilder.rb +76 -58
- data/lib/review/htmlutils.rb +20 -13
- data/lib/review/i18n.rb +6 -2
- data/lib/review/idgxmlbuilder.rb +52 -41
- data/lib/review/init.rb +194 -0
- data/lib/review/latexbuilder.rb +118 -34
- data/lib/review/latexutils.rb +5 -5
- data/lib/review/logger.rb +2 -1
- data/lib/review/makerhelper.rb +1 -1
- data/lib/review/markdownbuilder.rb +66 -6
- data/lib/review/md2inaobuilder.rb +2 -2
- data/lib/review/pdfmaker.rb +74 -22
- data/lib/review/plaintextbuilder.rb +8 -4
- data/lib/review/preprocessor.rb +14 -17
- data/lib/review/sec_counter.rb +8 -2
- data/lib/review/textmaker.rb +2 -2
- data/lib/review/textutils.rb +9 -2
- data/lib/review/tocparser.rb +7 -4
- data/lib/review/tocprinter.rb +3 -1
- data/lib/review/version.rb +1 -1
- data/lib/review/webmaker.rb +19 -7
- data/lib/review/webtocprinter.rb +8 -4
- data/review.gemspec +4 -3
- data/templates/latex/config.erb +84 -0
- data/templates/latex/layout.tex.erb +76 -361
- data/templates/latex/review-jlreq/README.md +22 -0
- data/templates/latex/review-jlreq/review-base.sty +178 -0
- data/templates/latex/review-jlreq/review-custom.sty +1 -0
- data/templates/latex/review-jlreq/review-jlreq.cls +141 -0
- data/templates/latex/review-jlreq/review-style.sty +149 -0
- data/templates/latex/review-jlreq/reviewmacro.sty +8 -0
- data/templates/latex/review-jsbook/jumoline.sty +310 -0
- data/templates/latex/review-jsbook/plistings.sty +326 -0
- data/templates/latex/review-jsbook/review-base.sty +405 -0
- data/templates/latex/review-jsbook/review-custom.sty +1 -0
- data/templates/latex/review-jsbook/review-style.sty +38 -0
- data/templates/latex/review-jsbook/reviewmacro.sty +8 -0
- data/templates/latex-compat2/layout.tex.erb +387 -0
- data/test/assets/test_template.tex +105 -235
- data/test/assets/test_template_backmatter.tex +133 -14
- data/test/book_test_helper.rb +1 -1
- data/test/run_test.rb +2 -0
- data/test/sample-book/src/Rakefile +11 -6
- data/test/sample-book/src/config.yml +2 -2
- data/test/sample-book/src/sty/reviewmacro.sty +1 -39
- data/test/sample-book/src/style.css +6 -0
- data/test/syntax-book/config.yml +1 -1
- data/test/test_book.rb +13 -16
- data/test/test_book_chapter.rb +4 -10
- data/test/test_book_part.rb +4 -3
- data/test/test_catalog.rb +15 -4
- data/test/test_helper.rb +2 -2
- data/test/test_htmlbuilder.rb +78 -10
- data/test/test_htmlutils.rb +12 -5
- data/test/test_idgxmlbuilder.rb +1 -1
- data/test/test_latexbuilder.rb +94 -49
- data/test/test_latexbuilder_v2.rb +1077 -0
- data/test/test_logger.rb +20 -0
- data/test/test_markdownbuilder.rb +10 -0
- data/test/test_pdfmaker.rb +6 -7
- data/test/test_plaintextbuilder.rb +1 -1
- data/test/test_review_ext.rb +0 -1
- data/test/test_rstbuilder.rb +1 -1
- data/test/test_topbuilder.rb +19 -7
- data/test/test_webtocprinter.rb +14 -14
- data/{test/sample-book/src/vendor → vendor}/jumoline/README +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.dtx +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/jumoline.ins +0 -0
- data/{test/sample-book/src/vendor → vendor}/jumoline/lppl.txt +0 -0
- data/vendor/plistings/.gitignore +9 -0
- data/vendor/plistings/LICENSE +21 -0
- data/vendor/plistings/README.md +18 -0
- data/vendor/plistings/plistings.sty +326 -0
- data/vendor/plistings/test1.tex +174 -0
- data/vendor/plistings/test2.tex +54 -0
- metadata +48 -19
- data/lib/review/unfold.rb +0 -129
- data/test/CHAPS +0 -2
- data/test/bib.re +0 -13
- data/test/test.re +0 -43
data/lib/review/idgxmlbuilder.rb
CHANGED
@@ -16,7 +16,7 @@ module ReVIEW
|
|
16
16
|
include TextUtils
|
17
17
|
include HTMLUtils
|
18
18
|
|
19
|
-
%i[ttbold hint maru keytop labelref ref
|
19
|
+
%i[ttbold hint maru keytop labelref ref].each { |e| Compiler.definline(e) }
|
20
20
|
Compiler.defsingle(:dtp, 1)
|
21
21
|
|
22
22
|
Compiler.defblock(:insn, 0..1)
|
@@ -44,8 +44,7 @@ module ReVIEW
|
|
44
44
|
'.xml'
|
45
45
|
end
|
46
46
|
|
47
|
-
def builder_init
|
48
|
-
@no_error = no_error
|
47
|
+
def builder_init
|
49
48
|
end
|
50
49
|
private :builder_init
|
51
50
|
|
@@ -62,13 +61,12 @@ module ReVIEW
|
|
62
61
|
@ol_num = nil
|
63
62
|
@first_line_num = nil
|
64
63
|
@rootelement = 'doc'
|
65
|
-
@secttags = nil
|
66
64
|
@tsize = nil
|
67
65
|
@texblockequation = 0
|
68
66
|
@texinlineequation = 0
|
69
67
|
print %Q(<?xml version="1.0" encoding="UTF-8"?>\n)
|
70
68
|
print %Q(<#{@rootelement} xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">)
|
71
|
-
@secttags =
|
69
|
+
@secttags = @book.config['structuredxml']
|
72
70
|
end
|
73
71
|
private :builder_init_file
|
74
72
|
|
@@ -102,7 +100,7 @@ module ReVIEW
|
|
102
100
|
print '</sect>' if @section > 0
|
103
101
|
end
|
104
102
|
|
105
|
-
print %Q(<chapter id="chap:#{@chapter.number}">)
|
103
|
+
print %Q(<chapter id="chap:#{@chapter.number}">) if @secttags
|
106
104
|
|
107
105
|
@section = 0
|
108
106
|
@subsection = 0
|
@@ -116,7 +114,7 @@ module ReVIEW
|
|
116
114
|
print '</sect>' if @section > 0
|
117
115
|
end
|
118
116
|
@section += 1
|
119
|
-
print %Q(<sect id="sect:#{@chapter.number}.#{@section}">)
|
117
|
+
print %Q(<sect id="sect:#{@chapter.number}.#{@section}">) if @secttags
|
120
118
|
|
121
119
|
@subsection = 0
|
122
120
|
@subsubsection = 0
|
@@ -129,7 +127,7 @@ module ReVIEW
|
|
129
127
|
end
|
130
128
|
|
131
129
|
@subsection += 1
|
132
|
-
print %Q(<sect2 id="sect:#{@chapter.number}.#{@section}.#{@subsection}">)
|
130
|
+
print %Q(<sect2 id="sect:#{@chapter.number}.#{@section}.#{@subsection}">) if @secttags
|
133
131
|
|
134
132
|
@subsubsection = 0
|
135
133
|
@subsubsubsection = 0
|
@@ -155,7 +153,7 @@ module ReVIEW
|
|
155
153
|
prefix, _anchor = headline_prefix(level)
|
156
154
|
|
157
155
|
label = label.nil? ? '' : %Q( id="#{label}")
|
158
|
-
toccaption =
|
156
|
+
toccaption = escape(compile_inline(caption.gsub(/@<fn>\{.+?\}/, '')).gsub(/<[^>]+>/, ''))
|
159
157
|
puts %Q(<title#{label} aid:pstyle="h#{level}">#{prefix}#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{prefix}#{toccaption}"?>)
|
160
158
|
end
|
161
159
|
|
@@ -591,12 +589,12 @@ module ReVIEW
|
|
591
589
|
lines ||= []
|
592
590
|
lines.unshift comment unless comment.blank?
|
593
591
|
str = lines.join("\n")
|
594
|
-
print "<msg>#{
|
592
|
+
print "<msg>#{escape(str)}</msg>"
|
595
593
|
end
|
596
594
|
|
597
595
|
def inline_comment(str)
|
598
596
|
if @book.config['draft']
|
599
|
-
%Q(<msg>#{
|
597
|
+
%Q(<msg>#{escape(str)}</msg>)
|
600
598
|
else
|
601
599
|
''
|
602
600
|
end
|
@@ -613,34 +611,34 @@ module ReVIEW
|
|
613
611
|
end
|
614
612
|
|
615
613
|
def compile_ruby(base, ruby)
|
616
|
-
%Q(<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>#{
|
614
|
+
%Q(<GroupRuby><aid:ruby xmlns:aid="http://ns.adobe.com/AdobeInDesign/3.0/"><aid:rb>#{escape(base.strip)}</aid:rb><aid:rt>#{escape(ruby.strip)}</aid:rt></aid:ruby></GroupRuby>)
|
617
615
|
end
|
618
616
|
|
619
617
|
def compile_kw(word, alt)
|
620
618
|
'<keyword>' +
|
621
619
|
if alt
|
622
|
-
then
|
623
|
-
else
|
620
|
+
then escape("#{word}(#{alt.strip})")
|
621
|
+
else escape(word)
|
624
622
|
end +
|
625
623
|
'</keyword>' +
|
626
|
-
%Q(<index value="#{
|
624
|
+
%Q(<index value="#{escape(word)}" />) +
|
627
625
|
if alt
|
628
|
-
alt.split(/\s*,\s*/).collect! { |e| %Q(<index value="#{
|
626
|
+
alt.split(/\s*,\s*/).collect! { |e| %Q(<index value="#{escape(e.strip)}" />) }.join
|
629
627
|
else
|
630
628
|
''
|
631
629
|
end
|
632
630
|
end
|
633
631
|
|
634
632
|
def compile_href(url, label)
|
635
|
-
%Q(<a linkurl='#{
|
633
|
+
%Q(<a linkurl='#{escape(url)}'>#{label.nil? ? escape(url) : escape(label)}</a>)
|
636
634
|
end
|
637
635
|
|
638
636
|
def inline_sup(str)
|
639
|
-
%Q(<sup>#{
|
637
|
+
%Q(<sup>#{escape(str)}</sup>)
|
640
638
|
end
|
641
639
|
|
642
640
|
def inline_sub(str)
|
643
|
-
%Q(<sub>#{
|
641
|
+
%Q(<sub>#{escape(str)}</sub>)
|
644
642
|
end
|
645
643
|
|
646
644
|
def inline_raw(str)
|
@@ -649,9 +647,9 @@ module ReVIEW
|
|
649
647
|
|
650
648
|
def inline_hint(str)
|
651
649
|
if @book.config['nolf']
|
652
|
-
%Q(<hint>#{
|
650
|
+
%Q(<hint>#{escape(str)}</hint>)
|
653
651
|
else
|
654
|
-
%Q(\n<hint>#{
|
652
|
+
%Q(\n<hint>#{escape(str)}</hint>)
|
655
653
|
end
|
656
654
|
end
|
657
655
|
|
@@ -676,41 +674,41 @@ module ReVIEW
|
|
676
674
|
end
|
677
675
|
|
678
676
|
def inline_idx(str)
|
679
|
-
%Q(#{
|
677
|
+
%Q(#{escape(str)}<index value="#{escape(str)}" />)
|
680
678
|
end
|
681
679
|
|
682
680
|
def inline_hidx(str)
|
683
|
-
%Q(<index value="#{
|
681
|
+
%Q(<index value="#{escape(str)}" />)
|
684
682
|
end
|
685
683
|
|
686
684
|
def inline_ami(str)
|
687
|
-
%Q(<ami>#{
|
685
|
+
%Q(<ami>#{escape(str)}</ami>)
|
688
686
|
end
|
689
687
|
|
690
688
|
def inline_i(str)
|
691
|
-
%Q(<i>#{
|
689
|
+
%Q(<i>#{escape(str)}</i>)
|
692
690
|
end
|
693
691
|
|
694
692
|
def inline_b(str)
|
695
|
-
%Q(<b>#{
|
693
|
+
%Q(<b>#{escape(str)}</b>)
|
696
694
|
end
|
697
695
|
|
698
696
|
def inline_tt(str)
|
699
|
-
%Q(<tt>#{
|
697
|
+
%Q(<tt>#{escape(str)}</tt>)
|
700
698
|
end
|
701
699
|
|
702
700
|
def inline_ttb(str)
|
703
|
-
%Q(<tt style='bold'>#{
|
701
|
+
%Q(<tt style='bold'>#{escape(str)}</tt>)
|
704
702
|
end
|
705
703
|
|
706
704
|
alias_method :inline_ttbold, :inline_ttb
|
707
705
|
|
708
706
|
def inline_tti(str)
|
709
|
-
%Q(<tt style='italic'>#{
|
707
|
+
%Q(<tt style='italic'>#{escape(str)}</tt>)
|
710
708
|
end
|
711
709
|
|
712
710
|
def inline_u(str)
|
713
|
-
%Q(<underline>#{
|
711
|
+
%Q(<underline>#{escape(str)}</underline>)
|
714
712
|
end
|
715
713
|
|
716
714
|
def inline_icon(id)
|
@@ -723,25 +721,25 @@ module ReVIEW
|
|
723
721
|
end
|
724
722
|
|
725
723
|
def inline_bou(str)
|
726
|
-
%Q(<bou>#{
|
724
|
+
%Q(<bou>#{escape(str)}</bou>)
|
727
725
|
end
|
728
726
|
|
729
727
|
def inline_keytop(str)
|
730
|
-
%Q(<keytop>#{
|
728
|
+
%Q(<keytop>#{escape(str)}</keytop>)
|
731
729
|
end
|
732
730
|
|
733
731
|
def inline_labelref(idref)
|
734
|
-
%Q(<ref idref='#{
|
732
|
+
%Q(<ref idref='#{escape(idref)}'>「#{I18n.t('label_marker')}#{escape(idref)}」</ref>) # FIXME: 節名とタイトルも込みで要出力
|
735
733
|
end
|
736
734
|
|
737
735
|
alias_method :inline_ref, :inline_labelref
|
738
736
|
|
739
737
|
def inline_pageref(idref)
|
740
|
-
%Q(<pageref idref='#{
|
738
|
+
%Q(<pageref idref='#{escape(idref)}'>●●</pageref>) # ページ番号を参照
|
741
739
|
end
|
742
740
|
|
743
741
|
def inline_balloon(str)
|
744
|
-
%Q(<balloon>#{
|
742
|
+
%Q(<balloon>#{escape(str).gsub(/@maru\[(\d+)\]/) { inline_maru($1) }}</balloon>)
|
745
743
|
end
|
746
744
|
|
747
745
|
def inline_uchar(str)
|
@@ -750,7 +748,7 @@ module ReVIEW
|
|
750
748
|
|
751
749
|
def inline_m(str)
|
752
750
|
@texinlineequation += 1
|
753
|
-
%Q(<replace idref="texinline-#{@texinlineequation}"><pre>#{
|
751
|
+
%Q(<replace idref="texinline-#{@texinlineequation}"><pre>#{escape(str)}</pre></replace>)
|
754
752
|
end
|
755
753
|
|
756
754
|
def noindent
|
@@ -766,12 +764,25 @@ module ReVIEW
|
|
766
764
|
end
|
767
765
|
|
768
766
|
def nonum_begin(level, _label, caption)
|
769
|
-
puts %Q(<title aid:pstyle="h#{level}">#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{
|
767
|
+
puts %Q(<title aid:pstyle="h#{level}">#{compile_inline(caption)}</title><?dtp level="#{level}" section="#{escape(compile_inline(caption))}"?>)
|
770
768
|
end
|
771
769
|
|
772
770
|
def nonum_end(level)
|
773
771
|
end
|
774
772
|
|
773
|
+
def notoc_begin(level, _label, caption)
|
774
|
+
puts %Q(<title aid:pstyle="h#{level}">#{compile_inline(caption)}</title>)
|
775
|
+
end
|
776
|
+
|
777
|
+
def notoc_end(level)
|
778
|
+
end
|
779
|
+
|
780
|
+
def nodisp_begin(level, label, caption)
|
781
|
+
end
|
782
|
+
|
783
|
+
def nodisp_end(level)
|
784
|
+
end
|
785
|
+
|
775
786
|
def circle_begin(_level, _label, caption)
|
776
787
|
puts %Q(<title aid:pstyle="smallcircle">•#{compile_inline(caption)}</title>)
|
777
788
|
end
|
@@ -783,7 +794,7 @@ module ReVIEW
|
|
783
794
|
@column += 1
|
784
795
|
a_id = %Q(id="column-#{@column}")
|
785
796
|
print "<#{type}column #{a_id}>"
|
786
|
-
puts %Q(<title aid:pstyle="#{type}column-title">#{compile_inline(caption)}</title><?dtp level="9" section="#{
|
797
|
+
puts %Q(<title aid:pstyle="#{type}column-title">#{compile_inline(caption)}</title><?dtp level="9" section="#{escape(compile_inline(caption))}"?>)
|
787
798
|
end
|
788
799
|
|
789
800
|
def common_column_end(type)
|
@@ -1035,7 +1046,7 @@ module ReVIEW
|
|
1035
1046
|
end
|
1036
1047
|
|
1037
1048
|
def inline_code(str)
|
1038
|
-
%Q(<tt type='inline-code'>#{
|
1049
|
+
%Q(<tt type='inline-code'>#{escape(str)}</tt>)
|
1039
1050
|
end
|
1040
1051
|
|
1041
1052
|
def inline_br(_str)
|
@@ -1142,11 +1153,11 @@ module ReVIEW
|
|
1142
1153
|
|
1143
1154
|
def inline_recipe(id)
|
1144
1155
|
# FIXME
|
1145
|
-
%Q(<recipe idref="#{
|
1156
|
+
%Q(<recipe idref="#{escape(id)}">[XXX]「#{escape(id)}」 p.XX</recipe>)
|
1146
1157
|
end
|
1147
1158
|
|
1148
1159
|
def nofunc_text(str)
|
1149
|
-
|
1160
|
+
escape(str)
|
1150
1161
|
end
|
1151
1162
|
|
1152
1163
|
def image_ext
|
data/lib/review/init.rb
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018 Masanori Kado, Masayoshi Takahashi, Kenshi Muto
|
3
|
+
#
|
4
|
+
# This program is free software.
|
5
|
+
# You can distribute or modify this program under the terms of
|
6
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
7
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
8
|
+
|
9
|
+
require 'fileutils'
|
10
|
+
require 'optparse'
|
11
|
+
require 'review'
|
12
|
+
|
13
|
+
module ReVIEW
|
14
|
+
class Init
|
15
|
+
def self.execute(*args)
|
16
|
+
new.execute(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@template = 'review-jsbook'
|
21
|
+
@logger = ReVIEW.logger
|
22
|
+
@review_dir = File.dirname(File.expand_path('..', __dir__))
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute(*args)
|
26
|
+
initdir = parse_options(args)
|
27
|
+
|
28
|
+
generate_dir(initdir) do |dir|
|
29
|
+
generate_catalog_file(dir)
|
30
|
+
generate_sample(dir)
|
31
|
+
generate_images_dir(dir)
|
32
|
+
generate_cover_image(dir)
|
33
|
+
generate_layout(dir)
|
34
|
+
generate_style(dir)
|
35
|
+
generate_texmacro(dir)
|
36
|
+
generate_config(dir)
|
37
|
+
generate_locale(dir) if @locale
|
38
|
+
generate_rakefile(dir)
|
39
|
+
generate_gemfile(dir)
|
40
|
+
generate_doc(dir) unless @without_doc
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_options(args)
|
45
|
+
opts = OptionParser.new
|
46
|
+
opts.version = ReVIEW::VERSION
|
47
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [option] dirname"
|
48
|
+
opts.on('-h', '--help', 'print this message and quit.') do
|
49
|
+
puts opts.help
|
50
|
+
exit 0
|
51
|
+
end
|
52
|
+
opts.on('-f', '--force', 'generate files (except *.re) if directory has already existed.') do
|
53
|
+
@force = true
|
54
|
+
end
|
55
|
+
opts.on('-l', '--locale', 'generate locale.yml file.') do
|
56
|
+
@locale = true
|
57
|
+
end
|
58
|
+
opts.on('--latex-template name', 'specify LaTeX template name. (default: review-jsbook)') do |tname|
|
59
|
+
@template = tname
|
60
|
+
end
|
61
|
+
opts.on('', '--epub-version VERSION', 'define EPUB version') do |version|
|
62
|
+
@epub_version = version
|
63
|
+
end
|
64
|
+
opts.on('', '--without-doc', "don't generate doc files") do
|
65
|
+
@without_doc = true
|
66
|
+
end
|
67
|
+
|
68
|
+
begin
|
69
|
+
opts.parse!(args)
|
70
|
+
rescue OptionParser::ParseError => err
|
71
|
+
@logger.error err.message
|
72
|
+
$stderr.puts opts.help
|
73
|
+
exit 1
|
74
|
+
end
|
75
|
+
|
76
|
+
if args.empty?
|
77
|
+
$stderr.puts opts.help
|
78
|
+
exit 1
|
79
|
+
end
|
80
|
+
|
81
|
+
initdir = File.expand_path(args[0])
|
82
|
+
|
83
|
+
initdir
|
84
|
+
end
|
85
|
+
|
86
|
+
def generate_dir(dir)
|
87
|
+
if File.exist?(dir) && !@force
|
88
|
+
@logger.error "#{dir} already exists."
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
FileUtils.mkdir_p dir
|
92
|
+
yield dir
|
93
|
+
end
|
94
|
+
|
95
|
+
def generate_sample(dir)
|
96
|
+
unless @force
|
97
|
+
File.write("#{dir}/#{File.basename(dir)}.re", '= ')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def generate_layout(dir)
|
102
|
+
FileUtils.mkdir_p dir + '/layouts'
|
103
|
+
end
|
104
|
+
|
105
|
+
def generate_catalog_file(dir)
|
106
|
+
File.open(dir + '/catalog.yml', 'w') do |file|
|
107
|
+
file.write <<-EOS
|
108
|
+
PREDEF:
|
109
|
+
|
110
|
+
CHAPS:
|
111
|
+
- #{File.basename(dir)}.re
|
112
|
+
|
113
|
+
APPENDIX:
|
114
|
+
|
115
|
+
POSTDEF:
|
116
|
+
|
117
|
+
EOS
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def generate_images_dir(dir)
|
122
|
+
FileUtils.mkdir_p(dir + '/images')
|
123
|
+
end
|
124
|
+
|
125
|
+
def generate_cover_image(dir)
|
126
|
+
FileUtils.cp(@review_dir + '/test/sample-book/src/images/cover.jpg',
|
127
|
+
dir + '/images/')
|
128
|
+
end
|
129
|
+
|
130
|
+
def generate_config(dir)
|
131
|
+
today = Time.now.strftime('%Y-%m-%d')
|
132
|
+
content = File.read(@review_dir + '/doc/config.yml.sample', encoding: 'utf-8')
|
133
|
+
content.gsub!(/^#\s*coverimage:.*$/, 'coverimage: cover.jpg')
|
134
|
+
content.gsub!(/^#\s*date:.*$/, "date: #{today}")
|
135
|
+
content.gsub!(/^#\s*history:.*$/, %Q(history: [["#{today}"]]))
|
136
|
+
content.gsub!(/^#\s*texstyle:.*$/, 'texstyle: reviewmacro')
|
137
|
+
content.gsub!(/^(#\s*)?stylesheet:.*$/, %Q(stylesheet: ["style.css"]))
|
138
|
+
if @epub_version.to_i == 2
|
139
|
+
content.gsub!(/^#.*epubversion:.*$/, 'epubversion: 2')
|
140
|
+
content.gsub!(/^#.*htmlversion:.*$/, 'htmlversion: 4')
|
141
|
+
end
|
142
|
+
File.open(File.join(dir, 'config.yml'), 'w') { |f| f.write(content) }
|
143
|
+
end
|
144
|
+
|
145
|
+
def generate_style(dir)
|
146
|
+
FileUtils.cp @review_dir + '/test/sample-book/src/style.css', dir
|
147
|
+
end
|
148
|
+
|
149
|
+
def generate_texmacro(dir)
|
150
|
+
texmacrodir = dir + '/sty'
|
151
|
+
FileUtils.mkdir_p texmacrodir
|
152
|
+
tdir = File.join(@review_dir, '/templates/latex', @template)
|
153
|
+
@logger.error "#{tdir} not found." unless File.exist?(tdir)
|
154
|
+
FileUtils.cp Dir.glob(tdir + '/*.*'), texmacrodir
|
155
|
+
end
|
156
|
+
|
157
|
+
def generate_rakefile(dir)
|
158
|
+
FileUtils.mkdir_p dir + '/lib/tasks'
|
159
|
+
|
160
|
+
File.open(dir + '/Rakefile', 'w') do |file|
|
161
|
+
file.write <<-EOS
|
162
|
+
Dir.glob('lib/tasks/*.rake').each do |file|
|
163
|
+
load(file)
|
164
|
+
end
|
165
|
+
EOS
|
166
|
+
end
|
167
|
+
|
168
|
+
FileUtils.cp(@review_dir + '/test/sample-book/src/Rakefile',
|
169
|
+
dir + '/lib/tasks/review.rake')
|
170
|
+
end
|
171
|
+
|
172
|
+
def generate_locale(dir)
|
173
|
+
FileUtils.cp @review_dir + '/lib/review/i18n.yml', dir + '/locale.yml'
|
174
|
+
end
|
175
|
+
|
176
|
+
def generate_gemfile(dir)
|
177
|
+
File.open(dir + '/Gemfile', 'w') do |file|
|
178
|
+
file.write <<-EOS
|
179
|
+
source 'https://rubygems.org'
|
180
|
+
|
181
|
+
gem 'rake'
|
182
|
+
gem 'review', '#{ReVIEW::VERSION}'
|
183
|
+
EOS
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def generate_doc(dir)
|
188
|
+
docdir = dir + '/doc'
|
189
|
+
FileUtils.mkdir_p docdir
|
190
|
+
md_files = Dir.glob(@review_dir + '/doc/*.md').map.to_a
|
191
|
+
FileUtils.cp md_files, docdir
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|