From b41e20d264b3283581e6f4dbac669248a35de496 Mon Sep 17 00:00:00 2001 From: Jose Carlos Ustra Junior Date: Tue, 3 Jul 2012 12:03:38 -0300 Subject: [PATCH] releasing version 1.0.0 --- .gitignore | 18 ++- Gemfile | 2 +- LICENSE | 22 ++++ README.md | 106 ++++++++++++++++++ Rakefile | 3 +- app/assets/javascripts/jquery.notify_bar.js | 109 +++++++++++++++++++ app/assets/stylesheets/jquery.notify_bar.css | 42 +++++++ jquery_notify_bar.gemspec | 33 +++--- lib/jquery_notify_bar.rb | 2 +- lib/jquery_notify_bar/engine.rb | 10 ++ lib/jquery_notify_bar/version.rb | 2 +- lib/jquery_notify_bar/view_helpers.rb | 41 ++++--- spec/javascripts/jquery_notify_bar_spec.js | 3 + spec/spec_helper.rb | 6 + 14 files changed, 360 insertions(+), 39 deletions(-) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 app/assets/javascripts/jquery.notify_bar.js create mode 100644 app/assets/stylesheets/jquery.notify_bar.css create mode 100644 lib/jquery_notify_bar/engine.rb create mode 100644 spec/javascripts/jquery_notify_bar_spec.js create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore index 86339a0..d87d4be 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,17 @@ -*.gem \ No newline at end of file +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/Gemfile b/Gemfile index f66ed74..b960cdb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source 'https://rubygems.org' # Specify your gem's dependencies in jquery_notify_bar.gemspec gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..69de1f3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2012 Jose Carlos Ustra Junior + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9e8e30e --- /dev/null +++ b/README.md @@ -0,0 +1,106 @@ +#JqueryNotifyBar + +This is a simple ruby gem to include jquery.nofityBar from [Dmitri Smirnov](http://github.com/dknight/jQuery-Notify-bar) to your rails app. + +jquery.notifyBar is a twitter like notification bar. + +With this gem, all your flash messages will be showed in the nofity bar. + +## Installation + +In your gem file add: + +```ruby +gem 'jquery_notify_bar' +``` + +## Usage + +### Rails 3.0 + +Add this files to your javascripts and stylesheets folders +``` +https://raw.github.com/ustrajunior/jquery_notify_bar/master/apps/assets/javascripts/jquery.notify_bar.js +https://raw.github.com/ustrajunior/jquery_notify_bar/master/apps/assets/stylesheets/jquery.notify_bar.css +``` + +in the head section of your application.html.erb add this helper + +```rhtml +<%= jquery_notify_bar_assets %> +``` + +### Rails 3.1 +On your application.js add + +``` +//= require jquery.notify_bar +``` + +On your application.css add + +``` +*= require jquery.notify_bar +``` + +### In your application.html + +```rhtml +<%= jquery_notify_bar(flash) %> +``` + +Remember to add the helper after + +```rhtml +<%= javascript_include_tag "application" %> +``` + +Because it depends of jQuery. + +### Parameters + +You can pass options too: + +``` +:cls => :success +:animation_speed => 'normal' +:delay => 2000 +``` + +or all at the same time + +```rhtml +<%= jquery_notify_bar(flash, :cls => :success, :animation_speed => 'normal', :delay => 2000) %> +``` + +## TODO ## + +* write rspec and jasmine tests +* improve the css + +## Maintainer ## + +* José Carlos Ustra Júnior (http://ustrajunior.com) + +## License ## + +(The MIT License) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Rakefile b/Rakefile index 3561e51..f57ae68 100644 --- a/Rakefile +++ b/Rakefile @@ -1 +1,2 @@ -require 'bundler/gem_tasks' \ No newline at end of file +#!/usr/bin/env rake +require "bundler/gem_tasks" diff --git a/app/assets/javascripts/jquery.notify_bar.js b/app/assets/javascripts/jquery.notify_bar.js new file mode 100644 index 0000000..850eae5 --- /dev/null +++ b/app/assets/javascripts/jquery.notify_bar.js @@ -0,0 +1,109 @@ +/* +* Notify Bar - jQuery plugin +* +* Copyright (c) 2009-2010 Dmitri Smirnov +* +* Licensed under the MIT license: +* http://www.opensource.org/licenses/mit-license.php +* +* Version: 1.2.2 +* +* Project home: +* http://www.dmitri.me/blog/notify-bar +*/ + +/** +* param Object +*/ +jQuery.notifyBar = function(settings) { + + (function($) { + + var bar = notifyBarNS = {}; + notifyBarNS.shown = false; + + if( !settings) { + settings = {}; + } + // HTML inside bar + notifyBarNS.html = settings.html || "Your message here"; + + //How long bar will be delayed, doesn't count animation time. + notifyBarNS.delay = settings.delay || 2000; + + //How long notifyBarNS bar will be slided up and down + notifyBarNS.animationSpeed = settings.animationSpeed || 200; + + //Use own jquery object usually DIV, or use default + notifyBarNS.jqObject = settings.jqObject; + + //Set up own class + notifyBarNS.cls = settings.cls || ""; + + //close button + notifyBarNS.close = settings.close || false; + + if( notifyBarNS.jqObject) { + bar = notifyBarNS.jqObject; + notifyBarNS.html = bar.html(); + } else { + bar = jQuery("
") + .addClass("jquery-notify-bar") + .addClass(notifyBarNS.cls) + .attr("id", "__notifyBar"); + } + + bar.html(notifyBarNS.html).hide(); + var id = bar.attr("id"); + switch (notifyBarNS.animationSpeed) { + case "slow": + asTime = 600; + break; + case "normal": + asTime = 400; + break; + case "fast": + asTime = 200; + break; + default: + asTime = notifyBarNS.animationSpeed; + } + if( bar != 'object'); { + jQuery("body").prepend(bar); + } + + // Style close button in CSS file + if( notifyBarNS.close) { + bar.append(jQuery("Close [X]")); + jQuery(".notify-bar-close").click(function() { + if( bar.attr("id") == "__notifyBar") { + jQuery("#" + id).slideUp(asTime, function() { jQuery("#" + id).remove() }); + } else { + jQuery("#" + id).slideUp(asTime); + } + return false; + }); + } + + // Check if we've got any visible bars and if we have, slide them up before showing the new one + if($('.jquery-notify-bar:visible').length > 0) { + $('.jquery-notify-bar:visible').stop().slideUp(asTime, function() { + bar.stop().slideDown(asTime); + }); + } else { + bar.slideDown(asTime); + } + + // Allow the user to click on the bar to close it + bar.click(function() { + $(this).slideUp(asTime); + }) + + // If taken from DOM dot not remove just hide + if( bar.attr("id") == "__notifyBar") { + setTimeout("jQuery('#" + id + "').stop().slideUp(" + asTime +", function() {jQuery('#" + id + "').remove()});", notifyBarNS.delay + asTime); + } else { + setTimeout("jQuery('#" + id + "').stop().slideUp(" + asTime +", function() {jQuery('#" + id + "')});", notifyBarNS.delay + asTime); + } + +})(jQuery) }; \ No newline at end of file diff --git a/app/assets/stylesheets/jquery.notify_bar.css b/app/assets/stylesheets/jquery.notify_bar.css new file mode 100644 index 0000000..9cd9505 --- /dev/null +++ b/app/assets/stylesheets/jquery.notify_bar.css @@ -0,0 +1,42 @@ +/* +* Notify Bar - jQuery plugin +* +* Copyright (c) 2009-2010 Dmitri Smirnov +* +* Licensed under the MIT license: +* http://www.opensource.org/licenses/mit-license.php +* +* Version: 1.2 +* +* Project home: +* http://www.dmitri.me/blog/notify-bar +*/ + +.jquery-notify-bar { + width:100%; + position:fixed; + top:0; + left:0; + z-index:32768; + background-color:#efefef; + font-size:18px; + color:#000; + text-align:center; + font-family: Arial, Verdana, sans-serif; + padding:20px 0px; + border-bottom:1px solid #bbb; + cursor: pointer; +} +.jquery-notify-bar.error { + color:#f00; + background-color:#fdd; +} +.jquery-notify-bar.success { + color:#060; + background-color:#BBFFB6; +} +.notify-bar-close { + position:absolute; + left:95%; + font-size:11px; +} \ No newline at end of file diff --git a/jquery_notify_bar.gemspec b/jquery_notify_bar.gemspec index e4472b3..4f8a212 100644 --- a/jquery_notify_bar.gemspec +++ b/jquery_notify_bar.gemspec @@ -1,20 +1,21 @@ # -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require "jquery_notify_bar/version" +require File.expand_path('../lib/jquery_notify_bar/version', __FILE__) -Gem::Specification.new do |s| - s.name = "jquery_notify_bar" - s.version = JqueryNotifyBar::VERSION - s.authors = ["Jose Carlos Ustra Junior"] - s.email = ["contato@ustrajunior.com"] - s.homepage = "http://ustrajunior.com/apps/jquery_notify_bar" - s.summary = %q{jquery.notifyBar in your app} - s.description = %q{A simple gem to include jquery.notifyBar to your rails app.} +Gem::Specification.new do |gem| + gem.authors = ["Jose Carlos Ustra Junior"] + gem.email = ["ustrajunior@gmail.com"] + gem.description = "A simple gem to include jquery.notifyBar to your rails app." + gem.summary = "jquery.notifyBar in your app" + gem.homepage = "http://ustrajunior.com/apps/jquery_notify_bar" - s.rubyforge_project = "jquery_notify_bar" - - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] + gem.files = `git ls-files`.split($\) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.name = "jquery_notify_bar" + gem.require_paths = ["lib"] + gem.version = JqueryNotifyBar::VERSION + + gem.add_development_dependency 'rake' + gem.add_development_dependency 'rspec', '~> 2.8.0' + gem.add_development_dependency 'jasmine', '>= 1.1.1' end diff --git a/lib/jquery_notify_bar.rb b/lib/jquery_notify_bar.rb index ae7d569..313c72b 100644 --- a/lib/jquery_notify_bar.rb +++ b/lib/jquery_notify_bar.rb @@ -1,2 +1,2 @@ require "jquery_notify_bar/version" -require 'jquery_notify_bar/railtie' if defined?(Rails) \ No newline at end of file +require "jquery_notify_bar/engine" if defined? Rails diff --git a/lib/jquery_notify_bar/engine.rb b/lib/jquery_notify_bar/engine.rb new file mode 100644 index 0000000..3bd70c3 --- /dev/null +++ b/lib/jquery_notify_bar/engine.rb @@ -0,0 +1,10 @@ +require "jquery_notify_bar/view_helpers" + +module JqueryNotifyBar + class Engine < Rails::Engine + # Adds the ViewHelpers into ActionView::Base + initializer "jquery_notify_bar.view_helpers" do + ActionView::Base.send :include, ViewHelpers + end + end +end \ No newline at end of file diff --git a/lib/jquery_notify_bar/version.rb b/lib/jquery_notify_bar/version.rb index fcd4548..12d621f 100644 --- a/lib/jquery_notify_bar/version.rb +++ b/lib/jquery_notify_bar/version.rb @@ -1,3 +1,3 @@ module JqueryNotifyBar - VERSION = "0.0.4" + VERSION = "1.0.0" end diff --git a/lib/jquery_notify_bar/view_helpers.rb b/lib/jquery_notify_bar/view_helpers.rb index 90f8ff5..5b2496a 100644 --- a/lib/jquery_notify_bar/view_helpers.rb +++ b/lib/jquery_notify_bar/view_helpers.rb @@ -1,24 +1,29 @@ module JqueryNotifyBar module ViewHelpers - def include_jquery_notify_bar - content = - javascript_include_tag('jquery.notifyBar.js') - content << "\n#{stylesheet_link_tag('jquery.notifyBar.css')}".html_safe + def jquery_notify_bar_assets + content = javascript_include_tag('jquery.notify_bar.js') + content += stylesheet_link_tag('jquery.notify_bar.css') + content.html_safe end - - def jquery_notify_bar(key, msg, opts = {}) - opts.reverse_merge! :flash => :notice, :delay => 2000, :animation_speed => 'normal', :cls => 'notice' - content_tag :div, msg, :class => [key, " message"], :id => "notice_ #{key}" - javascript_tag do - %($(function () { - $.notifyBar({ - html: '#{msg}', - delay: #{opts[:delay]}, - animationSpeed: '#{opts[:animation_speed]}', - cls: '#{opts[:cls]}' - }); - });) + + def jquery_notify_bar(flash, opts = {}) + content = '' + unless flash.blank? + flash.each do |key, msg| + opts.reverse_merge! :flash => :notice, :delay => 2000, :animation_speed => 'normal', :cls => (key == :notice ? "success" : "error") + content += javascript_tag do + %($(function () { + $.notifyBar({ + html: '#{msg}', + delay: #{opts[:delay]}, + animationSpeed: '#{opts[:animation_speed]}', + cls: '#{opts[:cls]}' + }); + });) + end + end end - end + content.html_safe + end end end \ No newline at end of file diff --git a/spec/javascripts/jquery_notify_bar_spec.js b/spec/javascripts/jquery_notify_bar_spec.js new file mode 100644 index 0000000..b150083 --- /dev/null +++ b/spec/javascripts/jquery_notify_bar_spec.js @@ -0,0 +1,3 @@ +describe("JqueryNotifyBar", function() { + +}); \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..316be88 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,6 @@ +require 'rubygems' +require 'bundler/setup' +Bundler.require(:default) + +RSpec.configure do |config| +end \ No newline at end of file