f_dot_errors 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: e72351996906ab3527cf939146b24a6c7df89cf1
4
+ data.tar.gz: d3cba2efb8c0d7919037e1c97878d4b675bc8d02
5
+ SHA512:
6
+ metadata.gz: b12f4aa430d14ed65ca1fdddbd71d41276098ac27c87e32340c853205e8832f85961381c607d645ac4319cadf5cb84d6a1eea521c96cbbec14e0ce29254568b9
7
+ data.tar.gz: e7b2ecb65c4d410e5926049bdb9453a8d8753c4a4be3c21ee0e14522aebddc9725bf5366bd46ecfdf34b233aef43d94a01044a313870833fc76ebb297c1a9f8d
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
11
+ log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in f_dot_errors.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 yui-knk
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,112 @@
1
+ # FDotErrors
2
+
3
+ Add `f.errors(:method)` to Rails view.
4
+
5
+ ## Supported versions
6
+
7
+ Rails 4.2.x
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'f_dot_errors'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install f_dot_errors
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ # app/models/post.rb
29
+ # sure we support ActiveRecord model
30
+ class Post < Struct.new(:author_name, :body, :updated_at)
31
+ include ActiveModel::Model
32
+ end
33
+
34
+
35
+ # app/controllers/posts_controller.rb
36
+ class PostsController < ApplicationController
37
+ def create
38
+ @post = Post.new(post_params)
39
+ if @post.save
40
+ respond_to do |format|
41
+ format.html { redirect_to posts_path }
42
+ end
43
+ else
44
+ respond_to do |format|
45
+ format.html { render :new }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ ```
51
+
52
+ ```erb
53
+ # app/views/posts/new.html.erb
54
+ <%= form_for(@post) do |f| %>
55
+ <%= f.text_field(:author_name) %>
56
+ <%= f.errors(:author_name) %>
57
+
58
+ <%= f.text_field(:body) %>
59
+ <%= f.errors(:body) %>
60
+ <% end %>
61
+ ```
62
+
63
+ If `@post` has errors about `:author_name`, `f.errors` render errors:
64
+
65
+ ```html
66
+ <form class="new_post" id="new_post" action="/posts" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="&#x2713;" />
67
+ <input type="text" value="" name="post[author_name]" id="post_author_name" />
68
+ <div class="field_with_errors">Author name can't be empty</div>
69
+ <input type="text" value="" name="post[boyd]" id="post_boyd" />
70
+ </form>
71
+ ```
72
+
73
+ ## Configuring error wrapper
74
+
75
+ By default, these proc is used:
76
+
77
+ ```ruby
78
+ Proc.new { |instance, method, template|
79
+ msgs = instance.errors.full_messages_for(method).join("\n")
80
+ "<div class=\"field_with_errors\">#{msgs}</div>".html_safe
81
+ }
82
+ ```
83
+
84
+ If you would use a different proc, you can configure in your initializer.
85
+
86
+ ```ruby
87
+ FDotErrors.configure do |c|
88
+ c.field_error_proc = Proc.new { |instance, method, template|
89
+
90
+ lis = instance.errors.full_messages_for(method).map do |msg|
91
+ template.content_tag(:li, msg, {class: "field_with_errors_list_item"}, false)
92
+ end.join("\n").html_safe
93
+ template.content_tag(:ul, lis, class: "field_with_errors_list")
94
+ }
95
+ end
96
+ ```
97
+
98
+ ## Development
99
+
100
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
101
+
102
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
103
+
104
+ ## Contributing
105
+
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yui-knk/f_dot_errors. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
107
+
108
+
109
+ ## License
110
+
111
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
112
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "f_dot_errors"
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
@@ -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
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'f_dot_errors/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "f_dot_errors"
8
+ spec.version = FDotErrors::VERSION
9
+ spec.authors = ["yui-knk"]
10
+ spec.email = ["spiketeika@gmail.com"]
11
+
12
+ spec.summary = %q{Add `f.errors(:method)` to Rails view}
13
+ spec.description = %q{Add `f.errors(:method)` to Rails view}
14
+ spec.homepage = "https://github.com/yui-knk/f_dot_errors"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'rails', "~> 4.2"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec-rails"
27
+ end
@@ -0,0 +1,7 @@
1
+ require "f_dot_errors/config"
2
+ require "f_dot_errors/errors_helper"
3
+ require "f_dot_errors/railtie"
4
+ require "f_dot_errors/version"
5
+
6
+ module FDotErrors
7
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_support/configurable'
2
+
3
+ module FDotErrors
4
+ def self.configure(&block)
5
+ yield @config ||= FDotErrors::Configuration.new
6
+ end
7
+
8
+ def self.config
9
+ @config
10
+ end
11
+
12
+ class Configuration
13
+ include ActiveSupport::Configurable
14
+
15
+ # see ActionView::Base.field_error_proc
16
+ config_accessor :field_error_proc do
17
+ Proc.new { |instance, method, template|
18
+ msgs = instance.errors.full_messages_for(method).join("\n")
19
+ "<div class=\"field_with_errors\">#{msgs}</div>".html_safe
20
+ }
21
+ end
22
+ end
23
+
24
+ configure {}
25
+ end
@@ -0,0 +1,14 @@
1
+ module FDotErrors
2
+ module ErrorsHelper
3
+ def errors(method)
4
+ return unless object_has_errors?(method)
5
+
6
+ FDotErrors.config.field_error_proc.call(object, method, @template)
7
+ end
8
+
9
+ private
10
+ def object_has_errors?(key)
11
+ object.respond_to?(:errors) && object.errors.respond_to?(:[]) && object.errors[key].present?
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails'
2
+ require 'action_view'
3
+
4
+ module FDotErrors
5
+ class Railtie < ::Rails::Railtie
6
+ initializer "f_dot_errors" do
7
+ ActiveSupport.on_load(:action_view) do
8
+ require 'f_dot_errors/errors_helper'
9
+ ActionView::Helpers::FormBuilder.send :include, FDotErrors::ErrorsHelper
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module FDotErrors
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: f_dot_errors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yui-knk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Add `f.errors(:method)` to Rails view
70
+ email:
71
+ - spiketeika@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - f_dot_errors.gemspec
87
+ - lib/f_dot_errors.rb
88
+ - lib/f_dot_errors/config.rb
89
+ - lib/f_dot_errors/errors_helper.rb
90
+ - lib/f_dot_errors/railtie.rb
91
+ - lib/f_dot_errors/version.rb
92
+ homepage: https://github.com/yui-knk/f_dot_errors
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Add `f.errors(:method)` to Rails view
116
+ test_files: []