error_message_on 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/error_message_on.gemspec +19 -0
- data/lib/error_message_on/builder.rb +10 -0
- data/lib/error_message_on/engine.rb +16 -0
- data/lib/error_message_on/helper.rb +24 -0
- data/lib/error_message_on/version.rb +3 -0
- data/lib/error_message_on.rb +5 -0
- metadata +56 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrey
|
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,34 @@
|
|
1
|
+
# ErrorMessageOn
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'error_message_on'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install error_message_on
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Gem generate formtastic style inline errors (with <p class="inline-errors">error text</p>). You may override this.
|
22
|
+
|
23
|
+
<% semantic_form_for ... %>
|
24
|
+
<%= form.inputs do %>
|
25
|
+
<%= form.error_message_on :body %>
|
26
|
+
...
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'error_message_on/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "error_message_on"
|
8
|
+
gem.version = ErrorMessageOn::VERSION
|
9
|
+
gem.authors = ["Andrey"]
|
10
|
+
gem.email = ["railscode@gmail.com"]
|
11
|
+
gem.description = "Single error message for Rails Form"
|
12
|
+
gem.summary = "Single error message for Rails Form"
|
13
|
+
gem.homepage = "https://github.com/vav/error_message_on"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
class ActionView::Helpers::FormBuilder
|
3
|
+
def field_container(method, options = {}, &block)
|
4
|
+
@template.field_container(@object_name,method,options,&block)
|
5
|
+
end
|
6
|
+
|
7
|
+
def error_message_on(method, options = {})
|
8
|
+
@template.error_message_on(@object_name, method, objectify_options(options))
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module ErrorMessageOn
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
initializer 'error_message_on.initialize' do
|
5
|
+
config.to_prepare do
|
6
|
+
ActiveSupport.on_load(:action_view) do
|
7
|
+
include ErrorMessageOn::ErrorMessageHelper
|
8
|
+
|
9
|
+
# ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
|
10
|
+
# "<span class=\"field_with_errors\">#{html_tag}</span>".html_safe
|
11
|
+
# end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module ErrorMessageOn
|
3
|
+
module ErrorMessageHelper
|
4
|
+
def field_container(model, method, options = {}, &block)
|
5
|
+
css_classes = options[:class].to_a
|
6
|
+
if error_message_on(model, method).present?
|
7
|
+
css_classes << 'withError'
|
8
|
+
end
|
9
|
+
content_tag('p', capture(&block), :class => css_classes.join(' '), :id => "#{model}_#{method}_field")
|
10
|
+
end
|
11
|
+
|
12
|
+
def error_message_on(object, method, options = {})
|
13
|
+
object = convert_to_model(object)
|
14
|
+
obj = object.respond_to?(:errors) ? object : instance_variable_get("@#{object}")
|
15
|
+
|
16
|
+
if obj && obj.errors[method].present?
|
17
|
+
errors = obj.errors[method].map { |err| h(err) }.join('<br />').html_safe
|
18
|
+
content_tag(:p, errors, :class => 'inline-errors')
|
19
|
+
else
|
20
|
+
''
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: error_message_on
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-23 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Single error message for Rails Form
|
15
|
+
email:
|
16
|
+
- railscode@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- error_message_on.gemspec
|
27
|
+
- lib/error_message_on.rb
|
28
|
+
- lib/error_message_on/builder.rb
|
29
|
+
- lib/error_message_on/engine.rb
|
30
|
+
- lib/error_message_on/helper.rb
|
31
|
+
- lib/error_message_on/version.rb
|
32
|
+
homepage: https://github.com/vav/error_message_on
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.23
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Single error message for Rails Form
|
56
|
+
test_files: []
|