growlyflash 0.9.2 → 0.10.0

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: 119f6777b3a1d7d4c6d7c22284397c27095a79dc
4
- data.tar.gz: d385503f4843ea21f63770425477a68469b6c1ac
3
+ metadata.gz: 31ac0731d739e0bf94072acae27ec1e8a284eb9c
4
+ data.tar.gz: fb39aca149ec6badd0ae036d63243aedd9b4a414
5
5
  SHA512:
6
- metadata.gz: ba08a50c8830ae41579f1987c08661c66ed62cb7ba92edf2aef2a7ce3cabbfa71de04b09738b6b82d91ebb35ed02e914105c35301b204a97380e785d3c52dd72
7
- data.tar.gz: 0b57735dd401c6c1d9f0d4198b300530f8d03f3877fd6688268bdd2377291b9a2e29c0587d7055e57274d281b38f4223700ae576c6f6124aab25164909813751
6
+ metadata.gz: 666ae9b2d564eb68b4b862ae49e530325197cea43847ab0c02b9e601a37553f98cd01fba471d79d9d9db02ee1d8c87570e54956b52e9e295d9bab99451507a05
7
+ data.tar.gz: 0a0972863b3488223eec14afa49acfe546524ea3d118acb8f073a0eb24dc0b5dac1d392160132fca7e32dd9d24ea7c34f7ee2391a4978cfda450ab6edfb00879
data/README.md CHANGED
@@ -53,6 +53,16 @@ To make notifications also available with non-XHR requests, insert the following
53
53
  <%= growlyflash_static_notices %>
54
54
  ```
55
55
 
56
+ If you want your website to be compliant with Content-Security-Policy, and
57
+ especially avoid `script-src: 'unsafe-inline'`, you can use another helper to
58
+ render an html tag with data attributes instead of injecting javascript code
59
+ into your page:
60
+
61
+ ```erb
62
+ <%= growlyflash_tag %>
63
+ ```
64
+
65
+
56
66
  ## Customize
57
67
 
58
68
  If you want to change default options, you can override them somewhere in your coffee/js:
@@ -31,16 +31,20 @@ class Listener
31
31
 
32
32
  constructor: (context) ->
33
33
  @stack ?= new Stack()
34
- @process_static() if window.flashes?
34
+ @process_static(context)
35
35
  ($ context).on Growlyflash.Listener.EVENTS, (event, xhr) =>
36
36
  if xhr ?= event.data?.xhr
37
37
  source = process_from_header(xhr.getResponseHeader(Growlyflash.Listener.HEADER))
38
38
  @stack.push_only_fresh source
39
39
  return
40
40
 
41
- process_static: ->
42
- @stack.push alert for alert in process(window.flashes)
43
- delete window.flashes
41
+ process_static: (context)->
42
+ if tag = context.getElementById('growlyflash-tag')
43
+ tag_flashes = JSON.parse(tag.getAttribute('data-flashes'))
44
+ @stack.push alert for alert in process(tag_flashes)
45
+ else if window.flashes?
46
+ @stack.push alert for alert in process(window.flashes)
47
+ delete window.flashes
44
48
 
45
49
  @Growlyflash.Listener = Listener
46
50
  @Growlyflash.listen_on = (context) ->
@@ -4,7 +4,7 @@ module Growlyflash
4
4
  base.module_eval do
5
5
  extend ClassMethods
6
6
  if respond_to?(:helper_method)
7
- helper_method :growlyflash_static_notices, :growlyhash
7
+ helper_method :growlyflash_static_notices, :growlyhash, :growlyflash_tag
8
8
  end
9
9
  end
10
10
  end
@@ -38,6 +38,16 @@ module Growlyflash
38
38
  view_context.javascript_tag(script, defer: 'defer')
39
39
  end
40
40
 
41
+ # View helper which render a tag with flashes messages in data attribute.
42
+ def growlyflash_tag
43
+ return if flash.empty?
44
+ view_context.tag(
45
+ :div,
46
+ id: 'growlyflash-tag',
47
+ 'data-flashes': growlyhash.to_json.html_safe
48
+ )
49
+ end
50
+
41
51
  # Hash with available growl flash messages which contains a string object.
42
52
  def growlyhash(force = false)
43
53
  @growlyhash = nil if force
@@ -1,3 +1,3 @@
1
1
  module Growlyflash
2
- VERSION = "0.9.2"
2
+ VERSION = "0.10.0"
3
3
  end
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.9.2
4
+ version: 0.10.0
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: 2017-05-02 00:00:00.000000000 Z
11
+ date: 2017-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.6.11
120
+ rubygems_version: 2.6.13
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Popup ActionDispatch::Flash within Bootstrap alert in Rails app like a growl