announcements 0.1.0 → 0.2.0
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.
- data/.gitignore +7 -7
- data/.rspec +1 -1
- data/LICENSE +19 -19
- data/README.md +89 -89
- data/announcements.gemspec +26 -26
- data/lib/announcements/announcements_helper.rb +40 -40
- data/lib/announcements/version.rb +3 -3
- data/lib/generators/announcements/install/install_generator.rb +2 -2
- data/lib/generators/announcements/install/templates/announcement.rb +17 -17
- data/lib/generators/announcements/install/templates/announcements.js +20 -20
- data/spec/announcements/announcements_helper_spec.rb +43 -43
- data/spec/spec_helper.rb +4 -4
- data/spec/support/announcement.rb +3 -3
- metadata +32 -14
data/.gitignore
CHANGED
data/.rspec
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"--color"
|
|
1
|
+
"--color"
|
data/LICENSE
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
Copyright (c) 2012 Svilen Gospodinov
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
1
|
+
Copyright (c) 2012 Svilen Gospodinov
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
# announcements
|
|
2
|
-
|
|
3
|
-
The Announcements gem provides an easy way to publish short messages in your views, which the user can then hide permanently.
|
|
4
|
-
It was influenced by the gem `paul_revere` by thoughtbot, but unlike `paul_revere`, `announcements` doesn't use partials (instead,
|
|
5
|
-
there is a single helper method which you can customise) and is a bit more flexible (you have an additional 'type' attribute by default). Announcements can also output text in a twitter-bootstrap style format (see below).
|
|
6
|
-
|
|
7
|
-
## Quick start
|
|
8
|
-
|
|
9
|
-
1. Requirements: rails >= 3.1.0 and jquery-rails
|
|
10
|
-
2. Add `gem 'announcements'` to your Gemfile and run `bundle`
|
|
11
|
-
3. Run `rails g announcements:install`
|
|
12
|
-
4. Use `<%= announce Announcement.newest %>` in your views to display the latest announcement
|
|
13
|
-
5. Create your first announcement in `rails c` by simply creating a new Announcement record, like `Announcement.create(:body => 'This is my first announcement!')`
|
|
14
|
-
6.
|
|
15
|
-
|
|
16
|
-
## Styling
|
|
17
|
-
|
|
18
|
-
By default, the announcement text and hide message text are wrapped in a div called "info" (if you want to customise that, see the Customisation section below).
|
|
19
|
-
You can use the following css in your application.css file to start:
|
|
20
|
-
|
|
21
|
-
```css
|
|
22
|
-
.info {
|
|
23
|
-
background: #D5EDF8;
|
|
24
|
-
color: #205791;
|
|
25
|
-
padding: 0.8em;
|
|
26
|
-
margin-bottom: 1em;
|
|
27
|
-
border: 2px solid #92CAE4;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.hide_announcement {
|
|
31
|
-
cursor: pointer;
|
|
32
|
-
float: right;
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Customization
|
|
37
|
-
|
|
38
|
-
The default HTML output of the `announce` helper is
|
|
39
|
-
|
|
40
|
-
```html
|
|
41
|
-
<div class="info">
|
|
42
|
-
My announcement!
|
|
43
|
-
<span class="hide_announcement" data-announcementid="1">hide message</span>
|
|
44
|
-
</div>
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
The default div class is `info`. You can customise it like that:
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
<%= announce Announcement.newest, :div_class => "mydiv" %>
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
You can also change the "hide message" text:
|
|
54
|
-
|
|
55
|
-
```
|
|
56
|
-
<%= announce Announcement.newest, :hide_message => "×" %>
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
The output from the helper is marked as html_safe, so you can have links or add more formatting in the announcement text itself.
|
|
60
|
-
|
|
61
|
-
## For Twitter Bootstrap users
|
|
62
|
-
|
|
63
|
-
A new option has been added to `announcements` to display alerts in the `twitter-bootstrap` [style](http://twitter.github.com/bootstrap/components.html#alerts) through the following usage:
|
|
64
|
-
|
|
65
|
-
```
|
|
66
|
-
<%= announce Announcement.newest, :format => "bootstrap" %>
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
You can also change the "alert heading" text (twitter bootstrap option only):
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
<%= announce Announcement.newest, {:format => "bootstrap", :alert_heading => "Achtung!"} %>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Be sure to use one of the twitter-bootstrap gems.
|
|
76
|
-
|
|
77
|
-
## How it works
|
|
78
|
-
|
|
79
|
-
The gem creates an Announcement model with a few class methods like `Announcement.newest`. The Announcement model has a body:text (the actual announcement text)
|
|
80
|
-
and a type:string (which you can use for different types of announcements, e.g. public (everyone) and private (only for registered users)). There is also a js file in vendor/assets/javascripts
|
|
81
|
-
which permanently hides the announcement by creating a cookie (that's when you click on the 'hide message' text).
|
|
82
|
-
|
|
83
|
-
## How to uninstall
|
|
84
|
-
|
|
85
|
-
There is no uninstaller at this point, but you can simply remove the following files manually:
|
|
86
|
-
|
|
87
|
-
1. app/models/announcement.rb
|
|
88
|
-
2. vendor/assets/javascripts/announcements.js
|
|
89
|
-
|
|
1
|
+
# announcements
|
|
2
|
+
|
|
3
|
+
The Announcements gem provides an easy way to publish short messages in your views, which the user can then hide permanently.
|
|
4
|
+
It was influenced by the gem `paul_revere` by thoughtbot, but unlike `paul_revere`, `announcements` doesn't use partials (instead,
|
|
5
|
+
there is a single helper method which you can customise) and is a bit more flexible (you have an additional 'type' attribute by default). Announcements can also output text in a twitter-bootstrap style format (see below).
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
1. Requirements: rails >= 3.1.0 and jquery-rails
|
|
10
|
+
2. Add `gem 'announcements'` to your Gemfile and run `bundle`
|
|
11
|
+
3. Run `rails g announcements:install`
|
|
12
|
+
4. Use `<%= announce Announcement.newest %>` in your views to display the latest announcement
|
|
13
|
+
5. Create your first announcement in `rails c` by simply creating a new Announcement record, like `Announcement.create(:body => 'This is my first announcement!')`
|
|
14
|
+
6. You're done! You can now add some styling and have a look at the customization options below.
|
|
15
|
+
|
|
16
|
+
## Styling
|
|
17
|
+
|
|
18
|
+
By default, the announcement text and hide message text are wrapped in a div called "info" (if you want to customise that, see the Customisation section below).
|
|
19
|
+
You can use the following css in your application.css file to start:
|
|
20
|
+
|
|
21
|
+
```css
|
|
22
|
+
.info {
|
|
23
|
+
background: #D5EDF8;
|
|
24
|
+
color: #205791;
|
|
25
|
+
padding: 0.8em;
|
|
26
|
+
margin-bottom: 1em;
|
|
27
|
+
border: 2px solid #92CAE4;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.hide_announcement {
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
float: right;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Customization
|
|
37
|
+
|
|
38
|
+
The default HTML output of the `announce` helper is
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<div class="info">
|
|
42
|
+
My announcement!
|
|
43
|
+
<span class="hide_announcement" data-announcementid="1">hide message</span>
|
|
44
|
+
</div>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The default div class is `info`. You can customise it like that:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
<%= announce Announcement.newest, :div_class => "mydiv" %>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
You can also change the "hide message" text:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
<%= announce Announcement.newest, :hide_message => "×" %>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The output from the helper is marked as html_safe, so you can have links or add more formatting in the announcement text itself.
|
|
60
|
+
|
|
61
|
+
## For Twitter Bootstrap users
|
|
62
|
+
|
|
63
|
+
A new option has been added to `announcements` to display alerts in the `twitter-bootstrap` [style](http://twitter.github.com/bootstrap/components.html#alerts) through the following usage:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
<%= announce Announcement.newest, :format => "bootstrap" %>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
You can also change the "alert heading" text (twitter bootstrap option only):
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
<%= announce Announcement.newest, {:format => "bootstrap", :alert_heading => "Achtung!"} %>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Be sure to use one of the twitter-bootstrap gems.
|
|
76
|
+
|
|
77
|
+
## How it works
|
|
78
|
+
|
|
79
|
+
The gem creates an Announcement model with a few class methods like `Announcement.newest`. The Announcement model has a body:text (the actual announcement text)
|
|
80
|
+
and a type:string (which you can use for different types of announcements, e.g. public (everyone) and private (only for registered users)). There is also a js file in vendor/assets/javascripts
|
|
81
|
+
which permanently hides the announcement by creating a cookie (that's when you click on the 'hide message' text).
|
|
82
|
+
|
|
83
|
+
## How to uninstall
|
|
84
|
+
|
|
85
|
+
There is no uninstaller at this point, but you can simply remove the following files manually:
|
|
86
|
+
|
|
87
|
+
1. app/models/announcement.rb
|
|
88
|
+
2. vendor/assets/javascripts/announcements.js
|
|
89
|
+
|
|
90
90
|
You also have to remove the `//= require announcements` line in your app/assets/javascripts/application.js file, and rollback the `create_announcements` migration.
|
data/announcements.gemspec
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
-
require "announcements/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |s|
|
|
6
|
-
s.name = "announcements"
|
|
7
|
-
s.version = Announcements::VERSION
|
|
8
|
-
s.authors = ["Svilen Gospodinov", "
|
|
9
|
-
s.email = "svilen@
|
|
10
|
-
s.homepage = "https://github.com/svileng/announcements"
|
|
11
|
-
s.summary = "Announcements gem for Rails"
|
|
12
|
-
s.description = "The Announcements gem makes it easier to display short announcement messages in your views"
|
|
13
|
-
|
|
14
|
-
s.rubyforge_project = "announcements"
|
|
15
|
-
|
|
16
|
-
s.files = `git ls-files`.split("\n")
|
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
19
|
-
s.require_paths = ["lib"]
|
|
20
|
-
|
|
21
|
-
s.add_development_dependency "rspec"
|
|
22
|
-
|
|
23
|
-
s.add_runtime_dependency "rails", "
|
|
24
|
-
s.add_runtime_dependency "jquery-rails"
|
|
25
|
-
|
|
26
|
-
end
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "announcements/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "announcements"
|
|
7
|
+
s.version = Announcements::VERSION
|
|
8
|
+
s.authors = ["Svilen Gospodinov", "and others"]
|
|
9
|
+
s.email = "svilen.gospodinov@gmail.com"
|
|
10
|
+
s.homepage = "https://github.com/svileng/announcements"
|
|
11
|
+
s.summary = "Announcements gem for Rails"
|
|
12
|
+
s.description = "The Announcements gem makes it easier to display short announcement messages in your views"
|
|
13
|
+
|
|
14
|
+
s.rubyforge_project = "announcements"
|
|
15
|
+
|
|
16
|
+
s.files = `git ls-files`.split("\n")
|
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
19
|
+
s.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
s.add_development_dependency "rspec"
|
|
22
|
+
|
|
23
|
+
s.add_runtime_dependency "rails", ">= 3.1.0"
|
|
24
|
+
s.add_runtime_dependency "jquery-rails"
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
module AnnouncementsHelper
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if options[:format] == "bootstrap"
|
|
19
|
-
text = options[:hide_message] || "x"
|
|
20
|
-
div_class = options[:div_class] || "alert alert-
|
|
21
|
-
alert_heading = options[:alert_heading] || "Warning!"
|
|
22
|
-
|
|
23
|
-
close_content_tag = content_tag(:a, text, :class => "close", data: data_attribute)
|
|
24
|
-
alert_content_tag = content_tag(:h4, alert_heading, :class => "alert-heading")
|
|
25
|
-
|
|
26
|
-
result = content_tag(:div, close_content_tag + alert_content_tag + announcement.body.html_safe, class: div_class)
|
|
27
|
-
else
|
|
28
|
-
text = options[:hide_message] || "hide message"
|
|
29
|
-
div_class = options[:div_class] || "info"
|
|
30
|
-
|
|
31
|
-
close_content_tag = content_tag(:span, text, :class => "hide_announcement", data: data_attribute)
|
|
32
|
-
|
|
33
|
-
result = content_tag(:div, announcement.body.html_safe + close_content_tag, class: div_class)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
result
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
end
|
|
1
|
+
module AnnouncementsHelper
|
|
2
|
+
|
|
3
|
+
# Outputs given announcement in HTML (with optional twitter bootstrap style).
|
|
4
|
+
#
|
|
5
|
+
# Basic usage: <%= announce Announcement.newest %>
|
|
6
|
+
# Alt usage: <%= announce Announcement.newest, :format => "boostrap" %>
|
|
7
|
+
#
|
|
8
|
+
# Options:
|
|
9
|
+
# div_class -- name for a custom div class, which wraps the announcement text and hide message, default is "info"
|
|
10
|
+
# hide_message -- clickable text which hides the announcement, default is "hide message"
|
|
11
|
+
# format[:boostrap] -- format announcement to use the twitter bootstrap Alert style, defaults to normals stylings.
|
|
12
|
+
# alert_heading -- Adding an alert heading when used with the bootstrap option.
|
|
13
|
+
def announce announcement, options = {}
|
|
14
|
+
result = nil
|
|
15
|
+
|
|
16
|
+
if announcement != nil && cookies["announcement_" + announcement.id.to_s] != "hidden"
|
|
17
|
+
data_attribute = { :announcementid => announcement.id }
|
|
18
|
+
if options[:format] == "bootstrap"
|
|
19
|
+
text = options[:hide_message] || "x"
|
|
20
|
+
div_class = options[:div_class] || "alert alert-warning"
|
|
21
|
+
alert_heading = announcement.try(:heading) || options[:alert_heading] || "Warning!"
|
|
22
|
+
|
|
23
|
+
close_content_tag = content_tag(:a, text, :class => "close", data: data_attribute)
|
|
24
|
+
alert_content_tag = content_tag(:h4, alert_heading, :class => "alert-heading")
|
|
25
|
+
|
|
26
|
+
result = content_tag(:div, close_content_tag + alert_content_tag + announcement.body.html_safe, class: div_class)
|
|
27
|
+
else
|
|
28
|
+
text = options[:hide_message] || "hide message"
|
|
29
|
+
div_class = options[:div_class] || "info"
|
|
30
|
+
|
|
31
|
+
close_content_tag = content_tag(:span, text, :class => "hide_announcement", data: data_attribute)
|
|
32
|
+
|
|
33
|
+
result = content_tag(:div, announcement.body.html_safe + close_content_tag, class: div_class)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
result
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module Announcements
|
|
2
|
-
VERSION = "0.
|
|
3
|
-
end
|
|
1
|
+
module Announcements
|
|
2
|
+
VERSION = "0.2.0"
|
|
3
|
+
end
|
|
@@ -8,7 +8,7 @@ module Announcements
|
|
|
8
8
|
say "--- Creating model in app/models..."
|
|
9
9
|
template "announcement.rb", "app/models/announcement.rb"
|
|
10
10
|
say "--- Creating the migration ..."
|
|
11
|
-
generate("model", "announcement body:text type:string --skip")
|
|
11
|
+
generate("model", "announcement body:text heading:text type:string --skip")
|
|
12
12
|
say "--- Running the migration..."
|
|
13
13
|
rake("db:migrate")
|
|
14
14
|
end
|
|
@@ -22,4 +22,4 @@ module Announcements
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
end
|
|
25
|
-
end
|
|
25
|
+
end
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
class Announcement < ActiveRecord::Base
|
|
2
|
-
|
|
3
|
-
validates_presence_of :body
|
|
4
|
-
|
|
5
|
-
def self.newest
|
|
6
|
-
Announcement.last
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def self.newest_private
|
|
10
|
-
Announcement.where("type is null").order("id desc").first
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.newest_public
|
|
14
|
-
Announcement.where("type = 'public'").order("id desc").first
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
end
|
|
1
|
+
class Announcement < ActiveRecord::Base
|
|
2
|
+
|
|
3
|
+
validates_presence_of :body
|
|
4
|
+
|
|
5
|
+
def self.newest
|
|
6
|
+
Announcement.last
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.newest_private
|
|
10
|
+
Announcement.where("type is null").order("id desc").first
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.newest_public
|
|
14
|
+
Announcement.where("type = 'public'").order("id desc").first
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
$(function() {
|
|
2
|
-
|
|
3
|
-
$('.hide_announcement, .close').click(function() {
|
|
4
|
-
var a_id = $(this).data("announcementid");
|
|
5
|
-
createCookie("announcement_" + a_id, "hidden", 45);
|
|
6
|
-
$(this).parent().slideUp();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
function createCookie(name, value, days) {
|
|
10
|
-
var expires = "";
|
|
11
|
-
if (days) {
|
|
12
|
-
var date = new Date();
|
|
13
|
-
date.setTime(date.getTime() + (days*24*60*60*1000));
|
|
14
|
-
expires = "; expires=" + date.toGMTString();
|
|
15
|
-
} else {
|
|
16
|
-
expires = "";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
document.cookie = name + "=" + value + expires + "; path=/";
|
|
20
|
-
}
|
|
1
|
+
$(function() {
|
|
2
|
+
|
|
3
|
+
$('.hide_announcement, .close').click(function() {
|
|
4
|
+
var a_id = $(this).data("announcementid");
|
|
5
|
+
createCookie("announcement_" + a_id, "hidden", 45);
|
|
6
|
+
$(this).parent().slideUp();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
function createCookie(name, value, days) {
|
|
10
|
+
var expires = "";
|
|
11
|
+
if (days) {
|
|
12
|
+
var date = new Date();
|
|
13
|
+
date.setTime(date.getTime() + (days*24*60*60*1000));
|
|
14
|
+
expires = "; expires=" + date.toGMTString();
|
|
15
|
+
} else {
|
|
16
|
+
expires = "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
document.cookie = name + "=" + value + expires + "; path=/";
|
|
20
|
+
}
|
|
21
21
|
});
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
include ActionView::Context
|
|
3
|
-
include ActionView::Helpers
|
|
4
|
-
include AnnouncementsHelper
|
|
5
|
-
|
|
6
|
-
describe AnnouncementsHelper do
|
|
7
|
-
|
|
8
|
-
before do
|
|
9
|
-
@announcement = Announcement.new
|
|
10
|
-
@announcement.id = 1
|
|
11
|
-
@announcement.body = "announcement text"
|
|
12
|
-
|
|
13
|
-
@mocked_cookies = Hash.new
|
|
14
|
-
stub!(:cookies).and_return(@mocked_cookies)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should output announcement text with no params" do
|
|
18
|
-
@mocked_cookies["announcement_1"] = "not hidden"
|
|
19
|
-
output = announce(@announcement)
|
|
20
|
-
output.should include("x")
|
|
21
|
-
output.should include("announcement text")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should not output announcement if was already hidden by user" do
|
|
25
|
-
@mocked_cookies["announcement_1"] = "hidden"
|
|
26
|
-
output = announce(@announcement)
|
|
27
|
-
output.should be_nil
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should output custom hide message and div class" do
|
|
31
|
-
@mocked_cookies["announcement_1"] = "not hidden"
|
|
32
|
-
output = announce(@announcement, hide_message: "X", div_class: "customdiv")
|
|
33
|
-
output.should include("<div class=\"customdiv\"")
|
|
34
|
-
output.should include(">X</span>")
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "should output bootstrap style" do
|
|
38
|
-
@mocked_cookies["announcement_1"] = "not hidden"
|
|
39
|
-
output = announce(@announcement, format: "bootstrap")
|
|
40
|
-
output.should include("<a class=\"close\"")
|
|
41
|
-
output.should include("<h4 class=\"alert-heading\"")
|
|
42
|
-
end
|
|
43
|
-
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include ActionView::Context
|
|
3
|
+
include ActionView::Helpers
|
|
4
|
+
include AnnouncementsHelper
|
|
5
|
+
|
|
6
|
+
describe AnnouncementsHelper do
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@announcement = Announcement.new
|
|
10
|
+
@announcement.id = 1
|
|
11
|
+
@announcement.body = "announcement text"
|
|
12
|
+
|
|
13
|
+
@mocked_cookies = Hash.new
|
|
14
|
+
stub!(:cookies).and_return(@mocked_cookies)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should output announcement text with no params" do
|
|
18
|
+
@mocked_cookies["announcement_1"] = "not hidden"
|
|
19
|
+
output = announce(@announcement)
|
|
20
|
+
output.should include("x")
|
|
21
|
+
output.should include("announcement text")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should not output announcement if was already hidden by user" do
|
|
25
|
+
@mocked_cookies["announcement_1"] = "hidden"
|
|
26
|
+
output = announce(@announcement)
|
|
27
|
+
output.should be_nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should output custom hide message and div class" do
|
|
31
|
+
@mocked_cookies["announcement_1"] = "not hidden"
|
|
32
|
+
output = announce(@announcement, hide_message: "X", div_class: "customdiv")
|
|
33
|
+
output.should include("<div class=\"customdiv\"")
|
|
34
|
+
output.should include(">X</span>")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should output bootstrap style" do
|
|
38
|
+
@mocked_cookies["announcement_1"] = "not hidden"
|
|
39
|
+
output = announce(@announcement, format: "bootstrap")
|
|
40
|
+
output.should include("<a class=\"close\"")
|
|
41
|
+
output.should include("<h4 class=\"alert-heading\"")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
44
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require "action_view"
|
|
2
|
-
require "active_support/core_ext"
|
|
3
|
-
require "announcements"
|
|
4
|
-
|
|
1
|
+
require "action_view"
|
|
2
|
+
require "active_support/core_ext"
|
|
3
|
+
require "announcements"
|
|
4
|
+
|
|
5
5
|
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each{|f| require f}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Announcement
|
|
2
|
-
attr_accessor :body
|
|
3
|
-
attr_accessor :id
|
|
1
|
+
class Announcement
|
|
2
|
+
attr_accessor :body
|
|
3
|
+
attr_accessor :id
|
|
4
4
|
end
|
metadata
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: announcements
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Svilen Gospodinov
|
|
9
|
-
-
|
|
9
|
+
- and others
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rspec
|
|
17
|
-
requirement:
|
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
18
|
none: false
|
|
19
19
|
requirements:
|
|
20
20
|
- - ! '>='
|
|
@@ -22,21 +22,31 @@ dependencies:
|
|
|
22
22
|
version: '0'
|
|
23
23
|
type: :development
|
|
24
24
|
prerelease: false
|
|
25
|
-
version_requirements:
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
none: false
|
|
27
|
+
requirements:
|
|
28
|
+
- - ! '>='
|
|
29
|
+
- !ruby/object:Gem::Version
|
|
30
|
+
version: '0'
|
|
26
31
|
- !ruby/object:Gem::Dependency
|
|
27
32
|
name: rails
|
|
28
|
-
requirement:
|
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
34
|
none: false
|
|
30
35
|
requirements:
|
|
31
|
-
- -
|
|
36
|
+
- - ! '>='
|
|
32
37
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
38
|
+
version: 3.1.0
|
|
34
39
|
type: :runtime
|
|
35
40
|
prerelease: false
|
|
36
|
-
version_requirements:
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ! '>='
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 3.1.0
|
|
37
47
|
- !ruby/object:Gem::Dependency
|
|
38
48
|
name: jquery-rails
|
|
39
|
-
requirement:
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
40
50
|
none: false
|
|
41
51
|
requirements:
|
|
42
52
|
- - ! '>='
|
|
@@ -44,10 +54,15 @@ dependencies:
|
|
|
44
54
|
version: '0'
|
|
45
55
|
type: :runtime
|
|
46
56
|
prerelease: false
|
|
47
|
-
version_requirements:
|
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - ! '>='
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
48
63
|
description: The Announcements gem makes it easier to display short announcement messages
|
|
49
64
|
in your views
|
|
50
|
-
email: svilen@
|
|
65
|
+
email: svilen.gospodinov@gmail.com
|
|
51
66
|
executables: []
|
|
52
67
|
extensions: []
|
|
53
68
|
extra_rdoc_files: []
|
|
@@ -88,8 +103,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
88
103
|
version: '0'
|
|
89
104
|
requirements: []
|
|
90
105
|
rubyforge_project: announcements
|
|
91
|
-
rubygems_version: 1.8.
|
|
106
|
+
rubygems_version: 1.8.19
|
|
92
107
|
signing_key:
|
|
93
108
|
specification_version: 3
|
|
94
109
|
summary: Announcements gem for Rails
|
|
95
|
-
test_files:
|
|
110
|
+
test_files:
|
|
111
|
+
- spec/announcements/announcements_helper_spec.rb
|
|
112
|
+
- spec/spec_helper.rb
|
|
113
|
+
- spec/support/announcement.rb
|