Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 48 lines (39 sloc) 1.093 kb
232b53d @balinterdi - implementing a simple flash
authored
1 require "ruby-debug"
2
3 module Sinatra::MyHelpers
4
5 def self.included(base)
6 base.class_eval do
7 include Flash
2f679d9 @balinterdi - adding helper for partial rendering
authored
8 include Partial
232b53d @balinterdi - implementing a simple flash
authored
9 end
10 end
11
12 module Flash
13
14 def flash
9308679 @balinterdi a flash implementation where flash_reset need not to be integrated in…
authored
15 if !@flash
16 @flash = (session["flash"] = Hash.new)
232b53d @balinterdi - implementing a simple flash
authored
17 end
9308679 @balinterdi a flash implementation where flash_reset need not to be integrated in…
authored
18 @flash
232b53d @balinterdi - implementing a simple flash
authored
19 end
20
21 def reset_flash
22 session.delete("flash")
23 end
24 end
25
2f679d9 @balinterdi - adding helper for partial rendering
authored
26 # taken -and slightly modified- from http://sinatra.github.com/book.html#partials
27 module Partial
28
29 def partial(template, *args)
30 options = args.last.is_a?(::Hash) ? args.pop : {}
31 options.merge!(:layout => false)
e64f250 @balinterdi fixing partial generation for single instance (not collection)
authored
32 template_name = "_#{template}".to_sym
2f679d9 @balinterdi - adding helper for partial rendering
authored
33 if collection = options.delete(:collection) then
34 collection.inject([]) do |buffer, member|
e64f250 @balinterdi fixing partial generation for single instance (not collection)
authored
35 buffer << haml(template_name, options.merge(
2f679d9 @balinterdi - adding helper for partial rendering
authored
36 :layout => false,
37 :locals => {template.to_sym => member} # :todo = <Todo:3e345>
38 )
39 )
40 end.join("\n")
41 else
e64f250 @balinterdi fixing partial generation for single instance (not collection)
authored
42 haml(template_name, options)
2f679d9 @balinterdi - adding helper for partial rendering
authored
43 end
44 end
45 end
46
47
232b53d @balinterdi - implementing a simple flash
authored
48 end
Something went wrong with that request. Please try again.