Skip to content
Browse files

adds flash-messages

  • Loading branch information...
1 parent 76613c2 commit 0c045ff0e2ab974b1118a5177e1c7fa045726e09 @slagyr slagyr committed Jan 15, 2014
View
2 example/project.clj
@@ -3,7 +3,7 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
- :dependencies [[com.8thlight/filament "1.2.0"]
+ :dependencies [[com.8thlight/filament "1.2.1"]
[com.8thlight/hiccup "1.1.1"]
[org.clojure/clojure "1.5.1"]]
View
30 example/src/cljs/example/flash_demo.cljs
@@ -0,0 +1,30 @@
+(ns example.flash-demo
+ (:require-macros [hiccup.core :as h])
+ (:require [clojure.string :as string]
+ [com.eighthlight.filament.flash :as flash]
+ [com.eighthlight.filament.util :as util]
+ [domina :as dom]
+ [hiccup.core]))
+
+(def dom [:div.example
+ [:h2 "com.eighthlight.filament.flash"]
+ [:p "Try clicking the buttons below.
+ You'll see the text below added to the page as a flash message. error, notice, and success use distinct and expressive colors.
+ clear-flash! will remove them all."]
+ [:input#flash-input {:type "text" :value "A flash message"}]
+ [:br]
+ [:button#flash-error-button "flash-error!"]
+ [:button#flash-notice-button "flash-notice!"]
+ [:button#flash-success-button "flash-success!"]
+ [:button#clear-flash-button "clear-flash!"]
+ [:button#flash-messages-button "flash-messages"]
+ ])
+
+(defn demo-flash []
+ (dom/append! (.-body js/document) (h/html dom))
+ (util/override-click! (dom/by-id "flash-error-button") #(flash/flash-error! (dom/value (dom/by-id "flash-input"))))
+ (util/override-click! (dom/by-id "flash-notice-button") #(flash/flash-notice! (dom/value (dom/by-id "flash-input"))))
+ (util/override-click! (dom/by-id "flash-success-button") #(flash/flash-success! (dom/value (dom/by-id "flash-input"))))
+ (util/override-click! (dom/by-id "clear-flash-button") #(flash/clear-flash!))
+ (util/override-click! (dom/by-id "flash-messages-button") #(js/alert (flash/flash-messages))))
+
View
2 project.clj
@@ -1,4 +1,4 @@
-(defproject com.8thlight/filament "1.2.0"
+(defproject com.8thlight/filament "1.2.1"
:description "Rich client utilities"
:url "http://github.com/8thlight/filament"
:license {:name "Eclipse Public License"
View
20 spec/cljs/com/eighthlight/filament/flash_spec.cljs
@@ -73,10 +73,28 @@
(should= nil (dom/by-id "flash-notices"))
(should= nil (dom/by-id "flash-successes")))
-
(it "css classes"
(should-contain "flash-container" (dom/classes (flash/flash-container-node)))
(should-contain "flash-errors" (dom/classes (flash/errors-node)))
(should-contain "flash-notices" (dom/classes (flash/notices-node)))
(should-contain "flash-successes" (dom/classes (flash/successes-node))))
+
+ (it "returns all the flash messages"
+ (should= {:error [] :notice [] :success []} (flash/flash-messages))
+
+ (flash/flash-error! "1")
+ (should= {:error ["1"] :notice [] :success []} (flash/flash-messages))
+
+ (flash/flash-notice! "2")
+ (should= {:error ["1"] :notice ["2"] :success []} (flash/flash-messages))
+
+ (flash/flash-success! "3")
+ (should= {:error ["1"] :notice ["2"] :success ["3"]} (flash/flash-messages))
+
+ (flash/flash-success! "4")
+ (should= {:error ["1"] :notice ["2"] :success ["3" "4"]} (flash/flash-messages))
+
+ (flash/clear-flash!)
+ (should= {:error [] :notice [] :success []} (flash/flash-messages))
+ )
)
View
11 src/cljs/com/eighthlight/filament/flash.cljs
@@ -72,4 +72,13 @@
"Removes all flash nodes from the DOM."
[]
(when-let [container (dom/by-id "flash-container")]
- (dom/destroy! container)))
+ (dom/destroy! container)))
+
+(defn flash-messages
+ "Returns a map of currently displayed flash messages in the form:
+
+ {:error [] :notice [] :success []}"
+ []
+ {:error (map dom/text (rest (dom/children (dom/by-id "flash-errors"))))
+ :notice (map dom/text (rest (dom/children (dom/by-id "flash-notices"))))
+ :success (map dom/text (rest (dom/children (dom/by-id "flash-successes"))))})

0 comments on commit 0c045ff

Please sign in to comment.
Something went wrong with that request. Please try again.