Skip to content
Browse files

refactoring: make showoff.json a method call

  • Loading branch information...
1 parent fad9baf commit 77cab9c01c40ca1841331f77fc0a9ca79dd3c14c @alexch committed May 4, 2011
Showing with 11 additions and 9 deletions.
  1. +11 −9 lib/showoff_utils.rb
View
20 lib/showoff_utils.rb
@@ -1,5 +1,7 @@
class ShowOffUtils
- SHOWOFF_JSON_FILE = 'showoff.json'
+ def self.presentation_config_file
+ @presentation_config_file ||= 'showoff.json'
+ end
def self.create(dirname,create_samples,dir='one')
Dir.mkdir(dirname) if !File.exists?(dirname)
@@ -16,14 +18,14 @@ def self.create(dirname,create_samples,dir='one')
end
# create showoff.json
- File.open(SHOWOFF_JSON_FILE, 'w+') do |f|
+ File.open(ShowOffUtils.presentation_config_file, 'w+') do |f|
f.puts "{ \"name\": \"My Preso\", \"sections\": [ {\"section\":\"#{dir}\"} ]}"
end
if create_samples
puts "done. run 'showoff serve' in #{dirname}/ dir to see slideshow"
else
- puts "done. add slides, modify #{SHOWOFF_JSON_FILE} and then run 'showoff serve' in #{dirname}/ dir to see slideshow"
+ puts "done. add slides, modify #{ShowOffUtils.presentation_config_file} and then run 'showoff serve' in #{dirname}/ dir to see slideshow"
end
end
end
@@ -39,7 +41,7 @@ def self.create(dirname,create_samples,dir='one')
# password - String containing password to protect your heroku site; nil means no password protection
# use_dot_gems - boolea that, if true, indicates we should use the old, deprecated .gems file instead of Bundler
def self.heroku(name,force,password,use_dot_gems)
- if !File.exists?(SHOWOFF_JSON_FILE)
+ if !File.exists?(ShowOffUtils.presentation_config_file)
puts "fail. not a showoff directory"
return false
end
@@ -181,12 +183,12 @@ def self.add_new_dir(dir)
puts "Creating #{dir}..."
Dir.mkdir dir
- showoff_json = JSON.parse(File.read(SHOWOFF_JSON_FILE))
+ showoff_json = JSON.parse(File.read(ShowOffUtils.presentation_config_file))
showoff_json["section"] = dir
- File.open(SHOWOFF_JSON_FILE,'w') do |file|
+ File.open(ShowOffUtils.presentation_config_file,'w') do |file|
file.puts JSON.generate(showoff_json)
end
- puts "#{SHOWOFF_JSON_FILE} updated"
+ puts "#{ShowOffUtils.presentation_config_file} updated"
end
def self.blank?(string)
@@ -275,7 +277,7 @@ def self.read_code(source_file)
end
def self.showoff_sections(dir = '.')
- index = File.join(dir, ShowOffUtils::SHOWOFF_JSON_FILE )
+ index = File.join(dir, ShowOffUtils.presentation_config_file)
order = nil
if File.exists?(index)
data = JSON.parse(File.read(index))
@@ -293,7 +295,7 @@ def self.showoff_sections(dir = '.')
end
def self.showoff_title(dir = '.')
- index = File.join(dir, ShowOffUtils::SHOWOFF_JSON_FILE )
+ index = File.join(dir, ShowOffUtils.presentation_config_file )
order = nil
if File.exists?(index)
data = JSON.parse(File.read(index))

0 comments on commit 77cab9c

Please sign in to comment.
Something went wrong with that request. Please try again.