Permalink
Browse files

extract option parsing to remove duplication

  • Loading branch information...
goncalossilva committed Nov 17, 2011
1 parent 6e4c696 commit 26b712f5e4f4d1e44acc3a06fc89ad45c8d9a3a3
Showing with 7 additions and 10 deletions.
  1. +7 −10 lib/showoff_utils.rb
View
@@ -274,21 +274,18 @@ def self.showoff_sections(dir,logger)
end
def self.showoff_title(dir = '.')
- index = File.join(dir, ShowOffUtils.presentation_config_file )
- order = nil
- if File.exists?(index)
- data = JSON.parse(File.read(index))
- data.is_a?(Hash) && data['name'] || "Presentation"
- end
+ get_config_option(dir, 'name', "Presentation")
end
def self.showoff_pdf_options(dir = '.')
- index = File.join(dir, ShowOffUtils.presentation_config_file )
- order = nil
+ get_config_option(dir, 'pdf_options', {:page_size => 'Letter', :orientation => 'Landscape'})
+ end
+
+ def self.get_config_option(dir, option, default = nil)
+ index = File.join(dir, ShowOffUtils.presentation_config_file)
if File.exists?(index)
data = JSON.parse(File.read(index))
- data.is_a?(Hash) && data['pdf_options'] || {:page_size => 'Letter',
- :orientation => 'Landscape'}
+ data.is_a?(Hash) && data[option] || default
end
end

0 comments on commit 26b712f

Please sign in to comment.