rb_latex 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dca154aba4bc70953a487e613982442284045992fc03a28b760ca98b4be91efe
4
- data.tar.gz: c86e0d3eb16abd4496166dc2fe9951e6912deb60db874e47e74dc01dd687b3d7
3
+ metadata.gz: f23586d00b1e945e6b2d7be44e10132f18f5e5887805727d61388e813a426978
4
+ data.tar.gz: ab0cd3bdbf6578bde98a32c358c54470f93bcf8b035b03e696672c24bd25ad63
5
5
  SHA512:
6
- metadata.gz: a3abc1eef1e91e6ed289c28b080663a263d6a30e6e11d11a3937de26ea62f34b9a9d332ab020701304b0a6ec1d914edaae09b16d554f939f0031fa2e490aeaea
7
- data.tar.gz: 07d05a3045cb831898a51efb068100f50cc887b1643565b0c6aa8e2473a00c040562d1a5914cfbaa0694f70d91bb546098710a6b1ce7c575948a7aaa46961db9
6
+ metadata.gz: eddef7a892507795391daf04981430594eddd564a99ad8e782c76447c17e8a9071799e52eec454aebc7635bf846f14743ed885924d91e45fbc8a76c6bd78ebe7
7
+ data.tar.gz: 2f19b3faab3c6c07c5e36dbcd6253b1021746d59eec25f1b52c4c868bf23dbe11b64b9a480f9bf278ddb276fce5edd974a71fd740d9f9158a7d4c0f5b4a89594
data/lib/rb_latex.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require "rb_latex/version"
2
2
  require "rb_latex/error"
3
+ require "rb_latex/utils"
3
4
  require "rb_latex/maker"
4
5
  require "rb_latex/item_list"
5
6
  require "rb_latex/meta_info"
6
7
  require "rb_latex/logger"
7
- require "rb_latex/utils"
8
8
 
9
9
  module RbLatex
10
10
  TEMPLATES_DIR = File.join(File.dirname(__FILE__), "../templates")
@@ -12,7 +12,11 @@ module RbLatex
12
12
  attr_accessor :dvipdf_command
13
13
  attr_accessor :debug
14
14
  attr_accessor :book_name
15
- attr_accessor :colophons
15
+ attr_accessor :titlepage
16
+ attr_accessor :colophon
17
+ attr_accessor :colophon_before
18
+ attr_accessor :colophon_after
19
+ attr_accessor :colophon_template
16
20
  attr_reader :work_dir
17
21
 
18
22
  RbLatex::MetaInfo::ATTRS.each do |name|
@@ -37,7 +41,11 @@ module RbLatex
37
41
  @debug = nil
38
42
  @book_name = "book"
39
43
  @default_option = nil
40
- @colophons = nil
44
+ @colophon_template = "colophon.tex.erb"
45
+ @colophon = nil
46
+ @colophon_before = nil
47
+ @colophon_after = nil
48
+ @titlepage = nil
41
49
  end
42
50
 
43
51
  def add_item(filename, content)
@@ -79,8 +87,8 @@ module RbLatex
79
87
  File.write(File.join(dir, book_filename(".tex")), book_tex)
80
88
  rblatexdefault_sty = apply_template("rblatexdefault.sty")
81
89
  File.write(File.join(dir, "rblatexdefault.sty"), rblatexdefault_sty)
82
- if @colophons
83
- colophon_tex = apply_template("colophon.tex.erb")
90
+ if @colophon
91
+ colophon_tex = apply_template(@colophon_template, template_dir: @colophon_dir)
84
92
  File.write(File.join(dir, "colophon.tex"), colophon_tex)
85
93
  end
86
94
  end
@@ -142,8 +150,9 @@ module RbLatex
142
150
  end
143
151
  end
144
152
 
145
- def apply_template(template_file)
146
- template = File.read(File.join(RbLatex::TEMPLATES_DIR, template_file))
153
+ def apply_template(template_file, template_dir: nil)
154
+ template_dir ||= RbLatex::TEMPLATES_DIR
155
+ template = File.read(File.join(template_dir, template_file))
147
156
  return ERB.new(template, nil, '-').result(binding)
148
157
  end
149
158
 
@@ -1,5 +1,6 @@
1
1
  module RbLatex
2
2
  class MetaInfo
3
+ include RbLatex::Utils
3
4
 
4
5
  ATTRS = %i(title creator page_progression_direction language publisher)
5
6
 
@@ -43,15 +44,22 @@ module RbLatex
43
44
  end
44
45
 
45
46
  def to_latex
47
+ "\\title{#{escape_latex(title)}}\n"+
48
+ "\\author{#{escape_latex(author)}}\n"+
49
+ "\\date{}\n"+
46
50
  "\\newcommand{\\rblatexTitle}{#{escape_latex(title)}}\n"+
47
51
  "\\newcommand{\\rblatexAuthor}{#{escape_latex(author)}}\n"+
48
- "\\newcommand{\\rblatexPubdate}{#{escape_latex(date_to_s)}}\n"+
52
+ "\\newcommand{\\rblatexPubdate}{#{escape_latex(pubdate_to_s)}}\n"+
49
53
  "\\newcommand{\\rblatexPublisher}{#{escape_latex(publisher)}}\n"+
50
54
  "\\newcommand{\\rblatexPageDirection}{#{escape_latex(page_progression_direction)}}\n"
51
55
  end
52
56
 
53
57
  def date_format(time)
54
- time.strftime("%Y年%-m月%-d日")
58
+ if time
59
+ time.strftime("%Y年%-m月%-d日")
60
+ else
61
+ ""
62
+ end
55
63
  end
56
64
 
57
65
  def add_creator(name, role)
@@ -15,7 +15,7 @@ module RbLatex
15
15
  }
16
16
 
17
17
  def escape_latex(str)
18
- str.each_char.map do |char|
18
+ str.to_s.each_char.map do |char|
19
19
  ESCAPE_CHARS[char] || char
20
20
  end.join("")
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module RbLatex
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,5 +1,8 @@
1
1
  \documentclass[<%= @dclass_option %>]{<%= @dclass %>}
2
2
 
3
+ %% meta_info
4
+ <%= @meta_info.to_latex %>
5
+
3
6
  %% load RbLatex default stlye
4
7
  \usepackage[<%= @default_option %>]{rblatexdefault}
5
8
 
@@ -9,6 +12,9 @@
9
12
  }
10
13
 
11
14
  \begin{document}
15
+ <% if @titlepage %>
16
+ \maketitle
17
+ <% end %>
12
18
  <% @item_list.filenames.each_with_index do |filename, idx| %>
13
19
  \input{<%= filename %>}
14
20
  <% if @item_list.filenames.size > idx + 1 %>
@@ -1,8 +1,11 @@
1
1
  \newpage
2
2
  \thispagestyle{empty}
3
3
  \vspace*{\fill}
4
+ {\noindent\Large \rblatexTitle } \\
5
+ \rule[0pt]{\textwidth}{0.5pt} \\
6
+ <%= @colophon_before || "\\rblatexColophonBefore" %>
4
7
  \begin{tabular}{ll}
5
- <%- @colophons.each do |key, val| -%>
8
+ <%- @colophon.each do |key, val| -%>
6
9
  <%- if val.kind_of? Array -%>
7
10
  <%- val.each_with_index do |item, idx| -%>
8
11
  <%- if idx > 0 -%>
@@ -16,3 +19,6 @@
16
19
  <%- end -%>
17
20
  <%- end -%>
18
21
  \end{tabular}
22
+ ~ \\
23
+ \rule[0pt]{\textwidth}{0.5pt} \\
24
+ {\small <%= @colophon_after || "\\rblatexColophonAfter" %>}
@@ -33,4 +33,7 @@
33
33
  \newcommand{\rblatexFileSeparator}{\newpage}
34
34
  \newcommand{\rblatexEmptyLine}{\hspace{0pt}\par}
35
35
 
36
+ \newcommand{\rblatexColophonBefore}{~}
37
+ \newcommand{\rblatexColophonAfter}{~}
38
+
36
39
  \endinput
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb_latex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takahashim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-09 00:00:00.000000000 Z
11
+ date: 2018-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler