flasherella 0.2.alpha → 0.3.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cd7d44727aa4675c2721f0c237e4f501496301e
4
- data.tar.gz: eccad46199451f156d4dc16e425a69fe86990b29
3
+ metadata.gz: 38e36dfddb4a9f6b3e073300b0628ccfd1b24f28
4
+ data.tar.gz: d12250d49d356295a033ac28e9e48c3dabb018fc
5
5
  SHA512:
6
- metadata.gz: 5dba0d1a5cef0ccbbe1ea80d84edec35282731cbe866f76d08906d5c18fd460ab0cf4f98580670e66be90ec4638df92fd5560cb251e284e1c113734faaaefdd8
7
- data.tar.gz: 007734e23aa9e402ac8dc7c43ed8882b586801e6f24c68780f108280df59e3ee5d2b5695afe9dfd04f5611229caf237f24d08f10a9ceffc8c1be3b25c127437a
6
+ metadata.gz: 2695edf4e2637397b3f7a122a6c2d4b4d018935888642954be163241c78e6c90bc4f9fb964c2fc4eefa7ccc0ca1071fb69f822e7d29ffe77ac3670c34344b2ed
7
+ data.tar.gz: 235f1a3f6323b3f575cf14411239ebe11543d8032f8c564e9e48b700c57e0964028780afeb8727918c509c08b3994c5d7af34983c72ea786befc37287ed492ff
data/.gitignore CHANGED
@@ -4,7 +4,7 @@
4
4
  /_yardoc/
5
5
  /coverage/
6
6
  /doc/
7
- /pkg/
7
+ /pkg/*
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  *.bundle
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .DS_Store
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Automatically display flash messages when an XHR request is made. No more having to manually insert them into the DOM.
4
4
 
5
+ This has been extracted from numerous projects.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -20,4 +22,29 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
23
- TODO: Write usage instructions here
25
+ In your application.js file,
26
+
27
+ ```
28
+ //= require flasherella
29
+ ```
30
+
31
+ And somewhere in your application.html.erb layout,
32
+
33
+ ```
34
+ <div id="flashes"></div>
35
+ ```
36
+
37
+ ## Options
38
+
39
+ ```
40
+ Flasherella.config do |config|
41
+ config.flash_container_element = '#flashes' # or where your flashes are contained.
42
+ config.flash_keys = [:success, :notice, :error, :warning] # valid keys for flashing - this can also be a
43
+ hash of valid flash keys, and their CSS class names.
44
+ config.flash_key_prefix = 'alert-' # prefixes the names of the CSS classes for each flash key.
45
+ config.flash_html = '<div class="flash alert {{klass}} ">{{msg}}<button type="button" class="close"
46
+ data-dismiss="alert"><span aria-hidden="true">&times;</span>
47
+ <span class="sr-only">Close</span></button></div>'
48
+ # can be anything. just make sure you have {{klass}} and {{msg}} somewhere for everything to render properly.
49
+ end
50
+ ```
@@ -0,0 +1,14 @@
1
+ $(document).ajaxComplete(function(event, request) {
2
+ var alert_class, klass, msg;
3
+ msg = request.getResponseHeader("X-Flash-Message");
4
+ alert_class = request.getResponseHeader("X-Flash-Type");
5
+ flash_classes = <%=Flasherella.flash_classes.to_json%>;
6
+ klass = flash_classes[alert_class];
7
+ if (msg) {
8
+ var flashes_el = $("<%=Flasherella.config.flash_container_element%>");
9
+ var flash_html = '<%= Flasherella.config.flash_html%>';
10
+ var html = flash_html.replace("{{klass}}", klass).replace("{{msg}}", msg);
11
+ flashes_el.html(html);
12
+ }
13
+ });
14
+
data/lib/flasherella.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "flasherella/config"
1
2
  require "flasherella/version"
2
3
  require 'flasherella/engine'
3
4
  require "flasherella/application_controller"
@@ -1,4 +1,22 @@
1
1
  module Flasherella
2
+
3
+ def self.config
4
+ @@config ||= Flasherella::Config.instance
5
+ yield @@config if block_given?
6
+ @@config
7
+ end
8
+
9
+ def self.flash_classes
10
+ keys = Flasherella.config.flash_keys
11
+ if keys.is_a?(Hash)
12
+ return keys
13
+ end
14
+
15
+ classes = []; keys.each { |key| classes << "#{Flasherella.config.flash_key_prefix}#{key}"}
16
+ hash = keys.zip(classes)
17
+ Hash[hash]
18
+ end
19
+
2
20
  module ApplicationController
3
21
 
4
22
  def self.included(base)
@@ -14,20 +32,19 @@ module Flasherella
14
32
  end
15
33
 
16
34
  def flash_message
17
- [:error, :warning, :notice, :success].each do |type|
35
+ Flasherella.config.flash_keys.each do |type|
18
36
  return flash[type] unless flash[type].blank?
19
37
  end
20
38
  ''
21
39
  end
22
40
 
23
41
  def flash_type
24
- [:error, :warning, :notice, :success].each do |type|
42
+ Flasherella.config.flash_keys.each do |type|
25
43
  return type unless flash[type].blank?
26
44
  end
27
45
  :empty
28
46
  end
29
47
 
30
- end
31
-
32
-
33
- end
48
+ end
49
+
50
+ end
@@ -0,0 +1,15 @@
1
+ require 'singleton'
2
+
3
+ module Flasherella
4
+ class Config
5
+ include Singleton
6
+ attr_accessor :flash_container_element, :flash_keys, :flash_html, :flash_key_prefix
7
+
8
+ def initialize(&block)
9
+ @flash_container_element = '#flashes'
10
+ @flash_keys = [:success, :notice, :error, :warning]
11
+ @flash_key_prefix = 'alert-'
12
+ @flash_html = '<div class="flash alert {{klass}} ">{{msg}}<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button></div>';
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Flasherella
2
- VERSION = "0.2.alpha"
2
+ VERSION = "0.3.alpha"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flasherella
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.alpha
4
+ version: 0.3.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-25 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,14 +50,12 @@ files:
50
50
  - LICENSE.txt
51
51
  - README.md
52
52
  - Rakefile
53
- - app/assets/javascripts/flasherella.coffee
54
- - flasherella-0.1.alpha.gem
53
+ - app/assets/javascripts/flasherella.js.erb
55
54
  - flasherella.gemspec
56
55
  - gem-public_cert.pem
57
- - lib/.DS_Store
58
56
  - lib/flasherella.rb
59
- - lib/flasherella/.DS_Store
60
57
  - lib/flasherella/application_controller.rb
58
+ - lib/flasherella/config.rb
61
59
  - lib/flasherella/engine.rb
62
60
  - lib/flasherella/version.rb
63
61
  homepage: ''
@@ -1,5 +0,0 @@
1
- $(document).ajaxComplete (event, request) ->
2
- msg = request.getResponseHeader("X-Flash-Message")
3
- alert_class = request.getResponseHeader("X-Flash-Type")
4
- klass = { success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[alert_class]
5
- $("#flashes").html('<div class="flash alert ' + klass + ' ">' + msg + '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button></div>') if msg
Binary file
data/lib/.DS_Store DELETED
Binary file
Binary file