Merge pull request #1185 from namusyaka/fix-a-little-coding-style
A few small code-style improvements
This commit is contained in:
commit
5db06e8356
|
@ -469,8 +469,8 @@ module Sinatra
|
||||||
def cache_control(*values)
|
def cache_control(*values)
|
||||||
if values.last.kind_of?(Hash)
|
if values.last.kind_of?(Hash)
|
||||||
hash = values.pop
|
hash = values.pop
|
||||||
hash.reject! { |k,v| v == false }
|
hash.reject! { |k, v| v == false }
|
||||||
hash.reject! { |k,v| values << k if v == true }
|
hash.reject! { |k, v| values << k if v == true }
|
||||||
else
|
else
|
||||||
hash = {}
|
hash = {}
|
||||||
end
|
end
|
||||||
|
@ -705,7 +705,7 @@ module Sinatra
|
||||||
render :less, template, options, locals
|
render :less, template, options, locals
|
||||||
end
|
end
|
||||||
|
|
||||||
def stylus(template, options={}, locals={})
|
def stylus(template, options = {}, locals = {})
|
||||||
options.merge! :layout => false, :default_content_type => :css
|
options.merge! :layout => false, :default_content_type => :css
|
||||||
render :styl, template, options, locals
|
render :styl, template, options, locals
|
||||||
end
|
end
|
||||||
|
@ -807,7 +807,7 @@ module Sinatra
|
||||||
|
|
||||||
def render(engine, data, options = {}, locals = {}, &block)
|
def render(engine, data, options = {}, locals = {}, &block)
|
||||||
# merge app-level options
|
# merge app-level options
|
||||||
engine_options = settings.respond_to?(engine) ? settings.send(engine) : {}
|
engine_options = settings.respond_to?(engine) ? settings.send(engine) : {}
|
||||||
options.merge!(engine_options) { |key, v1, v2| v1 }
|
options.merge!(engine_options) { |key, v1, v2| v1 }
|
||||||
|
|
||||||
# extract generic options
|
# extract generic options
|
||||||
|
@ -1081,7 +1081,7 @@ module Sinatra
|
||||||
|
|
||||||
# Creates a Hash with indifferent access.
|
# Creates a Hash with indifferent access.
|
||||||
def indifferent_hash
|
def indifferent_hash
|
||||||
Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
Hash.new { |hash, key| hash[key.to_s] if Symbol === key }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the block with 'throw :halt' support and apply result to the response.
|
# Run the block with 'throw :halt' support and apply result to the response.
|
||||||
|
@ -1207,7 +1207,7 @@ module Sinatra
|
||||||
@extensions = []
|
@extensions = []
|
||||||
|
|
||||||
if superclass.respond_to?(:templates)
|
if superclass.respond_to?(:templates)
|
||||||
@templates = Hash.new { |hash,key| superclass.templates[key] }
|
@templates = Hash.new { |hash, key| superclass.templates[key] }
|
||||||
else
|
else
|
||||||
@templates = {}
|
@templates = {}
|
||||||
end
|
end
|
||||||
|
@ -1283,7 +1283,7 @@ module Sinatra
|
||||||
# handled.
|
# handled.
|
||||||
def error(*codes, &block)
|
def error(*codes, &block)
|
||||||
args = compile! "ERROR", /.*/, block
|
args = compile! "ERROR", /.*/, block
|
||||||
codes = codes.map { |c| Array(c) }.flatten
|
codes = codes.flat_map(&method(:Array))
|
||||||
codes << Exception if codes.empty?
|
codes << Exception if codes.empty?
|
||||||
codes << Sinatra::NotFound if codes.include?(404)
|
codes << Sinatra::NotFound if codes.include?(404)
|
||||||
codes.each { |c| (@errors[c] ||= []) << args }
|
codes.each { |c| (@errors[c] ||= []) << args }
|
||||||
|
@ -1639,8 +1639,8 @@ module Sinatra
|
||||||
unbound_method = generate_method(method_name, &block)
|
unbound_method = generate_method(method_name, &block)
|
||||||
conditions, @conditions = @conditions, []
|
conditions, @conditions = @conditions, []
|
||||||
wrapper = block.arity != 0 ?
|
wrapper = block.arity != 0 ?
|
||||||
proc { |a,p| unbound_method.bind(a).call(*p) } :
|
proc { |a, p| unbound_method.bind(a).call(*p) } :
|
||||||
proc { |a,p| unbound_method.bind(a).call }
|
proc { |a, p| unbound_method.bind(a).call }
|
||||||
|
|
||||||
[ pattern, conditions, wrapper ]
|
[ pattern, conditions, wrapper ]
|
||||||
end
|
end
|
||||||
|
@ -1909,14 +1909,14 @@ module Sinatra
|
||||||
# top-level. Subclassing Sinatra::Base is highly recommended for
|
# top-level. Subclassing Sinatra::Base is highly recommended for
|
||||||
# modular applications.
|
# modular applications.
|
||||||
class Application < Base
|
class Application < Base
|
||||||
set :logging, Proc.new { ! test? }
|
set :logging, Proc.new { !test? }
|
||||||
set :method_override, true
|
set :method_override, true
|
||||||
set :run, Proc.new { ! test? }
|
set :run, Proc.new { !test? }
|
||||||
set :session_secret, Proc.new { super() unless development? }
|
set :session_secret, Proc.new { super() unless development? }
|
||||||
set :app_file, nil
|
set :app_file, nil
|
||||||
|
|
||||||
def self.register(*extensions, &block) #:nodoc:
|
def self.register(*extensions, &block) #:nodoc:
|
||||||
added_methods = extensions.map {|m| m.public_instance_methods }.flatten
|
added_methods = extensions.flat_map(&:public_instance_methods)
|
||||||
Delegator.delegate(*added_methods)
|
Delegator.delegate(*added_methods)
|
||||||
super(*extensions, &block)
|
super(*extensions, &block)
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Sinatra
|
||||||
def @@eats_errors.puts(*) end
|
def @@eats_errors.puts(*) end
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
|
@ -51,14 +51,14 @@ module Sinatra
|
||||||
|
|
||||||
def prefers_plain_text?(env)
|
def prefers_plain_text?(env)
|
||||||
!(Request.new(env).preferred_type("text/plain","text/html") == "text/html") &&
|
!(Request.new(env).preferred_type("text/plain","text/html") == "text/html") &&
|
||||||
[/curl/].index{|item| item =~ env["HTTP_USER_AGENT"]}
|
[/curl/].index { |item| item =~ env["HTTP_USER_AGENT"] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def frame_class(frame)
|
def frame_class(frame)
|
||||||
if frame.filename =~ /lib\/sinatra.*\.rb/
|
if frame.filename =~ %r{lib/sinatra.*\.rb}
|
||||||
"framework"
|
"framework"
|
||||||
elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
|
elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
|
||||||
frame.filename =~ /\/bin\/(\w+)$/
|
frame.filename =~ %r{/bin/(\w+)\z}
|
||||||
"system"
|
"system"
|
||||||
else
|
else
|
||||||
"app"
|
"app"
|
||||||
|
|
|
@ -161,7 +161,7 @@ module Sinatra
|
||||||
end
|
end
|
||||||
|
|
||||||
if hash.respond_to? :to_hash
|
if hash.respond_to? :to_hash
|
||||||
indifferent_hash = Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
indifferent_hash = Hash.new { |hash, key| hash[key.to_s] if Symbol === key }
|
||||||
indifferent_hash.merge hash.to_hash
|
indifferent_hash.merge hash.to_hash
|
||||||
else
|
else
|
||||||
hash
|
hash
|
||||||
|
|
|
@ -179,7 +179,7 @@ module Sinatra
|
||||||
private
|
private
|
||||||
|
|
||||||
def content_blocks
|
def content_blocks
|
||||||
@content_blocks ||= Hash.new {|h,k| h[k] = [] }
|
@content_blocks ||= Hash.new { |h, k| h[k] = [] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue