announcements 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in announcements.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +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
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+
2
+ ## Quick start
3
+
4
+ 1. Requirements: rails >= 3.1.0 and jquery
5
+ 2. Add `gem 'announcements'` to your Gemfile and run `bundle`
6
+ 3. Run `rails g announcements:install`
7
+ 4. Use `<%= announce Announcement.newest %>` in your views to display the latest announcement
8
+ 5. Create your first announcement in `rails c` by simply creating a new Announcement record, like `Announcement.create(:body => 'This is my first announcement!')`
9
+ 6. Next, add some CSS (find an example below; the default output is quite plain and ugly) and customise it.
10
+
11
+ ## Styling
12
+
13
+ ## Customisation
14
+
15
+ ## How it works
16
+
17
+ ## How to uninstall
18
+
19
+ There is no uninstaller at this point, but you can simply remove the following files manually:
20
+
21
+ 1. app/models/announcement.rb
22
+ 2. vendor/assets/javascripts/announcements.js
23
+
24
+ You also have to remove the `//= require announcements` line in your app/assets/javascripts/application.js file, and rollback the `create_announcements` migration.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
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@gospodinov.co.uk"]
10
+ s.homepage = ""
11
+ s.summary = "Announcements for Rails >= 3.1.0"
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
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "jquery-rails"
24
+ s.add_runtime_dependency "rails", ">= 3.1.0"
25
+ end
@@ -0,0 +1,9 @@
1
+ require "announcements/version"
2
+ require "announcements/announcements_helper.rb"
3
+
4
+ ActionView::Base.send :include, AnnouncementsHelper
5
+
6
+ module Announcements
7
+ # Your code goes here...
8
+ end
9
+
@@ -0,0 +1,22 @@
1
+ module AnnouncementsHelper
2
+
3
+ # Outputs given announcement in HTML.
4
+ #
5
+ # Basic usage: <%= announce Announcement.newest %>
6
+ #
7
+ # 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"
10
+ 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
20
+ end
21
+
22
+ end
@@ -0,0 +1,3 @@
1
+ module Announcements
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ module Announcements
2
+ class InstallGenerator < Rails::Generators::Base
3
+
4
+ desc "Installs the Announcement gem"
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def create_model
8
+ say "--- Creating model in app/models..."
9
+ template "announcement.rb", "app/models/announcement.rb"
10
+ say "--- Creating the migration ..."
11
+ generate("model", "announcement body:text type:string --skip")
12
+ say "--- Running the migration..."
13
+ rake("db:migrate")
14
+ end
15
+
16
+ def create_js_files
17
+ say "--- Copying js to vendor/assets/javascripts..."
18
+ template "announcements.js", "vendor/assets/javascripts/announcements.js"
19
+ say "--- Adding require in app/assets/javascripts/application.js..."
20
+ insert_into_file "app/assets/javascripts/application.js", "//= require announcements\n", :after => "jquery_ujs\n"
21
+ say "--- IMPORTANT: New asset was added in the vendor folder; you have to precompile assets for production!"
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +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
@@ -0,0 +1,21 @@
1
+ $(function() {
2
+
3
+ $('.hide_announcement').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
+ });
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: announcements
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Svilen Gospodinov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jquery-rails
16
+ requirement: &26346180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *26346180
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &26345736 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *26345736
36
+ description: The Announcements gem makes it easier to display short announcement messages
37
+ in your views
38
+ email:
39
+ - svilen@gospodinov.co.uk
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - announcements.gemspec
50
+ - lib/announcements.rb
51
+ - lib/announcements/announcements_helper.rb
52
+ - lib/announcements/version.rb
53
+ - lib/generators/announcements/install/install_generator.rb
54
+ - lib/generators/announcements/install/templates/announcement.rb
55
+ - lib/generators/announcements/install/templates/announcements.js
56
+ homepage: ''
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: announcements
76
+ rubygems_version: 1.8.11
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Announcements for Rails >= 3.1.0
80
+ test_files: []