flash_rails_messages 0.0.1

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: deb23dfab9f19d4dce2a82dfbcd69b72169d63f1
4
+ data.tar.gz: 9acce72fe337fdee59540916c0067e279f3c8df3
5
+ SHA512:
6
+ metadata.gz: b35805e4907edaa03698c4bee4ba75406e9cbfe61c14676174097f2a9c22c732f5e76534572485e5cb30223b0d90a3879049368e4f483afa619c2baff0b30038
7
+ data.tar.gz: 18629c9de86d70f6724a77edbd3bab167be560c8e8dd7cdcb983754d6a91b9fe40a2e60efe090746d419db8aab58a580142398d752596dcfed3d3518d79e2138
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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 2.0.0" > .rvmrc
9
+ environment_id="ruby-2.0.0-p195@flash_rails_messages"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.20.13 (version)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
+ do
28
+ if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
+ then \. "${__hook}" || true
30
+ fi
31
+ done
32
+ unset __hook
33
+ if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
34
+ then
35
+ if [[ $- == *i* ]] # check for interactive shells
36
+ then printf "%b" "Using: \E[32m$GEM_HOME\E[0m" # show the user the ruby and gemset they are using in green
37
+ else printf "%b" "Using: $GEM_HOME" # don't use colors in non-interactive shells
38
+ fi
39
+ fi
40
+ else
41
+ # If the environment file has not yet been created, use the RVM CLI to select.
42
+ rvm --create "$environment_id" || {
43
+ echo "Failed to create RVM environment '${environment_id}'."
44
+ return 1
45
+ }
46
+ fi
47
+
48
+ # If you use bundler, this might be useful to you:
49
+ # if [[ -s Gemfile ]] && {
50
+ # ! builtin command -v bundle >/dev/null ||
51
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
52
+ # }
53
+ # then
54
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
55
+ # gem install bundler
56
+ # fi
57
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
58
+ # then
59
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
60
+ # fi
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ - "1.9.3"
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flash_rails_messages.gemspec
4
+ gemspec
5
+
6
+ gem 'rails'
7
+ gem 'rspec'
8
+ gem 'simplecov'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alejandro Gutiérrez
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,45 @@
1
+ # FlashRailsMessages[![Build Status](https://travis-ci.org/alejandrogutierrez/flash_rails_messages.png?branch=master)](https://travis-ci.org/alejandrogutierrez/flash_rails_messages)
2
+
3
+ This gem provides an easy and simple way to display flash messages to your users to inform them that an action has or hasn't taken place. It's using the bootstrap framework.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'flash_rails_messages'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install flash_rails_messages
18
+
19
+ ## Usage
20
+
21
+ You only need to add this line wherever you want to display the messages:
22
+
23
+ <%= render_flash_messages %>
24
+
25
+ You can add the line above in your html in multiple places.
26
+
27
+
28
+ The flash messages are displayed according to the flash type.
29
+
30
+ - success = green alert
31
+ - notice = blue alert
32
+ - alert = red alert
33
+
34
+ **By default shows a yellow alert.**
35
+
36
+ *NOTE:*
37
+ In next versions styles will be customizable.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ namespace :rspec do
4
+ desc "Running all tests"
5
+ task :all do
6
+ system("rspec")
7
+ end
8
+ end
9
+
10
+ task default: ['rspec:all']
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flash_rails_messages/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flash_rails_messages"
8
+ spec.version = FlashRailsMessages::VERSION
9
+ spec.authors = ["Alejandro Gutiérrez"]
10
+ spec.email = ["alejandrodevs@gmail.com"]
11
+ spec.description = "A simple helper to display flash rails messages"
12
+ spec.summary = "This gems provides an easy way to display flash rails messages"
13
+ spec.homepage = "https://github.com/alejandrogutierrez/flash_rails_messages"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,3 @@
1
+ module FlashRailsMessages
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,52 @@
1
+ require "flash_rails_messages/version"
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module FlashRailsMessagesHelper
6
+
7
+ def render_flash_messages
8
+ flash.each do |type, msg|
9
+ flash_messages << alert_element(type, msg) if msg
10
+ clean_flash_message(type)
11
+ end
12
+
13
+ flash_messages.html_safe
14
+ end
15
+
16
+ private
17
+
18
+ def clean_flash_message type
19
+ flash[type] = nil
20
+ end
21
+
22
+ def alert_element type, msg
23
+ content_tag(:div, close_element + msg, :class => alert_classes(type))
24
+ end
25
+
26
+ def close_element
27
+ content_tag(:span, "&times;".html_safe, :class => "close", :"data-dismiss" => "alert")
28
+ end
29
+
30
+ def alert_classes type
31
+ "alert #{custom_classes(type)}"
32
+ end
33
+
34
+ def custom_classes type
35
+ case type
36
+ when :success then "alert-success"
37
+ when :notice then "alert-info"
38
+ when :alert then "alert-error"
39
+ end
40
+ end
41
+
42
+ def flash_messages
43
+ @flash_messages ||= ""
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
50
+ if defined?(ActionView::Helpers)
51
+ ActionView::Helpers.send(:include, ActionView::Helpers::FlashRailsMessagesHelper)
52
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActionView::Helpers::FlashRailsMessagesHelper do
4
+ let!(:subject){ ActionView::Base.new }
5
+
6
+ describe "#render_flash_messages" do
7
+ context "when flash does not have messages" do
8
+ it "returns nothing" do
9
+ subject.stub(:flash).and_return({})
10
+ expect(subject.render_flash_messages).to eql("")
11
+ end
12
+ end
13
+
14
+ context "when flash has messages" do
15
+ context "when flash type is notice" do
16
+ it "returns the correct message" do
17
+ subject.stub(:flash).and_return({:notice => "notice"})
18
+ expect(subject.render_flash_messages).to eql(alert_element("notice", "info"))
19
+ end
20
+ end
21
+
22
+ context "when flash type is success" do
23
+ it "returns the correct message" do
24
+ subject.stub(:flash).and_return({:success => "success"})
25
+ expect(subject.render_flash_messages).to eql(alert_element("success", "success"))
26
+ end
27
+ end
28
+
29
+ context "when flash type is alert" do
30
+ it "returns the correct message" do
31
+ subject.stub(:flash).and_return({:alert => "alert"})
32
+ expect(subject.render_flash_messages).to eql(alert_element("alert", "error"))
33
+ end
34
+ end
35
+
36
+ context "when has more than one message" do
37
+ it "returns all the correct messages" do
38
+ flash = {:alert => "alert", :notice => "notice"}
39
+ subject.stub(:flash).and_return(flash)
40
+ alerts_expected = alert_element("alert", "error") +
41
+ alert_element("notice", "info")
42
+ expect(subject.render_flash_messages).to eql(alerts_expected)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def alert_element msg, type
49
+ subject.content_tag(:div, close_element + msg ,:class => "alert alert-#{type}")
50
+ end
51
+
52
+ def close_element
53
+ subject.content_tag(:span, "&times;".html_safe, :class => "close", :"data-dismiss" => "alert")
54
+ end
55
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'action_view'
4
+ require 'flash_rails_messages'
5
+ require 'rails/all'
6
+ require 'simplecov'
7
+
8
+ SimpleCov.start do
9
+ minimum_coverage 90
10
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flash_rails_messages
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alejandro Gutiérrez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A simple helper to display flash rails messages
42
+ email:
43
+ - alejandrodevs@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rspec
50
+ - .rvmrc
51
+ - .travis.yml
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - flash_rails_messages.gemspec
57
+ - lib/flash_rails_messages.rb
58
+ - lib/flash_rails_messages/version.rb
59
+ - spec/flash_rails_messages_spec.rb
60
+ - spec/spec_helper.rb
61
+ homepage: https://github.com/alejandrogutierrez/flash_rails_messages
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.0.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: This gems provides an easy way to display flash rails messages
85
+ test_files:
86
+ - spec/flash_rails_messages_spec.rb
87
+ - spec/spec_helper.rb