From e0707f6d6a6c5e5b6ee8b99dd629fe3507c57b0d Mon Sep 17 00:00:00 2001 From: Masayoshi Takahashi Date: Wed, 13 Apr 2016 09:50:26 +0900 Subject: [PATCH] allow to use shortcut key of config (#540) enable to use @config["foo"] instead of @config["epubmaker"]["foo"] when using epubmaker --- lib/epubmaker/producer.rb | 2 +- lib/review/configure.rb | 7 ++++--- lib/review/epubmaker.rb | 1 + lib/review/pdfmaker.rb | 1 + test/test_configure.rb | 10 +++++++++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/epubmaker/producer.rb b/lib/epubmaker/producer.rb index 49bb9a0ac..0159c3f9b 100644 --- a/lib/epubmaker/producer.rb +++ b/lib/epubmaker/producer.rb @@ -69,7 +69,7 @@ def coverimage # Update parameters by merging from new parameter hash +params+. def merge_params(params) - @params = @params.deep_merge(params) + @params.deep_merge!(params) complement unless @params["epubversion"].nil? diff --git a/lib/review/configure.rb b/lib/review/configure.rb index 3aebaf7e5..5de06f016 100644 --- a/lib/review/configure.rb +++ b/lib/review/configure.rb @@ -58,12 +58,13 @@ def self.values end def [](key) + maker = self.maker + if maker && self.key?(maker) && self.fetch(maker).key?(key) + return self.fetch(maker).fetch(key, nil) + end if self.key?(key) return self.fetch(key) end - if @maker && self.key?(@maker) - return self.fetch(@maker).fetch(key, nil) - end end def name_of(key) diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index 41cb1cb22..06e683b35 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -33,6 +33,7 @@ def load_yaml(yamlfile) @producer = Producer.new(@params) @producer.load(yamlfile) @params = @producer.params + @params.maker = "epubmaker" end def produce(yamlfile, bookname=nil) diff --git a/lib/review/pdfmaker.rb b/lib/review/pdfmaker.rb index 8e43f4878..e68930490 100644 --- a/lib/review/pdfmaker.rb +++ b/lib/review/pdfmaker.rb @@ -97,6 +97,7 @@ def parse_opts(args) def execute(*args) @config = ReVIEW::Configure.values + @config.maker = "pdfmaker" cmd_config, yamlfile = parse_opts(args) loader = YAMLLoader.new @config.deep_merge!(loader.load_file(yamlfile)) diff --git a/test/test_configure.rb b/test/test_configure.rb index 970f16ddb..4cadb0322 100644 --- a/test/test_configure.rb +++ b/test/test_configure.rb @@ -16,7 +16,8 @@ def setup "urnid" => "http://example.jp/", "date" => "2011-01-01", "language" => "ja", - "epubmaker" => {"flattocindent" => true}, + "epubmaker" => {"flattocindent" => true, + "title" => "Sample Book(EPUB)"}, }) @output = StringIO.new I18n.setup(@config["language"]) @@ -41,6 +42,13 @@ def test_configure_with_maker assert_equal true, @config["epubmaker"]["flattocindent"] end + def test_configure_with_maker_override + @config.maker = "epubmaker" + assert_equal "Sample Book(EPUB)", @config["title"] + @config.maker = "pdfmaker" + assert_equal "Sample Book", @config["title"] + end + def test_configure_with_invalidmaker @config.maker = "pdfmaker" assert_equal nil, @config["flattocindent"]