interage-helpers 0.0.1
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +4 -0
- data/.rubocop.yml +22 -0
- data/.travis.yml +7 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +80 -0
- data/README.md +216 -0
- data/Rakefile +8 -0
- data/bin/brakeman +29 -0
- data/bin/bundle +105 -0
- data/bin/ci +12 -0
- data/bin/console +14 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/bin/setup +8 -0
- data/interage-helpers.gemspec +43 -0
- data/lib/generators/interage/helper/install/USAGE +8 -0
- data/lib/generators/interage/helper/install/install_generator.rb +26 -0
- data/lib/generators/interage/helper/install/templates/application_helper.rb +5 -0
- data/lib/generators/interage/helper/install/templates/application_helper.yml +124 -0
- data/lib/interage/application_helper.rb +64 -0
- data/lib/interage/application_icon_helper.rb +28 -0
- data/lib/interage/bootstrap_helper.rb +68 -0
- data/lib/interage/cep_helper.rb +11 -0
- data/lib/interage/cnpj_helper.rb +11 -0
- data/lib/interage/cocoon_helper.rb +26 -0
- data/lib/interage/controller_active_helper.rb +23 -0
- data/lib/interage/cpf_helper.rb +11 -0
- data/lib/interage/date_time_helper.rb +27 -0
- data/lib/interage/favicon_helper.rb +31 -0
- data/lib/interage/flash_message_helper.rb +21 -0
- data/lib/interage/font_awesome_helper.rb +30 -0
- data/lib/interage/gravatar_helper.rb +13 -0
- data/lib/interage/helpers/version.rb +7 -0
- data/lib/interage/helpers.rb +33 -0
- data/lib/interage/link_to_helper.rb +65 -0
- data/lib/interage/material_design_icons_helper.rb +25 -0
- data/lib/interage/number_helper.rb +13 -0
- data/lib/interage/pagination_helper.rb +11 -0
- data/lib/interage/parsers/parser_cep.rb +29 -0
- data/lib/interage/parsers/parser_cnpj.rb +37 -0
- data/lib/interage/parsers/parser_cpf.rb +37 -0
- data/lib/interage/parsers/parser_phone.rb +49 -0
- data/lib/interage/phone_helper.rb +11 -0
- data/lib/interage/text_helper.rb +13 -0
- data/lib/interage/translation_helper.rb +127 -0
- data/lib/interage/version_helper.rb +21 -0
- metadata +136 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module Helper
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
desc 'Generates a application helpers.'
|
9
|
+
|
10
|
+
def create_application_helper
|
11
|
+
copy_file 'application_helper.rb', application_helper_path
|
12
|
+
copy_file 'application_helper.yml', application_locales_path
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def application_helper_path
|
18
|
+
Rails.root.join('app/helpers/application_helper.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
def application_locales_path
|
22
|
+
Rails.root.join('config/locales/pt-BR/application_helper.yml')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
pt-BR:
|
2
|
+
boolean:
|
3
|
+
truly: 'Sim'
|
4
|
+
falsely: 'Não'
|
5
|
+
|
6
|
+
application:
|
7
|
+
name: ''
|
8
|
+
destroy_confirm_message: Tem certeza que deseja apagar?
|
9
|
+
|
10
|
+
bootstrap:
|
11
|
+
alert:
|
12
|
+
icons:
|
13
|
+
default: info-circle
|
14
|
+
info: info-circle
|
15
|
+
warning: exclamation-triangle
|
16
|
+
success: check
|
17
|
+
notice: check
|
18
|
+
danger: ban
|
19
|
+
error: ban
|
20
|
+
subtitles:
|
21
|
+
info: Informação
|
22
|
+
warning: Atenção
|
23
|
+
success: Sucesso
|
24
|
+
notice: Sucesso
|
25
|
+
danger: Erro
|
26
|
+
error: Erro
|
27
|
+
not_found: Nenhum registro foi encontrado
|
28
|
+
male:
|
29
|
+
not_found: Nenhum %{model} foi encontrado
|
30
|
+
female:
|
31
|
+
not_found: Nenhuma %{model} foi encontrada
|
32
|
+
|
33
|
+
menu:
|
34
|
+
default:
|
35
|
+
index: Listar
|
36
|
+
create: Criar
|
37
|
+
update: Editar
|
38
|
+
show: Mostrar
|
39
|
+
destroy: Apagar
|
40
|
+
|
41
|
+
links:
|
42
|
+
new: Adicionar %{model}
|
43
|
+
show: Ver
|
44
|
+
edit: Editar
|
45
|
+
destroy: Apagar
|
46
|
+
cancel: Cancelar
|
47
|
+
duplicate: Duplicar
|
48
|
+
back: Voltar
|
49
|
+
|
50
|
+
icons:
|
51
|
+
new: plus
|
52
|
+
show: eye
|
53
|
+
edit: pencil
|
54
|
+
destroy: trash
|
55
|
+
cancel: ban
|
56
|
+
duplicate: files-o
|
57
|
+
back: arrow-left
|
58
|
+
|
59
|
+
buttons:
|
60
|
+
cocoon:
|
61
|
+
add:
|
62
|
+
icon: plus
|
63
|
+
text: adicionar
|
64
|
+
remove:
|
65
|
+
icon: times
|
66
|
+
text: excluir
|
67
|
+
|
68
|
+
icons_alias:
|
69
|
+
arrow-down: arrow_downward
|
70
|
+
arrow-left: arrow_back
|
71
|
+
arrow-right: arrow_forward
|
72
|
+
arrow-up: arrow_upward
|
73
|
+
arrows-h: compare_arrows
|
74
|
+
ban: cancel
|
75
|
+
bars: menu
|
76
|
+
bell: notifications
|
77
|
+
calendar: today
|
78
|
+
calendar-o: today
|
79
|
+
calendar-check-o: event_available
|
80
|
+
calendar-times-o: event_busy
|
81
|
+
calendar-minus-o: date_range
|
82
|
+
camera: camera_enhance
|
83
|
+
check: done
|
84
|
+
check-square: check_box
|
85
|
+
minus-square: indeterminate_check_box
|
86
|
+
chevron-down: expand_more
|
87
|
+
chevron-right: chevron_right
|
88
|
+
chevron-up: expand_less
|
89
|
+
chevron-left: chevron_left
|
90
|
+
cog: settings
|
91
|
+
cogs: settings
|
92
|
+
comment: mode_comment
|
93
|
+
comments: question_answer
|
94
|
+
dollar: attach_money
|
95
|
+
envelope: email
|
96
|
+
eye: visibility
|
97
|
+
exclamation-triangle: report_problem
|
98
|
+
info-circle: info
|
99
|
+
hdd-o: save_alt
|
100
|
+
paperclip: attachment
|
101
|
+
files-o: file_copy
|
102
|
+
file-pdf-o: picture_as_pdf
|
103
|
+
list-alt: reorder
|
104
|
+
money: local_atm
|
105
|
+
pencil: edit
|
106
|
+
pencil-square: rate_review
|
107
|
+
pencil-square-o: edit_location
|
108
|
+
picture-o: insert_photo
|
109
|
+
plus: add
|
110
|
+
plus-circle: add_circle
|
111
|
+
plus-square: add_circle_outline
|
112
|
+
key: vpn_key
|
113
|
+
search: search
|
114
|
+
sign-in: exit_to_app
|
115
|
+
sign-out: power_settings_new
|
116
|
+
square-o: crop_square
|
117
|
+
ticket: local_activity
|
118
|
+
times: clear
|
119
|
+
trash: delete_sweep
|
120
|
+
trash-o: delete_sweep
|
121
|
+
upload: cloud_upload
|
122
|
+
user: person
|
123
|
+
user-plus: person_add
|
124
|
+
users: people
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module ApplicationHelper
|
5
|
+
include ::Interage::ApplicationIconHelper
|
6
|
+
include ::Interage::BootstrapHelper
|
7
|
+
include ::Interage::CEPHelper
|
8
|
+
include ::Interage::CNPJHelper
|
9
|
+
include ::Interage::CocoonHelper
|
10
|
+
include ::Interage::ControllerActiveHelper
|
11
|
+
include ::Interage::CPFHelper
|
12
|
+
include ::Interage::DateTimeHelper
|
13
|
+
include ::Interage::FaviconHelper
|
14
|
+
include ::Interage::FlashMessageHelper
|
15
|
+
include ::Interage::FontAwesomeHelper
|
16
|
+
include ::Interage::GravatarHelper
|
17
|
+
include ::Interage::LinkToHelper
|
18
|
+
include ::Interage::MaterialDesignIconsHelper
|
19
|
+
include ::Interage::NumberHelper
|
20
|
+
include ::Interage::PaginationHelper
|
21
|
+
include ::Interage::PhoneHelper
|
22
|
+
include ::Interage::TextHelper
|
23
|
+
include ::Interage::TranslationHelper
|
24
|
+
include ::Interage::VersionHelper
|
25
|
+
|
26
|
+
def format_seconds(seconds)
|
27
|
+
t('time.seconds.short', count: seconds)
|
28
|
+
end
|
29
|
+
|
30
|
+
def app_page_title(area = '')
|
31
|
+
strip_tags "#{env_name_upcase}#{page_title}#{area}#{app_name}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def admin_page_title
|
35
|
+
app_page_title(ENV['PREFIX_ADMIN_PAGE_TITLE'])
|
36
|
+
end
|
37
|
+
|
38
|
+
def devise_page_title
|
39
|
+
app_page_title(ENV['PREFIX_DEVISE_PAGE_TITLE'])
|
40
|
+
end
|
41
|
+
|
42
|
+
def page_title
|
43
|
+
content_for?(:page_title) ? "#{content_for(:page_title)} » " : ''
|
44
|
+
end
|
45
|
+
|
46
|
+
def app_name
|
47
|
+
ENV.fetch('APP_NAME', t('application.name', default: rails_app_name))
|
48
|
+
end
|
49
|
+
|
50
|
+
def rails_app_name
|
51
|
+
rails_class = Rails.application.class
|
52
|
+
|
53
|
+
rails_class.try(:module_parent_name) || rails_class.parent_name
|
54
|
+
end
|
55
|
+
|
56
|
+
def env_name_upcase
|
57
|
+
"[#{env_name.upcase}] " if env_name.present?
|
58
|
+
end
|
59
|
+
|
60
|
+
def env_name
|
61
|
+
ENV['ENV_NAME']
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module ApplicationIconHelper
|
5
|
+
ALLOWED_FONT_ICONS = ['fa', 'md'].freeze
|
6
|
+
DEFAULT_FONT_ICON = ENV.fetch('DEFAULT_FONT_ICON', 'fa')
|
7
|
+
|
8
|
+
def app_icon(icon, options = {})
|
9
|
+
execute_method("#{DEFAULT_FONT_ICON}_icon", icon, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def app_icon_text(icon, text, options = {})
|
13
|
+
execute_method("#{DEFAULT_FONT_ICON}_icon_text", icon, text, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def app_icon_classes(icon, prefix, separator, options = {})
|
17
|
+
icon_classes = icon.to_s.split(' ').uniq.join(" #{separator}-")
|
18
|
+
|
19
|
+
"#{prefix} #{separator}-#{icon_classes} #{options[:class]}".strip
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute_method(method_name, *arguments)
|
23
|
+
return unless ALLOWED_FONT_ICONS.include?(DEFAULT_FONT_ICON)
|
24
|
+
|
25
|
+
try(method_name, *arguments)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module BootstrapHelper
|
5
|
+
DEFAULT_BTN_CLASS = 'btn btn-sm btn-outline-'
|
6
|
+
|
7
|
+
def bootstrap_alert(type, message)
|
8
|
+
icon = t("bootstrap.alert.icons.#{type}", default: type)
|
9
|
+
|
10
|
+
content_tag :div, class: "no-margin alert alert-#{type}" do
|
11
|
+
app_icon_text(icon, message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def bootstrap_alert_default(message)
|
16
|
+
bootstrap_alert(:default, message)
|
17
|
+
end
|
18
|
+
|
19
|
+
def bootstrap_alert_info(message)
|
20
|
+
bootstrap_alert(:info, message)
|
21
|
+
end
|
22
|
+
|
23
|
+
def bootstrap_alert_warning(message)
|
24
|
+
bootstrap_alert(:warning, message)
|
25
|
+
end
|
26
|
+
|
27
|
+
def bootstrap_alert_success(message)
|
28
|
+
bootstrap_alert(:success, message)
|
29
|
+
end
|
30
|
+
|
31
|
+
def bootstrap_alert_danger(message)
|
32
|
+
bootstrap_alert(:danger, message)
|
33
|
+
end
|
34
|
+
|
35
|
+
def bootstrap_alert_not_found(gender, model)
|
36
|
+
bootstrap_alert_info(text_not_found(gender, model))
|
37
|
+
end
|
38
|
+
|
39
|
+
def bootstrap_alert_not_found_male(model)
|
40
|
+
bootstrap_alert_not_found(:male, model)
|
41
|
+
end
|
42
|
+
|
43
|
+
def bootstrap_alert_not_found_female(model)
|
44
|
+
bootstrap_alert_not_found(:female, model)
|
45
|
+
end
|
46
|
+
|
47
|
+
def text_not_found(gender, model)
|
48
|
+
default_not_found = t('bootstrap.alert.not_found', default: '')
|
49
|
+
|
50
|
+
t("bootstrap.alert.#{gender}.not_found", model: tm(model).downcase,
|
51
|
+
default: default_not_found)
|
52
|
+
end
|
53
|
+
|
54
|
+
def text_not_found_male(model)
|
55
|
+
text_not_found(:male, model)
|
56
|
+
end
|
57
|
+
|
58
|
+
def text_not_found_female(model)
|
59
|
+
text_not_found(:female, model)
|
60
|
+
end
|
61
|
+
|
62
|
+
def bootstrap_default_btn_class(type)
|
63
|
+
default_btn_class = ENV.fetch('DEFAULT_BTN_TYPE_CLASS', DEFAULT_BTN_CLASS)
|
64
|
+
|
65
|
+
"#{default_btn_class}#{type} text-truncate"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module CocoonHelper
|
5
|
+
def cocoon_link_to_add_association(form, association, options = {})
|
6
|
+
label = options[:label] || t('buttons.cocoon.add.text')
|
7
|
+
html_class =
|
8
|
+
options[:html_class] || bootstrap_default_btn_class('success')
|
9
|
+
|
10
|
+
link_to_add_association(form, association, class: html_class) do
|
11
|
+
app_icon_text(t('buttons.cocoon.add.icon'), label)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def cocoon_link_to_remove_association(form, label = nil)
|
16
|
+
label ||= t('buttons.cocoon.remove.text')
|
17
|
+
html_class = bootstrap_default_btn_class('danger')
|
18
|
+
|
19
|
+
content_tag :div, class: 'cocoon-link-to-remove' do
|
20
|
+
link_to_remove_association(form, class: html_class, title: label) do
|
21
|
+
app_icon_text(t('buttons.cocoon.remove.icon'), label)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module ControllerActiveHelper
|
5
|
+
HTML_SHOW_CLASS = ENV.fetch('CONTROLLER_SHOW_CLASS', 'show')
|
6
|
+
HTML_ACTIVE_CLASS = ENV.fetch('CONTROLLER_ACTIVE_CLASS', 'active')
|
7
|
+
|
8
|
+
def menu_class_show(*controllers)
|
9
|
+
HTML_SHOW_CLASS if current_controller?(*controllers)
|
10
|
+
end
|
11
|
+
|
12
|
+
def menu_active(*controllers)
|
13
|
+
HTML_ACTIVE_CLASS if current_controller?(*controllers)
|
14
|
+
end
|
15
|
+
alias menu_class_active menu_active
|
16
|
+
|
17
|
+
def current_controller?(*controllers)
|
18
|
+
controllers = controllers.is_a?(Array) ? controllers : [controllers]
|
19
|
+
|
20
|
+
controllers.include?(params[:controller])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module DateTimeHelper
|
5
|
+
def business_days_from_now(days = 2)
|
6
|
+
date = days.to_i.business_days.from_now.to_date
|
7
|
+
|
8
|
+
return l(date) if business_day?(date)
|
9
|
+
|
10
|
+
business_days_from_now(days + 1)
|
11
|
+
end
|
12
|
+
|
13
|
+
def business_day?(date)
|
14
|
+
Holidays.on(date, :br).empty? && date.to_date.workday?
|
15
|
+
end
|
16
|
+
|
17
|
+
def format_date(date, date_format = :date_time)
|
18
|
+
l(date, format: date_format)
|
19
|
+
end
|
20
|
+
|
21
|
+
def format_time(time)
|
22
|
+
return if time.blank?
|
23
|
+
|
24
|
+
time.strftime('%H:%M')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module FaviconHelper
|
5
|
+
EXTENTION = ENV.fetch('FAVICON_EXTENTION', 'png')
|
6
|
+
FILE_NAME = ENV.fetch('FAVICON_FILE_NAME', 'icons/apple-touch-icon')
|
7
|
+
FAVICON_SIZES = [nil, 57, 72, 76, 114, 120, 144, 152, 180].freeze
|
8
|
+
|
9
|
+
def favicon_link_tags
|
10
|
+
safe_join favicon_size_link_tags.push(favicon_link_tag)
|
11
|
+
end
|
12
|
+
|
13
|
+
def favicon_size_link_tags
|
14
|
+
FAVICON_SIZES.map do |s|
|
15
|
+
favicon_link_tag(handler_name(s), favicon_options(s))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def handler_name(size)
|
20
|
+
"#{FILE_NAME}#{handler_size(size, '-')}.#{EXTENTION}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def favicon_options(size)
|
24
|
+
{ type: 'image/png', rel: 'apple-touch-icon', sizes: handler_size(size) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def handler_size(size, prefix = '')
|
28
|
+
"#{prefix}#{size}x#{size}" if size.present?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module FlashMessageHelper
|
5
|
+
def flash_messages
|
6
|
+
messages ||= flashes.map do |type, message|
|
7
|
+
bootstrap_alert(handle_type(type), message)
|
8
|
+
end
|
9
|
+
|
10
|
+
safe_join(messages || [])
|
11
|
+
end
|
12
|
+
|
13
|
+
def flashes
|
14
|
+
flash.to_h.symbolize_keys
|
15
|
+
end
|
16
|
+
|
17
|
+
def handle_type(type)
|
18
|
+
type == :notice ? :success : type
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module FontAwesomeHelper
|
5
|
+
def fa_icons
|
6
|
+
t('icons_alias', default: {}).keys
|
7
|
+
end
|
8
|
+
|
9
|
+
def fa_icon(icon, options = {})
|
10
|
+
content_tag :i, nil, options.merge(class: fa_classes(icon, options))
|
11
|
+
end
|
12
|
+
|
13
|
+
def fa_fw_icon(icon, options = {})
|
14
|
+
fa_icon("fw #{icon}", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def fa_icon_text(icon, text, options = {})
|
18
|
+
content_tag :span do
|
19
|
+
concat fa_fw_icon(icon, options)
|
20
|
+
concat text
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def fa_classes(icon, options = {})
|
25
|
+
icon_classes = icon.to_s.split(' ').uniq.join(' fa-')
|
26
|
+
|
27
|
+
"fa fa-#{icon_classes} #{options[:class]}".strip
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module GravatarHelper
|
5
|
+
BASE_URL = 'https://www.gravatar.com/avatar'
|
6
|
+
|
7
|
+
def gravatar_image_tag(email, size = 50, options = {})
|
8
|
+
hexdigest = Digest::MD5.hexdigest(email)
|
9
|
+
|
10
|
+
image_tag("#{BASE_URL}/#{hexdigest}?size=#{size}", options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'interage/helpers/version'
|
4
|
+
require 'active_support/core_ext/module'
|
5
|
+
|
6
|
+
module Interage
|
7
|
+
module Helper
|
8
|
+
class Error < StandardError
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
autoload :ApplicationHelper, 'interage/application_helper'
|
13
|
+
autoload :ApplicationIconHelper, 'interage/application_icon_helper'
|
14
|
+
autoload :BootstrapHelper, 'interage/bootstrap_helper'
|
15
|
+
autoload :CEPHelper, 'interage/cep_helper'
|
16
|
+
autoload :CNPJHelper, 'interage/cnpj_helper'
|
17
|
+
autoload :CocoonHelper, 'interage/cocoon_helper'
|
18
|
+
autoload :ControllerActiveHelper, 'interage/controller_active_helper'
|
19
|
+
autoload :CPFHelper, 'interage/cpf_helper'
|
20
|
+
autoload :DateTimeHelper, 'interage/date_time_helper'
|
21
|
+
autoload :FaviconHelper, 'interage/favicon_helper'
|
22
|
+
autoload :FlashMessageHelper, 'interage/flash_message_helper'
|
23
|
+
autoload :FontAwesomeHelper, 'interage/font_awesome_helper'
|
24
|
+
autoload :GravatarHelper, 'interage/gravatar_helper'
|
25
|
+
autoload :LinkToHelper, 'interage/link_to_helper'
|
26
|
+
autoload :MaterialDesignIconsHelper, 'interage/material_design_icons_helper'
|
27
|
+
autoload :NumberHelper, 'interage/number_helper'
|
28
|
+
autoload :PaginationHelper, 'interage/pagination_helper'
|
29
|
+
autoload :PhoneHelper, 'interage/phone_helper'
|
30
|
+
autoload :TextHelper, 'interage/text_helper'
|
31
|
+
autoload :TranslationHelper, 'interage/translation_helper'
|
32
|
+
autoload :VersionHelper, 'interage/version_helper'
|
33
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module LinkToHelper
|
5
|
+
ASIDE_DEFAULT_CLASS = 'list-group-item'
|
6
|
+
PREFIX_BUTTON_CLASS = 'btn btn-sm btn-outline-'
|
7
|
+
DESTROY_CONFIRM_MESSAGE = 'Tem certeza que deseja apagar?'
|
8
|
+
NEW_BUTTON_CLASS = 'btn text-truncate btn-outline-application'
|
9
|
+
|
10
|
+
def aside_link_to(text, url = '#', html_options = {})
|
11
|
+
html_options[:class] = "#{ASIDE_DEFAULT_CLASS} #{html_options[:class]}"
|
12
|
+
html_options[:title] = strip_tags(text)
|
13
|
+
|
14
|
+
link_to text, url, html_options
|
15
|
+
end
|
16
|
+
|
17
|
+
def link_to_modal(text, url = '#', html_options = {})
|
18
|
+
link_to text, url, html_options.merge('data-toggle': 'modal')
|
19
|
+
end
|
20
|
+
|
21
|
+
def link_to_new(resource, url)
|
22
|
+
text = t('menu.links.new', model: tm(resource).downcase)
|
23
|
+
|
24
|
+
link_to url, title: strip_tags(text), class: NEW_BUTTON_CLASS do
|
25
|
+
app_icon_text(t('menu.icons.new'), text)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def link_to_edit(url)
|
30
|
+
link_to_default(:edit, url, class: button_class('info'))
|
31
|
+
end
|
32
|
+
|
33
|
+
def link_to_back(url)
|
34
|
+
link_to_default(:back, url, class: button_class('secondary'))
|
35
|
+
end
|
36
|
+
|
37
|
+
def link_to_show(url)
|
38
|
+
link_to_default(:show, url, class: button_class('dark'))
|
39
|
+
end
|
40
|
+
|
41
|
+
def link_to_destroy(url, html_options = {})
|
42
|
+
html_options.merge!(method: :delete,
|
43
|
+
'data-confirm' => destroy_confirm_message,
|
44
|
+
class: button_class('danger', html_options[:class]))
|
45
|
+
|
46
|
+
link_to_default(:destroy, url, html_options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def link_to_default(type, url, html_options = {})
|
50
|
+
text = t("menu.links.#{type}")
|
51
|
+
html_options = html_options.merge(title: strip_tags(text),
|
52
|
+
data: { tooltip: 'top' })
|
53
|
+
|
54
|
+
link_to(app_icon_text(t("menu.icons.#{type}"), text), url, html_options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def button_class(type, addicional_class = nil)
|
58
|
+
"#{PREFIX_BUTTON_CLASS}#{type} #{addicional_class}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def destroy_confirm_message
|
62
|
+
t('application.destroy_confirm_message', default: DESTROY_CONFIRM_MESSAGE)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module MaterialDesignIconsHelper
|
5
|
+
def md_icon(icon, options = {})
|
6
|
+
icon_classes = icon.to_s.split(' ')
|
7
|
+
icon = icon_classes.shift
|
8
|
+
|
9
|
+
content_tag :i, class: md_classes(icon, options) do
|
10
|
+
t("icons_alias.#{icon}", default: icon)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def md_icon_text(icon, text, options = {})
|
15
|
+
content_tag :span do
|
16
|
+
concat md_icon(icon, options)
|
17
|
+
concat " #{text}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def md_classes(icon, options = {})
|
22
|
+
app_icon_classes(icon, 'material-icons', 'md', options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Interage
|
4
|
+
module NumberHelper
|
5
|
+
def default_currency_format(number, precision = 2, unit = 'R$')
|
6
|
+
number_to_currency(number, precision: precision, unit: unit)
|
7
|
+
end
|
8
|
+
|
9
|
+
def only_numbers(number)
|
10
|
+
number.to_s.gsub(/[^0-9]/, '')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|