interage-helpers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +4 -0
  4. data/.rubocop.yml +22 -0
  5. data/.travis.yml +7 -0
  6. data/Gemfile +22 -0
  7. data/Gemfile.lock +80 -0
  8. data/README.md +216 -0
  9. data/Rakefile +8 -0
  10. data/bin/brakeman +29 -0
  11. data/bin/bundle +105 -0
  12. data/bin/ci +12 -0
  13. data/bin/console +14 -0
  14. data/bin/rspec +29 -0
  15. data/bin/rubocop +29 -0
  16. data/bin/setup +8 -0
  17. data/interage-helpers.gemspec +43 -0
  18. data/lib/generators/interage/helper/install/USAGE +8 -0
  19. data/lib/generators/interage/helper/install/install_generator.rb +26 -0
  20. data/lib/generators/interage/helper/install/templates/application_helper.rb +5 -0
  21. data/lib/generators/interage/helper/install/templates/application_helper.yml +124 -0
  22. data/lib/interage/application_helper.rb +64 -0
  23. data/lib/interage/application_icon_helper.rb +28 -0
  24. data/lib/interage/bootstrap_helper.rb +68 -0
  25. data/lib/interage/cep_helper.rb +11 -0
  26. data/lib/interage/cnpj_helper.rb +11 -0
  27. data/lib/interage/cocoon_helper.rb +26 -0
  28. data/lib/interage/controller_active_helper.rb +23 -0
  29. data/lib/interage/cpf_helper.rb +11 -0
  30. data/lib/interage/date_time_helper.rb +27 -0
  31. data/lib/interage/favicon_helper.rb +31 -0
  32. data/lib/interage/flash_message_helper.rb +21 -0
  33. data/lib/interage/font_awesome_helper.rb +30 -0
  34. data/lib/interage/gravatar_helper.rb +13 -0
  35. data/lib/interage/helpers/version.rb +7 -0
  36. data/lib/interage/helpers.rb +33 -0
  37. data/lib/interage/link_to_helper.rb +65 -0
  38. data/lib/interage/material_design_icons_helper.rb +25 -0
  39. data/lib/interage/number_helper.rb +13 -0
  40. data/lib/interage/pagination_helper.rb +11 -0
  41. data/lib/interage/parsers/parser_cep.rb +29 -0
  42. data/lib/interage/parsers/parser_cnpj.rb +37 -0
  43. data/lib/interage/parsers/parser_cpf.rb +37 -0
  44. data/lib/interage/parsers/parser_phone.rb +49 -0
  45. data/lib/interage/phone_helper.rb +11 -0
  46. data/lib/interage/text_helper.rb +13 -0
  47. data/lib/interage/translation_helper.rb +127 -0
  48. data/lib/interage/version_helper.rb +21 -0
  49. metadata +136 -0
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ module PaginationHelper
5
+ def pagination_links(collection)
6
+ return if collection.empty?
7
+
8
+ render 'kaminari/pagination', collection: collection
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ class ParserCep
5
+ include Interage::NumberHelper
6
+
7
+ ALLOWED_SIZE = 8
8
+
9
+ def self.call(cep)
10
+ new(cep).perform
11
+ end
12
+
13
+ def initialize(cep)
14
+ @cep = only_numbers(cep).to_i
15
+ end
16
+
17
+ def perform
18
+ "#{digits[-8..-4]}-#{digits[-3..-1]}" if cep.positive?
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :cep
24
+
25
+ def digits
26
+ @digits ||= cep.to_s.rjust(ALLOWED_SIZE, '0')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ class ParserCNPJ
5
+ include Interage::NumberHelper
6
+
7
+ ALLOWED_SIZE = 14
8
+
9
+ def self.call(cnpj)
10
+ new(cnpj).perform
11
+ end
12
+
13
+ def initialize(cnpj)
14
+ @cnpj = only_numbers(cnpj).to_i
15
+ end
16
+
17
+ def perform
18
+ "#{prefix_cnpj}/#{sufix_cnpj}".strip if cnpj.positive?
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :cnpj
24
+
25
+ def prefix_cnpj
26
+ [digits[-14..-13], digits[-12..-10], digits[-9..-7]].join('.')
27
+ end
28
+
29
+ def sufix_cnpj
30
+ [digits[-6..-3], digits[-2..-1]].join('-')
31
+ end
32
+
33
+ def digits
34
+ @digits ||= cnpj.to_s.rjust(ALLOWED_SIZE, '0')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ class ParserCPF
5
+ include Interage::NumberHelper
6
+
7
+ ALLOWED_SIZE = 11
8
+
9
+ def self.call(cpf)
10
+ new(cpf).perform
11
+ end
12
+
13
+ def initialize(cpf)
14
+ @cpf = only_numbers(cpf).to_i
15
+ end
16
+
17
+ def perform
18
+ "#{prefix_cpf}-#{sufix_cpf}".strip if cpf.positive?
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :cpf
24
+
25
+ def prefix_cpf
26
+ [digits[-11..-9], digits[-8..-6], digits[-5..-3]].join('.')
27
+ end
28
+
29
+ def sufix_cpf
30
+ digits[-2..-1]
31
+ end
32
+
33
+ def digits
34
+ @digits ||= cpf.to_s.rjust(ALLOWED_SIZE, '0')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ class ParserPhone
5
+ include Interage::NumberHelper
6
+
7
+ ALLOWED_SIZES = [13, 11, 9, 8].freeze
8
+
9
+ def self.call(phone)
10
+ new(phone).perform
11
+ end
12
+
13
+ def initialize(phone)
14
+ @phone = only_numbers(phone).to_i.to_s
15
+ end
16
+
17
+ def perform
18
+ formatted_phone
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :phone
24
+
25
+ def formatted_phone
26
+ "#{country_code} #{ddd} #{prefix_phone}-#{sufix_phone}".strip
27
+ end
28
+
29
+ def country_code
30
+ "+#{phone[-13..-12]}" if phone[-13..-12].present?
31
+ end
32
+
33
+ def ddd
34
+ "(#{phone[-11..-10]})" if phone[-13..-12].present?
35
+ end
36
+
37
+ def prefix_phone
38
+ phone.size == 8 ? phone[-8..-5] : phone[-9..-5]
39
+ end
40
+
41
+ def sufix_phone
42
+ phone[-4..-1]
43
+ end
44
+
45
+ def valid?
46
+ ALLOWED_SIZES.include?(phone.size)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'parsers/parser_phone'
4
+
5
+ module Interage
6
+ module PhoneHelper
7
+ def format_phone(phone)
8
+ ParserPhone.call(phone)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ module TextHelper
5
+ def nl2br(string, options = {})
6
+ out = string.split("\n").map do |str|
7
+ content_tag :div, str, options
8
+ end
9
+
10
+ safe_join out
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ module TranslationHelper
5
+ ##
6
+ # Public: Translate a model name.
7
+ #
8
+ # model: Model class.
9
+ # count: Count.
10
+ #
11
+ # Examples:
12
+ #
13
+ # <%= tm Post %>
14
+ # # => 'Artigo'
15
+ #
16
+ # <%= tm Post, 2 %>
17
+ # # => 'Artigos'
18
+ #
19
+ # Returns translated model.
20
+ def translate_model_name(model, count = 1)
21
+ count.to_i > 1 ? model.model_name.human.pluralize : model.model_name.human
22
+ end
23
+ alias tm translate_model_name
24
+
25
+ ##
26
+ # Public: Translate a model name pluralized.
27
+ #
28
+ # model: Model class.
29
+ #
30
+ # Examples:
31
+ #
32
+ # <%= tm Post %>
33
+ # # => 'Artigos'
34
+ #
35
+ # Returns translated model pluralized.
36
+ def translate_model_name_pluralized(model)
37
+ translate_model_name(model, 2)
38
+ end
39
+ alias tmp translate_model_name_pluralized
40
+
41
+ ##
42
+ # Public: Translate a model attribute.
43
+ #
44
+ # model: Model class.
45
+ # attribute: Attribute name.
46
+ # count: Count.
47
+ #
48
+ # Examples
49
+ #
50
+ # <%= ta Post, :title %>
51
+ # # => 'Titulo'
52
+ #
53
+ # <%= ta Post, :title, 2 %>
54
+ # # => 'Titulos'
55
+ #
56
+ # Returns translated model's attribute.
57
+ def translate_model_attribute(model, attribute, count = 1)
58
+ model.human_attribute_name(attribute, count: count)
59
+ end
60
+ alias ta translate_model_attribute
61
+
62
+ ##
63
+ # Public: Translate a boolean attribute.
64
+ #
65
+ # value: TrueClass or FalseClass.
66
+ #
67
+ # Examples
68
+ #
69
+ # <%= tb true %>
70
+ # # => 'Sim'
71
+ #
72
+ # <%= tb false %>
73
+ # # => 'Nao'
74
+ #
75
+ # Returns translated boolean's attribute.
76
+ def translate_boolean(value)
77
+ value ? t('boolean.truly') : t('boolean.falsely')
78
+ end
79
+ alias tb translate_boolean
80
+
81
+ ##
82
+ # Public: Translate a boolean attribute in an icon.
83
+ #
84
+ # value: TrueClass or FalseClass.
85
+ #
86
+ # Examples
87
+ #
88
+ # <%= tbi true %>
89
+ # # => '<i class="fa fa-check text-success"></i>'
90
+ #
91
+ # <%= tbi false %>
92
+ # # => '<i class="fa fa-times text-danger"></i>'
93
+ #
94
+ # Returns translated boolean's attribute in an icon.
95
+ def translate_boolean_in_icon(value)
96
+ if value
97
+ content_tag(:span, '✓', class: 'text-success')
98
+ else
99
+ content_tag(:span, '×', class: 'text-danger')
100
+ end
101
+ end
102
+ alias tbi translate_boolean_in_icon
103
+
104
+ ##
105
+ # Public: Translate a boolean attribute in an icon.
106
+ #
107
+ # value: TrueClass or FalseClass.
108
+ #
109
+ # Examples
110
+ #
111
+ # <%= tbci true %>
112
+ # # => '<i class="fa fa-check-square-o text-default"></i>'
113
+ #
114
+ # <%= tbci false %>
115
+ # # => '<i class="fa fa-square-o text-default"></i>'
116
+ #
117
+ # Returns translated boolean's attribute in an icon.
118
+ def translate_boolean_in_check_box_icon(value)
119
+ if value
120
+ app_icon('check', class: 'text-success')
121
+ else
122
+ app_icon('times', class: 'text-danger')
123
+ end
124
+ end
125
+ alias tbci translate_boolean_in_check_box_icon
126
+ end
127
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Interage
4
+ module VersionHelper
5
+ def app_version
6
+ return if app_text_version.blank?
7
+
8
+ content_tag :div, app_text_version, id: 'app-version'
9
+ end
10
+
11
+ def app_text_version
12
+ return unless file_version_exist?
13
+
14
+ "#{app_name} - v#{File.read('VERSION').strip}"
15
+ end
16
+
17
+ def file_version_exist?
18
+ File.exist?('VERSION')
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: interage-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Walmir Neto
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Classes to encapsulate helpers
56
+ email:
57
+ - owalmirneto@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - README.md
69
+ - Rakefile
70
+ - bin/brakeman
71
+ - bin/bundle
72
+ - bin/ci
73
+ - bin/console
74
+ - bin/rspec
75
+ - bin/rubocop
76
+ - bin/setup
77
+ - interage-helpers.gemspec
78
+ - lib/generators/interage/helper/install/USAGE
79
+ - lib/generators/interage/helper/install/install_generator.rb
80
+ - lib/generators/interage/helper/install/templates/application_helper.rb
81
+ - lib/generators/interage/helper/install/templates/application_helper.yml
82
+ - lib/interage/application_helper.rb
83
+ - lib/interage/application_icon_helper.rb
84
+ - lib/interage/bootstrap_helper.rb
85
+ - lib/interage/cep_helper.rb
86
+ - lib/interage/cnpj_helper.rb
87
+ - lib/interage/cocoon_helper.rb
88
+ - lib/interage/controller_active_helper.rb
89
+ - lib/interage/cpf_helper.rb
90
+ - lib/interage/date_time_helper.rb
91
+ - lib/interage/favicon_helper.rb
92
+ - lib/interage/flash_message_helper.rb
93
+ - lib/interage/font_awesome_helper.rb
94
+ - lib/interage/gravatar_helper.rb
95
+ - lib/interage/helpers.rb
96
+ - lib/interage/helpers/version.rb
97
+ - lib/interage/link_to_helper.rb
98
+ - lib/interage/material_design_icons_helper.rb
99
+ - lib/interage/number_helper.rb
100
+ - lib/interage/pagination_helper.rb
101
+ - lib/interage/parsers/parser_cep.rb
102
+ - lib/interage/parsers/parser_cnpj.rb
103
+ - lib/interage/parsers/parser_cpf.rb
104
+ - lib/interage/parsers/parser_phone.rb
105
+ - lib/interage/phone_helper.rb
106
+ - lib/interage/text_helper.rb
107
+ - lib/interage/translation_helper.rb
108
+ - lib/interage/version_helper.rb
109
+ homepage: https://gitlab.com/interage/patterns/helpers
110
+ licenses:
111
+ - MIT
112
+ metadata:
113
+ allowed_push_host: https://rubygems.org
114
+ homepage_uri: https://gitlab.com/interage/patterns/helpers
115
+ source_code_uri: https://gitlab.com/interage/patterns/helpers
116
+ changelog_uri: https://gitlab.com/interage/patterns/helpers
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubygems_version: 3.0.6
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Application Helper for Interage
136
+ test_files: []