Skip to content

Commit

Permalink
extract option parsing to remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalossilva committed Nov 17, 2011
1 parent 6e4c696 commit 26b712f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/showoff_utils.rb
Expand Up @@ -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

Expand Down

0 comments on commit 26b712f

Please sign in to comment.