sinatra-contrib 2.0.7 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/sinatra/capture.rb +1 -1
- data/lib/sinatra/config_file.rb +2 -2
- data/lib/sinatra/content_for.rb +1 -1
- data/lib/sinatra/contrib/setup.rb +3 -5
- data/lib/sinatra/contrib/version.rb +1 -1
- data/lib/sinatra/contrib.rb +16 -16
- 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 +7 -8
- 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: 56bc8589a21075194b76aa26daae7790568dddf0d3f4094ba980aee8319d70e4
|
4
|
+
data.tar.gz: e5c414d4d897a18dbf4338e0f6dd034e4b0074091f44ad844cbbb76f1d85be33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cc49665d4b53a9e3c284f4d7a2ef8e3d92eea9dc7fbf01e427e4a23dff912b524cbe8548e363fb2a888a1f925a3a4a25c36c71cde7934b9cf652c338aa4a196
|
7
|
+
data.tar.gz: ef656443050ea347f37a535524a6767b4fba9505ba6cdcde03a6a78042bb649278ae22e08e4c43192cf0c58fd1eaaa19a16b04a22b51b72a2a9712e553bd04af
|
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/capture.rb
CHANGED
@@ -86,7 +86,7 @@ module Sinatra
|
|
86
86
|
|
87
87
|
def capture(*args, &block)
|
88
88
|
return block[*args] if ruby?
|
89
|
-
if haml?
|
89
|
+
if haml? && Tilt[:haml] == Tilt::HamlTemplate
|
90
90
|
buffer = Haml::Buffer.new(nil, Haml::Options.new.for_buffer)
|
91
91
|
with_haml_buffer(buffer) { capture_haml(*args, &block) }
|
92
92
|
else
|
data/lib/sinatra/config_file.rb
CHANGED
@@ -121,7 +121,7 @@ module Sinatra
|
|
121
121
|
Dir.chdir(root || '.') do
|
122
122
|
paths.each do |pattern|
|
123
123
|
Dir.glob(pattern) do |file|
|
124
|
-
raise UnsupportedConfigType unless ['.yml', '.erb'].include?(File.extname(file))
|
124
|
+
raise UnsupportedConfigType unless ['.yml', '.yaml', '.erb'].include?(File.extname(file))
|
125
125
|
logger.info "loading config file '#{file}'" if logging? && respond_to?(:logger)
|
126
126
|
document = ERB.new(IO.read(file)).result
|
127
127
|
yaml = YAML.load(document)
|
@@ -134,7 +134,7 @@ module Sinatra
|
|
134
134
|
|
135
135
|
class UnsupportedConfigType < Exception
|
136
136
|
def message
|
137
|
-
'Invalid config file type, use .yml or .
|
137
|
+
'Invalid config file type, use .yml, .yaml or .erb'
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
data/lib/sinatra/content_for.rb
CHANGED
@@ -174,7 +174,7 @@ module Sinatra
|
|
174
174
|
# for <tt>:head</tt>.
|
175
175
|
def yield_content(key, *args, &block)
|
176
176
|
if block_given? && !content_for?(key)
|
177
|
-
haml? ? capture_haml(*args, &block) : yield(*args)
|
177
|
+
(haml? && Tilt[:haml] == Tilt::HamlTemplate) ? capture_haml(*args, &block) : yield(*args)
|
178
178
|
else
|
179
179
|
content = content_blocks[key.to_sym].map { |b| capture(*args, &b) }
|
180
180
|
content.join.tap do |c|
|
@@ -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/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
|
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
|
@@ -278,8 +284,8 @@ module Sinatra
|
|
278
284
|
end
|
279
285
|
|
280
286
|
def set(key, value = self, &block)
|
281
|
-
|
282
|
-
|
287
|
+
return key.each { |k,v| set(k, v) } if key.respond_to?(:each) and block.nil? and value == self
|
288
|
+
raise ArgumentError, "may not set #{key}" unless ([:views] + ALLOWED_ENGINES).include?(key)
|
283
289
|
block ||= proc { value }
|
284
290
|
singleton_class.send(:define_method, key, &block)
|
285
291
|
end
|
@@ -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
@@ -169,15 +169,14 @@ module Sinatra
|
|
169
169
|
settings.template_engines[:all].each do |engine|
|
170
170
|
exts.each { |ext| possible << [engine, "#{name}.#{ext}"] }
|
171
171
|
end
|
172
|
+
|
172
173
|
exts.each do |ext|
|
173
174
|
settings.template_engines[ext].each { |e| possible << [e, name] }
|
174
175
|
end
|
176
|
+
|
175
177
|
possible.each do |engine, template|
|
176
|
-
|
177
|
-
|
178
|
-
rescue LoadError
|
179
|
-
next
|
180
|
-
end
|
178
|
+
klass = Tilt.default_mapping.template_map[engine.to_s] ||
|
179
|
+
Tilt.lazy_map[engine.to_s].fetch(0, [])[0]
|
181
180
|
|
182
181
|
find_template(settings.views, template, klass) do |file|
|
183
182
|
next unless File.exist? file
|
@@ -222,7 +221,7 @@ module Sinatra
|
|
222
221
|
|
223
222
|
private
|
224
223
|
|
225
|
-
def compile!(verb, path, block, options
|
224
|
+
def compile!(verb, path, block, **options)
|
226
225
|
options[:provides] ||= respond_to if respond_to
|
227
226
|
super
|
228
227
|
end
|
@@ -241,8 +240,8 @@ module Sinatra
|
|
241
240
|
:css => [:less, :sass, :scss],
|
242
241
|
:xml => [:builder, :nokogiri],
|
243
242
|
:js => [:coffee],
|
244
|
-
:html => [:erb, :erubi, :erubis, :haml, :slim, :liquid, :radius,
|
245
|
-
:markdown, :textile, :rdoc],
|
243
|
+
:html => [:erb, :erubi, :erubis, :haml, :hamlit, :slim, :liquid, :radius,
|
244
|
+
:mab, :markdown, :textile, :rdoc],
|
246
245
|
:all => (Sinatra::Templates.instance_methods.map(&:to_sym) +
|
247
246
|
[:mab] - [:find_template, :markaby]),
|
248
247
|
:json => [:yajl],
|
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.2.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:
|
11
|
+
date: 2022-02-15 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.2.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.2.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.2.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.2.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
|