Skip to content

Commit

Permalink
Merge pull request #1549 from kmuto/add-configure-create
Browse files Browse the repository at this point in the history
add ReVIEW::Configure.create
  • Loading branch information
takahashim authored Aug 18, 2020
2 parents 2d89aa0 + 360f17c commit c43ffd1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 52 deletions.
20 changes: 20 additions & 0 deletions lib/review/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ def self.values
conf
end

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 => e
error "yaml error #{e.message}"
end
end
# YAML configs will be overridden by command line options.
if config
conf.deep_merge!(config)
end

conf
end

def [](key)
maker = self.maker
if maker && self.key?(maker) && self.fetch(maker) && self.fetch(maker).key?(key)
Expand Down
15 changes: 3 additions & 12 deletions lib/review/epubmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,9 @@ def log(msg)
end

def load_yaml(yamlfile)
loader = ReVIEW::YAMLLoader.new
@config = ReVIEW::Configure.values
begin
@config.deep_merge!(loader.load_file(yamlfile))
rescue => e
error "yaml error #{e.message}"
end

@producer = Producer.new(@config)
@producer.load(yamlfile)
@config = @producer.config
@config.maker = 'epubmaker'
end

def self.execute(*args)
Expand Down Expand Up @@ -94,13 +85,13 @@ def parse_opts(args)
end

def execute(*args)
@config = ReVIEW::Configure.values
@config.maker = 'epubmaker'
cmd_config, yamlfile, exportfile = parse_opts(args)
error "#{yamlfile} not found." unless File.exist?(yamlfile)

@config = ReVIEW::Configure.create(maker: 'epubmaker',
yamlfile: yamlfile,
config: cmd_config)
load_yaml(yamlfile)
@config.deep_merge!(cmd_config)
update_log_level
log("Loaded yaml file (#{yamlfile}).")

Expand Down
13 changes: 3 additions & 10 deletions lib/review/idgxmlmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,12 @@ def remove_old_files(path)
end

def execute(*args)
@config = ReVIEW::Configure.values
@config.maker = 'idgxmlmaker'
cmd_config, yamlfile = parse_opts(args)
error "#{yamlfile} not found." unless File.exist?(yamlfile)

begin
loader = ReVIEW::YAMLLoader.new
@config.deep_merge!(loader.load_file(yamlfile))
rescue => e
error "yaml error #{e.message}"
end
# YAML configs will be overridden by command line options.
@config.deep_merge!(cmd_config)
@config = ReVIEW::Configure.create(maker: 'idgxmlmaker',
yamlfile: yamlfile,
config: cmd_config)
I18n.setup(@config['language'])
begin
generate_idgxml_files(yamlfile)
Expand Down
13 changes: 3 additions & 10 deletions lib/review/pdfmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,13 @@ def parse_opts(args)
end

def execute(*args)
@config = ReVIEW::Configure.values
@config.maker = 'pdfmaker'
cmd_config, yamlfile = parse_opts(args)
error "#{yamlfile} not found." unless File.exist?(yamlfile)

begin
loader = ReVIEW::YAMLLoader.new
@config.deep_merge!(loader.load_file(yamlfile))
rescue => e
error "yaml error #{e.message}"
end
@config = ReVIEW::Configure.create(maker: 'pdfmaker',
yamlfile: yamlfile,
config: cmd_config)

# YAML configs will be overridden by command line options.
@config.deep_merge!(cmd_config)
I18n.setup(@config['language'])
@basedir = File.absolute_path(File.dirname(yamlfile))

Expand Down
13 changes: 3 additions & 10 deletions lib/review/textmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,13 @@ def remove_old_files(path)
end

def execute(*args)
@config = ReVIEW::Configure.values
@config.maker = 'textmaker'
cmd_config, yamlfile = parse_opts(args)
error "#{yamlfile} not found." unless File.exist?(yamlfile)

begin
loader = ReVIEW::YAMLLoader.new
@config.deep_merge!(loader.load_file(yamlfile))
rescue => e
error "yaml error #{e.message}"
end
@config = ReVIEW::Configure.create(maker: 'textmaker',
yamlfile: yamlfile,
config: cmd_config)

# YAML configs will be overridden by command line options.
@config.deep_merge!(cmd_config)
I18n.setup(@config['language'])
begin
generate_text_files(yamlfile)
Expand Down
14 changes: 4 additions & 10 deletions lib/review/webmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,13 @@ def remove_old_files(path)
end

def execute(*args)
@config = ReVIEW::Configure.values
@config.maker = 'webmaker'
cmd_config, yamlfile = parse_opts(args)
error "#{yamlfile} not found." unless File.exist?(yamlfile)

begin
loader = ReVIEW::YAMLLoader.new
@config.deep_merge!(loader.load_file(yamlfile))
rescue => e
error "yaml error #{e.message}"
end
# YAML configs will be overridden by command line options.
@config.deep_merge!(cmd_config)
@config = ReVIEW::Configure.create(maker: 'webmaker',
yamlfile: yamlfile,
config: cmd_config)

@config['htmlext'] = 'html'
I18n.setup(@config['language'])
begin
Expand Down

0 comments on commit c43ffd1

Please sign in to comment.