sinatra-contrib 2.0.8.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/sinatra/contrib.rb +16 -16
- data/lib/sinatra/contrib/setup.rb +3 -5
- data/lib/sinatra/contrib/version.rb +1 -1
- data/lib/sinatra/namespace.rb +9 -3
- data/lib/sinatra/quiet_logger.rb +50 -0
- data/lib/sinatra/reloader.rb +2 -2
- data/lib/sinatra/respond_with.rb +2 -2
- data/sinatra-contrib.gemspec +1 -2
- metadata +9 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b975fa7ce92c5cf316ecd5435760f80079cfe461ca28ff298b188eb08519dc52
|
4
|
+
data.tar.gz: a7ec2909d72329c6d9089a00013c02aa11c308ce842f8ba3784dc76253eafa3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eabdb605ec4c7b4dd0a7cbd7159ed048facdf215e35c6221de15dd0761466e58fc0276e9581f27dbfe78a7849dd481d072aaa5f4b1406899975187c84d89529
|
7
|
+
data.tar.gz: 7bc7a597c8b679045302d66e4e12bfb4e6ce7e5ed1b064b28b8d0c6ae98986e8868a78a63bd9be7a7c2f689d30f514693c25daa2856c22f4ecfe9ac50f2e8f36
|
data/README.md
CHANGED
@@ -67,6 +67,9 @@ Currently included:
|
|
67
67
|
* [`sinatra/test_helpers`][sinatra-test-helpers]: Helper methods to ease testing your Sinatra
|
68
68
|
application. Partly extracted from Sinatra. Testing framework agnostic
|
69
69
|
|
70
|
+
* `sinatra/quiet_logger`: Extension to exclude specific pathes from access log.
|
71
|
+
It works by patching Rack::CommonLogger
|
72
|
+
|
70
73
|
## Installation
|
71
74
|
|
72
75
|
Add `gem 'sinatra-contrib'` to *Gemfile*, then execute `bundle install`.
|
data/lib/sinatra/contrib.rb
CHANGED
@@ -7,32 +7,32 @@ module Sinatra
|
|
7
7
|
# or breaks if external dependencies are missing. Will extend
|
8
8
|
# Sinatra::Application by default.
|
9
9
|
module Common
|
10
|
-
register :ConfigFile
|
11
|
-
register :MultiRoute
|
12
|
-
register :Namespace
|
13
|
-
register :RespondWith
|
10
|
+
register :ConfigFile, 'sinatra/config_file'
|
11
|
+
register :MultiRoute, 'sinatra/multi_route'
|
12
|
+
register :Namespace, 'sinatra/namespace'
|
13
|
+
register :RespondWith, 'sinatra/respond_with'
|
14
14
|
|
15
|
-
helpers :Capture
|
16
|
-
helpers :ContentFor
|
17
|
-
helpers :Cookies
|
18
|
-
helpers :EngineTracking
|
19
|
-
helpers :JSON
|
20
|
-
helpers :LinkHeader
|
21
|
-
helpers :Streaming
|
22
|
-
helpers :RequiredParams
|
15
|
+
helpers :Capture, 'sinatra/capture'
|
16
|
+
helpers :ContentFor, 'sinatra/content_for'
|
17
|
+
helpers :Cookies, 'sinatra/cookies'
|
18
|
+
helpers :EngineTracking, 'sinatra/engine_tracking'
|
19
|
+
helpers :JSON, 'sinatra/json'
|
20
|
+
helpers :LinkHeader, 'sinatra/link_header'
|
21
|
+
helpers :Streaming, 'sinatra/streaming'
|
22
|
+
helpers :RequiredParams, 'sinatra/required_params'
|
23
23
|
end
|
24
24
|
|
25
25
|
##
|
26
26
|
# Other extensions you don't want to be loaded unless needed.
|
27
27
|
module Custom
|
28
|
-
# register :Compass
|
29
|
-
register :Reloader
|
28
|
+
# register :Compass, 'sinatra/compass'
|
29
|
+
register :Reloader, 'sinatra/reloader'
|
30
30
|
end
|
31
31
|
|
32
32
|
##
|
33
33
|
# Stuff that aren't Sinatra extensions, technically.
|
34
|
-
autoload :Extension
|
35
|
-
autoload :TestHelpers
|
34
|
+
autoload :Extension, 'sinatra/extension'
|
35
|
+
autoload :TestHelpers, 'sinatra/test_helpers'
|
36
36
|
end
|
37
37
|
|
38
38
|
register Sinatra::Contrib::Common
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'sinatra/contrib/version'
|
3
|
-
require 'backports/rails/string' # for String#underscore
|
4
3
|
|
5
4
|
module Sinatra
|
6
5
|
module Contrib
|
@@ -9,16 +8,15 @@ module Sinatra
|
|
9
8
|
@extensions ||= {:helpers => [], :register => []}
|
10
9
|
end
|
11
10
|
|
12
|
-
def register(name, path
|
11
|
+
def register(name, path)
|
13
12
|
autoload name, path, :register
|
14
13
|
end
|
15
14
|
|
16
|
-
def helpers(name, path
|
15
|
+
def helpers(name, path)
|
17
16
|
autoload name, path, :helpers
|
18
17
|
end
|
19
18
|
|
20
|
-
def autoload(name, path
|
21
|
-
path ||= "sinatra/#{name.to_s.underscore}"
|
19
|
+
def autoload(name, path, method = nil)
|
22
20
|
extensions[method] << name if method
|
23
21
|
Sinatra.autoload(name, path)
|
24
22
|
end
|
data/lib/sinatra/namespace.rb
CHANGED
@@ -224,6 +224,12 @@ module Sinatra
|
|
224
224
|
include SharedMethods
|
225
225
|
attr_reader :base, :templates
|
226
226
|
|
227
|
+
ALLOWED_ENGINES = [
|
228
|
+
:erb, :erubi, :erubis, :haml, :hamlit, :builder, :nokogiri, :sass, :scss,
|
229
|
+
:less, :liquid, :markdown, :textile, :rdoc, :asciidoc, :radius, :markaby,
|
230
|
+
:rabl, :slim, :creole, :mediawiki, :coffee, :stylus, :yajl, :wlang
|
231
|
+
]
|
232
|
+
|
227
233
|
def self.prefixed(*names)
|
228
234
|
names.each { |n| define_method(n) { |*a, &b| prefixed(n, *a, &b) }}
|
229
235
|
end
|
@@ -232,7 +238,7 @@ module Sinatra
|
|
232
238
|
|
233
239
|
def helpers(*extensions, &block)
|
234
240
|
class_eval(&block) if block_given?
|
235
|
-
|
241
|
+
prepend(*extensions) if extensions.any?
|
236
242
|
end
|
237
243
|
|
238
244
|
def register(*extensions, &block)
|
@@ -278,7 +284,7 @@ module Sinatra
|
|
278
284
|
end
|
279
285
|
|
280
286
|
def set(key, value = self, &block)
|
281
|
-
raise ArgumentError, "may not set #{key}"
|
287
|
+
raise ArgumentError, "may not set #{key}" unless ([:views] + ALLOWED_ENGINES).include?(key)
|
282
288
|
return key.each { |k,v| set(k, v) } if block.nil? and value == self
|
283
289
|
block ||= proc { value }
|
284
290
|
singleton_class.send(:define_method, key, &block)
|
@@ -332,7 +338,7 @@ module Sinatra
|
|
332
338
|
def prefixed(method, pattern = nil, conditions = {}, &block)
|
333
339
|
default = %r{(?:/.*)?} if method == :before or method == :after
|
334
340
|
pattern, conditions = compile pattern, conditions, default
|
335
|
-
result = base.send(method, pattern, conditions, &block)
|
341
|
+
result = base.send(method, pattern, **conditions, &block)
|
336
342
|
invoke_hook :route_added, method.to_s.upcase, pattern, block
|
337
343
|
result
|
338
344
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Sinatra
|
2
|
+
# = Sinatra::QuietLogger
|
3
|
+
#
|
4
|
+
# QuietLogger extension allows you to define paths excluded
|
5
|
+
# from logging using the +quiet_logger_prefixes+ setting.
|
6
|
+
# It is inspired from rails quiet_logger, but handles multiple paths.
|
7
|
+
#
|
8
|
+
# == Usage
|
9
|
+
#
|
10
|
+
# === Classic Application
|
11
|
+
#
|
12
|
+
# You have to require the quiet_logger, set the prefixes
|
13
|
+
# and register the extension in your application.
|
14
|
+
#
|
15
|
+
# require 'sinatra'
|
16
|
+
# require 'sinatra/quiet_logger'
|
17
|
+
#
|
18
|
+
# set :quiet_logger_prefixes, %w(css js images fonts)
|
19
|
+
# register Sinatra::QuietLogger
|
20
|
+
#
|
21
|
+
# === Modular Application
|
22
|
+
#
|
23
|
+
# The same for modular application:
|
24
|
+
#
|
25
|
+
# require 'sinatra/base'
|
26
|
+
# require 'sinatra/quiet_logger'
|
27
|
+
#
|
28
|
+
# set :quiet_logger_prefixes, %w(css js images fonts)
|
29
|
+
#
|
30
|
+
# class App < Sinatra::Base
|
31
|
+
# register Sinatra::QuietLogger
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
module QuietLogger
|
35
|
+
|
36
|
+
def self.registered(app)
|
37
|
+
quiet_logger_prefixes = app.settings.quiet_logger_prefixes.join('|') rescue ''
|
38
|
+
return warn('You need to specify the paths you wish to exclude from logging via `set :quiet_logger_prefixes, %w(images css fonts)`') if quiet_logger_prefixes.empty?
|
39
|
+
const_set('QUIET_LOGGER_REGEX', %r(\A/{0,2}(?:#{quiet_logger_prefixes})))
|
40
|
+
::Rack::CommonLogger.prepend(
|
41
|
+
::Module.new do
|
42
|
+
def log(env, *)
|
43
|
+
super unless env['PATH_INFO'] =~ QUIET_LOGGER_REGEX
|
44
|
+
end
|
45
|
+
end
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/sinatra/reloader.rb
CHANGED
@@ -269,7 +269,7 @@ module Sinatra
|
|
269
269
|
#
|
270
270
|
# Note: We are using #compile! so we don't interfere with extensions
|
271
271
|
# changing #route.
|
272
|
-
def compile!(verb, path, block, options
|
272
|
+
def compile!(verb, path, block, **options)
|
273
273
|
source_location = block.respond_to?(:source_location) ?
|
274
274
|
block.source_location.first : caller_files[1]
|
275
275
|
signature = super
|
@@ -302,7 +302,7 @@ module Sinatra
|
|
302
302
|
# Does everything Sinatra::Base#add_filter does, but it also tells
|
303
303
|
# the +Watcher::List+ for the Sinatra application to watch the defined
|
304
304
|
# filter.
|
305
|
-
def add_filter(type, path = nil, options
|
305
|
+
def add_filter(type, path = nil, **options, &block)
|
306
306
|
source_location = block.respond_to?(:source_location) ?
|
307
307
|
block.source_location.first : caller_files[1]
|
308
308
|
result = super
|
data/lib/sinatra/respond_with.rb
CHANGED
@@ -221,7 +221,7 @@ module Sinatra
|
|
221
221
|
|
222
222
|
private
|
223
223
|
|
224
|
-
def compile!(verb, path, block, options
|
224
|
+
def compile!(verb, path, block, **options)
|
225
225
|
options[:provides] ||= respond_to if respond_to
|
226
226
|
super
|
227
227
|
end
|
@@ -240,7 +240,7 @@ module Sinatra
|
|
240
240
|
:css => [:less, :sass, :scss],
|
241
241
|
:xml => [:builder, :nokogiri],
|
242
242
|
:js => [:coffee],
|
243
|
-
:html => [:erb, :erubi, :erubis, :haml, :
|
243
|
+
:html => [:erb, :erubi, :erubis, :haml, :hamlit, :slim, :liquid, :radius,
|
244
244
|
:mab, :markdown, :textile, :rdoc],
|
245
245
|
:all => (Sinatra::Templates.instance_methods.map(&:to_sym) +
|
246
246
|
[:mab] - [:find_template, :markaby]),
|
data/sinatra-contrib.gemspec
CHANGED
@@ -34,11 +34,10 @@ RubyGems 2.0 or newer is required to protect against public gem pushes. You can
|
|
34
34
|
EOF
|
35
35
|
end
|
36
36
|
|
37
|
-
s.required_ruby_version = '>= 2.
|
37
|
+
s.required_ruby_version = '>= 2.3.0'
|
38
38
|
|
39
39
|
s.add_dependency "sinatra", version
|
40
40
|
s.add_dependency "mustermann", "~> 1.0"
|
41
|
-
s.add_dependency "backports", ">= 2.8.2"
|
42
41
|
s.add_dependency "tilt", "~> 2.0"
|
43
42
|
s.add_dependency "rack-protection", version
|
44
43
|
s.add_dependency "multi_json"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/sinatra/sinatra/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0
|
19
|
+
version: 2.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0
|
26
|
+
version: 2.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mustermann
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: backports
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2.8.2
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.8.2
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: tilt
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +58,14 @@ dependencies:
|
|
72
58
|
requirements:
|
73
59
|
- - '='
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.0
|
61
|
+
version: 2.1.0
|
76
62
|
type: :runtime
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - '='
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.0
|
68
|
+
version: 2.1.0
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: multi_json
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -400,6 +386,7 @@ files:
|
|
400
386
|
- lib/sinatra/link_header.rb
|
401
387
|
- lib/sinatra/multi_route.rb
|
402
388
|
- lib/sinatra/namespace.rb
|
389
|
+
- lib/sinatra/quiet_logger.rb
|
403
390
|
- lib/sinatra/reloader.rb
|
404
391
|
- lib/sinatra/required_params.rb
|
405
392
|
- lib/sinatra/respond_with.rb
|
@@ -423,15 +410,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
423
410
|
requirements:
|
424
411
|
- - ">="
|
425
412
|
- !ruby/object:Gem::Version
|
426
|
-
version: 2.
|
413
|
+
version: 2.3.0
|
427
414
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
428
415
|
requirements:
|
429
416
|
- - ">="
|
430
417
|
- !ruby/object:Gem::Version
|
431
418
|
version: '0'
|
432
419
|
requirements: []
|
433
|
-
|
434
|
-
rubygems_version: 2.7.3
|
420
|
+
rubygems_version: 3.1.2
|
435
421
|
signing_key:
|
436
422
|
specification_version: 4
|
437
423
|
summary: Collection of useful Sinatra extensions
|