i_flash 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.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
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.
@@ -0,0 +1,57 @@
1
+ = IFlash
2
+
3
+ Rails Flash Internationalization Plugin.
4
+
5
+ Easily sets flash messages in your controllers, reading from locale.yml files.
6
+
7
+ == Install
8
+
9
+ gem install i_flash
10
+
11
+ == Usage
12
+
13
+ === In your controller:
14
+
15
+ i_flash :success
16
+ i_flash :failure
17
+ i_flash_auto :success
18
+ i_flash_auto :failure
19
+ i_flash_for some_condition?
20
+
21
+ === In your locale file (en.yml)
22
+
23
+ en:
24
+ actions:
25
+ controller_name:
26
+ action_name:
27
+ success: "Action is successful!"
28
+ failure: "Action failed!"
29
+
30
+ === In your view (or layout)
31
+
32
+ = notice
33
+ = alert
34
+
35
+ == Example
36
+
37
+ === /app/controllers/posts_controller.rb:
38
+
39
+ def destroy
40
+ @post = Post.where(params[:id]).first
41
+ i_flash_for @post.delete
42
+ redirect_to :back
43
+ end
44
+
45
+ === /config/locales/en.yml:
46
+
47
+ en:
48
+ actions:
49
+ posts:
50
+ destroy:
51
+ success: "Post is deleted."
52
+ failure: "Couldn't delete post."
53
+
54
+ = Copyright
55
+
56
+ Copyright (c) 2010 [vladalive.com], released under the MIT license
57
+
@@ -0,0 +1,99 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the i_flash plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the i_flash plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'IFlash'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ require "rubygems"
26
+ require "rake/gempackagetask"
27
+ require "rake/rdoctask"
28
+
29
+ require "rake/testtask"
30
+ Rake::TestTask.new do |t|
31
+ t.libs << "test"
32
+ t.test_files = FileList["test/**/*_test.rb"]
33
+ t.verbose = true
34
+ end
35
+
36
+
37
+ task :default => ["test"]
38
+
39
+ # This builds the actual gem. For details of what all these options
40
+ # mean, and other ones you can add, check the documentation here:
41
+ #
42
+ # http://rubygems.org/read/chapter/20
43
+ #
44
+ spec = Gem::Specification.new do |s|
45
+
46
+ # Change these as appropriate
47
+ s.name = "i_flash"
48
+ s.version = "0.1.0"
49
+ s.summary = "Rails Flash Internationalization Plugin"
50
+ s.author = "Vlad Alive"
51
+ s.email = "vladalive@gmail.com"
52
+ s.homepage = "http://github.com/vladalive/i_flash"
53
+
54
+ s.has_rdoc = true
55
+ s.extra_rdoc_files = %w(README.rdoc)
56
+ s.rdoc_options = %w(--main README.rdoc)
57
+
58
+ # Add any extra files to include in the gem
59
+ s.files = %w(init.rb uninstall.rb MIT-LICENSE Rakefile install.rb README.rdoc) + Dir.glob("{test,lib/**/*}")
60
+ s.require_paths = ["lib"]
61
+
62
+ # If you want to depend on other gems, add them here, along with any
63
+ # relevant versions
64
+ # s.add_dependency("some_other_gem", "~> 0.1.0")
65
+
66
+ # If your tests use any gems, include them here
67
+ # s.add_development_dependency("mocha") # for example
68
+ end
69
+
70
+ # This task actually builds the gem. We also regenerate a static
71
+ # .gemspec file, which is useful if something (i.e. GitHub) will
72
+ # be automatically building a gem for this project. If you're not
73
+ # using GitHub, edit as appropriate.
74
+ #
75
+ # To publish your gem online, install the 'gemcutter' gem; Read more
76
+ # about that here: http://gemcutter.org/pages/gem_docs
77
+ Rake::GemPackageTask.new(spec) do |pkg|
78
+ pkg.gem_spec = spec
79
+ end
80
+
81
+ desc "Build the gemspec file #{spec.name}.gemspec"
82
+ task :gemspec do
83
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
84
+ File.open(file, "w") {|f| f << spec.to_ruby }
85
+ end
86
+
87
+ task :package => :gemspec
88
+
89
+ # Generate documentation
90
+ Rake::RDocTask.new do |rd|
91
+ rd.main = "README.rdoc"
92
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
93
+ rd.rdoc_dir = "rdoc"
94
+ end
95
+
96
+ desc 'Clear out RDoc and generated packages'
97
+ task :clean => [:clobber_rdoc, :clobber_package] do
98
+ rm "#{spec.name}.gemspec"
99
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'i_flash'
2
+
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,32 @@
1
+ module IFlash
2
+
3
+ def i_flash_auto(result = :notice, *args)
4
+ i_path = "actions.all.#{params[:action]}.#{result.to_s}"
5
+ object = params[:controller].singularize.titlecase
6
+ flash[message_type(result)] = t(i_path, :object => object)
7
+ end
8
+
9
+ def i_flash(result = :notice, *args)
10
+ i_path = "actions.#{params[:controller]}.#{params[:action]}.#{result.to_s}"
11
+ flash[message_type(result)] = t(i_path, *args)
12
+ end
13
+
14
+ def i_flash_for(condition = true, *args)
15
+ condition ? i_flash(:success, *args) : i_flash(:failure, *args)
16
+ end
17
+
18
+ protected
19
+
20
+ def message_type(result)
21
+ case result
22
+ when :failure then :alert
23
+ when :error then :alert
24
+ else :notice
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ ActionController::Base.send :include, IFlash
31
+ I18n.load_path << File.join(File.dirname(__FILE__), 'locale', 'en.yml')
32
+
@@ -0,0 +1,13 @@
1
+ en:
2
+ actions:
3
+ all:
4
+ create:
5
+ success: "New %{object} is created!"
6
+ failure: "%{object} couldn't be created!"
7
+ update:
8
+ success: "%{object} is updated!"
9
+ failure: "%{object} couldn't be updated!"
10
+ destroy:
11
+ success: "%{object} is deleted!"
12
+ failure: "%{object} couldn't be deleted!"
13
+
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i_flash
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Vlad Alive
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-08 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: vladalive@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - init.rb
32
+ - uninstall.rb
33
+ - MIT-LICENSE
34
+ - Rakefile
35
+ - install.rb
36
+ - README.rdoc
37
+ - lib/locale/en.yml
38
+ - lib/i_flash.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/vladalive/i_flash
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --main
46
+ - README.rdoc
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Rails Flash Internationalization Plugin
74
+ test_files: []
75
+