flash_it 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 094727b01f91e09eaba77c35cb42b20754397427
4
+ data.tar.gz: bcd58c95fd1a4fd3b68091043816ed03fdfe9c1b
5
+ SHA512:
6
+ metadata.gz: f12100602904289ddfb8b7c7bab8235c8fd15a2b6746af4afcc336b2f241ba01c406e2a014812a2c6feedac24b16d6085542cce73bfcaf52ee8ab27b907f0444
7
+ data.tar.gz: 6d40042aafb35c40a486e58a86e1f93fea86f76cab1004489896bea47266eb81748a5784b0c9d4097267f33da4db88408ca988edde95a74059882350d94abdd0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flash_it.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # FlashIt
2
+
3
+ Welcome to flash_it - the flash helper for translating your flash messages with ease!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'flash_it'
11
+ ```
12
+
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ class UsersController < ApplicationController
18
+ def update
19
+ if current_user.profile.update_attributes(user_params)
20
+ flash_it(:success)
21
+ return redirect_to edit_user_profile_path
22
+ else
23
+ flash_it(:error)
24
+ render :edit
25
+ end
26
+ end
27
+ end
28
+ ```
29
+
30
+ flash_it will make a lookup in your translation files for ``flash_messages.users.update.success`` or ``flash_messages.users.update.error``
31
+
32
+ By default, the `:error` messages will become a `flash[:error]` and everything else becomes a `flash[:success]` but of course you're able to customize it, by given the type of the flash message: ``flash_it(:success, :notice)``
33
+
34
+ Also this is able ``flash_it(:attention, :warning)`` which will lookup into ``flash_messages.controller.action.attention`` and uses a ``flash[:warning]``
35
+
36
+ ### Controller Namespacing
37
+
38
+ If you are having namespaced controllers, just edit your yml file to the namespaces
39
+ Lets say we have a Admin::Users::PaymentHistoryController, then your yml file needs to look like this
40
+ ```yml
41
+ en:
42
+ flash_messages:
43
+ admin:
44
+ users:
45
+ payment_history:
46
+ key: value
47
+
48
+ ```
49
+
50
+
51
+
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/krtschmr/flash_it.
56
+
57
+
58
+ ## License
59
+
60
+ Released under the MIT License
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "flash_it"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/flash_it.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flash_it/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flash_it"
8
+ spec.version = FlashIt::VERSION
9
+ spec.authors = ["Tim Kretschmer"]
10
+ spec.email = ["tim@krtschmr.de"]
11
+
12
+ spec.summary = "Helper for using translated flash messages with ease"
13
+ spec.description = "Helper for using translated flash messages with ease"
14
+ spec.homepage = "https://github.com/krtschmr/flash_it."
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ end
@@ -0,0 +1,3 @@
1
+ module FlashIt
2
+ VERSION = "0.1.0"
3
+ end
data/lib/flash_it.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "flash_it/version"
2
+ require 'active_support/concern'
3
+
4
+ module FlashIt
5
+
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+
10
+ # setting flash messages, based on controller/action/key
11
+ def flash_it(key, style=nil)
12
+
13
+ # default style is "success"
14
+ (style = (key == :error ? :error : :success)) unless style
15
+
16
+ # namespace lookup
17
+ # User::SomethingController
18
+ # => ["user", "something"]
19
+ namespacing = self.class.to_s.split("::").map{|x| x.underscore.gsub("_controller", "")}
20
+
21
+ #looking in flash_messages.user.something.action.key
22
+ lookup = "flash_messages."
23
+ lookup << namespacing.join(".") << "."
24
+ lookup << "#{action_name}."
25
+ lookup << "#{key}"
26
+
27
+ #set the flash message
28
+ flash[style] = t(lookup)
29
+ end
30
+ end
31
+ end
32
+ ActionController::Base.include FlashIt
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flash_it
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Kretschmer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-27 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: Helper for using translated flash messages with ease
42
+ email:
43
+ - tim@krtschmr.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - flash_it.gemspec
56
+ - lib/flash_it.rb
57
+ - lib/flash_it/version.rb
58
+ homepage: https://github.com/krtschmr/flash_it.
59
+ licenses: []
60
+ metadata:
61
+ allowed_push_host: https://rubygems.org
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.8
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Helper for using translated flash messages with ease
82
+ test_files: []