sinatra-contrib 1.4.2 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f89a241902ac4cbe6b66947850f41b59c8ec4df0
4
- data.tar.gz: f3eabb61ed63b18eba33dc07fc3dc88681bb91da
3
+ metadata.gz: 7b10e547ab4dd6286fab1c7d2d5fb9d76f68410f
4
+ data.tar.gz: f10a9b4b327486c4aab7ea05d4fd7987b4f3ffc1
5
5
  SHA512:
6
- metadata.gz: 6918bd27ea9e20c5dc3841b623e862aa4894cc42baea4b9497f416ccd99d844d557c23451794168345f7759b3d074d794bd87b2a5e4827e1a720508474c9f660
7
- data.tar.gz: 426d596d464fc3865916a65de23ca3effeab6a14da81f0bd11e84fd8d16aeb3a2f0becebb2971551bd561326fbec6864673898f647b5efce9da6bea63e67f84a
6
+ metadata.gz: d2d939d7d4592bce5e0b191127a99c6b661950d6b3d42f2996b6acac5ef1ee47b88f80f0d74faa2b889c745c62a3b748d7f2c59ab9aea31f500b7e81b690e343
7
+ data.tar.gz: c85fcf0b78d0826c927beb11ceda86c6f984f04a34373c3cdbae5416391518e58bf1719720af6e5ce616502d275217a272c01facc0b26765c397c7c46ff2fe76
data/LICENSE CHANGED
@@ -1,3 +1,5 @@
1
+ The MIT License (MIT)
2
+
1
3
  Copyright (c) 2008-2011 Nicolas Sanguinetti, entp.com, Konstantin Haase
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
data/README.md CHANGED
@@ -45,6 +45,9 @@ Currently included:
45
45
  depending on the incoming request. Adds helpers `respond_to` and
46
46
  `respond_with`.
47
47
 
48
+ * `sinatra/custom_logger`: This extension allows you to define your own
49
+ logger instance using +logger+ setting. That logger then will
50
+ be available as #logger helper method in your routes and views.
48
51
 
49
52
  ## Custom Extensions
50
53
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'yaml'
4
4
  require 'sinatra/contrib/version'
5
5
 
6
6
  desc "run specs"
7
- task(:spec) { ruby '-S rspec spec -c' }
7
+ task(:spec) { ruby '-S rspec spec -cw' }
8
8
  task(:test => :spec)
9
9
  task(:default => :spec)
10
10
 
@@ -67,8 +67,8 @@ task :release => :gemspec do
67
67
  git commit --allow-empty -a -m '#{Sinatra::Contrib::VERSION} release' &&
68
68
  git tag -s v#{Sinatra::Contrib::VERSION} -m '#{Sinatra::Contrib::VERSION} release' &&
69
69
  git tag -s #{Sinatra::Contrib::VERSION} -m '#{Sinatra::Contrib::VERSION} release' &&
70
- git push && (git push sinatra || true) &&
71
- git push --tags && (git push sinatra --tags || true)
70
+ git push && (git push origin master || true) &&
71
+ git push --tags && (git push origin --tags || true)
72
72
  SH
73
73
  end
74
74
 
@@ -95,7 +95,7 @@ module Sinatra
95
95
  @capture = nil
96
96
  if current_engine == :ruby
97
97
  result = block[*args]
98
- elsif current_engine == :erb
98
+ elsif current_engine == :erb || current_engine == :slim
99
99
  @_out_buf, _buf_was = '', @_out_buf
100
100
  block[*args]
101
101
  result = eval('@_out_buf', block.binding)
@@ -69,8 +69,9 @@ module Sinatra
69
69
  # b: 2
70
70
  #
71
71
  # But it also can provide specific environment configuration. There are two
72
- # ways to do that: at the file level and at the setting level. They are
73
- # illustrated, repsectively, as follows:
72
+ # ways to do that: at the file level and at the settings level.
73
+ #
74
+ # At the settings level (e.g. in 'path/to/config.yml'):
74
75
  #
75
76
  # development:
76
77
  # foo: development
@@ -82,7 +83,7 @@ module Sinatra
82
83
  # foo: production
83
84
  # bar: bar
84
85
  #
85
- # and
86
+ # Or at the file level:
86
87
  #
87
88
  # foo:
88
89
  # development: development
@@ -4,7 +4,7 @@ module Sinatra
4
4
  VERSION
5
5
  end
6
6
 
7
- SIGNATURE = [1, 4, 2]
7
+ SIGNATURE = [1, 4, 4]
8
8
  VERSION = SIGNATURE.join('.')
9
9
 
10
10
  VERSION.extend Comparable
@@ -66,14 +66,12 @@ module Sinatra
66
66
  @deleted = []
67
67
 
68
68
  @options = {
69
- :path => @request.script_name,
70
- :domain => @request.host,
69
+ :path => @request.script_name.to_s.empty? ? '/' : @request.script_name,
70
+ :domain => @request.host == 'localhost' ? nil : @request.host,
71
71
  :secure => @request.secure?,
72
72
  :httponly => true
73
73
  }
74
74
 
75
- @options[:path] = '/' if @options[:path].to_s.empty?
76
-
77
75
  if app.settings.respond_to? :cookie_options
78
76
  @options.merge! app.settings.cookie_options
79
77
  end
@@ -0,0 +1,60 @@
1
+ module Sinatra
2
+
3
+ # = Sinatra::CustomLogger
4
+ #
5
+ # CustomLogger extension allows you to define your own logger instance
6
+ # using +logger+ setting. That logger then will be available
7
+ # as #logger helper method in your routes and views.
8
+ #
9
+ # == Usage
10
+ #
11
+ # === Classic Application
12
+ #
13
+ # To define your custom logger instance in a classic application:
14
+ #
15
+ # require 'sinatra'
16
+ # require 'sinatra/custom_logger'
17
+ # require 'logger'
18
+ #
19
+ # set :logger, Logger.new(STDOUT)
20
+ #
21
+ # get '/' do
22
+ # logger.info 'Some message' # STDOUT logger is used
23
+ # # Other code...
24
+ # end
25
+ #
26
+ # === Modular Application
27
+ #
28
+ # The same for modular application:
29
+ #
30
+ # require 'sinatra/base'
31
+ # require 'sinatra/custom_logger'
32
+ # require 'logger'
33
+ #
34
+ # class MyApp < Sinatra::Base
35
+ # helpers Sinatra::CustomLogger
36
+ #
37
+ # configure :development, :production do
38
+ # logger = Logger.new(File.open("#{root}/log/#{environment}.log", 'a'))
39
+ # logger.level = Logger::DEBUG if development?
40
+ # set :logger, logger
41
+ # end
42
+ #
43
+ # get '/' do
44
+ # logger.info 'Some message' # File-based logger is used
45
+ # # Other code...
46
+ # end
47
+ # end
48
+ #
49
+ module CustomLogger
50
+ def logger
51
+ if settings.respond_to?(:logger)
52
+ settings.logger
53
+ else
54
+ request.logger
55
+ end
56
+ end
57
+ end
58
+
59
+ helpers CustomLogger
60
+ end
@@ -110,11 +110,17 @@ module Sinatra
110
110
 
111
111
  def encoded(char)
112
112
  return super if defined? super
113
- enc = URI.escape(char)
113
+ enc = uri_parser.escape(char)
114
114
  enc = "(?:#{escaped(char, enc).join('|')})" if enc == char
115
115
  enc = "(?:#{enc}|#{encoded('+')})" if char == " "
116
116
  enc
117
117
  end
118
+
119
+ def uri_parser
120
+ #TODO: Remove check after dropping support for 1.8.7
121
+ @_uri_parser ||= defined?(URI::Parser) ? URI::Parser.new : URI
122
+ end
123
+
118
124
  end
119
125
 
120
126
  register Decompile
@@ -116,6 +116,8 @@ module Sinatra
116
116
  module Namespace
117
117
  def self.new(base, pattern, conditions = {}, &block)
118
118
  Module.new do
119
+ #quelch uninitialized variable warnings, since these get used by compile method.
120
+ @pattern, @conditions = nil, nil
119
121
  extend NamespacedMethods
120
122
  include InstanceMethods
121
123
  @base, @extensions, @errors = base, [], {}
@@ -173,7 +175,7 @@ module Sinatra
173
175
  end
174
176
 
175
177
  def not_found(&block)
176
- error(404, &block)
178
+ error(Sinatra::NotFound, &block)
177
179
  end
178
180
 
179
181
  def errors
@@ -185,9 +187,10 @@ module Sinatra
185
187
  end
186
188
 
187
189
  def error(*codes, &block)
188
- args = Sinatra::Base.send(:compile!, "ERROR", /^#{@pattern}/, block)
190
+ args = Sinatra::Base.send(:compile!, "ERROR", regexpify(@pattern), block)
189
191
  codes = codes.map { |c| Array(c) }.flatten
190
192
  codes << Exception if codes.empty?
193
+
191
194
  codes.each do |c|
192
195
  errors = @errors[c] ||= []
193
196
  errors << args
@@ -253,7 +256,7 @@ module Sinatra
253
256
 
254
257
  def regexpify(pattern)
255
258
  pattern = Sinatra::Base.send(:compile, pattern).first.inspect
256
- pattern.gsub! /^\/(\^|\\A)?|(\$|\\Z)?\/$/, ''
259
+ pattern.gsub! /^\/(\^|\\A)?|(\$|\\z)?\/$/, ''
257
260
  Regexp.new pattern
258
261
  end
259
262
 
@@ -268,6 +271,10 @@ module Sinatra
268
271
  def method_missing(method, *args, &block)
269
272
  base.send(method, *args, &block)
270
273
  end
274
+
275
+ def respond_to?(method, include_private = false)
276
+ super || base.respond_to?(method, include_private)
277
+ end
271
278
  end
272
279
 
273
280
  module BaseMethods
@@ -164,6 +164,7 @@ module Sinatra
164
164
 
165
165
  # Creates a new +Watcher+ instance for the file located at +path+.
166
166
  def initialize(path)
167
+ @ignore = nil
167
168
  @path, @elements = path, []
168
169
  update
169
170
  end
@@ -202,7 +203,7 @@ module Sinatra
202
203
  end
203
204
  end
204
205
 
205
- # When the extension is registed it extends the Sinatra application
206
+ # When the extension is registered it extends the Sinatra application
206
207
  # +klass+ with the modules +BaseMethods+ and +ExtensionMethods+ and
207
208
  # defines a before filter to +perform+ the reload of the modified files.
208
209
  def self.registered(klass)
@@ -244,7 +245,7 @@ module Sinatra
244
245
  Thread and Thread.list.size > 1 and Thread.respond_to?(:exclusive)
245
246
  end
246
247
 
247
- # Contains the methods defined in Sinatra::Base that are overriden.
248
+ # Contains the methods defined in Sinatra::Base that are overridden.
248
249
  module BaseMethods
249
250
  # Protects Sinatra::Base.run! from being called more than once.
250
251
  def run!(*args)
@@ -369,7 +370,8 @@ module Sinatra
369
370
 
370
371
  private
371
372
 
372
- attr_reader :register_path
373
+ # attr_reader :register_path warn on -w (private attribute)
374
+ def register_path; @register_path ||= nil; end
373
375
 
374
376
  # Indicates an extesion is being registered.
375
377
  def start_registering_extension
@@ -391,7 +393,7 @@ module Sinatra
391
393
  # in the file located at +path+.
392
394
  #
393
395
  # If an extension is being registered, it also tells the list to
394
- # watch it in the file where the extesion has been registered.
396
+ # watch it in the file where the extension has been registered.
395
397
  # This prevents the duplication of the elements added by the
396
398
  # extension in its +registered+ method with every reload.
397
399
  def watch_element(path, type, representation=nil)
@@ -1,6 +1,8 @@
1
1
  require 'sinatra/json'
2
2
  require 'sinatra/base'
3
3
 
4
+ $KCODE = "UTF-8"
5
+
4
6
  module Sinatra
5
7
  #
6
8
  # = Sinatra::RespondWith
@@ -174,7 +176,11 @@ module Sinatra
174
176
  end
175
177
  possible.each do |engine, template|
176
178
  # not exactly like Tilt[engine], but does not trigger a require
177
- klass = Tilt.mappings[Tilt.normalize(engine)].first
179
+ if Tilt.respond_to?(:mappings)
180
+ klass = Tilt.mappings[Tilt.normalize(engine)].first
181
+ else
182
+ klass = Tilt[engine]
183
+ end
178
184
  find_template(settings.views, template, klass) do |file|
179
185
  next unless File.exist? file
180
186
  return settings.rendering_method(engine) << template.to_sym
@@ -221,22 +227,33 @@ module Sinatra
221
227
  super
222
228
  end
223
229
 
224
- ENGINES = {
225
- :css => [:less, :sass, :scss],
226
- :xml => [:builder, :nokogiri],
227
- :js => [:coffee],
228
- :json => [:yajl],
229
- :html => [:erb, :erubis, :haml, :slim, :liquid, :radius, :mab, :markdown,
230
- :textile, :rdoc],
231
- :all => Sinatra::Templates.instance_methods.map(&:to_sym) + [:mab] -
232
- [:find_template, :markaby]
233
- }
230
+ def self.jrubyify(engs)
231
+ not_supported = [:markdown]
232
+ engs.keys.each do |key|
233
+ engs[key].collect! { |eng| (eng == :yajl) ? :json_pure : eng }
234
+ engs[key].delete_if { |eng| not_supported.include?(eng) }
235
+ end
236
+ engs
237
+ end
234
238
 
235
- ENGINES.default = []
239
+ def self.engines
240
+ engines = {
241
+ :css => [:less, :sass, :scss],
242
+ :xml => [:builder, :nokogiri],
243
+ :js => [:coffee],
244
+ :html => [:erb, :erubis, :haml, :slim, :liquid, :radius, :mab,
245
+ :markdown, :textile, :rdoc],
246
+ :all => (Sinatra::Templates.instance_methods.map(&:to_sym) +
247
+ [:mab] - [:find_template, :markaby]),
248
+ :json => [:yajl],
249
+ }
250
+ engines.default = []
251
+ (defined? JRUBY_VERSION) ? jrubyify(engines) : engines
252
+ end
236
253
 
237
254
  def self.registered(base)
238
255
  base.set :ext_map, Hash.new { |h,k| h[k] = [] }
239
- base.set :template_engines, ENGINES.dup
256
+ base.set :template_engines, engines
240
257
  base.remap_extensions
241
258
  base.helpers Helpers
242
259
  end
@@ -6,7 +6,7 @@ module Sinatra
6
6
  # = Sinatra::Streaming
7
7
  #
8
8
  # Sinatra 1.3 introduced the +stream+ helper. This addon improves the
9
- # streaming API by making the stream object immitate an IO object, turning
9
+ # streaming API by making the stream object imitate an IO object, turning
10
10
  # it into a real Deferrable and making the body play nicer with middleware
11
11
  # unaware of streaming.
12
12
  #
@@ -7,46 +7,57 @@ Gem::Specification.new do |s|
7
7
  s.version = Sinatra::Contrib::VERSION
8
8
  s.description = "Collection of useful Sinatra extensions"
9
9
  s.homepage = "http://github.com/sinatra/sinatra-contrib"
10
+ s.license = "MIT"
10
11
  s.summary = s.description
11
12
 
12
13
  # generated from git shortlog -sn
13
14
  s.authors = [
14
15
  "Konstantin Haase",
15
16
  "Gabriel Andretta",
16
- "Trevor Bramble",
17
17
  "Zachary Scott",
18
+ "Trevor Bramble",
18
19
  "Katrina Owen",
19
20
  "Nicolas Sanguinetti",
21
+ "Ashley Williams",
20
22
  "Hrvoje Šimić",
21
23
  "Masahiro Fujiwara",
22
24
  "Rafael Magana",
25
+ "Vipul A M",
23
26
  "Jack Chu",
24
27
  "Ilya Shindyapin",
28
+ "Jake Worth",
25
29
  "Kashyap",
26
30
  "Sumeet Singh",
27
31
  "lest",
28
32
  "Adrian Pacała",
29
33
  "Aish",
34
+ "Alexey Chernenkov",
30
35
  "Andrew Crump",
36
+ "Bo Jeanes",
31
37
  "David Asabina",
32
38
  "Eliot Shepard",
33
39
  "Eric Marden",
34
40
  "Gray Manley",
35
41
  "Guillaume Bouteille",
36
42
  "Jamie Hodge",
43
+ "Koichi Sasada",
37
44
  "Kyle Lacy",
45
+ "Lars Vonk",
38
46
  "Martin Frost",
39
47
  "Mathieu Allaire",
40
48
  "Matt Lyon",
41
49
  "Matthew Conway",
42
50
  "Meck",
43
51
  "Michi Huber",
52
+ "Nic Benders",
44
53
  "Patricio Mac Adden",
45
54
  "Reed Lipman",
46
55
  "Samy Dindane",
56
+ "Sergey Nartimov",
47
57
  "Thibaut Sacreste",
48
58
  "Uchio KONDO",
49
59
  "Will Bailey",
60
+ "ashley williams",
50
61
  "undr"
51
62
  ]
52
63
 
@@ -55,41 +66,52 @@ Gem::Specification.new do |s|
55
66
  "konstantin.mailinglists@googlemail.com",
56
67
  "ohhgabriel@gmail.com",
57
68
  "inbox@trevorbramble.com",
69
+ "e@zzak.io",
58
70
  "zachary@zacharyscott.net",
59
71
  "katrina.owen@gmail.com",
60
72
  "contacto@nicolassanguinetti.info",
73
+ "ashley@bocoup.com",
61
74
  "shime.ferovac@gmail.com",
62
75
  "m-fujiwara@axsh.net",
63
76
  "raf.magana@gmail.com",
77
+ "vipulnsward@gmail.com",
64
78
  "jack@jackchu.com",
65
79
  "konstantin.haase@gmail.com",
66
80
  "ilya@shindyapin.com",
81
+ "jworth@prevailhs.com",
67
82
  "kashyap.kmbc@gmail.com",
68
83
  "ortuna@gmail.com",
69
- "e@zzak.io",
84
+ "tbramble@chef.io",
70
85
  "just.lest@gmail.com",
71
86
  "altpacala@gmail.com",
72
87
  "aisha.fenton@visfleet.com",
88
+ "laise@pisem.net",
73
89
  "andrew.crump@ieee.org",
90
+ "me@bjeanes.com",
74
91
  "david@supr.nu",
75
92
  "eshepard@slower.net",
76
93
  "eric.marden@gmail.com",
77
94
  "g.manley@tukaiz.com",
78
95
  "duffman@via.ecp.fr",
79
96
  "jamiehodge@me.com",
97
+ "ko1@atdot.net",
80
98
  "kylewlacy@me.com",
99
+ "lars.vonk@gmail.com",
81
100
  "blame@kth.se",
82
101
  "mathieuallaire@gmail.com",
83
102
  "matt@flowerpowered.com",
84
103
  "himself@mattonrails.com",
85
104
  "yesmeck@gmail.com",
86
105
  "michi.huber@gmail.com",
106
+ "nic@newrelic.com",
87
107
  "patriciomacadden@gmail.com",
88
108
  "rmlipman@gmail.com",
89
109
  "samy@dindane.com",
110
+ "just.lest@gmail.com",
90
111
  "thibaut.sacreste@gmail.com",
91
112
  "udzura@udzura.jp",
92
113
  "will.bailey@gmail.com",
114
+ "ashley666ashley@gmail.com",
93
115
  "undr@yandex.ru"
94
116
  ]
95
117
 
@@ -107,6 +129,7 @@ Gem::Specification.new do |s|
107
129
  "lib/sinatra/contrib/setup.rb",
108
130
  "lib/sinatra/contrib/version.rb",
109
131
  "lib/sinatra/cookies.rb",
132
+ "lib/sinatra/custom_logger.rb",
110
133
  "lib/sinatra/decompile.rb",
111
134
  "lib/sinatra/engine_tracking.rb",
112
135
  "lib/sinatra/extension.rb",
@@ -161,6 +184,7 @@ Gem::Specification.new do |s|
161
184
  "spec/content_for/takes_values.slim",
162
185
  "spec/content_for_spec.rb",
163
186
  "spec/cookies_spec.rb",
187
+ "spec/custom_logger_spec.rb",
164
188
  "spec/decompile_spec.rb",
165
189
  "spec/extension_spec.rb",
166
190
  "spec/json_spec.rb",
@@ -184,7 +208,7 @@ Gem::Specification.new do |s|
184
208
 
185
209
  s.add_dependency "sinatra", "~> 1.4.0"
186
210
  s.add_dependency "backports", ">= 2.0"
187
- s.add_dependency "tilt", "~> 1.3"
211
+ s.add_dependency "tilt", ">= 1.3", "< 3"
188
212
  s.add_dependency "rack-test"
189
213
  s.add_dependency "rack-protection"
190
214
  s.add_dependency "multi_json"
@@ -193,5 +217,18 @@ Gem::Specification.new do |s|
193
217
  s.add_development_dependency "haml"
194
218
  s.add_development_dependency "erubis"
195
219
  s.add_development_dependency "slim"
220
+ s.add_development_dependency "less"
221
+ s.add_development_dependency "sass"
222
+ s.add_development_dependency "builder"
223
+ s.add_development_dependency "liquid"
224
+ s.add_development_dependency "redcarpet"
225
+ s.add_development_dependency "RedCloth"
226
+ s.add_development_dependency "asciidoctor"
227
+ s.add_development_dependency "radius"
228
+ s.add_development_dependency "coffee-script"
229
+ s.add_development_dependency "nokogiri"
230
+ s.add_development_dependency "creole"
231
+ s.add_development_dependency "wikicloth"
232
+ s.add_development_dependency "markaby"
196
233
  s.add_development_dependency "rake"
197
234
  end