sinatra-settings 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ doc
21
+
22
+ ## PROJECT::SPECIFIC
23
+ spec/fixtures/
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 kematzy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,133 @@
1
+ = Sinatra::Settings
2
+
3
+ A Sinatra Extension that shows your app's settings and other debug information.
4
+
5
+ Ever wanted an overview of all Sinatra settings (formerly options) in your app?
6
+
7
+ Well, now you can through this Sinatra Extension which makes that task dead simple,
8
+ while also adding in some other useful debug information in the output.
9
+
10
+ With a heavy dose of inspiration taken from Sinatra's Show Exception output page.
11
+
12
+
13
+ == Installation
14
+
15
+ # Add Gemcutter to your RubyGems sources
16
+ $ gem sources -a http://gemcutter.com
17
+
18
+ $ (sudo)? gem install sinatra-settings
19
+
20
+ == Dependencies
21
+
22
+ This Gem depends upon the following:
23
+
24
+ === Runtime:
25
+
26
+ * sinatra ( >= 1.0.a )
27
+
28
+
29
+ === Development & Tests:
30
+
31
+ * rspec (>= 1.3.0 )
32
+ * rack-test (>= 0.5.3)
33
+ * rspec_hpricot_matchers (>= 0.1.0)
34
+ * sinatra-tests (>= 0.1.6)
35
+
36
+
37
+ == Getting Started
38
+
39
+ To view the settings in your app, just require and register the extension
40
+ in your sub-classed Sinatra app:
41
+
42
+ require 'sinatra/settings'
43
+
44
+ class YourApp < Sinatra::Base
45
+
46
+ register(Sinatra::Settings)
47
+
48
+ enable :show_settings # turn it on
49
+
50
+ <snip...>
51
+ end
52
+
53
+
54
+ Then at the bottom of your App's layout - <tt>layout.(erb|haml)</tt> add the following:
55
+
56
+
57
+ <snip...>
58
+
59
+ <%= show_settings_output? %>
60
+
61
+ </body>
62
+ </html>
63
+
64
+
65
+ Reload your app and view the added content at the bottom of your page.
66
+
67
+ You can see an example of the output here:
68
+
69
+ http://kematzy.com/tmp/sinatra-settings/sinatra-settings-extension-output-50.jpg
70
+
71
+
72
+
73
+ That's really all there is.
74
+
75
+
76
+ == Configuration Options
77
+
78
+ By default, these are the settings:
79
+
80
+
81
+ # don't show settings by default
82
+ set :show_settings, false
83
+
84
+ # only show the settings in development mode.
85
+ set :show_settings_environment, :development
86
+
87
+
88
+ Apart from turning it On / Off, you can also set the output to show up
89
+ in <tt>:production</tt> or <tt>:test</tt> enviroments.
90
+
91
+ The advantage of having two configuration 'switches' is that you can leave
92
+ all the code as is, and in +:development+ it will show the output, but in
93
+ <tt>:production</tt> no output will be shown
94
+ (other than a tiny HTML comment telling you it's Off)
95
+
96
+
97
+ That's it. I hope that's easy enough.
98
+
99
+
100
+ == RTFM
101
+
102
+ If the above is not clear enough, please check the Specs for a better understanding.
103
+
104
+
105
+ == Errors / Bugs
106
+
107
+ If something is not behaving intuitively, it is a bug, and should be reported.
108
+ Report it here: http://github.com/kematzy/sinatra-settings/issues
109
+
110
+
111
+ == TODOs
112
+
113
+ * Decide whether this functionality should really be incorporated into a
114
+ Sinatra::Debug extension instead.
115
+
116
+ * Any other improvements you or I can think of.
117
+
118
+
119
+ == Note on Patches/Pull Requests
120
+
121
+ * Fork the project.
122
+ * Make your feature addition or bug fix.
123
+ * Add tests for it. This is important so I don't break it in a
124
+ future version unintentionally.
125
+ * Commit, do not mess with rakefile, version, or history.
126
+ * (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
127
+ * Send me a pull request. Bonus points for topic branches.
128
+
129
+ == Copyright
130
+
131
+ Copyright (c) 2010 kematzy. Released under the MIT License.
132
+
133
+ See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,90 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sinatra-settings"
8
+ gem.summary = %Q{A Sinatra Extension that shows your app's settings and other debug information}
9
+ gem.description = %Q{Want an overview of all Sinatra settings (formerly options) in your app? This Sinatra Extension makes that dead simple.}
10
+ gem.email = "kematzy@gmail.com"
11
+ gem.homepage = "http://github.com/kematzy/sinatra-settings"
12
+ gem.authors = ["kematzy"]
13
+ gem.add_dependency "sinatra", ">= 0.10.1"
14
+ gem.add_development_dependency "sinatra-tests", ">= 0.1.6"
15
+ gem.add_development_dependency "rspec", ">= 1.3.0"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
33
+ spec.pattern = 'spec/**/*_spec.rb'
34
+ spec.rcov = true
35
+ end
36
+
37
+ namespace :spec do
38
+
39
+ desc "Run all specifications quietly"
40
+ Spec::Rake::SpecTask.new(:quiet) do |t|
41
+ t.libs << "lib"
42
+ t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
43
+ end
44
+
45
+ desc "Run specific spec (SPEC=/path/2/file)"
46
+ Spec::Rake::SpecTask.new(:select) do |t|
47
+ t.libs << "lib"
48
+ t.spec_files = [ENV["SPEC"]]
49
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
50
+ end
51
+
52
+ end
53
+
54
+ task :spec => :check_dependencies
55
+
56
+ task :default => :spec
57
+
58
+ require 'rake/rdoctask'
59
+ Rake::RDocTask.new do |rdoc|
60
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
61
+
62
+ rdoc.rdoc_dir = 'rdoc'
63
+ rdoc.title = "sinatra-settings #{version}"
64
+ rdoc.rdoc_files.include('README*')
65
+ rdoc.rdoc_files.include('lib/**/*.rb')
66
+ end
67
+
68
+
69
+ desc 'Build the rdoc HTML Files'
70
+ task :docs do
71
+ version = File.exist?('VERSION') ? IO.read('VERSION').chomp : "[Unknown]"
72
+
73
+ sh "sdoc -N --title 'Sinatra::Settings v#{version}' lib/ README.rdoc"
74
+ end
75
+
76
+ namespace :docs do
77
+
78
+ desc 'Remove rdoc products'
79
+ task :remove => [:clobber_rdoc]
80
+
81
+ desc 'Force a rebuild of the RDOC files'
82
+ task :rebuild => [:rerdoc]
83
+
84
+ desc 'Build docs, and open in browser for viewing (specify BROWSER)'
85
+ task :open => [:docs] do
86
+ browser = ENV["BROWSER"] || "safari"
87
+ sh "open -a #{browser} doc/index.html"
88
+ end
89
+
90
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,428 @@
1
+
2
+ require 'sinatra/base'
3
+
4
+
5
+ module Sinatra
6
+
7
+ # :stopdoc:
8
+ ##
9
+ # Add :sinatra_settings_for_inspection setting to base, so that it's
10
+ # always available
11
+ #
12
+ class Base
13
+
14
+ set :sinatra_settings_for_inspection, %w(
15
+ app_file bind clean_trace dump_errors environment lock
16
+ logging method_override port public raise_errors reload_templates
17
+ root run running server sessions show_exceptions static views
18
+ )
19
+
20
+ end #/class Base
21
+
22
+ # :startdoc:
23
+
24
+ # = Sinatra::Settings
25
+ #
26
+ # A Sinatra Extension that shows your app's settings and other debug information.
27
+ #
28
+ # Ever wanted an overview of all Sinatra settings (formerly options) in your app?
29
+ #
30
+ # Well, now you can through this Sinatra Extension which makes that task dead simple,
31
+ # while also adding in some other useful debug information in the output.
32
+ #
33
+ # With a heavy dose of inspiration taken from Sinatra's Show Exception output page.
34
+ #
35
+ #
36
+ # == Installation
37
+ #
38
+ # # Add Gemcutter to your RubyGems sources
39
+ # $ gem sources -a http://gemcutter.com
40
+ #
41
+ # $ (sudo)? gem install sinatra-settings
42
+ #
43
+ # == Dependencies
44
+ #
45
+ # This Gem depends upon the following:
46
+ #
47
+ # === Runtime:
48
+ #
49
+ # * sinatra ( >= 1.0.a )
50
+ #
51
+ #
52
+ # === Development & Tests:
53
+ #
54
+ # * rspec (>= 1.3.0 )
55
+ # * rack-test (>= 0.5.3)
56
+ # * rspec_hpricot_matchers (>= 0.1.0)
57
+ # * sinatra-tests (>= 0.1.6)
58
+ #
59
+ #
60
+ # == Getting Started
61
+ #
62
+ # To view the settings in your app, just require and register the extension
63
+ # in your sub-classed Sinatra app:
64
+ #
65
+ # require 'sinatra/settings'
66
+ #
67
+ # class YourApp < Sinatra::Base
68
+ #
69
+ # register(Sinatra::Settings)
70
+ #
71
+ # enable :show_settings # turn it on
72
+ #
73
+ # <snip...>
74
+ # end
75
+ #
76
+ #
77
+ # Then at the bottom of your App's layout - <tt>layout.(erb|haml)</tt> add the following:
78
+ #
79
+ #
80
+ # <snip...>
81
+ #
82
+ # <%= show_settings_output? %>
83
+ #
84
+ # </body>
85
+ # </html>
86
+ #
87
+ #
88
+ # Reload your app and view the added content at the bottom of your page.
89
+ #
90
+ # You can see an example of the output here:
91
+ #
92
+ # http://kematzy.com/tmp/sinatra-settings/sinatra-settings-extension-output-50.jpg
93
+ #
94
+ #
95
+ # That's really all there is.
96
+ #
97
+ #
98
+ # == Configuration Options
99
+ #
100
+ # By default, these are the settings:
101
+ #
102
+ #
103
+ # # don't show settings by default
104
+ # set :show_settings, false
105
+ #
106
+ # # only show the settings in development mode.
107
+ # set :show_settings_environment, :development
108
+ #
109
+ #
110
+ # Apart from turning it On / Off, you can also set the output to show up
111
+ # in <tt>:production</tt> or <tt>:test</tt> enviroments.
112
+ #
113
+ # The advantage of having two configuration 'switches' is that you can leave
114
+ # all the code as is, and in +:development+ it will show the output, but in
115
+ # <tt>:production</tt> no output will be shown
116
+ # (other than a tiny HTML comment telling you it's Off)
117
+ #
118
+ #
119
+ # That's it. I hope that's easy enough.
120
+ #
121
+ #
122
+ # == TODOs
123
+ #
124
+ # * Decide whether this functionality should really be incorporated into a
125
+ # Sinatra::Debug extension instead.
126
+ #
127
+ # * Any other improvements you or I can think of.
128
+ #
129
+ # == Copyright
130
+ #
131
+ # Copyright (c) 2010 kematzy. Released under the MIT License.
132
+ #
133
+ # See LICENSE for details.
134
+ #
135
+
136
+ module Settings
137
+
138
+ VERSION = '0.1.0' unless const_defined?(:VERSION)
139
+ def self.version; "Sinatra::Settings v#{VERSION}"; end
140
+
141
+
142
+ module Helpers
143
+
144
+ # Add Rack::Utils if not already present
145
+ unless respond_to?(:h)
146
+ include Rack::Utils
147
+ alias_method :h, :escape_html
148
+ end
149
+
150
+
151
+ ##
152
+ # Convenience helper method that returns a Hash, nicely
153
+ # formatted with all 'registered' settings in the app.
154
+ #
155
+ # Mainly used in the HTML output of :show_settings_output? method,
156
+ # but can be used for other debug purposes.
157
+ #
158
+ # ==== Examples
159
+ #
160
+ # settings_inspect => {...} # a Hash with settings.
161
+ #
162
+ #
163
+ # @api public
164
+ def settings_inspect
165
+ out = {}
166
+ settings.sinatra_settings_for_inspection.uniq.each do |s|
167
+ out[s.to_sym] = self.class.respond_to?(s.to_sym) ? self.class.send(s) : nil
168
+ end
169
+ out
170
+ end
171
+
172
+
173
+ ##
174
+ # Add settings debug output to the page.
175
+ # Controlled by the following configurations:
176
+ #
177
+ # * set :show_settings_output, (boolean) => turns output On / Off
178
+ # * set :show_settings_environment, (symbol) :development/:production => turns output On in the given environment
179
+ #
180
+ # ==== Examples
181
+ #
182
+ # <%= show_settings_output? %> => will output the settings debug if enabled.
183
+ #
184
+ # @api public/private
185
+ def show_settings_output?
186
+ if _show_settings_output?
187
+ erb(TEMPLATE, :layout => false)
188
+ else
189
+ "<!-- :show_settings is [#{settings.show_settings ? 'ON' : 'OFF'}] -->"
190
+ end
191
+ end
192
+
193
+
194
+ protected
195
+
196
+ # :stopdoc:
197
+
198
+ def _show_settings_output?
199
+ return (
200
+ settings.show_settings === true &&
201
+ ( settings.show_settings_environment == (settings.environment || :development) )
202
+ )
203
+ end
204
+
205
+
206
+ TEMPLATE = <<HTML
207
+ <style type="text/css" media="screen">
208
+ #debug { border: 1px solid #ccc; background: #fff; width: 870px; margin: 2em auto; font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Garuda';}
209
+ #debug h2 { text-align: center; border-bottom: 1px solid #ccc; background-color: #eee; font-size: 1.4em; }
210
+ #explanation { text-align: center; }
211
+ #debug h3 { margin: 1em 0 0.2em 0.4em; }
212
+ #settings, #params, #get, #post, #cookies, #sessions, #rack { width: 860px; margin: 0 auto 10px auto;}
213
+ p.no-data {padding-top: 2px; color: #666; margin: -1.8em 0 0.8em 10em; }
214
+ table.req { width: 850px; text-align: left; color: #666; padding: 0; border-spacing: 0; border: 1px solid #eee; border-bottom: 0; border-left: 0; margin: 0 auto;}
215
+ table.req tr th { padding: 2px 10px; font-weight: bold; background: #F7F7F7; border-bottom: 1px solid #eee; border-left: 1px solid #eee;}
216
+ table.req tr td { padding: 2px 20px 2px 10px; border-bottom: 1px solid #eee; border-left: 1px solid #eee; }
217
+ table.req tr td.key {vertical-align: top; width: 150px;}
218
+ /* table.req tr td.code { white-space: pre-wrap; word-wrap: break-word; } */
219
+ table.req tr td.key { width: 200px; overflow:hidden; }
220
+ table.req tr td.code div { width: 650px; overflow:hidden; }
221
+
222
+ </style>
223
+
224
+ <div id="debug">
225
+
226
+ <h2>PAGE DEBUG</h2>
227
+
228
+ <div id="get">
229
+ <h3>GET</h3>
230
+ <% unless request.GET.empty? %>
231
+ <table class="req">
232
+ <tr>
233
+ <th>Variable</th>
234
+ <th>Value</th>
235
+ </tr>
236
+ <% request.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
237
+ <tr>
238
+ <td class="key"><%=h key %></td>
239
+ <td class="code"><div><%=h val.inspect %></div></td>
240
+ </tr>
241
+ <% } %>
242
+ </table>
243
+ <% else %>
244
+ <p class="no-data">No GET data.</p>
245
+ <% end %>
246
+ <div class="clear"></div>
247
+ </div> <!-- /GET -->
248
+
249
+ <hr>
250
+
251
+ <div id="params">
252
+ <h3>PARAMS</h3>
253
+ <% unless params.empty? %>
254
+ <table class="req">
255
+ <tr>
256
+ <th>Variable</th>
257
+ <th>Value</th>
258
+ </tr>
259
+ <% params.sort_by { |k, v| k.to_s }.each { |key, val| %>
260
+ <tr>
261
+ <td class="key"><%=h key %></td>
262
+ <td class="code"><div><%=h val %></div></td>
263
+ </tr>
264
+ <% } %>
265
+ </table>
266
+ <% else %>
267
+ <p class="no-data">No PARAMS data.</p>
268
+ <% end %>
269
+ <div class="clear"></div>
270
+ </div> <!-- /PARAMS -->
271
+
272
+ <hr>
273
+
274
+ <div id="sessions">
275
+ <h3>SESSIONS</h3>
276
+ <% unless session.empty? %>
277
+ <table class="req">
278
+ <tr>
279
+ <th>Variable</th>
280
+ <th>Value</th>
281
+ </tr>
282
+ <% session.sort_by { |k, v| k.to_s }.each { |key, val| %>
283
+ <tr>
284
+ <td class="key"><%=h key %></td>
285
+ <td class="code"><div><%=h val.inspect %></div></td>
286
+ </tr>
287
+ <% } %>
288
+ </table>
289
+ <% else %>
290
+ <p class="no-data">No SESSION data.</p>
291
+ <% end %>
292
+ <div class="clear"></div>
293
+ </div> <!-- /SESSIONS -->
294
+
295
+ <hr>
296
+
297
+ <div id="cookies">
298
+ <h3>COOKIES</h3>
299
+ <% unless request.cookies.empty? %>
300
+ <table class="req">
301
+ <tr>
302
+ <th>Variable</th>
303
+ <th>Value</th>
304
+ </tr>
305
+ <% request.cookies.each { |key, val| %>
306
+ <tr>
307
+ <td class="key"><%=h key %></td>
308
+ <td class="code"><div><%= nl2br(val) %></div></td>
309
+ </tr>
310
+ <% } %>
311
+ </table>
312
+ <% else %>
313
+ <p class="no-data">No COOKIE data.</p>
314
+ <% end %>
315
+ <div class="clear"></div>
316
+ </div> <!-- /COOKIES -->
317
+
318
+ <hr>
319
+
320
+ <div id="routes">
321
+ <h3>ROUTES</h3>
322
+ <% r = self.methods.sort.reject { |i| i !~ /^(DELETE|GET|POST|PUT)\s/ } %>
323
+ <% unless r.empty? %>
324
+ <table class="req">
325
+ <tr>
326
+ <th>Verb</th>
327
+ <th>Path</th>
328
+ </tr>
329
+ <% r.each { |route| %>
330
+ <tr>
331
+ <td class="key"><%=h route.split(' ').first %></td>
332
+ <td class="code"><div><%= request.script_name %><%=h route.split(' ')[1] %></div></td>
333
+ </tr>
334
+ <% } %>
335
+ </table>
336
+ <% else %>
337
+ <p class="no-data">No ROUTES declared.</p>
338
+ <% end %>
339
+ <div class="clear"></div>
340
+ </div> <!-- /ROUTES -->
341
+
342
+ <hr>
343
+
344
+ <div id="settings">
345
+ <h3>SETTINGS</h3>
346
+ <table class="req">
347
+ <tr>
348
+ <th>Variable</th>
349
+ <th>Value</th>
350
+ </tr>
351
+ <% settings_inspect.sort_by { |k, v| k.to_s }.each { |key, val| %>
352
+ <tr>
353
+ <td class="key"><%=h key %></td>
354
+ <% if !val.is_a?(String) %>
355
+ <% if( key == :sass) %>
356
+ <%# val[:load_paths] = val[:load_paths].uniq! %>
357
+ <td class="code">SASS
358
+ <div><%= h val.inspect %></div>
359
+ </td>
360
+ <% else %>
361
+ <td class="code"><div><%=h val.inspect %></div></td>
362
+ <% end %>
363
+ <% else %>
364
+ <td class="code"><div><%=h val %></div></td>
365
+ <% end %>
366
+ </tr>
367
+ <% } %>
368
+ </table>
369
+ <div class="clear"></div>
370
+ </div> <!-- /SETTINGS -->
371
+
372
+ <hr>
373
+
374
+ <div id="rack">
375
+ <h3 id="env-info">Rack ENV</h3>
376
+ <table class="req">
377
+ <tr>
378
+ <th>Variable</th>
379
+ <th>Value</th>
380
+ </tr>
381
+ <% env.sort_by { |k, v| k.to_s }.each { |key, val| %>
382
+ <tr>
383
+ <td class="key"><%=h key %></td>
384
+ <% unless val.is_a?(String) %>
385
+ <td class="code"><div><%=h(val.inspect).gsub('\n','<br>').gsub('%0A','<br>') %></div></td>
386
+ <% else %>
387
+ <td class="code"><div><%=h(val).gsub('\n','<br>').gsub('%0A','<br>') %></div></td>
388
+ <% end %>
389
+ </tr>
390
+ <% } %>
391
+ </table>
392
+ <div class="clear"></div>
393
+ </div> <!-- /RACK ENV -->
394
+
395
+ <p id="explanation">You're seeing this output because you have enabled the <code>show_settings</code> option.</p>
396
+
397
+
398
+ </div>
399
+ HTML
400
+
401
+ # :startdoc:
402
+
403
+ end #/module Helpers
404
+
405
+
406
+
407
+ def self.registered(app)
408
+ app.helpers Sinatra::Settings::Helpers
409
+
410
+ # don't show settings by default
411
+ app.set :show_settings, false
412
+ # only show the settings in development mode.
413
+ app.set :show_settings_environment, :development
414
+
415
+ ## add the extension specific settings to those inspectable by the :settings_inspect method
416
+ if app.respond_to?(:sinatra_settings_for_inspection)
417
+ %w(show_settings show_settings_environment).each do |s|
418
+ app.sinatra_settings_for_inspection << s
419
+ end
420
+ end
421
+
422
+ end
423
+
424
+
425
+ end #/module Settings
426
+
427
+ end #/module Sinatra
428
+
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sinatra-settings}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kematzy"]
12
+ s.date = %q{2010-02-23}
13
+ s.description = %q{Want an overview of all Sinatra settings (formerly options) in your app? This Sinatra Extension makes that dead simple.}
14
+ s.email = %q{kematzy@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/sinatra/settings.rb",
27
+ "sinatra-settings.gemspec",
28
+ "spec/sinatra/settings_spec.rb",
29
+ "spec/spec.opts",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/kematzy/sinatra-settings}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.6}
36
+ s.summary = %q{A Sinatra Extension that shows your app's settings and other debug information}
37
+ s.test_files = [
38
+ "spec/sinatra/settings_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<sinatra>, [">= 0.10.1"])
48
+ s.add_development_dependency(%q<sinatra-tests>, [">= 0.1.6"])
49
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
50
+ else
51
+ s.add_dependency(%q<sinatra>, [">= 0.10.1"])
52
+ s.add_dependency(%q<sinatra-tests>, [">= 0.1.6"])
53
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<sinatra>, [">= 0.10.1"])
57
+ s.add_dependency(%q<sinatra-tests>, [">= 0.1.6"])
58
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,215 @@
1
+
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+
5
+ describe "Sinatra" do
6
+
7
+ class MyTestApp
8
+ register Sinatra::Settings
9
+ end
10
+
11
+ before(:each) do
12
+ @sinatra_default_settings = %w(
13
+ app_file bind clean_trace dump_errors environment lock
14
+ logging method_override port public raise_errors reload_templates
15
+ root run running server sessions show_exceptions static views
16
+ )
17
+ end
18
+
19
+ describe "Base" do
20
+
21
+ describe "#sinatra_settings_for_inspection" do
22
+
23
+ it "should be an Array" do
24
+ Sinatra::Base.sinatra_settings_for_inspection.should be_a_kind_of(Array)
25
+ end
26
+
27
+ it "should include all the default Sinatra configuration settings" do
28
+ @sinatra_default_settings.each do |s|
29
+ Sinatra::Base.sinatra_settings_for_inspection.should include(s)
30
+ end
31
+ end
32
+
33
+ end #/ #sinatra_settings_for_inspection
34
+
35
+ end #/ Base
36
+
37
+ describe "Settings" do
38
+
39
+ before(:each) do
40
+ class ::Test::Unit::TestCase
41
+ def app; ::MyTestApp.new ; end
42
+ end
43
+ @app = app
44
+ end
45
+
46
+ after(:each) do
47
+ class ::Test::Unit::TestCase
48
+ def app; nil ; end
49
+ end
50
+ @app = nil
51
+ end
52
+
53
+ describe "VERSION" do
54
+
55
+ it "should return the VERSION string" do
56
+ Sinatra::Settings::VERSION.should be_a_kind_of(String)
57
+ Sinatra::Settings::VERSION.should match(/\d\.\d+\.\d+(\.\d)?/)
58
+ end
59
+
60
+ end #/ VERSION
61
+
62
+ describe "#self.version" do
63
+
64
+ it "should return a string with the version number" do
65
+ Sinatra::Settings.version.should match(/Sinatra::Settings v\d\.\d\.\d/)
66
+ end
67
+
68
+ end #/ #version
69
+
70
+ describe "Configuration" do
71
+
72
+ it "should set :show_settings to FALSE" do
73
+ MyTestApp.show_settings.should == false
74
+ app.settings.show_settings.should == false
75
+ end
76
+
77
+ it "should set :show_settings_environment to :development" do
78
+ MyTestApp.show_settings_environment.should == :development
79
+ app.settings.show_settings_environment.should == :development
80
+ end
81
+
82
+ end #/ Configuration
83
+
84
+ describe "#sinatra_settings_for_inspection" do
85
+
86
+ it "should return an Array of Sinatra configuration settings" do
87
+ app.settings.sinatra_settings_for_inspection.should be_a_kind_of(Array)
88
+ end
89
+
90
+ it "should include all the Sinatra default configuration settings" do
91
+ @sinatra_default_settings.each do |s|
92
+ MyTestApp.sinatra_settings_for_inspection.should include(s)
93
+ app.settings.sinatra_settings_for_inspection.should include(s)
94
+ end
95
+ end
96
+
97
+ it "should include the settings from this extension" do
98
+ %w( show_settings show_settings_environment ).each do |s|
99
+ MyTestApp.sinatra_settings_for_inspection.should include(s)
100
+ app.settings.sinatra_settings_for_inspection.should include(s)
101
+ end
102
+ end
103
+
104
+ it "should not duplicate settings in the array" do
105
+ pending %Q{ allows duplicate values in array }
106
+ # TODO: This is not a big issue, since we do .uniq on the output in :settings_inspect,
107
+ # which is where it's important, but still it would be nice to not have it from the start
108
+
109
+ %w(foo bar foo bar).each do |s|
110
+ app.settings.sinatra_settings_for_inspection << s
111
+ end
112
+ app.settings.sinatra_settings_for_inspection.should == app.settings.sinatra_settings_for_inspection.uniq
113
+ end
114
+
115
+ end #/ #sinatra_settings_for_inspection
116
+
117
+ describe "Helpers" do
118
+
119
+ describe "#settings_inspect" do
120
+
121
+ it "should return a Hash" do
122
+ app.settings_inspect.should be_a_kind_of(Hash)
123
+ end
124
+
125
+ it "should contain the Sinatra default configurations" do
126
+ @sinatra_default_settings.each do |s|
127
+ app.settings_inspect.keys.should include(s.to_sym)
128
+ # app.settings.sinatra_settings_for_inspection.should include(s)
129
+ end
130
+ end
131
+
132
+ it "should contain no duplicates" do
133
+ app.settings_inspect.keys.map(&:to_s).sort.should ==
134
+ app.settings.sinatra_settings_for_inspection.uniq.sort
135
+ end
136
+
137
+ end #/ #settings_inspect
138
+
139
+ describe "#show_settings_output?" do
140
+
141
+ describe "with :show_settings disabled" do
142
+
143
+ it "should show the :show_settings HTML comment output" do
144
+ erb_app "<%= show_settings_output? %>"
145
+ body.should == '<!-- :show_settings is [OFF] -->'
146
+ end
147
+
148
+ end #/ with :show_settings disabled
149
+
150
+ describe "with :show_settings enabled" do
151
+
152
+ class MyCustomTestApp < Sinatra::Base
153
+ set :app_dir, "#{fixtures_path}/app"
154
+ set :public, "#{public_fixtures_path}"
155
+ set :views, "#{app_dir}/views"
156
+ register(Sinatra::Tests)
157
+ register(Sinatra::Settings)
158
+
159
+ enable :show_settings
160
+ set :show_settings_environment, :test
161
+ enable :raise_errors
162
+ end
163
+
164
+ before(:each) do
165
+ class ::Test::Unit::TestCase
166
+ def app; ::MyCustomTestApp.new ; end
167
+ end
168
+ @app = app
169
+ end
170
+
171
+ after(:each) do
172
+ class ::Test::Unit::TestCase
173
+ def app; nil ; end
174
+ end
175
+ @app = nil
176
+ end
177
+
178
+ it "should show the full HTML output" do
179
+ erb_app "<%= show_settings_output? %>"
180
+ # body.should have_tag(:debug)
181
+ body.should have_tag('div#debug') do |div|
182
+ div.should have_tag('h2', 'PAGE DEBUG')
183
+ div.should have_tag('div#get > table.req')
184
+
185
+ div.should have_tag('div#params > table.req')
186
+
187
+ div.should have_tag('div#sessions > h3','SESSIONS')
188
+
189
+ div.should have_tag('div#cookies > h3','COOKIES')
190
+
191
+ div.should have_tag('div#routes > h3','ROUTES')
192
+
193
+ div.should have_tag('div#settings') do |settings_div|
194
+ settings_div.should have_tag('h3', 'SETTINGS')
195
+ settings_div.should have_tag('table.req') do |table|
196
+ table.should have_tag('tr > td.key', 'show_settings')
197
+ table.should have_tag('tr > td.code > div', 'true')
198
+
199
+ table.should have_tag('tr > td.key', 'show_settings_environment')
200
+ table.should have_tag('tr > td.code > div', ':test')
201
+ end
202
+ end
203
+ div.should have_tag('div#rack > h3#env-info','Rack ENV')
204
+ end
205
+ end
206
+
207
+ end #/ with :show_settings enabled
208
+
209
+ end #/ #show_settings_output?
210
+
211
+ end #/ Helpers
212
+
213
+ end #/ Settings
214
+
215
+ end #/ Sinatra
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,57 @@
1
+
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+
6
+
7
+ #--
8
+ # DEPENDENCIES
9
+ #++
10
+ %w(
11
+ sinatra/base
12
+ ).each {|lib| require lib }
13
+
14
+ #--
15
+ ## SINATRA EXTENSIONS
16
+ #++
17
+ %w(
18
+ sinatra/tests
19
+ sinatra/settings
20
+ ).each {|ext| require ext }
21
+
22
+
23
+ Spec::Runner.configure do |config|
24
+ config.include RspecHpricotMatchers
25
+ config.include Sinatra::Tests::TestCase
26
+ config.include Sinatra::Tests::RSpec::SharedSpecs
27
+ end
28
+
29
+
30
+ # quick convenience methods..
31
+
32
+ def fixtures_path
33
+ "#{File.dirname(File.expand_path(__FILE__))}/fixtures"
34
+ end
35
+
36
+ def public_fixtures_path
37
+ "#{fixtures_path}/public"
38
+ end
39
+
40
+
41
+ class MyTestApp < Sinatra::Base
42
+
43
+ set :app_dir, "#{fixtures_path}/app"
44
+ set :public, "#{public_fixtures_path}"
45
+ # set :views, "#{fixtures_path}/app/views"
46
+ set :views, "#{app_dir}/views"
47
+
48
+ register(Sinatra::Tests)
49
+
50
+ enable :raise_errors
51
+
52
+ end #/class MyTestApp
53
+
54
+
55
+ class Test::Unit::TestCase
56
+ Sinatra::Base.set :environment, :test
57
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-settings
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - kematzy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-02-23 00:00:00 +08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sinatra
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 10
30
+ - 1
31
+ version: 0.10.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: sinatra-tests
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 1
44
+ - 6
45
+ version: 0.1.6
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 3
58
+ - 0
59
+ version: 1.3.0
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: Want an overview of all Sinatra settings (formerly options) in your app? This Sinatra Extension makes that dead simple.
63
+ email: kematzy@gmail.com
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files:
69
+ - LICENSE
70
+ - README.rdoc
71
+ files:
72
+ - .document
73
+ - .gitignore
74
+ - LICENSE
75
+ - README.rdoc
76
+ - Rakefile
77
+ - VERSION
78
+ - lib/sinatra/settings.rb
79
+ - sinatra-settings.gemspec
80
+ - spec/sinatra/settings_spec.rb
81
+ - spec/spec.opts
82
+ - spec/spec_helper.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/kematzy/sinatra-settings
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --charset=UTF-8
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project:
109
+ rubygems_version: 1.3.6
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: A Sinatra Extension that shows your app's settings and other debug information
113
+ test_files:
114
+ - spec/sinatra/settings_spec.rb
115
+ - spec/spec_helper.rb