active_admin-form_errors 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d917a0f34844c53959aaf1f3dbe9b3f68f8ebc4
4
+ data.tar.gz: 0a2515b2e2f21f953c1237d7dfbef42e47f04848
5
+ SHA512:
6
+ metadata.gz: b1eea213925e91457e98c3231471da922494eb6e2f1f95ee42ac458d37c914c3b37ad1d96ddd1d4b737dcbb8b8ad18aa9eb63dd98f5a5b5bad884a56a158e8d2
7
+ data.tar.gz: 91d7977bf3706a9b22c983d25619e5972e647b82570f0f0ad804de8fd4aaca4a12997bbce9f567ade382aac4a181159271e0bdaa7d12a6f6f6b2e96bd3957e45
data/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg
2
+ doc
3
+ log
4
+ *.lock
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,39 @@
1
+ # Contributing
2
+
3
+ ## Issues
4
+
5
+ If you want to request a feature or report a bug, please use the following template.
6
+
7
+ ```markdown
8
+ ## Description
9
+
10
+ [Add feature/bug description here]
11
+
12
+ ## How to reproduce
13
+
14
+ [Add steps on how to reproduce this issue]
15
+
16
+ ## What do you expect
17
+
18
+ [Describe what do you expect to happen]
19
+
20
+ ## What happened instead
21
+
22
+ [Describe the actual results]
23
+
24
+ ## Gem version:
25
+
26
+ Version: [Add gem version here]
27
+ ```
28
+
29
+ ## Writing code
30
+
31
+ Once you've made your great commits (include tests, please):
32
+
33
+ 1. [Fork](http://help.github.com/forking/) the [original repository](http://github.com/dhyegofernando/active_admin-form_errors)
34
+ 2. Create a topic branch - `git checkout -b my_branch`
35
+ 3. Push to your branch - `git push origin my_branch`
36
+ 4. [Create an Issue](http://github.com/dhyegofernando/active_admin-form_errors/issues) with a link to your branch
37
+ 5. That's it!
38
+
39
+ Please respect the code style using [editorconfig](http://editorconfig.org/) in your text editor.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_admin-form_errors.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Dhyego Fernando
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.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # ActiveAdmin Form Errors
2
+ Pretty form errors by default in your ActiveAdmin.
3
+
4
+ ## Installation
5
+ **1. Import gem**
6
+ ```ruby
7
+ gem 'active_admin-form_errors'
8
+ ```
9
+
10
+ **2. Import stylesheets (change `app/assets/stylesheets/active_admin.scss`)**
11
+ ```scss
12
+ @import 'active_admin/form_errors';
13
+ ```
14
+
15
+ ## Options
16
+ **Disable it in a specific resource**
17
+ ```ruby
18
+ ActiveAdmin.register User do
19
+ config.form_errors = false
20
+ end
21
+ ```
22
+
23
+ **Disable by default at all resources (change `config/initializers/active_admin.rb`)**
24
+ ```ruby
25
+ ActiveAdmin.setup do
26
+ config.form_errors = false
27
+ end
28
+ ```
29
+
30
+ **Show only specific errors**
31
+ ```ruby
32
+ ActiveAdmin.register User do
33
+ config.form_errors = lambda do
34
+ if current_user.admin?
35
+ resource.errors.keys
36
+ else
37
+ [:name, :email]
38
+ end
39
+ end
40
+ end
41
+ ```
42
+
43
+ **Change the color base**
44
+ ```scss
45
+ $form-errors-color: red; // must be before the import
46
+
47
+ @import 'active_admin/form_errors';
48
+ ```
49
+
50
+ ## Maintainer
51
+ [Dhyego Fernando](https://github.com/dhyegofernando)
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['./test/**/*_test.rb']
7
+ end
8
+
9
+ task default: :test
@@ -0,0 +1,26 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ require './lib/active_admin/form_errors/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'active_admin-form_errors'
7
+ spec.version = ActiveAdmin::FormErrors::Version::STRING
8
+ spec.authors = ['Dhyego Fernando']
9
+ spec.email = ['dhyegofernando@gmail.com']
10
+
11
+ spec.summary = 'Pretty form errors by default in your ActiveAdmin.'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'http://github.com/dhyegofernando/active_admin-form_errors'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+
18
+ spec.add_dependency 'railties'
19
+ spec.add_dependency 'activeadmin'
20
+
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'minitest'
24
+ spec.add_development_dependency 'minitest-utils'
25
+ spec.add_development_dependency 'pry-meta'
26
+ end
@@ -0,0 +1,26 @@
1
+ $form-errors-color: #a61a14 !default;
2
+
3
+ .errors {
4
+ display: flex;
5
+ flex-flow: row wrap;
6
+ justify-content: left;
7
+ margin-bottom: 20px;
8
+ padding: 10px;
9
+ background-color: lighten($form-errors-color, 60);
10
+ border: 1px solid $form-errors-color;
11
+ border-radius: 4px;
12
+ color: $form-errors-color;
13
+
14
+ li {
15
+ list-style: disc;
16
+ margin: 2px 0 0 45px;
17
+
18
+ @media (min-width: 768px) {
19
+ width: 50%;
20
+ }
21
+
22
+ @media (min-width: 1024px) {
23
+ width: 30%;
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,16 @@
1
+ require 'active_support/core_ext'
2
+ require 'active_admin'
3
+
4
+ module ActiveAdmin
5
+ module FormErrors
6
+ autoload :Version, 'active_admin/form_errors/version'
7
+ end
8
+ end
9
+
10
+ require 'active_admin/form_errors/engine'
11
+ require 'active_admin/form_errors/form'
12
+ require 'active_admin/form_errors/resource'
13
+
14
+ ActiveAdmin::Application.inheritable_setting :form_errors, true
15
+ ActiveAdmin::Views::ActiveAdminForm.prepend(ActiveAdmin::FormErrors::Form)
16
+ ActiveAdmin::Resource.include(ActiveAdmin::FormErrors::Resource)
@@ -0,0 +1,6 @@
1
+ module ActiveAdmin
2
+ module FormErrors
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,33 @@
1
+ module ActiveAdmin
2
+ module FormErrors
3
+ module Form
4
+ def build(resource, options = {}, &block)
5
+ wrapped_block =
6
+ if active_admin_config.form_errors == false
7
+ block
8
+ elsif block_given?
9
+ proc do |f|
10
+ add_semantic_errors(resource)
11
+ instance_eval(&block)
12
+ end
13
+ else
14
+ proc { |f| add_semantic_errors(resource) }
15
+ end
16
+
17
+ super(resource, options, &wrapped_block)
18
+ end
19
+
20
+ def add_semantic_errors(resource)
21
+ semantic_errors(*parse_resource_errors(resource))
22
+ end
23
+
24
+ def parse_resource_errors(resource)
25
+ if active_admin_config.form_errors.respond_to?(:call)
26
+ instance_exec(&active_admin_config.form_errors)
27
+ else
28
+ resource.errors.keys
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ module ActiveAdmin
2
+ module FormErrors
3
+ module Resource
4
+ attr_writer :form_errors
5
+
6
+ def form_errors
7
+ instance_variable_defined?(:@form_errors) ? @form_errors : namespace.form_errors
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveAdmin
2
+ module FormErrors
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 0
7
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin-form_errors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dhyego Fernando
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activeadmin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-utils
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-meta
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Pretty form errors by default in your ActiveAdmin.
112
+ email:
113
+ - dhyegofernando@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".editorconfig"
119
+ - ".gitignore"
120
+ - CONTRIBUTING.md
121
+ - Gemfile
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - active_admin-form_errors.gemspec
126
+ - app/assets/stylesheets/active_admin/form_errors.scss
127
+ - lib/active_admin/form_errors.rb
128
+ - lib/active_admin/form_errors/engine.rb
129
+ - lib/active_admin/form_errors/form.rb
130
+ - lib/active_admin/form_errors/resource.rb
131
+ - lib/active_admin/form_errors/version.rb
132
+ homepage: http://github.com/dhyegofernando/active_admin-form_errors
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.8
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Pretty form errors by default in your ActiveAdmin.
156
+ test_files: []