Permalink
Browse files

flash text

  • Loading branch information...
1 parent 1876925 commit 29dc13bced1a1ae1bae6b21eebe5b2b7ea47492b Fernando Via committed Dec 14, 2011
View
0 .gitignore 100644 → 100755
No changes.
View
28 README.rdoc 100644 → 100755
@@ -190,6 +190,34 @@ Another helper you may find useful is <tt>extract("source_text/html", word_count
%p= extract content, 25
+=== <tt>flash</tt> & <tt>flash?</tt>
+
+Most times on a POST request the server performs an action and you want to give the user some feedback about that action. The data for that feedback has become known as "flash text" steming from the Rails argot.
+
+Piano provides <tt>flash</tt> for you, ease to use. A sample
+
+==== Pianofile
+
+ post "/article/new" do
+ Article.create params # ActiveRecord-like article creation
+
+ flash "The article was created" # You set the flash text by calling `flash`
+ # with an argument
+ end
+
+==== articles.haml
+
+ %html
+ %head
+ %title Articles index
+ %body
+ - if flash? # Checks if any flash text is setted
+ %output= flash
+
+<tt>flash</tt> called without an argument destructively returns the flash text. Destructively so further request to <tt>/articles</tt> (which in this case will bring up <tt>articles.haml</tt>) will not display the flash text.
+
+Internally, <tt>flash</tt> and <tt>flash?</tt> set and check the <tt>session[:flash]</tt> object.
+
Code is poetry.
=== Etags
View
0 Rakefile 100644 → 100755
No changes.
View
0 bin/piano~ 100644 → 100755
No changes.
View
0 lib/piano.rb 100644 → 100755
No changes.
View
0 lib/piano/controllerloader.rb 100644 → 100755
No changes.
View
0 lib/piano/routes.rb 100644 → 100755
No changes.
View
2 lib/piano/version.rb 100644 → 100755
@@ -1,3 +1,3 @@
module Piano
- VERSION = "0.10.6"
+ VERSION = "0.10.7"
end
View
21 lib/sinatra/piano.rb 100644 → 100755
@@ -131,10 +131,29 @@ def etags?
end
end
+ # Returns the session[:flash] if is defined, nil otherwise
+ def flash?
+ session[:flash]
+ end
+
+ # If an argument is passed, it sets the `session[:flash]` to the passed argument
+ #
+ # Otherwise, returns `session[:flash]` and removes `:flash` from the `session`
+ # hash to make it available for subsequent requests.
+ def flash data = nil
+ if data
+ session[:flash] = data
+ else
+ flash_text = session[:flash]
+ session.delete :flash
+ return flash_text
+ end
+ end
+
# Non implemented yet
def t(key)
I18n.translate key
- end
+ end
end
register Piano
View
0 piano.gemspec 100644 → 100755
No changes.
View
0 sample/app.coffee 100644 → 100755
No changes.
View
0 sample/data/index.yaml 100644 → 100755
No changes.
View
0 sample/index.haml 100644 → 100755
No changes.
View
0 sample/style.sass 100644 → 100755
No changes.

0 comments on commit 29dc13b

Please sign in to comment.