31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/notehub/notehub.rb', line 31
def initialize(opts={})
opts['config_location'] ||= "#{ENV['HOME']}/.notehub"
opts['config_file'] ||= "#{opts['config_location']}/config.yml"
opts['notes_db'] ||= "#{opts['config_location']}/notes.db"
config_file = opts['config_file']
@notes_db = opts['notes_db']
FileUtils.mkdir_p(opts['config_location'],:mode => 0755) unless File.directory? opts['config_location']
unless File.exists?(config_file)
new_config = {
'publisher_id' => "your_publisher_id",
'secret_key' => "your_secret_key",
'default_password' => "default password for editing notes",
'default_theme' => "light",
'default_font' => 'Georgia'
}
File.open(config_file, 'w') { |yf| YAML::dump(new_config, yf) }
end
config = YAML.load_file(config_file)
@pid = config['publisher_id']
@psk = config['secret_key']
if config['default_password'] && config['default_password'].length > 0
@default_password = config['default_password']
else
@default_password = false
end
@default_theme = config['default_theme'] || 'light'
@default_font = config['default_font'] || 'Georgia'
@default_header_font = config['default_header_font'] || 'Georgia'
if @pid == "your_publisher_id" || @psk == "your_secret_key"
puts "Please edit #{config_file} and run again"
Process.exit 1
end
unless File.exists?(@notes_db)
new_db = {'notes' => {}}
File.open(@notes_db, 'w') { |yf| YAML::dump(new_db, yf) }
end
@notes = YAML.load_file(@notes_db)
end
|