growlyflash 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 485585c27a4f5e90dfe84007c2cd0134e74f678f
4
- data.tar.gz: f1f6e60ee67820bb9ca39c0a488397f7a0809e57
3
+ metadata.gz: 0916448044b4b1ad571a79e8fdf5d0a2e3b9c84e
4
+ data.tar.gz: e4742b531cbaceb86fbfa2580c8be42f14ffff5f
5
5
  SHA512:
6
- metadata.gz: 3a13f00010ee6d5eba34cf62253b140405b6979d0f6fc6ae8fb6584859bf7091059fbc60804053cf412ebb461fff7fa9078de139240aa0402c827b8193070ea4
7
- data.tar.gz: 3ec0206479ebe6aab5552b9a02e6d5722d0cd464efb8f2f314ead255496571ef3ab18abb65b658d20fcac1abd0c8e34c4cee5d81377d183226905daac83da1a4
6
+ metadata.gz: 29ff204c2aec4df289e9806f9fc6589e2a1df0698f62848660d96916e6aa995073304cccfc3594580459ee12609a96d98095a6d1f6577f6acc973f8b55f5ccb5
7
+ data.tar.gz: f8bb6a87feefe6c0b243d0f35bea97ac00509c2ce497a587a670c2aebecdcd613768a9ee9f59df29f41acfaaaef085648855f6491f2cb9d38cc93ec0bd9bad51
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Growlyflash
2
2
 
3
- Tiny gem which provides growl-styled flash messages for Ruby on Rails with Bootstrap.
3
+ The growlyflash gem turns boring [ActionDispatch::Flash](http://api.rubyonrails.org/v3.2.14/?q=ActionDispatch::Flash) messages in your Rails 3 app to asynchronous Growl-like notifications with [Bootstrap Alert](http://getbootstrap.com/2.3.2/components.html#alerts) markup.
4
4
 
5
- For XHR requests flash messages are transfering in 'X-Messages' headers, otherwise they are storing in js variables.
5
+ With XHR requests it places flash hash to the `X-Messages` HTTP header or inline in javascript.
6
6
 
7
- Based on [Bootstrap Growl](https://github.com/ifightcrime/bootstrap-growl) and little bit on [Bootstrap Flash Messages](https://github.com/RobinBrouwer/bootstrap_flash_messages)
7
+ Based on rewritten in coffeescript [Bootstrap Growl](https://github.com/ifightcrime/bootstrap-growl) plugin and inspired by [Bootstrap Flash Messages](https://github.com/RobinBrouwer/bootstrap_flash_messages)
8
8
 
9
9
  ## Installation
10
10
 
@@ -16,19 +16,53 @@ And then execute:
16
16
 
17
17
  $ bundle
18
18
 
19
- Or install it yourself as:
20
-
21
- $ gem install growlyflash
22
-
23
- Also you need to put this line inside `head` tag in your layout, before any different javascripts:
19
+ For non-XHR requests append the following before other javascripts inside `<head>`:
24
20
 
25
21
  <%= growlyflash_static_notices %>
26
22
 
27
- And require it in your javascript:
23
+ And require glowlyflash in `app/assets/javascripts/application.js`
28
24
 
29
25
  //= require growlyflash/growlyflash
30
26
 
31
- See [Bootstrap Growl](https://github.com/ifightcrime/bootstrap-growl) for any customisations.
27
+ ## Customize
28
+
29
+ If you want to change default options, you can override them somewhere in your coffee/js:
30
+
31
+ $.bootstrapGrowl.defaults = $.extend on, $.bootstrapGrowl.defaults,
32
+ # Box width (number or css-like string, etc. "auto")
33
+ width: 250
34
+
35
+ # Auto-dismiss timeout. Set it to 0 if you want to disable auto-dismiss
36
+ delay: 4000
37
+
38
+ # Spacing between boxes in stack
39
+ spacing: 10
40
+
41
+ # Appends boxes to a specific container
42
+ target: 'body'
43
+
44
+ # Show close button
45
+ dismiss: true
46
+
47
+ # Default class suffix for alert boxes.
48
+ # Use the following mapping (Flash key => Bootstrap Alert)
49
+ # warning: null
50
+ # error: "error"
51
+ # notice: "info"
52
+ # success: "success"
53
+ type: null
54
+
55
+ # Horizontal aligning (left, right or center)
56
+ align: 'right'
57
+
58
+ # Margin from the closest side
59
+ alignAmount: 20
60
+
61
+ # Offset from window bounds
62
+ offset:
63
+ from: 'top'
64
+ amount: 20
65
+
32
66
 
33
67
  ## Contributing
34
68
 
data/lib/growlyflash.rb CHANGED
@@ -3,8 +3,7 @@
3
3
  require "growlyflash/version"
4
4
  require "uri"
5
5
 
6
- module Growlyflash
7
-
6
+ module Growlyflash
8
7
  module XMessageHeaders
9
8
  def flash_to_headers
10
9
  xmessage = URI.escape(Hash[flash].to_json) # URI escape to fix strange things with headers encoding
@@ -13,30 +12,25 @@ module Growlyflash
13
12
  end
14
13
 
15
14
  private
16
- def is_xhr_request?
17
- request.xhr?
18
- end
19
- end
20
-
15
+ def is_xhr_request?
16
+ request.xhr?
17
+ end
18
+ end
21
19
 
22
20
  module NoticeHelpers
23
21
  def growlyflash_static_notices
24
22
  return nil unless flash.any?
25
- javascript_tag("window.flashes = #{ raw(Hash[ flash ].to_json) };", defer: 'defer')
23
+ javascript_tag "window.flashes = #{raw(Hash[flash].to_json)};", defer: 'defer'
26
24
  end
27
25
  end
28
26
 
29
-
30
27
  class Engine < ::Rails::Engine
31
28
  initializer :growlyflash_xmessage_headers do |config|
32
-
33
29
  ActionController::Base.class_eval do
34
30
  include XMessageHeaders
35
31
  helper NoticeHelpers
36
-
37
32
  after_filter :flash_to_headers, if: :is_xhr_request?
38
33
  end
39
-
40
34
  end
41
35
  end
42
36
  end
@@ -1,3 +1,3 @@
1
1
  module Growlyflash
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -1,65 +1,95 @@
1
1
  # https://github.com/ifightcrime/bootstrap-growl
2
2
 
3
- $ = jQuery
4
-
5
- old = $.bootstrapGrowl
6
-
7
- $.bootstrapGrowl = (message, options) ->
8
- settings = $.extend {}, $.bootstrapGrowl.defaults, options
9
-
10
- box_classes = ["bootstrap-growl", "alert"]
11
- box_classes.push "alert-#{settings.type}" if settings.type?
3
+ do ($ = jQuery) ->
4
+ old = $.bootstrapGrowl
12
5
 
13
- box_alert = jQuery """
14
- <div class="#{box_classes.join(' ')}">
15
- #{'<a class="close" data-dismiss="alert" href="#">&times;</a>' if settings.dismiss}
16
- #{message}
17
- </div>
18
- """
6
+ alert_classes_add = (list...) ->
7
+ ['bootstrap-growl', 'alert'].concat("alert-#{type}" for type in list when type?)
19
8
 
20
- # calculate any 'stack-up'
21
- offset = settings.offset.amount
22
- $(".bootstrap-growl").each ->
23
- offset_from = parseInt $(@).css settings.offset.from
24
- height = $(@).outerHeight()
25
- offset = Math.max offset, offset_from + height + settings.spacing
9
+ css_metrics_val = (val) ->
10
+ str = "#{val ? 0}"
11
+ str += "px" if /\d$/.test str
12
+ str
26
13
 
27
- box_alert.css
28
- position: (if settings.target is 'body' then 'fixed' else 'absolute')
29
- margin: 0
30
- zIndex: 9999
31
- display: 'none'
32
- width: (if settings.width isnt 'auto' then "#{settings.width}px" else 'auto')
33
-
34
- box_alert.css settings.offset.from, "#{offset}px"
35
-
36
- # have to append before we can use outerWidth()
37
- $(settings.target).append box_alert
38
-
39
- box_alert.css switch settings.align
40
- when "center" then left: '50%', marginLeft:"-#{box_alert.outerWidth() / 2}px"
41
- when "left" then left: "#{settings.alignAmount}px"
42
- else right: "#{settings.alignAmount}px"
43
- box_alert.fadeIn()
14
+ $.bootstrapGrowl = (message, options) ->
15
+ {width, delay, spacing, target, align, alignAmount, dismiss, type, offset} = $.extend({}, $.bootstrapGrowl.defaults, options)
16
+ width = css_metrics_val width
17
+ alignAmount = css_metrics_val alignAmount
18
+
19
+ box_alert = $ """
20
+ <div class="#{alert_classes_add type}">
21
+ #{'<a class="close" data-dismiss="alert" href="#">&times;</a>' if dismiss}
22
+ #{message}
23
+ </div>
24
+ """
25
+
26
+ # calculate any 'stack-up'
27
+ $(".bootstrap-growl").each ->
28
+ height = $(@).outerHeight()
29
+ _from = parseInt $(@).css offset.from
30
+ offset.amount = Math.max offset.amount, _from + height + spacing
31
+
32
+ box_alert.css offset.from, css_metrics_val(offset.amount)
33
+ box_alert.css
34
+ position: (if target is 'body' then 'fixed' else 'absolute')
35
+ width: width
36
+ display: 'none'
37
+ zIndex: 9999
38
+ margin: 0
39
+
40
+ $(target).append box_alert
41
+ box_alert.css switch align
42
+ when "center" then left: '50%', marginLeft: "-#{box_alert.outerWidth() / 2}px"
43
+ when "left" then left: alignAmount
44
+ else right: alignAmount
45
+
46
+ box_alert.fadeIn()
47
+
48
+ # Only remove after delay if delay is more than 0
49
+ if delay > 0
50
+ box_alert.delay(settings.delay).fadeOut -> $(@).remove()
44
51
 
45
- # Only remove after delay if delay is more than 0
46
- if settings.delay > 0
47
- box_alert.delay(settings.delay).fadeOut -> $(@).remove()
48
- @
49
-
50
- $.bootstrapGrowl.defaults =
51
- width: 250
52
- delay: 4000
53
- spacing: 10
54
- target: 'body'
55
- align: 'right'
56
- alignAmount: 20
57
- dismiss: true
58
- type: null
59
- offset:
60
- from: 'top'
61
- amount: 20
52
+ return this
53
+
54
+
55
+ $.bootstrapGrowl.defaults =
56
+ # Width of the box (number or css-like string, etc. "auto")
57
+ width: 250
58
+
59
+ # Auto-dismiss timeout. Set it to 0 if you want to disable auto-dismiss
60
+ delay: 4000
61
+
62
+ # Spacing between boxes in stack
63
+ spacing: 10
64
+
65
+ # Appends boxes to a specific container
66
+ target: 'body'
67
+
68
+ # Show close button
69
+ dismiss: true
70
+
71
+ # Default class suffix for alert boxes.
72
+ # Use the following mapping (Flash key => Bootstrap Alert)
73
+ # warning: null
74
+ # error: "error"
75
+ # notice: "info"
76
+ # success: "success"
77
+ type: null
78
+
79
+ # Horizontal aligning (left, right or center)
80
+ align: 'right'
81
+
82
+ # Margin from the closest side
83
+ alignAmount: 20
84
+
85
+ # Offset from window bounds
86
+ offset:
87
+ from: 'top'
88
+ amount: 20
62
89
 
63
- $.bootstrapGrowl.noConflict = ->
64
- $.bootstrapGrowl = old
65
- @
90
+
91
+ $.bootstrapGrowl.noConflict = ->
92
+ $.bootstrapGrowl = old
93
+ return this
94
+
95
+ return this
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growlyflash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tõnis Simo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-08 00:00:00.000000000 Z
11
+ date: 2013-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties