crouton 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 547d77e7d2b5efcaac506b282fa5572bc0989fd3
4
+ data.tar.gz: 81e881ab0ef92b2c4dca9d7fefc209e55dbf7eac
5
+ SHA512:
6
+ metadata.gz: c3a8841f50d17158041be5e3dee63697856df8659f9336fe54e1e0a803f4afdb5e848fecd32517825ba573acd9a8f2a0894acad241356534de52281deaaadb47
7
+ data.tar.gz: e9e177e8dedf83704121d7a3962b876f82e254215067fc239a2b1535cdb92a2fa86b7db12e5b4f42199d82bfc96a935141c836c0feb94eef6da0f0111cb29462
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 crouton.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Máximo Mussini
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ Crouton
2
+ =====================
3
+ [![Gem Version](https://badge.fury.io/rb/crouton.svg)](http://badge.fury.io/rb/crouton)
4
+
5
+ Context sensitive notifications for Rails && XHR.
6
+
7
+ ## Installation
8
+
9
+ gem install 'crouton'
10
+
11
+ ## Usage
12
+
13
+ Simply require `crouton` in your javascript and css:
14
+
15
+ ``` javascript
16
+ //= require crouton
17
+ ```
18
+
19
+ ``` sass
20
+ @import crouton
21
+ ```
22
+
23
+ Now, use the `render_crouton` method in your controllers, any option you pass
24
+ will be converted to a message, and displayed in the browser.
25
+
26
+ ``` ruby
27
+ class PostsController < ActionController::Base
28
+
29
+ def update
30
+ if @post.save
31
+ render_crouton notice: 'Saved'
32
+ else
33
+ render_crouton errors: @post.errors
34
+ end
35
+ end
36
+ end
37
+ ```
38
+
39
+ ## Customization
40
+ Three styles are supported out of the box: __info__, __warning__ and __danger__.
41
+ The duration of each message is 1500, 2000 and 3000 respectively.
42
+
43
+ ![screen shot 2014-08-11 at 3 44 10 pm](https://cloud.githubusercontent.com/assets/1158253/3881070/74f526c4-218a-11e4-8ada-63110a789647.png)
44
+ ![screen shot 2014-08-11 at 3 43 44 pm](https://cloud.githubusercontent.com/assets/1158253/3881068/74eb79e4-218a-11e4-9734-3a118e9ff853.png)
45
+ ![screen shot 2014-08-11 at 3 43 23 pm](https://cloud.githubusercontent.com/assets/1158253/3881069/74ebb8a0-218a-11e4-90e6-3efe5cfade53.png)
46
+
47
+ You can customize the colours for this three styles by defining the following SASS variables:
48
+ - `$crouton-info`
49
+ - `$crouton-warning`
50
+ - `$crouton-danger`
51
+
52
+ You can also create your custom messages:
53
+
54
+ ```ruby
55
+ render_crouton Crouton::Message.new(:hint, 'You can double tap for more info.', duration: 5000)
56
+ ```
57
+
58
+ License
59
+ --------
60
+
61
+ Copyright (c) 2014 Máximo Mussini
62
+
63
+ Permission is hereby granted, free of charge, to any person obtaining
64
+ a copy of this software and associated documentation files (the
65
+ "Software"), to deal in the Software without restriction, including
66
+ without limitation the rights to use, copy, modify, merge, publish,
67
+ distribute, sublicense, and/or sell copies of the Software, and to
68
+ permit persons to whom the Software is furnished to do so, subject to
69
+ the following conditions:
70
+
71
+ The above copyright notice and this permission notice shall be
72
+ included in all copies or substantial portions of the Software.
73
+
74
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
75
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
76
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
77
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
78
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
79
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
80
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81
+
82
+
83
+ Credits
84
+ --------
85
+
86
+ The name and the idea of Crouton originates in a [blog article](http://cyrilmottier.com/2012/07/24/the-making-of-prixing-4-activity-tied-notifications/) by Cyril Mottier.
@@ -0,0 +1,3 @@
1
+ $('<%= croutons.placeholder %>').showCroutons(
2
+ '<%=j (render partial: 'crouton/message', collection: croutons.messages, as: :message) %>'
3
+ );
@@ -0,0 +1,4 @@
1
+ <div class="crouton crouton-<%= message.css %>" data-duration="<%= message.duration %>">
2
+ <button aria-hidden="true" class="close" data-dismiss="alert">&times;</button>
3
+ <span class="message"><%= message.content %></span>
4
+ </div>
data/crouton.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "crouton"
6
+ s.version = '0.1.0'
7
+ s.description = "Context sensitive notifications for Rails."
8
+ s.summary = "Context sensitive notifications for Rails, the name and idea originated in a blog article written by Cyril Mottier on Android notifications."
9
+ s.licenses = ['MIT']
10
+
11
+ s.authors = ["Máximo Mussini"]
12
+ s.email = ["maximomussini@gmail.com"]
13
+ s.homepage = %q{https://github.com/ElMassimo/crouton}
14
+
15
+ s.platform = Gem::Platform::RUBY
16
+ s.required_ruby_version = '>=1.9'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- test/*`.split("\n")
20
+ s.require_paths = ["lib"]
21
+
22
+ s.rdoc_options = ["--charset=UTF-8"]
23
+ s.extra_rdoc_files = ["README.md"]
24
+
25
+ s.add_dependency 'railties'
26
+ s.add_dependency 'sass-rails'
27
+ s.add_dependency 'jquery-rails'
28
+
29
+ s.add_development_dependency 'bundler', '~> 1.3'
30
+ s.add_development_dependency 'rake'
31
+ end
@@ -0,0 +1,27 @@
1
+ var DEFAULT_ANIMATION_MILLIS = 300;
2
+ var DEFAULT_DURATION_MILLIS = 1500;
3
+
4
+ function animateCrouton(crouton) {
5
+ animationMillis = crouton.data('animation') || DEFAULT_ANIMATION_MILLIS;
6
+ durationMillis = crouton.data('duration') || DEFAULT_DURATION_MILLIS;
7
+
8
+ crouton.animate({height: 'toggle'}, animationMillis, 'swing', function hideCrouton() {
9
+ crouton.delay(durationMillis).animate({ height: 'toggle' }, animationMillis, 'swing', removeCrouton);
10
+ });
11
+ }
12
+
13
+ function removeCrouton() {
14
+ $(this).remove();
15
+ }
16
+
17
+ $.fn.showCrouton = function(crouton) {
18
+ $(this).before(crouton.hide());
19
+ animateCrouton(crouton);
20
+ }
21
+
22
+ $.fn.showCroutons = function(croutons) {
23
+ placeholder = $(this);
24
+ $(croutons).each(function(i) {
25
+ placeholder.showCrouton($(this));
26
+ });
27
+ }
@@ -0,0 +1,42 @@
1
+ $crouton-height: 36px !default;
2
+ $crouton-big-height: $crouton-height*1.5 !default;
3
+
4
+ $crouton-info: #0A97B1 !default;
5
+ $crouton-warning: #E1AA27 !default;
6
+ $crouton-danger: #B10A0A !default;
7
+
8
+ .crouton {
9
+ height: $crouton-height; line-height: $crouton-height;
10
+ color: white;
11
+ text-align: center;
12
+ font-weight: 100;
13
+ position: relative;
14
+
15
+ &.crouton-info {
16
+ background: $crouton-info;
17
+ }
18
+ &.crouton-warning {
19
+ background: $crouton-warning;
20
+ }
21
+ &.crouton-danger{
22
+ background: $crouton-danger;
23
+ }
24
+ }
25
+
26
+ .crouton, .crouton + .card-content {
27
+ box-shadow: inset 0px 4px 6px -7px black;
28
+ }
29
+
30
+ .crouton > .close {
31
+ position: absolute;
32
+ right: 8px;
33
+ font-size: 28px;
34
+ line-height: inherit;
35
+ }
36
+
37
+ .crouton-big {
38
+ height: inherit;
39
+ line-height: $crouton-big-height - 20px;
40
+ font-size: 25px;
41
+ padding: 8px 10%;
42
+ }
data/lib/crouton.rb ADDED
@@ -0,0 +1 @@
1
+ require 'crouton/crouton'
@@ -0,0 +1,18 @@
1
+ require 'crouton/presenter'
2
+
3
+ module Crouton
4
+
5
+ module Concern
6
+ def render_crouton(messages={}, options={})
7
+ render partial: 'crouton/croutons', locals: { croutons: Presenter.new(messages, options) }
8
+ end
9
+ end
10
+
11
+ class Engine < Rails::Engine
12
+ initializer :crouton_controller do
13
+ ActionController::Base.class_eval do
14
+ include Crouton::Concern
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module Crouton
2
+ class Message
3
+ attr_reader :type, :content, :duration
4
+
5
+ DEFAULT_MESSAGE = 'Saved'
6
+ CSS = { notice: :info, error: :danger, alert: :warning }
7
+
8
+ def initialize(type=:info, content=DEFAULT_MESSAGE, options={})
9
+ @type, @content = type.to_sym, content
10
+ @duration = options[:duration] || default_duration
11
+ end
12
+
13
+ def css
14
+ CSS[@type] || @type
15
+ end
16
+
17
+ private
18
+
19
+ def default_duration
20
+ case css
21
+ when :danger then 3000
22
+ when :warning then 2000
23
+ end
24
+ end
25
+
26
+ def self.to_proc
27
+ ->(args){ new(*args) }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require 'crouton/message'
2
+
3
+ module Crouton
4
+ class Presenter
5
+ attr_reader :placeholder, :messages
6
+ delegate :each, to: :messages
7
+
8
+ def initialize(messages, options={})
9
+ @placeholder = options.delete(:placeholder) || '.crouton-placeholder'
10
+ messages = from_hash(messages) if messages.is_a?(Hash)
11
+ @messages = *messages
12
+ end
13
+
14
+ private
15
+
16
+ def from_hash(messages)
17
+ messages.delete_if {|name, msg| msg.blank? }
18
+
19
+ if (errors = messages[:errors]).present?
20
+ errors_to_messages(errors)
21
+ else
22
+ messages.map(&Message).presence || [Message.new]
23
+ end
24
+ end
25
+
26
+ # Internal: Converts errors to an array of error messages.
27
+ def errors_to_messages(errors)
28
+ errors.full_messages.map {|error| Message.new(:error, error) }
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crouton
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Máximo Mussini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-11 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sass-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: jquery-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Context sensitive notifications for Rails.
84
+ email:
85
+ - maximomussini@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files:
89
+ - README.md
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - app/views/crouton/_croutons.js.erb
96
+ - app/views/crouton/_message.html.erb
97
+ - crouton.gemspec
98
+ - lib/assets/javascripts/crouton.js
99
+ - lib/assets/stylesheets/crouton.css.scss
100
+ - lib/crouton.rb
101
+ - lib/crouton/crouton.rb
102
+ - lib/crouton/message.rb
103
+ - lib/crouton/presenter.rb
104
+ homepage: https://github.com/ElMassimo/crouton
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options:
110
+ - "--charset=UTF-8"
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '1.9'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Context sensitive notifications for Rails, the name and idea originated in
129
+ a blog article written by Cyril Mottier on Android notifications.
130
+ test_files: []
131
+ has_rdoc: