yorisoi 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/yorisoi/version.rb +1 -1
- data/lib/yorisoi.rb +42 -10
- data/spec/controllers/samples_controller_spec.rb +14 -1
- data/spec/dummy/app/controllers/samples_controller.rb +5 -2
- data/spec/dummy/app/views/samples/new.html.erb +0 -51
- data/spec/dummy/app/views/samples/remnant.html.erb +107 -0
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/libs/yorisoi_spec.rb +23 -2
- data/yorisoi-0.0.1.gem +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0f95438615085c743c53f193e9743c03b3085af
|
4
|
+
data.tar.gz: 2d54df0cc3cf706af58327545e0729b16c531b07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 841ef79b76da7304363f073cd846052b2c5b957728115bef08e2abb5d1ac3005786437f951375ddad67ec2436632f916802ebb5734ecf7eb847615095c730129
|
7
|
+
data.tar.gz: d1629b2f3d3ea2e5462920cd38d0229d98d1d8f6900974038e178db420c89b0809b8abe0d083530f05adcf31fb249675a7eb1e217d2582b7dda425e350c2924f
|
data/lib/yorisoi/version.rb
CHANGED
data/lib/yorisoi.rb
CHANGED
@@ -39,15 +39,21 @@ module Yorisoi
|
|
39
39
|
using Arralizer
|
40
40
|
using Flipper
|
41
41
|
|
42
|
-
attr_accessor :wrapper, :invalid_wrapper, :errors_wrapper, :error_wrapper
|
42
|
+
attr_accessor :wrapper, :invalid_wrapper, :errors_wrapper, :error_wrapper, :stored_error
|
43
43
|
|
44
44
|
|
45
45
|
def initialize(object_name, object, template, options)
|
46
46
|
self.default_tag = options[:builder_tag] || {}
|
47
|
+
store_error(object)
|
47
48
|
super
|
48
49
|
end
|
49
50
|
|
50
51
|
|
52
|
+
def store_error(object)
|
53
|
+
@stored_error = object.errors.presence || {}
|
54
|
+
end
|
55
|
+
|
56
|
+
|
51
57
|
(field_helpers - [:check_box, :radio_button, :fields_for, :hidden_field, :label]).each do |selector|
|
52
58
|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
53
59
|
def #{selector}(attribute, options = {})
|
@@ -95,13 +101,6 @@ module Yorisoi
|
|
95
101
|
end
|
96
102
|
|
97
103
|
|
98
|
-
def pick_error(attribute)
|
99
|
-
return nil if @object.nil? || !(messages = @object.errors.messages[attribute]).present?
|
100
|
-
|
101
|
-
errors_wrapper.(messages.map(&error_wrapper.(attribute)).join.html_safe, attribute)
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
104
|
def radio_button(attribute, label_and_value, options = {})
|
106
105
|
wrap_field(attribute, options) do
|
107
106
|
if label_and_value.is_a?(Array)
|
@@ -124,6 +123,16 @@ module Yorisoi
|
|
124
123
|
end
|
125
124
|
|
126
125
|
|
126
|
+
def remnant
|
127
|
+
return if @stored_error.blank?
|
128
|
+
errors_wrapper.(@stored_error.map { |attribute, *errors|
|
129
|
+
errors.map { |message|
|
130
|
+
error_wrapper.(attribute, message)
|
131
|
+
}
|
132
|
+
}.flatten.join.html_safe, :remnant)
|
133
|
+
end
|
134
|
+
|
135
|
+
|
127
136
|
def select(attribute, choices = nil, options = {}, html_options = {}, &block)
|
128
137
|
wrap_field(attribute, options) { super }
|
129
138
|
end
|
@@ -134,13 +143,29 @@ module Yorisoi
|
|
134
143
|
no_wrap = options.delete(:no_wrap)
|
135
144
|
|
136
145
|
if (error_html = pick_error(attribute)).present?
|
137
|
-
no_errors
|
146
|
+
if no_errors
|
147
|
+
yield
|
148
|
+
else
|
149
|
+
delete_stored_error!(attribute)
|
150
|
+
yield + error_html
|
151
|
+
end
|
138
152
|
else
|
139
153
|
no_wrap ? yield : wrapper.(yield, attribute)
|
140
154
|
end.html_safe
|
141
155
|
end
|
142
156
|
|
143
157
|
|
158
|
+
def write_error(attribute)
|
159
|
+
delete_stored_error!(attribute)
|
160
|
+
pick_error(attribute)
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def delete_stored_error!(attribute)
|
165
|
+
@stored_error.delete(attribute)
|
166
|
+
end
|
167
|
+
|
168
|
+
|
144
169
|
private
|
145
170
|
def around_proc(label_text)
|
146
171
|
->(tag) {
|
@@ -179,6 +204,13 @@ module Yorisoi
|
|
179
204
|
end
|
180
205
|
|
181
206
|
|
207
|
+
def pick_error(attribute)
|
208
|
+
return nil if @object.nil? || !(messages = @object.errors.messages[attribute]).present?
|
209
|
+
|
210
|
+
errors_wrapper.(messages.map(&error_wrapper.(attribute)).join.html_safe, attribute)
|
211
|
+
end
|
212
|
+
|
213
|
+
|
182
214
|
def radio_button_wrapper
|
183
215
|
->(content, attribute) { content_tag(:ul, content, class: %w(radio-buttons).push(attribute)) }
|
184
216
|
end
|
@@ -218,4 +250,4 @@ module Yorisoi
|
|
218
250
|
end
|
219
251
|
end
|
220
252
|
end
|
221
|
-
end
|
253
|
+
end
|
@@ -10,7 +10,20 @@ RSpec.describe SamplesController, :type => :controller do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe "
|
13
|
+
describe "display remnant" do
|
14
|
+
it 'valid params NOT render error message' do
|
15
|
+
post :create, remnant: true, sample: attributes_for(:sample)
|
16
|
+
expect(response.body).not_to have_tag('ul.errors.text')
|
17
|
+
expect(response.body).not_to have_tag('ul.errors.password')
|
18
|
+
expect(response.body).not_to have_tag('ul.errors.textarea')
|
19
|
+
expect(response.body).to have_tag('ul.errors.select')
|
20
|
+
expect(response.body).to have_tag('ul.errors.radio')
|
21
|
+
expect(response.body).to have_tag('ul.errors.checkbox')
|
22
|
+
expect(response.body).to have_tag('ul.errors.remnant li.error', count: 6)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "POST create" do
|
14
27
|
it 'valid params NOT render error message' do
|
15
28
|
post :create, sample: attributes_for(:valid_sample)
|
16
29
|
expect(response.body).not_to have_tag('ul.errors.text')
|
@@ -3,13 +3,16 @@ class SamplesController < ApplicationController
|
|
3
3
|
@sample = Sample.new
|
4
4
|
end
|
5
5
|
|
6
|
+
def remnant
|
7
|
+
@sample = Sample.new
|
8
|
+
end
|
6
9
|
|
7
10
|
def create
|
8
11
|
Sample.create!(sample_params)
|
9
|
-
redirect_to new_path
|
12
|
+
redirect_to params[:remnant] ? remnant_path : new_path
|
10
13
|
rescue ActiveRecord::RecordInvalid => e
|
11
14
|
@sample = e.record
|
12
|
-
render :new
|
15
|
+
render params[:remnant] ? :remnant : :new
|
13
16
|
end
|
14
17
|
|
15
18
|
|
@@ -101,55 +101,4 @@
|
|
101
101
|
<li><%= f.submit :submit, class: [:button, :green] %></li>
|
102
102
|
</ul>
|
103
103
|
<% end %>
|
104
|
-
</article>
|
105
|
-
<article class="w400 floater">
|
106
|
-
<h1>Default</h1>
|
107
|
-
<%= form_for @sample, url: create_path, method: :post do |f| %>
|
108
|
-
<div class="input-box p100">
|
109
|
-
<section class="input-set">
|
110
|
-
<label class="input-head">text</label>
|
111
|
-
<div class="input-body p100">
|
112
|
-
<%= f.text_field :text, class: [:p100] %>
|
113
|
-
</div>
|
114
|
-
</section>
|
115
|
-
<section class="input-set">
|
116
|
-
<label class="input-head">password</label>
|
117
|
-
<div class="input-body p100">
|
118
|
-
<%= f.password_field :password, class: [:p100] %>
|
119
|
-
</div>
|
120
|
-
</section>
|
121
|
-
<section class="input-set">
|
122
|
-
<label class="input-head">textarea</label>
|
123
|
-
<div class="input-body p100">
|
124
|
-
<%= f.text_area :textarea, class: [:p100] %>
|
125
|
-
</div>
|
126
|
-
</section>
|
127
|
-
<section class="input-set">
|
128
|
-
<label class="input-head">select</label>
|
129
|
-
<div class="input-body p100">
|
130
|
-
<%= f.select :select, Const::SELECT, {prompt: :select}, {class: [:p100]} %>
|
131
|
-
</div>
|
132
|
-
</section>
|
133
|
-
<section class="input-set">
|
134
|
-
<label class="input-head">collection<br>radio buttons</label>
|
135
|
-
<div class="input-body p100 collection">
|
136
|
-
<%#= f.radio_buttons :radio, {class: [:bigger]}, Const::RADIO.zip(Const::RADIO) %>
|
137
|
-
<%= f.collection_radio_buttons :radio, Const::RADIO.zip(Const::RADIO), :last, :first, {}, class: [:bigger] do |b| %>
|
138
|
-
<% b.label { b.radio_button + b.text } %>
|
139
|
-
<% end %>
|
140
|
-
</div>
|
141
|
-
</section>
|
142
|
-
<section class="input-set">
|
143
|
-
<label class="input-head">collection<br>check boxes</label>
|
144
|
-
<div class="input-body p100 collection">
|
145
|
-
<%= f.collection_check_boxes :checkbox, Const::CHECKBOX.zip(Const::CHECKBOX), :last, :first, {}, class: [:bigger] do |b| %>
|
146
|
-
<% b.label { b.check_box + b.text } %>
|
147
|
-
<% end %>
|
148
|
-
</div>
|
149
|
-
</section>
|
150
|
-
</div>
|
151
|
-
<ul class="form-button-area">
|
152
|
-
<li><%= f.submit :submit, class: [:button, :green] %></li>
|
153
|
-
</ul>
|
154
|
-
<% end %>
|
155
104
|
</article>
|
@@ -0,0 +1,107 @@
|
|
1
|
+
<style type="text/css">
|
2
|
+
<!--
|
3
|
+
h1 {
|
4
|
+
margin: 10px 0;
|
5
|
+
font-size: 24px;
|
6
|
+
font-weight: bold;
|
7
|
+
}
|
8
|
+
|
9
|
+
ul.errors {
|
10
|
+
margin: 10px 0 0 25px;
|
11
|
+
}
|
12
|
+
|
13
|
+
ul.errors li {
|
14
|
+
list-style: square;
|
15
|
+
color: #c00;
|
16
|
+
}
|
17
|
+
|
18
|
+
.collection label,
|
19
|
+
ul.radio-buttons > li,
|
20
|
+
ul.check-boxes > li {
|
21
|
+
display: inline-block;
|
22
|
+
padding-right: 10px;
|
23
|
+
}
|
24
|
+
|
25
|
+
.input-head,
|
26
|
+
.input-body {
|
27
|
+
border-top: 1px solid #ccc;
|
28
|
+
padding-top: 15px;
|
29
|
+
padding-bottom: 15px;
|
30
|
+
}
|
31
|
+
|
32
|
+
.input-head {
|
33
|
+
vertical-align: top;
|
34
|
+
padding-top: 20px;
|
35
|
+
}
|
36
|
+
|
37
|
+
.field_with_errors input,
|
38
|
+
.field_with_errors textarea,
|
39
|
+
.field_with_errors select {
|
40
|
+
border-color: #c00;
|
41
|
+
}
|
42
|
+
|
43
|
+
.field_with_errors {
|
44
|
+
padding-bottom: 1px;
|
45
|
+
border-bottom: 2px solid #c00;
|
46
|
+
}
|
47
|
+
|
48
|
+
.floater {
|
49
|
+
padding: 30px;
|
50
|
+
float: left;
|
51
|
+
}
|
52
|
+
|
53
|
+
.collection label div {
|
54
|
+
display: inline-block;
|
55
|
+
}
|
56
|
+
|
57
|
+
-->
|
58
|
+
</style>
|
59
|
+
<article class="w400 floater">
|
60
|
+
<h1>Yorisoi Remnant Error</h1>
|
61
|
+
<%= form_for @sample, url: create_path, method: :post, builder: Yorisoi::Builder do |f| %>
|
62
|
+
<%= hidden_field :remnant, value: true %>
|
63
|
+
<%= yield :remnant %>
|
64
|
+
<div class="input-box p100">
|
65
|
+
<section class="input-set">
|
66
|
+
<label class="input-head">text</label>
|
67
|
+
<div class="input-body p100">
|
68
|
+
<%= f.text_field :text, class: [:p100], no_errors: true %>
|
69
|
+
</div>
|
70
|
+
</section>
|
71
|
+
<section class="input-set">
|
72
|
+
<label class="input-head">password</label>
|
73
|
+
<div class="input-body p100">
|
74
|
+
<%= f.password_field :password, class: [:p100], no_errors: true %>
|
75
|
+
</div>
|
76
|
+
</section>
|
77
|
+
<section class="input-set">
|
78
|
+
<label class="input-head">textarea</label>
|
79
|
+
<div class="input-body p100">
|
80
|
+
<%= f.text_area :textarea, class: [:p100], no_errors: true %>
|
81
|
+
</div>
|
82
|
+
</section>
|
83
|
+
<section class="input-set">
|
84
|
+
<label class="input-head">select</label>
|
85
|
+
<div class="input-body p100">
|
86
|
+
<%= f.select :select, Const::SELECT, {prompt: :select}, {class: [:p100]} %>
|
87
|
+
</div>
|
88
|
+
</section>
|
89
|
+
<section class="input-set">
|
90
|
+
<label class="input-head">radio buttons</label>
|
91
|
+
<div class="input-body p100">
|
92
|
+
<%= f.radio_buttons :radio, {class: [:bigger]}, Const::RADIO.zip(Const::RADIO) %>
|
93
|
+
</div>
|
94
|
+
</section>
|
95
|
+
<section class="input-set">
|
96
|
+
<label class="input-head">check boxes</label>
|
97
|
+
<div class="input-body p100">
|
98
|
+
<%= f.check_boxes :checkbox, {class: [:bigger]}, Const::CHECKBOX.zip(Const::CHECKBOX) %>
|
99
|
+
</div>
|
100
|
+
</section>
|
101
|
+
</div>
|
102
|
+
<%= f.remnant %>
|
103
|
+
<ul class="form-button-area">
|
104
|
+
<li><%= f.submit :submit, class: [:button, :green] %></li>
|
105
|
+
</ul>
|
106
|
+
<% end %>
|
107
|
+
</article>
|
data/spec/dummy/config/routes.rb
CHANGED
data/spec/libs/yorisoi_spec.rb
CHANGED
@@ -16,12 +16,12 @@ RSpec.describe Yorisoi::Builder do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'change error child' do
|
19
|
-
|
19
|
+
changed = Yorisoi::Builder.new(:sample, @sample, TestHelper.new, {
|
20
20
|
builder_tag: {
|
21
21
|
errors_wrapper: ->(error_children, attribute) { %{<div class="error-messages #{attribute}">#{error_children}</div>}.html_safe },
|
22
22
|
error_wrapper: ->(error, attribute) { %{<p class="error-message #{attribute}">#{error}</p>}.html_safe }
|
23
23
|
}})
|
24
|
-
expect(
|
24
|
+
expect(changed.text_field(:text)).to have_tag('div.error-messages.text p.error-message.text')
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -39,6 +39,27 @@ RSpec.describe Yorisoi::Builder do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
context 'remnant errors' do
|
43
|
+
before :each do
|
44
|
+
@sample.valid?
|
45
|
+
@count = @sample.errors.count
|
46
|
+
@fr = Yorisoi::Builder.new(:sample, @sample, TestHelper.new, {})
|
47
|
+
end
|
48
|
+
|
49
|
+
it do
|
50
|
+
@fr.write_error(:text)
|
51
|
+
|
52
|
+
p @fr.remnant
|
53
|
+
expect(@fr.remnant).to have_tag('li.error', count: 11)
|
54
|
+
end
|
55
|
+
|
56
|
+
it do
|
57
|
+
@fr.text_field(:text)
|
58
|
+
|
59
|
+
expect(@fr.remnant).to have_tag('li.error', count: 11)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
42
63
|
context 'with label expanded' do
|
43
64
|
let(:label_and_value) do
|
44
65
|
%w(label_name value_name)
|
data/yorisoi-0.0.1.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yorisoi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mmmpa
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- spec/dummy/app/models/sample.rb
|
174
174
|
- spec/dummy/app/views/layouts/application.html.erb
|
175
175
|
- spec/dummy/app/views/samples/new.html.erb
|
176
|
+
- spec/dummy/app/views/samples/remnant.html.erb
|
176
177
|
- spec/dummy/bin/bundle
|
177
178
|
- spec/dummy/bin/rails
|
178
179
|
- spec/dummy/bin/rake
|
@@ -217,6 +218,7 @@ files:
|
|
217
218
|
- spec/rails_helper.rb
|
218
219
|
- spec/spec_helper.rb
|
219
220
|
- spec/supports/active_model.rb
|
221
|
+
- yorisoi-0.0.1.gem
|
220
222
|
- yorisoi.gemspec
|
221
223
|
homepage: http://mmmpa.net/
|
222
224
|
licenses:
|