Class: Relaton::Render::Plateau::General

Inherits:
Jis::General
  • Object
show all
Defined in:
lib/relaton/render-plateau/general.rb

Constant Summary collapse

SWITCH_PUNCT_KEYS =
%w(open-title close-title open-secondary-title close-secondary-title
biblio-field-delimiter comma).freeze

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ General

Returns a new instance of General.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/relaton/render-plateau/general.rb', line 12

def initialize(opt = {})
  @configpath = opt[:config]
  i18n = opt[:i18n] ||
    i18n_klass(language: opt[:language], script: opt[:script],
               locale: opt[:locale], i18nhash: opt[:i18nhash])
  opt["i18n_multi"] = {
    en: i18n_config("en", i18n),
    ja: i18n_config("ja", i18n),
  }
  super
end

Instance Method Details

#bibrenderer_lang(lang, options) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/relaton/render-plateau/general.rb', line 75

def bibrenderer_lang(lang, options)
  yaml, script = bibrenderer_lang_prep(lang)
  # i18n = bibrenderer_lang_config(lang)
  i18n = i18n_config(lang, @i18n.config[@lang]).get
  ::Relaton::Render::Plateau::General.new(options
    .deep_merge(yaml)
    .merge(language: lang, script: script, i18nhash: i18n,
           config: @configpath))
end

#bibrenderer_lang_config(lang) ⇒ Object

cit_i18n is citation lang i18n return merger of the two KILL



47
48
49
50
51
52
53
54
55
56
# File 'lib/relaton/render-plateau/general.rb', line 47

def bibrenderer_lang_config(lang)
  script = lang == "ja" ? "Jpan" : "Latn"
  cit_i18n = ::IsoDoc::Plateau::I18n.new(lang, script).get
  i18n = deep_clone(@i18n.get)
  SWITCH_PUNCT_KEYS.each { |k| i18n["punct"][k] = cit_i18n["punct"][k] }
  # keep Latin punct half-width in Japanese context
  lang == "en" and
    i18n["punct"]["biblio-field-delimiter"] = "<esc>.</esc> "
  i18n
end

#bibrenderer_lang_prep(lang) ⇒ Object



85
86
87
88
89
90
# File 'lib/relaton/render-plateau/general.rb', line 85

def bibrenderer_lang_prep(lang)
  yaml = YAML.load_file(File.join(File.dirname(__FILE__),
                                  "config-#{lang}.yml"))
  script = lang == "ja" ? "Jpan" : "Latn"
  [yaml, script]
end

#citation_renderersObject



34
35
36
37
# File 'lib/relaton/render-plateau/general.rb', line 34

def citation_renderers
  { en: bibrenderer_lang("en", deep_clone(@config)),
    ja: bibrenderer_lang("ja", deep_clone(@config)) }
end

#deep_clone(obj) ⇒ Object



30
31
32
# File 'lib/relaton/render-plateau/general.rb', line 30

def deep_clone(obj)
  Marshal.load(Marshal.dump(obj))
end

#i18n_config(lang, i18n) ⇒ Object

cit_i18n is citation lang i18n i18n is document lang i18n return customised merger of the two



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/relaton/render-plateau/general.rb', line 61

def i18n_config(lang, i18n)
  script = lang == "ja" ? "Jpan" : "Latn"
  cit_i18n = ::IsoDoc::Plateau::I18n.new(lang, script)
  i18n = deep_clone(i18n)
  punct = i18n.get["punct"]
  SWITCH_PUNCT_KEYS.each { |k| punct[k] = cit_i18n.get["punct"][k] }
  # keep Latin punct half-width in Japanese context
  lang == "en" and
    punct["biblio-field-delimiter"] = "<esc>.</esc> "
  i18n.set("punct", punct)
  i18n.set("author_and", cit_i18n.get["author_and"])
  i18n
end

#klass_initialize(_options) ⇒ Object



24
25
26
27
28
# File 'lib/relaton/render-plateau/general.rb', line 24

def klass_initialize(_options)
  super
  @i18nklass = Relaton::Render::Plateau::I18n
  @citeklass = Relaton::Render::Plateau::Citations
end