Skip to content

Commit

Permalink
allow to use shortcut key of config (#540)
Browse files Browse the repository at this point in the history
enable to use @config["foo"] instead of @config["epubmaker"]["foo"] when using epubmaker
  • Loading branch information
takahashim committed Apr 13, 2016
1 parent 785c7f6 commit e0707f6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/epubmaker/producer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
7 changes: 4 additions & 3 deletions lib/review/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/review/epubmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/review/pdfmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 9 additions & 1 deletion test/test_configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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"]
Expand Down

0 comments on commit e0707f6

Please sign in to comment.