alert-messages-for-hanami 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c50c33b86ec3df0b36f2a60835784691de6da57
4
+ data.tar.gz: 3a4e380f849c618b4d43f1e1be62c2a7d736145f
5
+ SHA512:
6
+ metadata.gz: a602b5a5a623209507c96d36b0bd9604b10e883e0fc3cd8f93303302af98a5c91fb74c8dfcb3c5cd0bbc54e31f52031fb2bac69979f5cc78cf7b3c1d04895c8f
7
+ data.tar.gz: 2b78be45a3624e4b6ff5ef36ae6cd318a2bb5b980ff08c2dbd963e4dee89fcde05537273f217dd1b92eb791364d7f864afbc8546e71a75d1d0595f33eb57376d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec-helper
2
+ --color
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - "2.2"
5
+
6
+ before_install: gem install bundler
7
+
8
+ script: bundle exec rspec
9
+
10
+ git:
11
+ submodules: false
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alert-messages.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec', require: false
7
+ gem 'simplecov', require: false
8
+ gem 'coveralls', require: false
9
+ gem 'hanami-controller', require: false
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 mrubi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,101 @@
1
+ # AlertMessages for Hanami
2
+
3
+ A helper to add alert messages (including flash ... aah! messages) to an [Hanami](http://hanamirb.org/) application.
4
+
5
+ ## Status
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/alert-messages-for-hanami.svg)](https://badge.fury.io/rb/alert-messages-for-hanami)
8
+ [![Build Status](https://travis-ci.org/cabeza-de-termo/alert-messages-for-hanami.svg?branch=master)](https://travis-ci.org/cabeza-de-termo/alert-messages-for-hanami)
9
+ [![Coverage Status](https://coveralls.io/repos/github/cabeza-de-termo/alert-messages-for-hanami/badge.svg?branch=master)](https://coveralls.io/github/cabeza-de-termo/alert-messages-for-hanami?branch=master)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'alert-messages-for-hanami', '~> 0.1'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Configuration
22
+
23
+ In your application.rb include
24
+
25
+ ```ruby
26
+ require 'alert-messages-for-hanami'
27
+ ```
28
+
29
+ and then
30
+
31
+ ```ruby
32
+ # Configure the code that will yield each time Admin::Action is included
33
+ # This is useful for sharing common functionality
34
+ #
35
+ # See: http://www.rubydoc.info/gems/hanami-controller#Configuration
36
+ controller.prepare do
37
+ # include MyAuthentication # included in all the actions
38
+ # before :authenticate! # run an authentication before callback
39
+
40
+ include CabezaDeTermo::AlertMessages::Behaviour
41
+ end
42
+ ```
43
+
44
+ ### Adding messages in your actions
45
+
46
+ To add a message to show in the current page, do
47
+
48
+ ```ruby
49
+ module Web::Controllers::Login
50
+ class Create
51
+ include Web::Action
52
+
53
+ def call(params)
54
+ alert_messages[:info] << 'You know nothing, John Snow'
55
+ end
56
+ end
57
+ end
58
+ ```
59
+
60
+ To add a message to show in next request or redirect, first enable sessions in your application and then you can do
61
+
62
+ ```ruby
63
+ module Web::Controllers::Login
64
+ class Create
65
+ def call(params)
66
+ alert_messages.flash_at(:info) << 'Flash! aah ... king of the immmmpossible'
67
+ end
68
+ end
69
+ end
70
+ ```
71
+
72
+ ### Showing messages
73
+
74
+ In your template do something like
75
+
76
+ ```ruby
77
+ - alert_messages[:success].each do |success_message|
78
+ .alert.alert-success role="alert"
79
+ = success_message
80
+
81
+ - alert_messages[:info].each do |info_message|
82
+ .alert.alert-info role="alert"
83
+ = info_message
84
+
85
+ - alert_messages[:warnings].each do |warning_message|
86
+ .alert.alert-warning role="alert"
87
+ = warning_message
88
+
89
+ - alert_messages[:errors].each do |error_message|
90
+ .alert.alert-danger role="alert"
91
+ = error_message
92
+ ```
93
+
94
+ ## Contributing
95
+
96
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cabeza-de-termo/alert-messages.
97
+
98
+ ## License
99
+
100
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
101
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -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 'alert-messages/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alert-messages-for-hanami"
8
+ spec.version = CabezaDeTermo::AlertMessages::VERSION
9
+ spec.authors = ["Martin Rubi"]
10
+ spec.email = ["martinrubi@gmail.com"]
11
+
12
+ spec.summary = %q{Helper to add alert messages (including flash .. aah! messages) to an Hanami application.}
13
+ spec.homepage = "https://github.com/cabeza-de-termo/alert-messages-for-hanami"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,3 @@
1
+ require 'alert-messages/version'
2
+ require 'alert-messages/alert-messages'
3
+ require 'alert-messages/alert-messages-behaviour'
@@ -0,0 +1,13 @@
1
+ module CabezaDeTermo::AlertMessages
2
+ module Behaviour
3
+ def self.included(action)
4
+ action.class_eval do |action_class|
5
+ expose :alert_messages
6
+ end
7
+ end
8
+
9
+ def alert_messages()
10
+ @alert_messages ||= Messages.new(flash: flash)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ module CabezaDeTermo::AlertMessages
2
+ class Messages
3
+ ALERT_MESSAGES = :alert_messages
4
+
5
+ # Instance methods
6
+
7
+ def initialize(flash:)
8
+ @messages = Hash.new { |hash, key| hash[key] = [] }
9
+ @flash = flash
10
+ transfer_flash_messages_for_this_request
11
+ end
12
+
13
+ def [](message_type)
14
+ messages[message_type]
15
+ end
16
+
17
+ def flash_at(message_type)
18
+ ensure_flash_message_type_exists message_type
19
+ flash_messages[message_type]
20
+ end
21
+
22
+ protected
23
+
24
+ # Accessing flash oh oh
25
+
26
+ def flash_messages()
27
+ @flash[ALERT_MESSAGES]
28
+ end
29
+
30
+ def transfer_flash_messages_for_this_request()
31
+ return if flash_messages.nil?
32
+
33
+ flash_messages.each_pair do |type, messages|
34
+ self[type].concat messages
35
+ end
36
+
37
+ drop_flash_messages
38
+ end
39
+
40
+ def drop_flash_messages()
41
+ @flash[ALERT_MESSAGES] = nil
42
+ end
43
+
44
+ def reset_flash_messages()
45
+ @flash[ALERT_MESSAGES] = Hash[]
46
+ end
47
+
48
+ def ensure_flash_message_type_exists(message_type)
49
+ reset_flash_messages if @flash[ALERT_MESSAGES].nil?
50
+ flash_messages[message_type] = [] unless flash_messages.key? message_type
51
+ end
52
+
53
+ # Accessing regular messages
54
+
55
+ def messages()
56
+ @messages
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ module CabezaDeTermo
2
+ module AlertMessages
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alert-messages-for-hanami
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Rubi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-17 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - martinrubi@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - alert-messages.gemspec
56
+ - lib/alert-messages-for-hanami.rb
57
+ - lib/alert-messages/alert-messages-behaviour.rb
58
+ - lib/alert-messages/alert-messages.rb
59
+ - lib/alert-messages/version.rb
60
+ homepage: https://github.com/cabeza-de-termo/alert-messages-for-hanami
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.6.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Helper to add alert messages (including flash .. aah! messages) to an Hanami
84
+ application.
85
+ test_files: []