sal-engine 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b96829266c56813153134128efe562fd8d0c0cf
4
- data.tar.gz: 8789169e581cfa3bd04df9fc44d5cc4676dac48d
3
+ metadata.gz: d59a3227f27a5896f4e181fef39bb5cbe29e9c94
4
+ data.tar.gz: 070b3a7074c1f80f43f3a921dbd31beee7c20a25
5
5
  SHA512:
6
- metadata.gz: 996a338bafd96bc0a2a68d248f5adeadd349692cbd1b230ff4946ccc21f8d85d8664c06959db2a903ce6f4b4bc7f3ef61bc3c67ce90c374ee8478b8e832cc541
7
- data.tar.gz: 9af8344760b3f572e6252cdcddfbad630d4e3e6c5a7a6a3fdabc4784275127065d1129649b450412ffc6a52c83d1a85acf970c501a3e3af2f512ce9cdac859e3
6
+ metadata.gz: 1bfe9d408f89c9c1ca2019bbf72254ded063c3eff6c60b12d2e583fd552223ea50cf048c9bce79f399b6f9db92879d389863236caf3cf6cd432fe12c67745354
7
+ data.tar.gz: e2b3d29114526f9c927765ae8f7901749346bd539adf7068de3958e2a4cea5b52db6925ae4b604da9fb37acd508bc18d4ea882795f88df80e6759256470a8327
data/README.md CHANGED
@@ -67,17 +67,47 @@ Parameters:
67
67
  - model: an active record model, or tableless
68
68
  - model2: you can provide more than one
69
69
 
70
+ The string `Please correct the highlighted fields.` is localized as `errors_bar_message`
71
+ into English, French, German, Italian, Portuguese and Spanish. You can override
72
+ this in your app if you need to, editing your locale yml files.
73
+
70
74
  ## Error messages
71
75
  I like to put the error messages right after the field in the form.
72
- An initializer will patch ActionView::Base to wrap the field with the error message.
73
- Given a model with an error on, let's say, _title_, we'll get:
76
+ sal provides an initializer that will patch ActionView::Base to wrap the field
77
+ with the extra markup and the error message.
78
+
79
+ Given a model with a field:
80
+ ```erb
81
+ <%= text_field_tag :title %>
82
+ ```
83
+ that renders this simple view:
84
+ ```html
85
+ <input type="text" name="title">
86
+ ```
87
+
88
+ Then it will add this extra HTML on an error:
74
89
  ```html
75
90
  <div class="has-error">
76
91
  <input type="text" name="title">
77
- <span class="help-block">⤷ Title can't be blank.</span>
92
+ <span class="help-block">✖ can't be blank</span>
78
93
  </div>
79
94
  ```
80
95
 
96
+ It plays nice with Bootstrap forms. You won't have to touch any CSS.
97
+ - Plain text fields:
98
+ ```erb
99
+ <div class="form-group">
100
+ <%= f.label :password, 'Password' %>
101
+ <%= f.password_field :password, :class => 'form-control' %>
102
+ </div>
103
+ ```
104
+ - Checkboxes. Use this code for proper margin and alignment:
105
+ ```erb
106
+ <div class="form-group checkbox">
107
+ <%= f.label :conditions, "#{f.check_box(:conditions)}I accept the terms and conditions".html_safe, :class => 'checkbox' %>
108
+ </div>
109
+ ```
110
+
81
111
  ## Generators
82
112
  Rails generators are very useful in the initial stages of development to create your admin interfaces.
83
113
  In particular:
@@ -3,8 +3,15 @@ module Sal
3
3
  def errors_bar(*entities)
4
4
  entities = Array(entities)
5
5
 
6
- if entities.detect { |entity| entity.errors.any? }
7
- content_tag :div, t(:errors_bar_message), class: 'alert alert-danger'
6
+ messages = entities.map { |entity| entity.errors[:base].map &:capitalize }.flatten
7
+
8
+ # is there any non-base error?
9
+ if entities.detect { |entity| entity.errors.keys.detect { |error| error != :base } }
10
+ messages << t(:errors_bar_message)
11
+ end
12
+
13
+ if messages.any?
14
+ content_tag :div, messages.join("\n"), class: 'alert alert-danger'
8
15
  end
9
16
  end
10
17
 
data/lib/sal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sal
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -4,8 +4,12 @@ describe ApplicationHelper do
4
4
 
5
5
  describe '#errors_bar' do
6
6
 
7
- let(:without) { double(errors: {}) }
8
- let(:with) { double(errors: {base: 'error'}) }
7
+ # Mocking ActiveRecord error format:
8
+ # - errors are presented as arrays
9
+ # - no errors in a category returns an empty array
10
+ let(:without) { double(errors: {base: []}) }
11
+ let(:with) { double(errors: {base: ['base error']}) }
12
+ let(:with_non_base) { double(errors: {base: [], email: ['is invalid']}) }
9
13
  let(:text) { 'Please correct the highlighted fields.' }
10
14
 
11
15
  context 'no errors' do
@@ -16,9 +20,12 @@ describe ApplicationHelper do
16
20
 
17
21
  context 'errors' do
18
22
 
19
- it { expect(helper.errors_bar(with)).to have_selector('div.alert.alert-danger', text: text) }
20
- it { expect(helper.errors_bar(with, without)).to have_selector('div.alert.alert-danger', text: text) }
21
- it { expect(helper.errors_bar(with, with)).to have_selector('div.alert.alert-danger', text: text) }
23
+ it { expect(helper.errors_bar(with)).to have_selector('div.alert.alert-danger', text: 'Base error') }
24
+ it { expect(helper.errors_bar(with, without)).to have_selector('div.alert.alert-danger', text: 'Base error') }
25
+ it { expect(helper.errors_bar(with, with_non_base)).to have_selector('div.alert.alert-danger', text: "Base error\n#{text}") }
26
+ it { expect(helper.errors_bar(with_non_base, without)).to have_selector('div.alert.alert-danger', text: text) }
27
+ it { expect(helper.errors_bar(with, with)).to have_selector('div.alert.alert-danger', text: "Base error\nBase error") }
28
+ it { expect(helper.errors_bar(with_non_base, with, with)).to have_selector('div.alert.alert-danger', text: "Base error\nBase error\n#{text}") }
22
29
  end
23
30
  end
24
31
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sal-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Cruz Horts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails