]> cat aescling's git repositories - mastodon.git/commitdiff
Clean up flash display in views (#2336)
authorMatt Jankowski <mjankowski@thoughtbot.com>
Sun, 23 Apr 2017 02:22:34 +0000 (22:22 -0400)
committerEugen <eugen@zeonfederated.com>
Sun, 23 Apr 2017 02:22:34 +0000 (04:22 +0200)
* Add flashes partial to DRY up admin/auth layouts

* Further consolidate flash messages

app/helpers/flashes_helper.rb [new file with mode: 0644]
app/views/application/_flashes.html.haml [new file with mode: 0644]
app/views/layouts/admin.html.haml
app/views/layouts/auth.html.haml

diff --git a/app/helpers/flashes_helper.rb b/app/helpers/flashes_helper.rb
new file mode 100644 (file)
index 0000000..6c5e937
--- /dev/null
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+module FlashesHelper
+  def user_facing_flashes
+    flash.to_hash.slice('alert', 'error', 'notice', 'success')
+  end
+end
diff --git a/app/views/application/_flashes.html.haml b/app/views/application/_flashes.html.haml
new file mode 100644 (file)
index 0000000..63587e7
--- /dev/null
@@ -0,0 +1,3 @@
+- user_facing_flashes.each do |key, value|
+  .flash-message{class: key}
+    %strong= value
index 892bcd596d3ff3ff8bd34d3d6c0fa0fc0a3f0311..d2cff5e303a95989234025635cf1ae2d539e656a 100644 (file)
       .content
         %h2= yield :page_title
 
-        - if flash[:notice]
-          .flash-message.notice
-            %strong= flash[:notice]
-
-        - if flash[:alert]
-          .flash-message.alert
-            %strong= flash[:alert]
+        = render 'flashes'
 
         = yield
 
index 899690419528a2d1c88fa0d59c082f3a4c5645ca..b2ceed12a9c2be937752fdcb6496cc23ab31dcc3 100644 (file)
@@ -9,13 +9,7 @@
           = image_tag 'logo.png'
 
     .form-container
-      - if flash[:notice]
-        .flash-message.notice
-          %strong= flash[:notice]
-
-      - if flash[:alert]
-        .flash-message.alert
-          %strong= flash[:alert]
+      = render 'flashes'
 
       = yield