sinatra-contrib 2.0.5 → 2.1.0

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
  SHA256:
3
- metadata.gz: 875fcac85ec3549476fa9363e6d74a93169d9bff6a285afa085dd9927e377b8f
4
- data.tar.gz: a6f37d1271320146ef8a988b236276bb9b5385a44839f26ccc9740e5bd1fba85
3
+ metadata.gz: b975fa7ce92c5cf316ecd5435760f80079cfe461ca28ff298b188eb08519dc52
4
+ data.tar.gz: a7ec2909d72329c6d9089a00013c02aa11c308ce842f8ba3784dc76253eafa3c
5
5
  SHA512:
6
- metadata.gz: 129dad2460c8a80bca9db661361479bf78a8c1369c053056414df493fc37a4b4135dd155c7bc0660b37a5ab03acc68da5dacea9fe35bf48e7493aab833ae5fde
7
- data.tar.gz: ee1bccd800b4636a48a74e31c0371ed3be754e5037c1bf9afe95d782cb3ce8ddabced908fbe1a32cc9841dce16729513cd5c61baf1c0853ca30eb27b8404e60e
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`.
@@ -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
@@ -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 .yml.erb'
137
+ 'Invalid config file type, use .yml, .yaml or .erb'
138
138
  end
139
139
  end
140
140
 
@@ -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|
@@ -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 = nil)
11
+ def register(name, path)
13
12
  autoload name, path, :register
14
13
  end
15
14
 
16
- def helpers(name, path = nil)
15
+ def helpers(name, path)
17
16
  autoload name, path, :helpers
18
17
  end
19
18
 
20
- def autoload(name, path = nil, method = nil)
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
@@ -1,6 +1,6 @@
1
1
  module Sinatra
2
2
  module Contrib
3
- VERSION = '2.0.5'
3
+ VERSION = '2.1.0'
4
4
  end
5
5
  end
6
6
 
@@ -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
- include(*extensions) if extensions.any?
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}" if key != :views
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
@@ -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 = {}, &block)
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
@@ -169,20 +169,15 @@ 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
- # not exactly like Tilt[engine], but does not trigger a require
177
- if Tilt.respond_to?(:mappings)
178
- klass = Tilt.mappings[Tilt.normalize(engine)].first
179
- else
180
- begin
181
- klass = Tilt[engine]
182
- rescue LoadError
183
- next
184
- end
185
- end
178
+ klass = Tilt.default_mapping.template_map[engine.to_s] ||
179
+ Tilt.lazy_map[engine.to_s].fetch(0, [])[0]
180
+
186
181
  find_template(settings.views, template, klass) do |file|
187
182
  next unless File.exist? file
188
183
  return settings.rendering_method(engine) << template.to_sym
@@ -226,7 +221,7 @@ module Sinatra
226
221
 
227
222
  private
228
223
 
229
- def compile!(verb, path, block, options = {})
224
+ def compile!(verb, path, block, **options)
230
225
  options[:provides] ||= respond_to if respond_to
231
226
  super
232
227
  end
@@ -245,8 +240,8 @@ module Sinatra
245
240
  :css => [:less, :sass, :scss],
246
241
  :xml => [:builder, :nokogiri],
247
242
  :js => [:coffee],
248
- :html => [:erb, :erubi, :erubis, :haml, :slim, :liquid, :radius, :mab,
249
- :markdown, :textile, :rdoc],
243
+ :html => [:erb, :erubi, :erubis, :haml, :hamlit, :slim, :liquid, :radius,
244
+ :mab, :markdown, :textile, :rdoc],
250
245
  :all => (Sinatra::Templates.instance_methods.map(&:to_sym) +
251
246
  [:mab] - [:find_template, :markaby]),
252
247
  :json => [:yajl],
@@ -34,12 +34,11 @@ 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.2.0'
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
- s.add_dependency "tilt", ">= 1.3", "< 3"
41
+ s.add_dependency "tilt", "~> 2.0"
43
42
  s.add_dependency "rack-protection", version
44
43
  s.add_dependency "multi_json"
45
44
 
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.5
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: 2018-12-22 00:00:00.000000000 Z
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.5
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.5
26
+ version: 2.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mustermann
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,54 +38,34 @@ 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
58
44
  requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '1.3'
62
- - - "<"
45
+ - - "~>"
63
46
  - !ruby/object:Gem::Version
64
- version: '3'
47
+ version: '2.0'
65
48
  type: :runtime
66
49
  prerelease: false
67
50
  version_requirements: !ruby/object:Gem::Requirement
68
51
  requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- version: '1.3'
72
- - - "<"
52
+ - - "~>"
73
53
  - !ruby/object:Gem::Version
74
- version: '3'
54
+ version: '2.0'
75
55
  - !ruby/object:Gem::Dependency
76
56
  name: rack-protection
77
57
  requirement: !ruby/object:Gem::Requirement
78
58
  requirements:
79
59
  - - '='
80
60
  - !ruby/object:Gem::Version
81
- version: 2.0.5
61
+ version: 2.1.0
82
62
  type: :runtime
83
63
  prerelease: false
84
64
  version_requirements: !ruby/object:Gem::Requirement
85
65
  requirements:
86
66
  - - '='
87
67
  - !ruby/object:Gem::Version
88
- version: 2.0.5
68
+ version: 2.1.0
89
69
  - !ruby/object:Gem::Dependency
90
70
  name: multi_json
91
71
  requirement: !ruby/object:Gem::Requirement
@@ -406,6 +386,7 @@ files:
406
386
  - lib/sinatra/link_header.rb
407
387
  - lib/sinatra/multi_route.rb
408
388
  - lib/sinatra/namespace.rb
389
+ - lib/sinatra/quiet_logger.rb
409
390
  - lib/sinatra/reloader.rb
410
391
  - lib/sinatra/required_params.rb
411
392
  - lib/sinatra/respond_with.rb
@@ -429,15 +410,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
429
410
  requirements:
430
411
  - - ">="
431
412
  - !ruby/object:Gem::Version
432
- version: 2.2.0
413
+ version: 2.3.0
433
414
  required_rubygems_version: !ruby/object:Gem::Requirement
434
415
  requirements:
435
416
  - - ">="
436
417
  - !ruby/object:Gem::Version
437
418
  version: '0'
438
419
  requirements: []
439
- rubyforge_project:
440
- rubygems_version: 2.7.6
420
+ rubygems_version: 3.1.2
441
421
  signing_key:
442
422
  specification_version: 4
443
423
  summary: Collection of useful Sinatra extensions