eac_rails_utils 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/app/helpers/eac_rails_utils/formatter_helper.rb +2 -0
- data/app/helpers/eac_rails_utils/links_helper.rb +4 -1
- data/app/helpers/eac_rails_utils/open_graph_protocol_helper.rb +2 -0
- data/lib/eac/common_form_helper.rb +3 -0
- data/lib/eac/common_form_helper/form_builder.rb +2 -0
- data/lib/eac/common_form_helper/form_builder/association_select_field.rb +4 -1
- data/lib/eac/common_form_helper/form_builder/common_text_fields.rb +3 -2
- data/lib/eac/common_form_helper/form_builder/currency_field.rb +13 -11
- data/lib/eac/common_form_helper/form_builder/date_field.rb +2 -0
- data/lib/eac/common_form_helper/form_builder/fields_for.rb +2 -0
- data/lib/eac/common_form_helper/form_builder/file_field.rb +1 -0
- data/lib/eac/common_form_helper/form_builder/radio_select_field.rb +4 -1
- data/lib/eac/common_form_helper/form_builder/searchable_association_field.rb +6 -2
- data/lib/eac/common_form_helper/form_builder/select_field.rb +2 -0
- data/lib/eac/common_form_helper/form_builder/time_field.rb +1 -0
- data/lib/eac/common_form_helper/form_builder/year_month_field.rb +1 -0
- data/lib/eac/cpf_validator.rb +7 -3
- data/lib/eac/data_table_helper.rb +1 -0
- data/lib/eac/data_table_helper/column.rb +5 -2
- data/lib/eac/data_table_helper/data_table.rb +11 -9
- data/lib/eac/data_table_helper/setup.rb +1 -0
- data/lib/eac/htmlbeautifier.rb +2 -0
- data/lib/eac/inequality_queries.rb +2 -1
- data/lib/eac/menus_helper.rb +5 -1
- data/lib/eac/menus_helper/bootstrap_gui_builder.rb +7 -4
- data/lib/eac/menus_helper/data_builder.rb +6 -1
- data/lib/eac/menus_helper/gui_builder.rb +5 -2
- data/lib/eac/model.rb +8 -5
- data/lib/eac/no_presence_validator.rb +2 -2
- data/lib/eac/test_utils.rb +17 -12
- data/lib/eac_rails_utils.rb +4 -5
- data/lib/eac_rails_utils/engine.rb +1 -0
- data/lib/eac_rails_utils/patches/action_controller_base.rb +1 -0
- data/lib/eac_rails_utils/patches/model_attribute_required.rb +3 -0
- data/lib/eac_rails_utils/patches/ofx_parser.rb +5 -4
- data/lib/eac_rails_utils/tableless_model.rb +6 -4
- data/lib/eac_rails_utils/version.rb +2 -1
- data/test/app/helpers/eac_rails_utils/formatter_helper_test.rb +1 -0
- data/test/dummy/Rakefile +3 -1
- data/test/dummy/app/models/job.rb +2 -0
- data/test/dummy/app/models/user.rb +2 -0
- data/test/dummy/config.ru +2 -0
- data/test/dummy/config/application.rb +3 -1
- data/test/dummy/config/boot.rb +3 -1
- data/test/dummy/config/environment.rb +3 -1
- data/test/dummy/config/environments/test.rb +2 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/db/migrate/20160415125333_create_users.rb +2 -0
- data/test/dummy/db/migrate/20160415143123_create_jobs.rb +2 -0
- data/test/dummy/db/migrate/20160415143229_add_job_to_users.rb +2 -0
- data/test/lib/eac/common_form_helper_test.rb +2 -0
- data/test/lib/eac/cpf_validator_test.rb +2 -0
- data/test/lib/eac/{data_table_test_helper.rb → data_table_test_helper_test.rb} +2 -1
- data/test/lib/eac/model_test.rb +2 -0
- data/test/lib/eac_rails_utils/patches/model_attribute_required_test.rb +2 -0
- data/test/lib/eac_rails_utils/tableless_model_test.rb +1 -1
- data/test/test_helper.rb +3 -1
- metadata +65 -51
- data/lib/eac/parsers/files_test.rb +0 -63
- data/lib/eac/source_target_fixtures.rb +0 -66
- data/test/lib/eac/parsers/files_test_test.rb +0 -27
- data/test/lib/eac/parsers/ok_test_files/a.source.yaml +0 -1
- data/test/lib/eac/parsers/ok_test_files/a.target.yaml +0 -1
- data/test/lib/eac/parsers/ok_test_files/b.source.yaml +0 -1
- data/test/lib/eac/parsers/ok_test_files/b.target.yaml +0 -1
- data/test/lib/eac/source_target_fixtures_test.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5d1603f1c60e9d64e4d2acc9e399fbef95660bde8e737a4c739481b6455733c
|
4
|
+
data.tar.gz: baa588fd3f6095129486e021671f8a934d6d6728e1bbea4a2742b375dd8b5572
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9c2b12877f921a3fa1c5cf23a36a0b6dae7e048e1a6814cc062c3238d3abad9e14e714f82d1415b3a706fe4f9c1bbcd10da0274ce28acc90bdb7cb09b0b0ba4
|
7
|
+
data.tar.gz: 6e83568342b4b9257d3c2c87959256b3c728e8e259b17991f71709a1ed10e80a42d9d4e1b4a7b21231a285dcb2013cc45ef7e609d32eb0d035edb7e99fa6124c
|
data/Rakefile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module EacRailsUtils
|
3
4
|
module FormatterHelper
|
4
5
|
extend ::ActiveSupport::Concern
|
@@ -10,6 +11,7 @@ module EacRailsUtils
|
|
10
11
|
def value_or_sign(value, sign = '-', &block)
|
11
12
|
return sign if value.blank?
|
12
13
|
return yield(value) if block
|
14
|
+
|
13
15
|
value
|
14
16
|
end
|
15
17
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module EacRailsUtils
|
3
4
|
module LinksHelper
|
4
5
|
def short_delete_link(object)
|
@@ -20,7 +21,8 @@ module EacRailsUtils
|
|
20
21
|
def short_goto_link(url)
|
21
22
|
value_or_sign(url, '') do |value|
|
22
23
|
link_to '', value, class: 'goto_link', target: '_blank',
|
23
|
-
title: ::I18n.t('eac_rails_base0.links.goto_url', url: value.to_s)
|
24
|
+
title: ::I18n.t('eac_rails_base0.links.goto_url', url: value.to_s),
|
25
|
+
rel: 'noopener'
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -38,6 +40,7 @@ module EacRailsUtils
|
|
38
40
|
while current_class
|
39
41
|
path = object_path_by_class(current_class, action)
|
40
42
|
return send(path, object) if respond_to?(path)
|
43
|
+
|
41
44
|
tried_paths << path
|
42
45
|
current_class = current_class.superclass
|
43
46
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module EacRailsUtils
|
3
4
|
module OpenGraphProtocolHelper
|
4
5
|
OGP_META_DEFAULT_PREFIX = 'og'
|
@@ -89,6 +90,7 @@ module EacRailsUtils
|
|
89
90
|
|
90
91
|
def tag
|
91
92
|
return ::ActiveSupport::SafeBuffer.new unless content?
|
93
|
+
|
92
94
|
view.tag(:meta, prefix: view.ogp_prefix, property: property_value, content: content)
|
93
95
|
end
|
94
96
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Eac
|
2
4
|
module CommonFormHelper
|
3
5
|
def common_form(model_instance, options = {}, &block)
|
@@ -29,6 +31,7 @@ module Eac
|
|
29
31
|
s = ActiveSupport::SafeBuffer.new
|
30
32
|
model_instance.errors.each do |k, v|
|
31
33
|
next if field_errors_showed.include?(k)
|
34
|
+
|
32
35
|
s << content_tag(:div, "#{k}: #{v}", class: 'error')
|
33
36
|
end
|
34
37
|
s
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Eac
|
3
4
|
module CommonFormHelper
|
4
5
|
class FormBuilder
|
@@ -67,6 +68,7 @@ module Eac
|
|
67
68
|
|
68
69
|
def field_errors_errors(field_name)
|
69
70
|
return nil unless model_instance.errors.messages[field_name]
|
71
|
+
|
70
72
|
s = ActiveSupport::SafeBuffer.new
|
71
73
|
model_instance.errors.messages[field_name].each { |error| s << field_error(error) }
|
72
74
|
@field_errors_showed.add(field_name)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Eac
|
2
4
|
module CommonFormHelper
|
3
5
|
class FormBuilder
|
@@ -31,7 +33,8 @@ module Eac
|
|
31
33
|
if model_instance.class.respond_to?(:reflect_on_association)
|
32
34
|
return model_instance.class.reflect_on_association(field_name).send(method)
|
33
35
|
end
|
34
|
-
|
36
|
+
|
37
|
+
raise "#{model_instance.class} não possui um método \"reflect_on_association\". " \
|
35
38
|
"Defina explicitamente a opção :#{key}"
|
36
39
|
end
|
37
40
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Eac
|
3
4
|
module CommonFormHelper
|
4
5
|
class FormBuilder
|
5
6
|
module CommonTextFields
|
6
|
-
%w
|
7
|
+
%w[email password text].each do |t|
|
7
8
|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
8
9
|
def #{t}_field(field_name, options = {}) # def text_field(field_name, options = {})
|
9
10
|
field(field_name, options) do # field(field_name, options) do
|
@@ -13,7 +14,7 @@ module Eac
|
|
13
14
|
input_options) # class: 'form-control')
|
14
15
|
end # end
|
15
16
|
end # end
|
16
|
-
|
17
|
+
RUBY_EVAL
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Eac
|
2
4
|
module CommonFormHelper
|
3
5
|
class FormBuilder
|
@@ -7,8 +9,8 @@ module Eac
|
|
7
9
|
visible_id = SecureRandom.hex(5)
|
8
10
|
cf = field(field_name, options) do
|
9
11
|
form.hidden_field(field_name, id: hidden_id) <<
|
10
|
-
|
11
|
-
|
12
|
+
helper.text_field_tag("#{field_name}_visible", '',
|
13
|
+
id: visible_id, class: 'form-control')
|
12
14
|
end
|
13
15
|
cf << javascript_currency_mask(hidden_id, visible_id)
|
14
16
|
end
|
@@ -23,15 +25,15 @@ module Eac
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def mask_money_options
|
26
|
-
|
27
|
-
{
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
|
28
|
+
<<~JSON_CODE
|
29
|
+
{
|
30
|
+
prefix: '#{I18n.t('number.currency.format.unit')} ',
|
31
|
+
allowNegative: true,
|
32
|
+
thousands: '#{I18n.t('number.currency.format.delimiter')}',
|
33
|
+
decimal: '#{I18n.t('number.currency.format.separator')}',
|
34
|
+
affixesStay: false
|
35
|
+
}
|
36
|
+
JSON_CODE
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Eac
|
2
4
|
module CommonFormHelper
|
3
5
|
class FormBuilder
|
@@ -35,7 +37,8 @@ module Eac
|
|
35
37
|
if model_instance.class.respond_to?(:reflect_on_association)
|
36
38
|
return model_instance.class.reflect_on_association(field_name).send(method)
|
37
39
|
end
|
38
|
-
|
40
|
+
|
41
|
+
raise "#{model_instance.class} não possui um método \"reflect_on_association\". " \
|
39
42
|
"Defina explicitamente a opção :#{key}"
|
40
43
|
end
|
41
44
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Eac
|
2
4
|
module CommonFormHelper
|
3
5
|
class FormBuilder
|
@@ -42,17 +44,19 @@ module Eac
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def association_column
|
45
|
-
@form_builder.model_instance
|
47
|
+
@form_builder.model_instance&.send(@field_name)
|
46
48
|
end
|
47
49
|
|
48
50
|
def initial_id
|
49
51
|
return association_column.id if association_column
|
52
|
+
|
50
53
|
''
|
51
54
|
end
|
52
55
|
|
53
56
|
def initial_label
|
54
57
|
return association_column.to_s if association_column
|
55
58
|
return params[visible_input_name] if params.key?(visible_input_name)
|
59
|
+
|
56
60
|
''
|
57
61
|
end
|
58
62
|
|
@@ -66,7 +70,7 @@ module Eac
|
|
66
70
|
|
67
71
|
def json_options
|
68
72
|
r = {}
|
69
|
-
[
|
73
|
+
%i[hidden_input_id visible_input_id initial_id initial_label url].each do |k|
|
70
74
|
r[k] = send(k)
|
71
75
|
end
|
72
76
|
r.to_json
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Eac
|
3
4
|
module CommonFormHelper
|
4
5
|
class FormBuilder
|
@@ -19,6 +20,7 @@ module Eac
|
|
19
20
|
def listable_select_options(field_name)
|
20
21
|
return nil unless model_instance.class.respond_to?(:lists)
|
21
22
|
return nil unless model_instance.class.lists.respond_to?(field_name)
|
23
|
+
|
22
24
|
model_instance.class.lists.send(field_name).options
|
23
25
|
end
|
24
26
|
end
|
data/lib/eac/cpf_validator.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Eac
|
2
4
|
class CpfValidator < ActiveModel::EachValidator
|
3
5
|
def validate_each(record, attribute, value)
|
4
6
|
return if Cpf.new(value).valid?
|
7
|
+
|
5
8
|
record.errors[attribute] << (options[:message] ||
|
6
9
|
'CPF inválido (9 caracteres, somente dígitos)')
|
7
10
|
end
|
@@ -13,6 +16,7 @@ module Eac
|
|
13
16
|
|
14
17
|
def valid?
|
15
18
|
return false if input_invalid?
|
19
|
+
|
16
20
|
digito_verificador1_calculo == values[9] && digito_verificador2_calculo == values[10]
|
17
21
|
end
|
18
22
|
|
@@ -25,8 +29,8 @@ module Eac
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def null?
|
28
|
-
%w
|
29
|
-
66666666666 77777777777 88888888888 99999999999 00000000000
|
32
|
+
%w[12345678909 11111111111 22222222222 33333333333 44444444444 55555555555
|
33
|
+
66666666666 77777777777 88888888888 99999999999 00000000000].member?(digits.join)
|
30
34
|
end
|
31
35
|
|
32
36
|
def digits
|
@@ -53,7 +57,7 @@ module Eac
|
|
53
57
|
c -= 1
|
54
58
|
end
|
55
59
|
s -= (11 * (s / 11))
|
56
|
-
|
60
|
+
[0, 1].include?(s) ? 0 : 11 - s
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Eac
|
3
4
|
module DataTableHelper
|
4
5
|
class Column
|
@@ -12,8 +13,8 @@ module Eac
|
|
12
13
|
@block = block
|
13
14
|
end
|
14
15
|
|
15
|
-
def record_value(
|
16
|
-
v = Node.new(
|
16
|
+
def record_value(record)
|
17
|
+
v = Node.new(record, @path).value
|
17
18
|
if v.present?
|
18
19
|
@block ? @block.call(v) : v
|
19
20
|
else
|
@@ -35,9 +36,11 @@ module Eac
|
|
35
36
|
|
36
37
|
def value
|
37
38
|
return @node if @node.nil? || @path.empty?
|
39
|
+
|
38
40
|
subpath = @path.dup
|
39
41
|
n = subpath.shift
|
40
42
|
return Node.new(@node.send(n), subpath).value if @node.respond_to?(n)
|
43
|
+
|
41
44
|
raise "Instance of #{@node.class} does not respond to #{n}"
|
42
45
|
end
|
43
46
|
end
|
@@ -32,20 +32,22 @@ module Eac
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def row(
|
35
|
+
def row(record)
|
36
36
|
@view.content_tag(:tr) do
|
37
|
-
@view.safe_join(
|
37
|
+
@view.safe_join(
|
38
|
+
@setup.columns.map { |c| @view.content_tag('td', c.record_value(record)) << "\n" }
|
39
|
+
)
|
38
40
|
end << "\n"
|
39
41
|
end
|
40
42
|
|
41
43
|
def script
|
42
|
-
@view.javascript_tag
|
43
|
-
$(document).ready(function () {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
@view.javascript_tag <<~JS_CODE
|
45
|
+
$(document).ready(function () {
|
46
|
+
$('##{id}').DataTable({
|
47
|
+
paging: #{@setup.paging ? 'true' : 'false'}
|
48
|
+
});
|
49
|
+
});
|
50
|
+
JS_CODE
|
49
51
|
end
|
50
52
|
|
51
53
|
def id
|
data/lib/eac/htmlbeautifier.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Eac
|
3
4
|
# == Example:
|
4
5
|
#
|
@@ -25,7 +26,7 @@ module Eac
|
|
25
26
|
|
26
27
|
module ClassMethods
|
27
28
|
def add_inequality_queries(attribute)
|
28
|
-
%w
|
29
|
+
%w[gt gteq lt lteq].each do |ineq|
|
29
30
|
scope "by_#{attribute}_#{ineq}", lambda { |v|
|
30
31
|
where(arel_table[attribute].send(ineq, v))
|
31
32
|
}
|
data/lib/eac/menus_helper.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Eac
|
2
4
|
module MenusHelper
|
3
5
|
def dropdown_menu(entries)
|
4
6
|
entries = DataBuilder.new(self).build(entries)
|
5
7
|
return nil unless entries
|
8
|
+
|
6
9
|
id = SecureRandom.hex(5)
|
7
10
|
GuiBuilder.new(self).build(entries, id: id, class: 'jMenu') <<
|
8
|
-
|
11
|
+
javascript_tag("$(document).ready(function(){$('\##{id}').jMenu();});")
|
9
12
|
end
|
10
13
|
|
11
14
|
def bootstrap_dropdown_menu(entries, options = {})
|
12
15
|
entries = DataBuilder.new(self).build(entries)
|
13
16
|
return nil unless entries
|
17
|
+
|
14
18
|
BootstrapGuiBuilder.new(self, options).build(entries)
|
15
19
|
end
|
16
20
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Eac
|
2
4
|
module MenusHelper
|
3
5
|
# http://bootsnipp.com/snippets/featured/multi-level-dropdown-menu-bs3
|
@@ -8,7 +10,8 @@ module Eac
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def build(entries)
|
11
|
-
|
13
|
+
raise 'Argument "entries" is not a array' unless entries.is_a?(Array)
|
14
|
+
|
12
15
|
@view.content_tag(:ul, class: "nav navbar-nav #{@options[:class]}".strip) do
|
13
16
|
menu_entries(entries)
|
14
17
|
end
|
@@ -28,12 +31,12 @@ module Eac
|
|
28
31
|
elsif entry[:type] == :item
|
29
32
|
menu_item(entry)
|
30
33
|
else
|
31
|
-
|
34
|
+
raise "Unknown menu entry type: \"#{entry[:type]}\""
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
38
|
def menu_group(entry)
|
36
|
-
if entry[:level]
|
39
|
+
if entry[:level].zero?
|
37
40
|
menu_group_root(entry)
|
38
41
|
else
|
39
42
|
menu_group_sub(entry)
|
@@ -82,7 +85,7 @@ module Eac
|
|
82
85
|
options[:method] = options[:link_method]
|
83
86
|
options.delete(:link_method)
|
84
87
|
end
|
85
|
-
options[:class] =
|
88
|
+
options[:class] = (@options[:button_class]).to_s.strip if entry[:level].zero?
|
86
89
|
options
|
87
90
|
end
|
88
91
|
end
|