announcements 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ "--color"
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The Announcements gem provides an easy way to publish short messages in your views, which the user can then hide permanently.
4
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).
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
6
 
7
7
  ## Quick start
8
8
 
@@ -11,7 +11,7 @@ there is a single helper method which you can customise) and is a bit more flexi
11
11
  3. Run `rails g announcements:install`
12
12
  4. Use `<%= announce Announcement.newest %>` in your views to display the latest announcement
13
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. Next, add some CSS (find an example below; the default output is quite plain and ugly) and customise it.
14
+ 6. Next, relax bootstrap's got the rest.
15
15
 
16
16
  ## Styling
17
17
 
@@ -33,7 +33,7 @@ You can use the following css in your application.css file to start:
33
33
  }
34
34
  ```
35
35
 
36
- ## Customisation
36
+ ## Customization
37
37
 
38
38
  The default HTML output of the `announce` helper is
39
39
 
@@ -44,7 +44,7 @@ The default HTML output of the `announce` helper is
44
44
  </div>
45
45
  ```
46
46
 
47
- The default div class is `info`. You can specify you own like that:
47
+ The default div class is `info`. You can customise it like that:
48
48
 
49
49
  ```
50
50
  <%= announce Announcement.newest, :div_class => "mydiv" %>
@@ -53,9 +53,27 @@ The default div class is `info`. You can specify you own like that:
53
53
  You can also change the "hide message" text:
54
54
 
55
55
  ```
56
- <%= announce Announcement.newest, :div_class => "mydiv", :hide_message => "X" %>
56
+ <%= announce Announcement.newest, :hide_message => "×" %>
57
57
  ```
58
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
+
59
77
  ## How it works
60
78
 
61
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)
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -5,9 +5,9 @@ require "announcements/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "announcements"
7
7
  s.version = Announcements::VERSION
8
- s.authors = ["Svilen Gospodinov"]
9
- s.email = ["svilen@gospodinov.co.uk"]
10
- s.homepage = ""
8
+ s.authors = ["Svilen Gospodinov", "Chase Southard"]
9
+ s.email = "svilen@gospodinov.co.uk"
10
+ s.homepage = "https://github.com/svileng/announcements"
11
11
  s.summary = "Announcements gem for Rails"
12
12
  s.description = "The Announcements gem makes it easier to display short announcement messages in your views"
13
13
 
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
21
+ s.add_development_dependency "rspec"
22
+
23
23
  s.add_runtime_dependency "rails", "~> 3.1"
24
24
  s.add_runtime_dependency "jquery-rails"
25
25
 
@@ -1,22 +1,40 @@
1
1
  module AnnouncementsHelper
2
2
 
3
- # Outputs given announcement in HTML.
3
+ # Outputs given announcement in HTML (with optional twitter bootstrap style).
4
4
  #
5
5
  # Basic usage: <%= announce Announcement.newest %>
6
+ # Alt usage: <%= announce Announcement.newest, :format => "boostrap" %>
6
7
  #
7
8
  # Options:
8
- # div_class -- name for a custom div class, which wraps the announcement text and hide message, default is "info"
9
- # hide_message -- clickable text which hides the announcement, default is "hide message"
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.
10
13
  def announce announcement, options = {}
11
- text = options[:hide_message] || "hide message"
12
- div_class = options[:div_class] || "info"
13
- if announcement != nil && cookies["announcement_" + announcement.id.to_s] != "hidden"
14
- content_tag :div, :class => div_class do
15
- result = announcement.body.html_safe
16
- result << content_tag(:span, text, :class => "hide_announcement", :data => { :announcementid => announcement.id })
17
- result
18
- end
19
- end
14
+ result = nil
15
+ data_attribute = { :announcementid => announcement.id }
16
+
17
+ if announcement != nil && cookies["announcement_" + announcement.id.to_s] != "hidden"
18
+ if options[:format] == "bootstrap"
19
+ text = options[:hide_message] || "x"
20
+ div_class = options[:div_class] || "alert alert-block"
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
20
38
  end
21
39
 
22
40
  end
@@ -1,3 +1,3 @@
1
1
  module Announcements
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  $(function() {
2
2
 
3
- $('.hide_announcement').click(function() {
3
+ $('.hide_announcement, .close').click(function() {
4
4
  var a_id = $(this).data("announcementid");
5
5
  createCookie("announcement_" + a_id, "hidden", 45);
6
6
  $(this).parent().slideUp();
@@ -0,0 +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
+
44
+ end
@@ -0,0 +1,5 @@
1
+ require "action_view"
2
+ require "active_support/core_ext"
3
+ require "announcements"
4
+
5
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].each{|f| require f}
@@ -0,0 +1,4 @@
1
+ class Announcement
2
+ attr_accessor :body
3
+ attr_accessor :id
4
+ end
metadata CHANGED
@@ -1,19 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: announcements
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Svilen Gospodinov
9
+ - Chase Southard
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000Z
13
+ date: 2012-04-19 00:00:00.000000000Z
13
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &30209508 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *30209508
14
26
  - !ruby/object:Gem::Dependency
15
27
  name: rails
16
- requirement: &28996596 !ruby/object:Gem::Requirement
28
+ requirement: &30209160 !ruby/object:Gem::Requirement
17
29
  none: false
18
30
  requirements:
19
31
  - - ~>
@@ -21,10 +33,10 @@ dependencies:
21
33
  version: '3.1'
22
34
  type: :runtime
23
35
  prerelease: false
24
- version_requirements: *28996596
36
+ version_requirements: *30209160
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: jquery-rails
27
- requirement: &28996212 !ruby/object:Gem::Requirement
39
+ requirement: &30208848 !ruby/object:Gem::Requirement
28
40
  none: false
29
41
  requirements:
30
42
  - - ! '>='
@@ -32,16 +44,16 @@ dependencies:
32
44
  version: '0'
33
45
  type: :runtime
34
46
  prerelease: false
35
- version_requirements: *28996212
47
+ version_requirements: *30208848
36
48
  description: The Announcements gem makes it easier to display short announcement messages
37
49
  in your views
38
- email:
39
- - svilen@gospodinov.co.uk
50
+ email: svilen@gospodinov.co.uk
40
51
  executables: []
41
52
  extensions: []
42
53
  extra_rdoc_files: []
43
54
  files:
44
55
  - .gitignore
56
+ - .rspec
45
57
  - Gemfile
46
58
  - LICENSE
47
59
  - README.md
@@ -53,7 +65,10 @@ files:
53
65
  - lib/generators/announcements/install/install_generator.rb
54
66
  - lib/generators/announcements/install/templates/announcement.rb
55
67
  - lib/generators/announcements/install/templates/announcements.js
56
- homepage: ''
68
+ - spec/announcements/announcements_helper_spec.rb
69
+ - spec/spec_helper.rb
70
+ - spec/support/announcement.rb
71
+ homepage: https://github.com/svileng/announcements
57
72
  licenses: []
58
73
  post_install_message:
59
74
  rdoc_options: []