interage-helper 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 593dbd3c407d8c8da4ebcc925193f901dd0dd69137d6a2d3874fbceca3e801a3
4
- data.tar.gz: 21f4c9ebca28b1dad4cc753bbd5f9a9de979aec3923b490d379b69c7a84f7d9d
3
+ metadata.gz: fb9c0473a691c92a53ae2b90a4d80aca3aa13ff41191be936ced2f0d8028e177
4
+ data.tar.gz: c696a79565e630384f88cad5c850faf23976aadb604f9bbb39d5d4957799e123
5
5
  SHA512:
6
- metadata.gz: 7891f4fb05d2622fcb8b2698828a501c2bab56da289e3aec66c8265d30cebd0e85c9f3e5ea25c8c96cc46404d62901e39d36b73011033cd89542b88511b04249
7
- data.tar.gz: 86907b95cd65c9a349110751b61c8fa747232b4ee3fba42e8195b01114949d0ddd9ad492a1056ec800d58098df3ceceb496a1e4168cd79779d8528c3604ba554
6
+ metadata.gz: 16e606987da232e70b0b6ac073e54e8e17717d0fabe27a28d3e77aae9705389a5319d1f4ec445e53b8773806e0be57a06ebf43b86dc3424c23b32dbf8f6f6732
7
+ data.tar.gz: 9337be99f21638dbed1ad095a20fe2e978a8df466aaff6cd3b3dda58eefe436bf0da64a1b3a2db299237644b6e1429b6d74c2337fc0fce612e3b0fb50f046384
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  # Interage::Helper
2
3
 
3
4
  ## Installation
@@ -22,17 +23,172 @@ gem install interage-helper
22
23
 
23
24
  ## Usage
24
25
 
25
- You can use a Rails generator to create `ApplicationHelper`:
26
+ You can use a Rails generator to create `ApplicationHelper` and add locales file:
26
27
 
27
28
  ```bash
28
29
  rails g interage:helper:install
29
30
  ```
30
31
 
31
- And you can use a Rails generator to create helper classes:
32
+ If you want to overwrite some variables:
32
33
 
34
+ ```env
35
+ ### APPLICATION HELPER
36
+ ## Interage::ApplicationHelper
37
+ #
38
+ APP_NAME='Nome da Aplicação'
39
+ ENV_NAME='development'
40
+ PREFIX_ADMIN_PAGE_TITLE='Administração :: '
41
+ PREFIX_DEVISE_PAGE_TITLE='Autenticação :: '
33
42
 
34
- ```bash
35
- rails g interage:helper:create UsersByEmail User
43
+ ## Interage::ApplicationIconHelper
44
+ #
45
+ # Use 'fa' or 'md'
46
+ DEFAULT_FONT_ICON='fa'
47
+
48
+ ## Interage::CocoonHelper
49
+ #
50
+ DEFAULT_COCOON_BTN_CLASS='btn btn-sm btn-outline-'
51
+
52
+ ## Interage::ControllerActiveHelper
53
+ #
54
+ CONTROLLER_SHOW_CLASS='show'
55
+ CONTROLLER_ACTIVE_CLASS='active'
56
+
57
+ ## Interage::FaviconHelper
58
+ #
59
+ FAVICON_EXTENTION='png'
60
+ FAVICON_FILE_NAME='icons/apple-touch-icon'
61
+ ```
62
+
63
+ ## Finally ... Some examples:
64
+
65
+ #### Interage::LinkToHelper
66
+
67
+ ```erb
68
+ <p><%= link_to_edit edit_user_path(user) %></p>
69
+ <p><%= link_to_back :back %></p>
70
+ <p><%= link_to_show user_path(user) %></p>
71
+ <p><%= link_to_destroy user_path(user) %></p>
72
+ <p><%= link_to_new User, users_path %></p>
73
+ ```
74
+
75
+ #### Interage::ApplicationIconHelper
76
+
77
+ ```erb
78
+ <p><%= app_icon('user', class: 'text-muted') %></p>
79
+ <p><%= app_icon_text('users', 'Usuários', class: 'text-muted') %></p>
80
+ ```
81
+
82
+ #### Interage::FontAwesomeHelper
83
+
84
+ ```erb
85
+ <p><%= fa_icon('user', class: 'text-muted') %></p>
86
+ <p><%= fa_icon_text('users', 'Usuários', class: 'text-muted') %></p>
87
+ ```
88
+
89
+ #### Interage::MaterialDesignIconsHelper
90
+
91
+ ```erb
92
+ <p><%= md_icon('user', class: 'text-muted') %></p>
93
+ <p><%= md_icon_text('users', 'Usuários', class: 'text-muted') %></p>
94
+ ```
95
+
96
+ #### Interage::VersionHelper
97
+
98
+ ```erb
99
+ <p><%= app_version %></p>
100
+ <p><%= app_text_version %></p>
101
+ ```
102
+
103
+ #### Interage::TranslationHelper
104
+
105
+ ```erb
106
+ <p><%= tm(User) %></p>
107
+ <p><%= tmp(User) %></p>
108
+ <p><%= ta(User, :name) %></p>
109
+ <p><%= tb(false) %></p>
110
+ <p><%= tb(true) %></p>
111
+ <p><%= tbi(false) %></p>
112
+ <p><%= tbi(true) %></p>
113
+ <p><%= tbci(false) %></p>
114
+ <p><%= tbci(true) %></p>
115
+ ```
116
+
117
+ #### Interage::TextHelper
118
+
119
+ ```erb
120
+ <p><%= nl2br("Hello\nWorld") %></p>
121
+ ```
122
+
123
+ #### Interage::PhoneHelper
124
+
125
+ ```erb
126
+ <p><%= format_phone('81999599805') %></p>
127
+ ```
128
+
129
+ #### Interage::PaginationHelper
130
+
131
+ ```erb
132
+ <p><%= pagination_links(@users) %></p>
133
+ ```
134
+
135
+ #### Interage::NumberHelper
136
+
137
+ ```erb
138
+ <p><%= default_currency_format(10_000) %></p>
139
+ ```
140
+
141
+ #### Interage::GravatarHelper
142
+
143
+ ```erb
144
+ <p><%= gravatar_image_tag('developer@interage.in') %></p>
145
+ ```
146
+
147
+ #### Interage::ControllerActiveHelper
148
+
149
+ ```erb
150
+ <p><%= menu_active('home') %></p>
151
+ <p><%= current_controller?('home') %></p>
152
+ ```
153
+
154
+ #### Interage::CEPHelper
155
+
156
+ ```erb
157
+ <p><%= format_cep('54754195') %></p>
158
+ ```
159
+
160
+ #### Interage::CPFCNPJHelper
161
+
162
+ ```erb
163
+ <p><%= format_cnpj('00000000000100') %></p>
164
+ <p><%= format_cpf('05488608400') %></p>
165
+ ```
166
+
167
+ #### Interage::ApplicationHelper
168
+
169
+ ```erb
170
+ <p><%= format_seconds(20) %></p>
171
+ <p><%= app_page_title('adsdasdasd ') %></p>
172
+ <p><%= admin_page_title %></p>
173
+ <p><%= devise_page_title %></p>
174
+ <p><%= page_title %></p>
175
+ <p><%= app_name %></p>
176
+ <p><%= env_name_upcase %></p>
177
+ ```
178
+
179
+ #### Interage::BootstrapHelper
180
+
181
+ ```erb
182
+ <%= bootstrap_alert('users', '') %>
183
+ <%= bootstrap_alert_default('users') %>
184
+ <%= bootstrap_alert_info('users') %>
185
+ <%= bootstrap_alert_warning('users') %>
186
+ <%= bootstrap_alert_success('users') %>
187
+ <%= bootstrap_alert_danger('users') %>
188
+ <%= bootstrap_alert_not_found_male(User) %>
189
+ <%= bootstrap_alert_not_found_female(User) %>
190
+ <p><%= text_not_found_male(User) %></p>
191
+ <p><%= text_not_found_female(User) %></p>
36
192
  ```
37
193
 
38
194
  ## Contributing
Binary file
@@ -31,11 +31,11 @@ module Interage
31
31
  end
32
32
 
33
33
  def admin_page_title
34
- app_page_title('Administração :: ')
34
+ app_page_title(ENV['PREFIX_ADMIN_PAGE_TITLE'])
35
35
  end
36
36
 
37
37
  def devise_page_title
38
- app_page_title('Autenticação :: ')
38
+ app_page_title(ENV['PREFIX_DEVISE_PAGE_TITLE'])
39
39
  end
40
40
 
41
41
  def page_title
@@ -43,13 +43,21 @@ module Interage
43
43
  end
44
44
 
45
45
  def app_name
46
- ENV.fetch('APP_NAME', Rails.application.class.module_parent_name)
46
+ ENV.fetch('APP_NAME', t('application.name', default: rails_app_name))
47
+ end
48
+
49
+ def rails_app_name
50
+ rails_class = Rails.application.class
51
+
52
+ rails_class.try(:module_parent_name) || rails_class.parent_name
47
53
  end
48
54
 
49
55
  def env_name_upcase
50
- return if ENV['ENV_NAME'].blank?
56
+ "[#{env_name.upcase}] " if env_name.present?
57
+ end
51
58
 
52
- "[#{ENV['ENV_NAME'].upcase}] "
59
+ def env_name
60
+ ENV['ENV_NAME']
53
61
  end
54
62
  end
55
63
  end
@@ -2,24 +2,15 @@
2
2
 
3
3
  module Interage
4
4
  module ApplicationIconHelper
5
+ ALLOWED_FONT_ICONS = ['fa', 'md'].freeze
5
6
  DEFAULT_FONT_ICON = ENV.fetch('DEFAULT_FONT_ICON', 'fa')
6
7
 
7
8
  def app_icon(icon, options = {})
8
- case DEFAULT_FONT_ICON
9
- when 'fa'
10
- fa_icon(icon, options)
11
- when 'md'
12
- md_icon(icon, options)
13
- end
9
+ execute_method("#{DEFAULT_FONT_ICON}_icon", icon, options)
14
10
  end
15
11
 
16
12
  def app_icon_text(icon, text, options = {})
17
- case DEFAULT_FONT_ICON
18
- when 'fa'
19
- fa_icon_text(icon, text, options)
20
- when 'md'
21
- md_icon_text(icon, text, options)
22
- end
13
+ execute_method("#{DEFAULT_FONT_ICON}_icon_text", icon, text, options)
23
14
  end
24
15
 
25
16
  def app_icon_classes(icon, prefix, separator, options = {})
@@ -27,5 +18,11 @@ module Interage
27
18
 
28
19
  "#{prefix} #{separator}-#{icon_classes} #{options[:class]}".strip
29
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
30
27
  end
31
28
  end
@@ -39,7 +39,10 @@ module Interage
39
39
  end
40
40
 
41
41
  def text_not_found(gender, model)
42
- t("index.model.#{gender}.not_found", model: tm(model).downcase)
42
+ default_not_found = t('index.model.not_found', default: '')
43
+
44
+ t("index.model.#{gender}.not_found", model: tm(model).downcase,
45
+ default: default_not_found)
43
46
  end
44
47
 
45
48
  def text_not_found_male(model)
@@ -25,7 +25,10 @@ module Interage
25
25
  end
26
26
 
27
27
  def cocoon_default_btn_class(type)
28
- "#{DEFAULT_BTN_CLASS}#{type} text-truncate"
28
+ default_btn_class =
29
+ ENV.fetch('DEFAULT_COCOON_BTN_CLASS', DEFAULT_BTN_CLASS)
30
+
31
+ "#{default_btn_class}#{type} text-truncate"
29
32
  end
30
33
  end
31
34
  end
@@ -2,11 +2,17 @@
2
2
 
3
3
  module Interage
4
4
  module ControllerActiveHelper
5
- HTML_ACTIVE_CLASS = 'active'
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
6
11
 
7
12
  def menu_active(*controllers)
8
13
  HTML_ACTIVE_CLASS if current_controller?(*controllers)
9
14
  end
15
+ alias menu_class_active menu_active
10
16
 
11
17
  def current_controller?(*controllers)
12
18
  controllers = controllers.is_a?(Array) ? controllers : [controllers]
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Interage
4
4
  module FaviconHelper
5
- EXTENTION = 'png'
6
- FILE_NAME = 'icons/apple-touch-icon'
5
+ EXTENTION = ENV.fetch('FAVICON_EXTENTION', 'png')
6
+ FILE_NAME = ENV.fetch('FAVICON_FILE_NAME', 'icons/apple-touch-icon')
7
7
  FAVICON_SIZES = [nil, 57, 72, 76, 114, 120, 144, 152, 180].freeze
8
8
 
9
9
  def favicon_link_tags
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Interage
4
4
  module Helper
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
@@ -3,8 +3,8 @@
3
3
  module Interage
4
4
  module LinkToHelper
5
5
  ASIDE_DEFAULT_CLASS = 'list-group-item'
6
- DESTROY_CONFIRM_MESSAGE = 'Tem certeza que deseja apagar?'
7
6
  PREFIX_BUTTON_CLASS = 'btn btn-sm btn-outline-'
7
+ DESTROY_CONFIRM_MESSAGE = 'Tem certeza que deseja apagar?'
8
8
 
9
9
  def aside_link_to(text, url = '#', html_options = {})
10
10
  html_options[:class] = "#{ASIDE_DEFAULT_CLASS} #{html_options[:class]}"
@@ -39,7 +39,7 @@ module Interage
39
39
 
40
40
  def link_to_destroy(url, html_options = {})
41
41
  html_options.merge!(method: :delete,
42
- 'data-confirm' => DESTROY_CONFIRM_MESSAGE,
42
+ 'data-confirm' => destroy_confirm_message,
43
43
  class: button_class('danger', html_options[:class]))
44
44
 
45
45
  link_to_default(:destroy, url, html_options)
@@ -56,5 +56,9 @@ module Interage
56
56
  def button_class(type, addicional_class = nil)
57
57
  "#{PREFIX_BUTTON_CLASS}#{type} #{addicional_class}"
58
58
  end
59
+
60
+ def destroy_confirm_message
61
+ t('application.destroy_confirm_message', default: DESTROY_CONFIRM_MESSAGE)
62
+ end
59
63
  end
60
64
  end
@@ -18,7 +18,7 @@ module Interage
18
18
  #
19
19
  # Returns translated model.
20
20
  def translate_model_name(model, count = 1)
21
- model.model_name.human(count: count)
21
+ count.to_i > 1 ? model.model_name.human : model.model_name.human.pluralize
22
22
  end
23
23
  alias tm translate_model_name
24
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interage-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Walmir Neto
@@ -74,6 +74,7 @@ files:
74
74
  - bin/rspec
75
75
  - bin/rubocop
76
76
  - bin/setup
77
+ - interage-helper-0.1.0.gem
77
78
  - interage-helper.gemspec
78
79
  - lib/generators/interage/helper/install/USAGE
79
80
  - lib/generators/interage/helper/install/install_generator.rb