Class: CortexReaver::Config

Inherits:
Construct
  • Object
show all
Defined in:
lib/cortex_reaver/config.rb

Overview

Contains site-specific configuration information for a CortexReaver site.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Config

Returns a new instance of Config.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/cortex_reaver/config.rb', line 4

def initialize(*args)
  super *args

  # Defaults
  define :root,
    :desc => 'The local directory where CortexReaver runs.',
    :default => CortexReaver::HOME_DIR
  define :log_root,
    :desc => 'Directory where logs are stored.',
    :default => File.join(root, 'log')
  define :layout_root,
    :desc => 'Local directory where layouts are found.',
    :default => File.join(root, 'layout')
  define :plugin_root,
    :desc => 'Local directory where plugins are found.',
    :default => File.join(root, 'plugins')
  define :public_root,
    :desc => 'Local directory where public files are found.',
    :default => File.join(root, 'public')
  define :view_root,
    :desc => 'Local directory where views are found.',
    :default => File.join(root, 'view')


  define :database, :default => Construct.new
  database.define :adapter,
    :desc => 'Database adapter',
    :default => 'sqlite'
  database.define :username,
    :desc => 'Username',
    :default => nil
  database.define :password,
    :desc => 'Database password',
    :default => nil
  database.define :host,
    :desc => 'Host to connect to for the database.',
    :default => nil
  database.define :port,
    :desc => 'Database port',
    :default => nil
  database.define :database,
    :desc => 'The database on the server to connect to.',
    :default => '/' + File.expand_path(File.join(root, 'cortex_reaver.db'))
  database.define :string,
    :desc => 'A Sequel connection string. If present, overrides the other DB fields.',
    :default => nil

  def database.str
    if string
      string
    else
      str = ''
      str << adapter + '://' if adapter
      str << username if username
      str << ':' + password if username and password
      str << '@' if username or password
      str << host if host
      str << ':' + port if host and port
      str << '/'
      str << database if database
    end
  end

  define :mode,
    :desc => 'Development or production mode.',
    :default => :production
  define :adapter,
    :desc => 'The web server adapter used for Cortex Reaver.',
    :default => 'thin'
  define :cache,
    :desc => 'The caching system used. One of :memory or :memcache',
    :default => :memory
  define :host,
    :desc => 'Host address to bind to.',
    :default => nil
  define :port,
    :desc => 'Port to bind to.',
    :default => 7000

  define :memcache,
    :desc => "Memcache options",
    :default => Construct.new

  memcache.define :servers,
    :desc => "Servers to use. An array of strings like 'host:port:weight'",
    :default => ['localhost']

  define :plugins,
    :desc => 'Plugins configuration space.',
    :default => Construct.new
  plugins.define :enabled, 
    :desc => 'Plugin names to enable.',
    :default => []

  define :site,
    :desc => 'Site configuration options',
    :default => Construct.new
  site.define :url,
    :desc => 'The URL base for the web site. No trailing /.',
    :default => 'http://localhost'
  site.define :name,
    :desc => 'The name of this web site. Used in titles, metadata, etc.',
    :default => 'Cortex Reaver'
  site.define :description,
    :desc => 'A brief description of this site.',
    :default => "Stalks the dark corridors of this station, converting humans to Shodan's perfection."
  site.define :keywords,
    :desc => 'Site keywords',
    :default => 'Cortex Reaver, blog'
  site.define :author,
    :desc => 'The primary author of this site, used in copyright & metadata.',
    :default => 'Shodan'

  define :pidfile,
    :desc => 'Filename which stores the process ID of Cortex Reaver.',
    :default => File.join(root, "cortex_reaver_#{host ? host.to_s + '_' : ''}#{port}.pid")
  define :daemon,
    :desc => "Whether to daemonize. Enabled by default in production mode."
  define :compile_views,
    :desc => 'Whether to compile views. Enabled by default in production.'

  define :view, 
    :desc => "Configuration options for content display.",
    :default => Construct.new
  view.define :sections,
    :desc => "A list of top-level sections for navigation. First is the human-readable name, and second is the URI for the link.",
    :default => [
      ['Journals', '/journals'],
      ['Photographs', '/photographs'],
      ['Tags', '/tags'],
      ['Comments', '/comments'],
      ['About', '/about']
    ]
  view.define :sidebar,
    :desc => "An array of sidebars: [path, view]. Path is matched against the current request path. * globs to any non-slash characters, ** globs to all characters. The view is a string referencing the view in view/sidebar/ to render.
    
For example, if you wanted to render view/sidebar/tweet.rhtml using the twitter plugin, but only on the main page, you could do:

  ['/', 'twitter']

Or to render a related entries box on all photograph pages...

  ['/photographs/show/*', 'related']

You can also just provide a regex for the path, in which case it is matched directly against path_info. For example, here's how I show some custom tags on /photographs and other photo index pages:

  [/^\/photographs(\/(page|tagged))?/, 'explore_photos']
  [/^\/journals(\/(page|tagged))?/, 'explore_journals']
",
    :default => [
      ['*', 'context_navigation'],
      ['/', 'photographs']
    ]

  define :css, :default => Construct.new
  css.define :first,
    :desc => "An array of CSS files to load first, in order.",
    :default => []
  css.define :last,
    :desc => "An array of CSS files to load last, in order.",
    :default => ['custom.css']
  
  define :js, :default => Construct.new
  js.define :first,
    :desc => "An array of Javascript files to load first, in order.",
    :default => [
      'jquery.js',
      'jquery.color.js',
      'jquery.dimensions.js',
      'jquery.hotkeys.js',
      'cookie.js'
    ]
  js.define :last,
    :desc => "An Array of Javascript files to load last, in order.",
    :default => []

  define :photographs,
    :desc => "Photograph configuration options.",
    :default => Construct.new
  photographs.define :sizes,
    :desc => "What sizes of each photograph to maintain.",
    :default => {
      :thumbnail => '168x',
      :grid => '140x140',
      :small => 'x512',
      :medium => 'x768',
      :large => 'x1024'
    }
end

Instance Method Details

#compile_viewsObject



194
195
196
197
198
199
200
# File 'lib/cortex_reaver/config.rb', line 194

def compile_views
  if include? :compile_views
    self[:compile_views]
  else
    mode == :production
  end
end

#daemonObject



202
203
204
205
206
207
208
# File 'lib/cortex_reaver/config.rb', line 202

def daemon
  if include? :daemon
    self[:daemon]
  else
    mode == :production
  end
end

#saveObject

Saves self to disk



211
212
213
214
215
216
# File 'lib/cortex_reaver/config.rb', line 211

def save
  Ramaze::Log.info "Saving config #{to_yaml}"
  File.open(CortexReaver.config_file, 'w') do |file|
    file.write to_yaml
  end
end