class Sinatra::Bells

Constants

VERSION

Public Class Methods

set(option, *args, &block) click to toggle source
Calls superclass method
   # File lib/sinatra/bells.rb
37 def set(option, *args, &block)
38   block ? args.empty? ? set_defer(option, &block) :
39     raise(ArgumentError, 'both block and arguments given') :
40       (set(option, nil) if args.first.is_a?(Hash); super(option, *args))
41 end
set_async(option, &block) click to toggle source
   # File lib/sinatra/bells.rb
47 def set_async(option, &block)
48   thread = Thread.new(&block)
49   set_defer(option) { thread.value }
50 end
set_defer(option, &block) click to toggle source
   # File lib/sinatra/bells.rb
43 def set_defer(option, &block)
44   set(option, lambda { set(option, value = instance_eval(&block)); value })
45 end
set_hash(opt, ary, suf = nil, &block) click to toggle source
   # File lib/sinatra/bells.rb
52 def set_hash(opt, ary, suf = nil, &block)
53   (a, b = suf; ary.map! { |i| %W[#{i}#{a} #{i}#{b}] }) if suf
54   ary.map!(&block) if block
55   set(opt, Hash[ary])
56 end
set_root(file) click to toggle source
   # File lib/sinatra/bells.rb
58 def set_root(file)
59   set(:root, file.chomp(File.extname(file)))
60 end

Private Class Methods

route(verb, path, options = {}, &block) click to toggle source
Calls superclass method
   # File lib/sinatra/bells.rb
64 def route(verb, path, options = {}, &block)
65   return super unless render = options.delete(:render)
66 
67   if render.is_a?(Hash)
68     template = render.delete(:html)
69   else
70     template, render = render, settings.default_render
71   end
72 
73   blocks = {}
74 
75   type_paths(render, path) { |type_path, type, method|
76     super(verb, type_path, options, &blocks[type] = lambda {
77       content_type(type)
78       instance_eval(&block)
79       instance_eval(&method)
80     })
81   }
82 
83   super(verb, path, options.merge(provides: :html)) {
84     instance_eval(&block)
85     send(settings.default_renderer, template)
86   }
87 
88   blocks.each { |type, type_block|
89     super(verb, path, options.merge(provides: type), &type_block)
90   }
91 end
type_paths(render, path) { |re ? regexp: type_path, type, method| ... } click to toggle source
    # File lib/sinatra/bells.rb
 93 def type_paths(render, path)
 94   path, re = path.source, path if path.is_a?(Regexp)
 95   anchor = $& if re && path.sub!(/\\z|\$/i, '')
 96 
 97   dot = '.' unless path.end_with?('/')
 98   dot = Regexp.escape(dot) if dot && re
 99 
100   render.each { |type, method|
101     type_path = "#{path}#{dot}#{type}#{anchor}"
102     yield re ? Regexp.new(type_path, re.options) : type_path, type, method
103   }
104 end