form_helper-error_messages 0.0.1

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.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in form_helper-error_messages.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 yalab
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,50 @@
1
+ # FormHelper::ErrorMessages
2
+
3
+ Extend ActionView::Helepr::FormHelper for rendering error message on any position.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'form_helper-error_messages'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install form_helper-error_messages
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ # You can put error message any position.
23
+ <%= from_for(@user) do |f| %>
24
+ <%= f.text_field :name %>
25
+ <%= f.error_messages :name %>
26
+ <% end %>
27
+
28
+ # <form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
29
+ # <div class="invalid">Name can&#x27;t be blank</div>
30
+ # </form>
31
+ ```
32
+ You can choose any tags or any class name like this.
33
+
34
+ ```ruby
35
+ <%= from_for(@user) do |f| %>
36
+ <%= f.text_field :name %>
37
+ <%= f.error_messages :name, tag: 'span', class: 'error' %>
38
+ <% end %>
39
+
40
+ # <form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
41
+ # <div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><span class="error">Name can&#x27;t be blank</span></form>
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'form_helper/error_messages/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "form_helper-error_messages"
8
+ gem.version = FormHelper::ErrorMessages::VERSION
9
+ gem.authors = ["yalab"]
10
+ gem.email = ["rudeboyjet@gmail.com"]
11
+ gem.description = %q{Extend ActionView::Helepr::FormHelper for rendering error message with using rails form_for.}
12
+ gem.summary = %q{You wish such semantics '<%= f.error_message(:name) %>' aren't you?} #'
13
+ gem.homepage = "https://github.com/yalab/form_helper-error_messages"
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
+ gem.add_dependency('actionpack')
20
+ gem.add_development_dependency('activemodel')
21
+ end
@@ -0,0 +1,3 @@
1
+ require "form_helper/error_messages/version"
2
+ require "form_helper/error_messages"
3
+ ActionView::Helpers::FormBuilder.send(:include, FormHelper::ErrorMessages)
@@ -0,0 +1,17 @@
1
+ module FormHelper
2
+ module ErrorMessages
3
+ def error_messages(attr, opts={})
4
+ tag = opts[:tag] || :div
5
+ class_name = opts[:class] || 'invalid'
6
+ errors = @object.errors
7
+ errors[attr].map{|message|
8
+ message = errors.full_message(attr, message)
9
+ if block_given?
10
+ yield message
11
+ else
12
+ @template.content_tag(tag, ERB::Util.html_escape(message), class: class_name)
13
+ end
14
+ }.join("\n").html_safe
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module FormHelper
2
+ module ErrorMessages
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class FormHelper::ErrorMessageTest < ActionView::TestCase
4
+ tests ActionView::Helpers::FormHelper
5
+
6
+ setup do
7
+ @user = User.new
8
+ end
9
+
10
+ test '#error_messages default' do
11
+ form_for(@user) do |f|
12
+ assert_dom_equal('<div class="invalid">Name can&#x27;t be blank</div>', f.error_messages(:name))
13
+ end
14
+ end
15
+
16
+ test "#error_messages with options" do
17
+ form_for(@user) do |f|
18
+ assert_dom_equal('<span class="error">Name can&#x27;t be blank</span>', f.error_messages(:name, tag: 'span', class: 'error'))
19
+ end
20
+ end
21
+
22
+ test "#error_messages with block" do
23
+ form_for(@user) do |f|
24
+ assert_dom_equal("It Name can't be blank!!",
25
+ f.error_messages(:name){|message| 'It ' + message + '!!' })
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ class User
2
+ extend ActiveModel::Naming
3
+ include ActiveModel::Conversion
4
+ attr_reader :errors
5
+
6
+ def persisted?
7
+ false
8
+ end
9
+
10
+ def initialize
11
+ @errors = ActiveModel::Errors.new(self)
12
+ @errors.add(:name, "can't be blank")
13
+ end
14
+
15
+ def self.human_attribute_name(attr, _)
16
+ attr.to_s.camelize
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+
3
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
4
+ require 'test/unit'
5
+ require 'action_view/test_case'
6
+ [:capture, :tag, :sanitize, :text, :url, :form_tag].each do |name|
7
+ require "action_view/helpers/#{name}_helper"
8
+ end
9
+
10
+ require 'form_helper-error_messages'
11
+ require 'models/user'
12
+
13
+ Routes = ActionDispatch::Routing::RouteSet.new
14
+ Routes.draw do
15
+ resources :users
16
+ end
17
+
18
+ class ActionView::TestCase::TestController
19
+ include Routes.url_helpers
20
+ def _routes
21
+ Routes
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: form_helper-error_messages
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - yalab
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionpack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activemodel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Extend ActionView::Helepr::FormHelper for rendering error message with
47
+ using rails form_for.
48
+ email:
49
+ - rudeboyjet@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - form_helper-error_messages.gemspec
60
+ - lib/form_helper-error_messages.rb
61
+ - lib/form_helper/error_messages.rb
62
+ - lib/form_helper/error_messages/version.rb
63
+ - test/form_helper/error_messages_test.rb
64
+ - test/models/user.rb
65
+ - test/test_helper.rb
66
+ homepage: https://github.com/yalab/form_helper-error_messages
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.24
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: You wish such semantics '<%= f.error_message(:name) %>' aren't you?
90
+ test_files:
91
+ - test/form_helper/error_messages_test.rb
92
+ - test/models/user.rb
93
+ - test/test_helper.rb
94
+ has_rdoc: