sal-engine 0.0.4 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5b96829266c56813153134128efe562fd8d0c0cf
4
- data.tar.gz: 8789169e581cfa3bd04df9fc44d5cc4676dac48d
2
+ SHA256:
3
+ metadata.gz: 568b9f369eef36d4fa28a32eb7841b1875a33623df118bb18c353c277961ad25
4
+ data.tar.gz: 89bc876c17241f10524f1871c26a75e1feee5aa2623dc047c73501586c8a56ff
5
5
  SHA512:
6
- metadata.gz: 996a338bafd96bc0a2a68d248f5adeadd349692cbd1b230ff4946ccc21f8d85d8664c06959db2a903ce6f4b4bc7f3ef61bc3c67ce90c374ee8478b8e832cc541
7
- data.tar.gz: 9af8344760b3f572e6252cdcddfbad630d4e3e6c5a7a6a3fdabc4784275127065d1129649b450412ffc6a52c83d1a85acf970c501a3e3af2f512ce9cdac859e3
6
+ metadata.gz: aa7bf9ca3ccae49be4505cbb9dcc32509b155c544c251e87ed29bdb3e3260322bc1fc6e210dcf7c386abe50ebf418f403a3aeffbac45ef4cf5f1177d887677a4
7
+ data.tar.gz: 81bcd86e3ef229ef091f8f4aa0c1d3d6790756a636dc768a0aa68d0b058d1f814170f29e198ad3057c10d650f1cafed7b2f834f6b8d55981c0d99284c0f41f5b
data/README.md CHANGED
@@ -35,20 +35,22 @@ When providing both, `notice` will prevail.
35
35
  ## menu_item helper
36
36
  Very handy for navigation menus:
37
37
  ```erb
38
- <%= menu_item 'first' %>First option<% end %>
39
- <%= menu_item 'second', :div %><%= link_to root_path, 'Second option' %><% end %>
38
+ <%= menu_item 'first' do %>First option<% end %>
39
+ <%= menu_item 'second', tag: :div do %><%= link_to root_path, 'Second option' %><% end %>
40
+ <%= menu_item 'third', class: 'nav-link' do %>Third option<% end %>
40
41
  ```
41
42
 
42
43
  Renders:
43
44
  ```html
44
45
  <li class="active">First option<li>
45
46
  <div><a href="/">Second option</a><div>
47
+ <li class="nav-link">Third option</li>
46
48
  ```
47
49
 
48
50
  Parameters:
49
- `menu_item(item, tag)`
51
+ `menu_item(item, options)`
50
52
  - item: item name
51
- - tag: `:li` by default
53
+ - options: a has of options such as :class, etc… An additional option :tag is provided in case you don't want to use LI as default
52
54
 
53
55
  ## errors_bar helper
54
56
  Will indicate if any model in your form has an error. It supports multiple models
@@ -67,17 +69,47 @@ Parameters:
67
69
  - model: an active record model, or tableless
68
70
  - model2: you can provide more than one
69
71
 
72
+ The string `Please correct the highlighted fields.` is localized as `errors_bar_message`
73
+ into English, French, German, Italian, Portuguese and Spanish. You can override
74
+ this in your app if you need to, editing your locale yml files.
75
+
70
76
  ## Error messages
71
77
  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:
78
+ sal provides an initializer that will patch ActionView::Base to wrap the field
79
+ with the extra markup and the error message.
80
+
81
+ Given a model with a field:
82
+ ```erb
83
+ <%= text_field_tag :title %>
84
+ ```
85
+ that renders this simple view:
86
+ ```html
87
+ <input type="text" name="title">
88
+ ```
89
+
90
+ Then it will add this extra HTML on an error:
74
91
  ```html
75
92
  <div class="has-error">
76
93
  <input type="text" name="title">
77
- <span class="help-block">⤷ Title can't be blank.</span>
94
+ <span class="help-block">✖ can't be blank</span>
78
95
  </div>
79
96
  ```
80
97
 
98
+ It plays nice with Bootstrap forms. You won't have to touch any CSS.
99
+ - Plain text fields:
100
+ ```erb
101
+ <div class="form-group">
102
+ <%= f.label :password, 'Password' %>
103
+ <%= f.password_field :password, :class => 'form-control' %>
104
+ </div>
105
+ ```
106
+ - Checkboxes. Use this code for proper margin and alignment:
107
+ ```erb
108
+ <div class="form-group checkbox">
109
+ <%= f.label :conditions, "#{f.check_box(:conditions)}I accept the terms and conditions".html_safe, :class => 'checkbox' %>
110
+ </div>
111
+ ```
112
+
81
113
  ## Generators
82
114
  Rails generators are very useful in the initial stages of development to create your admin interfaces.
83
115
  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.select { |error| error.attribute == :base }.map(&:to_s).map(&:capitalize) }.flatten
7
+
8
+ # is there any non-base error?
9
+ if entities.detect { |entity| entity.errors.detect { |error| error.attribute != :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
 
@@ -16,8 +23,12 @@ module Sal
16
23
  end
17
24
  end
18
25
 
19
- def menu_item(item, tag = :li)
20
- options = section == item ? {class: 'active'} : {}
26
+ def menu_item(item, options = {})
27
+ tag = options.delete(:tag) || 'li'
28
+ if section == item
29
+ klass = options[:class].to_s.split(' ').push('active').join(' ')
30
+ options[:class] = klass
31
+ end
21
32
  content_tag tag, options do
22
33
  yield
23
34
  end
data/lib/sal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sal
2
- VERSION = '0.0.4'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # Version of your assets, change this if you want to expire all your assets.
4
- Rails.application.config.assets.version = '1.0'
4
+ #Rails.application.config.assets.version = '1.0'
5
5
 
6
6
  # Precompile additional assets.
7
7
  # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
@@ -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
 
@@ -55,12 +62,28 @@ describe ApplicationHelper do
55
62
  allow(helper).to receive(:section) { 'selected_list_item' }
56
63
  end
57
64
 
58
- context 'list item is selected' do
65
+ context 'tag is selected' do
59
66
  let(:item) { 'selected_list_item' }
60
67
 
61
68
  it { is_expected.to have_selector('li.active', 'content') }
62
69
  end
63
70
 
71
+ context 'list item is selected' do
72
+ let(:item) { 'selected_list_item' }
73
+
74
+ it 'appends the active class' do
75
+ expect(helper.menu_item(item, tag: 'div') { 'content' }).to have_selector('div.active', 'content')
76
+ end
77
+ end
78
+
79
+ context 'list item is selected and there are other options' do
80
+ let(:item) { 'selected_list_item' }
81
+
82
+ it 'appends the active class' do
83
+ expect(helper.menu_item(item, class: 'nav-item') { 'content' }).to have_selector('li.nav-item.active', 'content')
84
+ end
85
+ end
86
+
64
87
  context 'list item is not selected' do
65
88
  let(:item) { 'unselected_list_item' }
66
89
 
metadata CHANGED
@@ -1,101 +1,101 @@
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Cruz Horts
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2022-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.1'
26
+ version: '7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: capybara
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '2.4'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '2.4'
97
97
  description: Sal (salt) is what you add to every meal. I add sal to my Rails projects
98
- email:
98
+ email:
99
99
  executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files: []
@@ -153,7 +153,6 @@ files:
153
153
  - spec/dummy/config/locales/en.yml
154
154
  - spec/dummy/config/routes.rb
155
155
  - spec/dummy/config/secrets.yml
156
- - spec/dummy/log/test.log
157
156
  - spec/dummy/public/404.html
158
157
  - spec/dummy/public/422.html
159
158
  - spec/dummy/public/500.html
@@ -167,7 +166,7 @@ homepage: https://github.com/dncrht/sal
167
166
  licenses:
168
167
  - MIT
169
168
  metadata: {}
170
- post_install_message:
169
+ post_install_message:
171
170
  rdoc_options: []
172
171
  require_paths:
173
172
  - lib
@@ -182,50 +181,47 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
181
  - !ruby/object:Gem::Version
183
182
  version: '0'
184
183
  requirements: []
185
- rubyforge_project:
186
- rubygems_version: 2.2.2
187
- signing_key:
184
+ rubygems_version: 3.1.6
185
+ signing_key:
188
186
  specification_version: 4
189
187
  summary: A Rails engine with my recurrent additions
190
188
  test_files:
189
+ - spec/spec_helper.rb
190
+ - spec/dummy/app/models/tableless.rb
191
+ - spec/dummy/app/controllers/application_controller.rb
192
+ - spec/dummy/app/views/layouts/application.html.erb
191
193
  - spec/dummy/app/assets/javascripts/application.js
192
194
  - spec/dummy/app/assets/stylesheets/application.css
193
- - spec/dummy/app/controllers/application_controller.rb
194
195
  - spec/dummy/app/helpers/application_helper.rb
195
- - spec/dummy/app/models/tableless.rb
196
- - spec/dummy/app/views/layouts/application.html.erb
196
+ - spec/dummy/bin/rake
197
197
  - spec/dummy/bin/bundle
198
198
  - spec/dummy/bin/rails
199
- - spec/dummy/bin/rake
200
- - spec/dummy/config/application.rb
201
- - spec/dummy/config/boot.rb
202
- - spec/dummy/config/database.yml
203
- - spec/dummy/config/environment.rb
204
- - spec/dummy/config/environments/development.rb
199
+ - spec/dummy/config/secrets.yml
200
+ - spec/dummy/config/routes.rb
201
+ - spec/dummy/config/locales/en.yml
205
202
  - spec/dummy/config/environments/production.rb
203
+ - spec/dummy/config/environments/development.rb
206
204
  - spec/dummy/config/environments/test.rb
207
- - spec/dummy/config/initializers/assets.rb
205
+ - spec/dummy/config/environment.rb
206
+ - spec/dummy/config/application.rb
207
+ - spec/dummy/config/database.yml
208
+ - spec/dummy/config/boot.rb
208
209
  - spec/dummy/config/initializers/backtrace_silencers.rb
209
- - spec/dummy/config/initializers/cookies_serializer.rb
210
- - spec/dummy/config/initializers/filter_parameter_logging.rb
211
- - spec/dummy/config/initializers/inflections.rb
212
210
  - spec/dummy/config/initializers/mime_types.rb
211
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
213
212
  - spec/dummy/config/initializers/session_store.rb
214
213
  - spec/dummy/config/initializers/wrap_parameters.rb
215
- - spec/dummy/config/locales/en.yml
216
- - spec/dummy/config/routes.rb
217
- - spec/dummy/config/secrets.yml
214
+ - spec/dummy/config/initializers/assets.rb
215
+ - spec/dummy/config/initializers/cookies_serializer.rb
216
+ - spec/dummy/config/initializers/inflections.rb
218
217
  - spec/dummy/config.ru
219
- - spec/dummy/log/test.log
220
- - spec/dummy/public/404.html
218
+ - spec/dummy/Rakefile
219
+ - spec/dummy/public/favicon.ico
221
220
  - spec/dummy/public/422.html
222
221
  - spec/dummy/public/500.html
223
- - spec/dummy/public/favicon.ico
224
- - spec/dummy/Rakefile
222
+ - spec/dummy/public/404.html
225
223
  - spec/dummy/README.rdoc
224
+ - spec/rails_helper.rb
226
225
  - spec/helpers/application_helper_spec.rb
227
226
  - spec/helpers/error_span_spec.rb
228
227
  - spec/helpers/error_span_view.html.erb
229
- - spec/rails_helper.rb
230
- - spec/spec_helper.rb
231
- has_rdoc:
@@ -1,4 +0,0 @@
1
- Rendered /Users/dani/Pasatiempos/ruby/sal/spec/helpers/error_span_view.html.erb (9.6ms)
2
- Rendered /Users/dani/Pasatiempos/ruby/sal/spec/helpers/error_span_view.html.erb (11.2ms)
3
- Rendered /Users/dani/Pasatiempos/ruby/sal/spec/helpers/error_span_view.html.erb (5.9ms)
4
- Rendered /Users/dani/Pasatiempos/ruby/sal/spec/helpers/error_span_view.html.erb (5.6ms)