growlyflash 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWY1NDI1MzcxMzgyZTMyZjBjM2Q4MzRlZmYzNGFlNWZmZTBkOWExYw==
5
+ data.tar.gz: !binary |-
6
+ NzBkNGY1NTJmN2EyZmExMWQ3NjZiZGQwNjk3NzBjNGU0N2RiY2IyZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YzRhMzU4OWE2NzI1Mjg3YjVmZTQzNjRjMWNiYjZhZDlmYmRmZWVmN2U2NTQx
10
+ ZGZlOThiZGFiNDhkNmE0NzQ1NWQ3NDRiM2FjMWRhMDUwMmI5YTMyYzM2Zjcw
11
+ ZWQ1N2ZmYWI2ZWI0ZTUwYWNiYTlkNTE0N2QxMDVlZTQ0Yjc1ZmE=
12
+ data.tar.gz: !binary |-
13
+ ZGU3ODg0ODA4YTAzNTg3NGJmZWUwNTg4MTAyNDEzODg3OTdiOWRkYzVhN2Jl
14
+ MDEwYmNkY2YyNzljMmY1YTEwOWQ0NmZjNDJiZTEzYWUwNTI3MzVjNzgyN2E0
15
+ NDYxMTc4ODI3ODJhMmZiNzA5ZTI2Yzc2NmZkNTQxMmMzZTBiZGQ=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in growlyflash.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Growlyflash
2
+
3
+ Tiny gem which provides growl-styled flash messages for Ruby on Rails with Bootstrap.
4
+
5
+ For XHR requests flash messages are transfering in 'X-Messages' headers, otherwise they are storing in js variables.
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)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'growlyflash'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
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:
24
+
25
+ <%= growlyflash_static_notices %>
26
+
27
+ And require it in your javascript:
28
+
29
+ //= require growlyflash/growlyflash
30
+
31
+ See [Bootstrap Growl](https://github.com/ifightcrime/bootstrap-growl) for any customisations.
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'growlyflash/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "growlyflash"
8
+ spec.version = Growlyflash::VERSION
9
+ spec.authors = ["Tõnis Simo"]
10
+ spec.email = ["anton.estum@gmail.com"]
11
+ spec.homepage = "https://github.com/tonissimo/growlyflash"
12
+ spec.summary = %q{Tiny gem which provides growl-styled flash messages for Ruby on Rails with Bootstrap.}
13
+ spec.description = %q{For XHR requests flash messages are transfering in 'X-Messages' headers, otherwise they are storing in js variables.}
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.require_paths = %w(lib vendor)
17
+
18
+ spec.add_dependency "railties", "~> 3.1"
19
+
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rails", '>= 3.2.0'
22
+ spec.add_development_dependency 'coffee-rails', '~> 3.2.1'
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ end
@@ -0,0 +1,22 @@
1
+ require "growlyflash/version"
2
+ require "growlyflash/controller"
3
+ require "growlyflash/helpers"
4
+
5
+ module Growlyflash
6
+ # Your code goes here...
7
+ def self.initialize
8
+ return if @initialized
9
+ raise "ActionController is not available yet." unless defined?(ActionController)
10
+ ActionController::Base.send(:helper, Growlyflash::Helpers)
11
+ ActionController::Base.send(:include, Growlyflash::Controller)
12
+ @initialized = true
13
+ end
14
+ end
15
+
16
+ if defined?(Rails)
17
+ require 'growlyflash/engine'
18
+ end
19
+
20
+ if defined?(Rails::Railtie)
21
+ require 'growlyflash/railtie'
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'active_support/concern'
2
+
3
+ module Growlyflash
4
+ module Controller
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ after_filter :flash_to_headers, if: :is_xhr_request?
9
+
10
+ def flash_to_headers
11
+ flash_json = Hash[ flash.map { |type, msg| [type, msg] } ].to_json
12
+ response.headers['X-Message'] = flash_json.clone
13
+ flash.discard # don't want the flash to appear when you reload page
14
+ end
15
+
16
+ private
17
+ def is_xhr_request?
18
+ request.xhr?
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ module Growlyflash
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ module Growlyflash
2
+ module Helpers
3
+
4
+ # Insert in head tag in your layout before any js.
5
+ def growlyflash_static_notices
6
+ if flash.any?
7
+ javascript_tag "window.flashes = #{ raw(Hash[ flash.map { |type, msg| [type, msg] } ].to_json) };", defer: 'defer'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ if defined?(Rails::Railtie)
2
+ module Growlyflash
3
+
4
+ class Railtie < ::Rails::Railtie
5
+ # initializer 'growlyflash.active_controller' do
6
+ initializer :growlyflash do
7
+ Growlyflash.initialize
8
+ # ActiveSupport.on_load(:action_controller) do
9
+ # include Growlyflash::Controller
10
+ # end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Growlyflash
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,57 @@
1
+ # https://github.com/ifightcrime/bootstrap-growl
2
+
3
+ $ = jQuery
4
+
5
+ $.extend
6
+ bootstrapGrowl: (message, options) ->
7
+ settings =
8
+ ele: 'body'
9
+ type: null
10
+ offset: from:'top', amount:20
11
+ align: "right"
12
+ width: 250
13
+ delay: 4000
14
+ allow_dismiss: true
15
+ stackup_spacing: 10
16
+
17
+ settings = $.extend settings, options
18
+
19
+ console.log settings
20
+
21
+ html_attrs =
22
+ class: 'bootstrap-growl alert'
23
+ html: ''
24
+ html_attrs.class += " alert-#{settings.type}" if settings.type?
25
+ html_attrs.html += """<a class="close" data-dismiss="alert" href="#">&times;</a>""" if settings.allow_dismiss
26
+ html_attrs.html += message
27
+
28
+ $alert = $ '<div />', html_attrs
29
+
30
+ # Prevent BC breaks
31
+ if settings.top_offset?
32
+ settings.offset = from:'top', amount:settings.top_offset
33
+
34
+ # calculate any 'stack-up'
35
+ offsetAmount = settings.offset.amount
36
+ $(".bootstrap-growl").each ->
37
+ offsetAmount = Math.max(offsetAmount, parseInt($(@).css(settings.offset.from)) + $(@).outerHeight() + settings.stackup_spacing)
38
+
39
+ $alert.css
40
+ position: (if (settings.ele == 'body') then 'fixed' else 'absolute')
41
+ margin: 0
42
+ zIndex: 9999
43
+ display: 'none'
44
+ width: (if (settings.width != 'auto') then "#{settings.width}px" else 'auto')
45
+ $alert.css settings.offset.from, "#{offsetAmount}px"
46
+
47
+ # have to append before we can use outerWidth()
48
+ $(settings.ele).append $alert
49
+ $alert.css switch settings.align
50
+ when "center" then left:'50%', marginLeft:"-#{($alert.outerWidth() / 2)}px"
51
+ when "left" then left:'20px'
52
+ else right:'20px'
53
+ $alert.fadeIn()
54
+
55
+ # Only remove after delay if delay is more than 0
56
+ if settings.delay > 0
57
+ $alert.delay(settings.delay).fadeOut -> $(@).remove()
@@ -0,0 +1,51 @@
1
+ #= require growlyflash/bootstrap-growl
2
+
3
+ # unless $.Growlyflash then $.Growlyflash = $.bootstrapGrowl
4
+
5
+ root = global ? window
6
+
7
+ class Growlyflash
8
+ TYPE_MAPPING =
9
+ warning: null
10
+ error : 'error'
11
+ notice : 'info'
12
+ success: 'success'
13
+
14
+ constructor: () ->
15
+ @flashes_log = []
16
+ @growl(window.flashes) if window.flashes?
17
+ $(document).on 'ajax:complete', @ajax_complete
18
+ $(document).ajaxComplete @ajax_complete
19
+
20
+ growl: (flashes) ->
21
+ for type, msg of flashes when msg?
22
+ @flashes_log.push type:type, msg:msg
23
+ $.bootstrapGrowl msg,
24
+ type: TYPE_MAPPING[type]
25
+
26
+ messages: (flashes) ->
27
+ { type:type, msg:msg } for type, msg of flashes
28
+
29
+ ajax_complete: (e, req) =>
30
+ flashes = $.parseJSON req.getResponseHeader 'X-Message'
31
+ return false if $.isEmptyObject flashes
32
+
33
+ messages = @messages flashes
34
+
35
+ if @flashes_log.length > 0
36
+ last_log = @flashes_log.slice( - messages.length )
37
+ not_matches = 0
38
+ not_matches++ for id, f of messages when (last_log[id].type isnt f.type) and (last_log[id].msg isnt f.msg)
39
+ unless not_matches > 0
40
+ @flashes_log = []
41
+ return true
42
+
43
+ $.merge @flashes_log, messages
44
+ @growl flashes
45
+ true
46
+
47
+ root.Growlyflash = Growlyflash
48
+
49
+ jQuery ->
50
+
51
+ new Growlyflash()
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: growlyflash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Tõnis Simo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: coffee-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ description: For XHR requests flash messages are transfering in 'X-Messages' headers,
84
+ otherwise they are storing in js variables.
85
+ email:
86
+ - anton.estum@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - growlyflash.gemspec
96
+ - lib/growlyflash.rb
97
+ - lib/growlyflash/controller.rb
98
+ - lib/growlyflash/engine.rb
99
+ - lib/growlyflash/helpers.rb
100
+ - lib/growlyflash/railtie.rb
101
+ - lib/growlyflash/version.rb
102
+ - vendor/assets/javascripts/growlyflash/bootstrap-growl.js.coffee
103
+ - vendor/assets/javascripts/growlyflash/growlyflash.js.coffee
104
+ homepage: https://github.com/tonissimo/growlyflash
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ - vendor
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.3
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Tiny gem which provides growl-styled flash messages for Ruby on Rails with
128
+ Bootstrap.
129
+ test_files: []