Class: ReVIEW::Configure

Inherits:
Hash show all
Defined in:
lib/review/configure.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#deep_merge, #deep_merge!

Instance Attribute Details

#makerObject

Returns the value of attribute maker.



14
15
16
# File 'lib/review/configure.rb', line 14

def maker
  @maker
end

Class Method Details

.create(maker: nil, yamlfile: nil, config: nil) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/review/configure.rb', line 160

def self.create(maker: nil, yamlfile: nil, config: nil)
  conf = self.values
  conf.maker = maker

  if yamlfile
    begin
      loader = ReVIEW::YAMLLoader.new
      conf.deep_merge!(loader.load_file(yamlfile))
    rescue StandardError => e
      raise ReVIEW::ConfigError, "yaml error #{e.message}"
    end
  end

  # YAML configs will be overridden by command line options.
  if config
    conf.deep_merge!(config)
  end

  conf.migrate_parameters

  conf
end

.valuesObject

rubocop:disable Metrics/MethodLength



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/review/configure.rb', line 16

def self.values # rubocop:disable Metrics/MethodLength
  conf = Configure[
    # These parameters can be overridden by YAML file.
    'bookname' => 'book', # it defines epub file name also
    'booktitle' => 'Re:VIEW Sample Book',
    'title' => nil,
    'aut' => nil, # author
    'prt' => nil, # printer(publisher)
    'asn' => nil, # associated name
    'ant' => nil, # bibliographic antecedent
    'clb' => nil, # Collaborator
    'edt' => nil, # Editor
    'dsr' => nil, # Designer
    'ill' => nil, # Illustrator
    'pht' => nil, # Photographer
    'trl' => nil, # Translator
    'date' => Time.now.strftime('%Y-%m-%d'), # publishing date
    'rights' => nil, # Copyright messages
    'description' => nil, # Description
    'urnid' => "urn:uuid:#{SecureRandom.uuid}", # Identifier
    'stylesheet' => [], # stylesheet file
    'coverfile' => nil, # content file of body of cover page
    'mytoc' => nil, # whether make own table of contents or not
    'params' => '', # specify review2html parameters
    'toclevel' => 3, # level of toc
    'secnolevel' => 2, # level of section #
    'epubversion' => 3,
    'titlepage' => true, # Use title page
    'toc' => nil, # Use table of contents in body
    'colophon' => nil, # Use colophon
    'debug' => nil, # debug flag
    'catalogfile' => 'catalog.yml',
    'language' => 'ja', # XXX default language should be JA??
    'math_format' => nil,
    'htmlext' => 'html',
    'htmlversion' => 5,
    'contentdir' => '.',
    'imagedir' => 'images',
    'image_ext' => %w[png gif jpg jpeg svg ttf woff otf],
    'fontdir' => 'fonts',
    'chapter_file' => 'CHAPS',
    'part_file' => 'PART',
    'reject_file' => 'REJECT',
    'predef_file' => 'PREDEF',
    'postdef_file' => 'POSTDEF',
    'page_metric' => ReVIEW::Book::PageMetric::A5,
    'ext' => '.re',
    'image_types' => %w[.ai .psd .eps .pdf .tif .tiff .png .bmp .jpg .jpeg .gif .svg],
    'bib_file' => 'bib.re',
    'words_file' => nil,
    'colophon_order' => %w[aut csl trl dsr ill cov edt pbl contact prt pht],
    'chapterlink' => true,
    'externallink' => true,
    'join_lines_by_lang' => nil, # experimental. default should be nil
    'table_row_separator' => 'tabs',
    # for Playwright
    'playwright_options' => {
      'playwright_path' => './node_modules/.bin/playwright',
      'selfcrop' => true,
      'pdfcrop_path' => 'pdfcrop',
      'pdftocairo_path' => 'pdftocairo'
    },
    # for IDGXML
    'tableopt' => nil,
    'listinfo' => nil,
    'nolf' => true,
    'chapref' => nil,
    'structuredxml' => nil,
    'pt_to_mm_unit' => 0.3528, # DTP: 1pt = 0.3528mm, JIS: 1pt = 0.3514mm
    # for LaTeX
    'footnotetext' => nil,
    'texcommand' => 'uplatex',
    'texoptions' => '-interaction=nonstopmode -file-line-error -halt-on-error',
    '_texdocumentclass' => ['review-jsbook', ''],
    'texstyle' => ['reviewmacro'],
    'dvicommand' => 'dvipdfmx',
    'dvioptions' => '-d 5 -z 9',
    # for PDFMaker
    'pdfmaker' => {
      'image_scale2width' => true,
      'makeindex' => nil, # Make index page
      'makeindex_command' => 'mendex', # works only when makeindex is true
      'makeindex_options' => '-f -r -I utf8',
      'makeindex_sty' => nil,
      'makeindex_dic' => nil,
      'makeindex_mecab' => true,
      'makeindex_mecab_opts' => '-Oyomi',
      'use_cover_nombre' => true,
      'use_original_image_size' => nil
    },
    'imgmath_options' => {
      'format' => 'png',
      'converter' => 'pdfcrop', # dvipng | pdfcrop
      'pdfcrop_cmd' => 'pdfcrop --hires %i %o',
      'extract_singlepage' => nil,
      'pdfextract_cmd' => 'pdfjam -q --outfile %o %i %p',
      'preamble_file' => nil,
      'fontsize' => 10,
      'lineheight' => 10 * 1.2,
      'pdfcrop_pixelize_cmd' => 'pdftocairo -%t -r 90 -f %p -l %p -singlefile %i %O',
      'dvipng_cmd' => 'dvipng -T tight -z 9 -p %p -l %p -o %o %i'
    },
    'caption_position' => {
      'list' => 'top',
      'image' => 'bottom',
      'table' => 'top',
      'equation' => 'top'
    },
    # for EPUBMaker
    'modified' => Time.now.utc.strftime('%Y-%02m-%02dT%02H:%02M:%02SZ'),
    'isbn' => nil,
    'titlefile' => nil,
    'originaltitlefile' => nil,
    'profile' => nil,
    'direction' => 'ltr',
    'image_maxpixels' => 4_000_000,
    'font_ext' => %w[ttf woff otf],
    'epubmaker' => {
      'flattoc' => nil,
      'flattocindent' => true,
      'ncx_indent' => [],
      'zip_stage1' => 'zip -0Xq',
      'zip_stage2' => 'zip -Xr9Dq',
      'zip_addpath' => nil,
      'hook_beforeprocess' => nil,
      'hook_afterfrontmatter' => nil,
      'hook_afterbody' => nil,
      'hook_afterbackmatter' => nil,
      'hook_aftercopyimage' => nil,
      'hook_prepack' => nil,
      'rename_for_legacy' => nil,
      'verify_target_images' => nil,
      'force_include_images' => [],
      'cover_linear' => nil,
      'back_footnote' => nil
    },
    'textmaker' => {
      'th_bold' => nil
    }
  ]
  conf.maker = nil
  conf
end

Instance Method Details

#[](key) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
# File 'lib/review/configure.rb', line 208

def [](key)
  maker = self.maker
  if maker && self.key?(maker) && self.fetch(maker) && self.fetch(maker).key?(key)
    return self.fetch(maker).fetch(key, nil)
  end
  if self.key?(key)
    return self.fetch(key)
  end

  nil
end

#check_version(version, exception: true) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/review/configure.rb', line 220

def check_version(version, exception: true)
  unless self.key?('review_version')
    if exception
      raise ReVIEW::ConfigError, 'configuration file has no review_version property.'
    else
      return false
    end
  end

  if self['review_version'].blank?
    return true
  end

  if self['review_version'].to_i != version.to_i ## major version
    if exception
      raise ReVIEW::ConfigError, 'major version of configuration file is different.'
    else
      return false
    end
  elsif self['review_version'].to_f > version.to_f ## minor version
    if exception
      raise ReVIEW::ConfigError, "Re:VIEW version '#{version}' is older than configuration file's version '#{self['review_version']}'."
    else
      return false
    end
  end
  return true
end

#migrate_parametersObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/review/configure.rb', line 183

def migrate_parameters
  # string to array
  %w[subject aut
     a-adp a-ann a-arr a-art a-asn a-aqt a-aft a-aui a-ant a-bkp a-clb a-cmm a-dsr a-edt
     a-ill a-lyr a-mdc a-mus a-nrt a-oth a-pht a-prt a-red a-rev a-spn a-ths a-trc a-trl
     adp ann arr art asn aut aqt aft aui ant bkp clb cmm dsr edt
     ill lyr mdc mus nrt oth pht pbl prt red rev spn ths trc trl
     stylesheet rights].each do |item|
    if self[item] && self[item].is_a?(String)
      self[item] = [self[item]]
    end
  end

  # backward compatibility
  if self['mathml']
    warn '"mathml: true" is obsoleted. Please use "math_format: mathml"'
    self['math_format'] = 'mathml'
  end

  if self['imgmath']
    warn '"imgmath: true" is obsoleted. Please use "math_format: imgmath"'
    self['math_format'] = 'imgmath'
  end
end

#name_of(key) ⇒ Object



249
250
251
252
253
254
255
256
257
# File 'lib/review/configure.rb', line 249

def name_of(key)
  if self[key].is_a?(Array)
    self[key].join(',') # i18n?
  elsif self[key].is_a?(Hash)
    self[key]['name']
  else
    self[key]
  end
end

#names_of(key) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/review/configure.rb', line 259

def names_of(key)
  if self[key].is_a?(Array)
    self[key].map do |a|
      if a.is_a?(Hash)
        a['name']
      else
        a
      end
    end
  elsif self[key].is_a?(Hash)
    [self[key]['name']]
  else
    [self[key]]
  end
end