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.



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

def maker
  @maker
end

Class Method Details

.valuesObject



15
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
# File 'lib/review/configure.rb', line 15

def self.values
  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' => ['anonymous'], # 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:uid:#{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??
    'mathml' => nil, # for HTML
    'imgmath' => nil, # for HTML
    '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],
    'externallink' => true,
    'join_lines_by_lang' => nil, # experimental. default should be nil
    # 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
    'image_scale2width' => true,
    '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' => {
      '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
    },
    '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'
    }
  ]
  conf.maker = nil
  conf
end

Instance Method Details

#[](key) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/review/configure.rb', line 113

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



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
# File 'lib/review/configure.rb', line 124

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

#name_of(key) ⇒ Object



153
154
155
156
157
158
159
160
161
# File 'lib/review/configure.rb', line 153

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



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/review/configure.rb', line 163

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