friendly_extensions 0.0.71 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c112e084650a0464425679769379135b2cfadd8
4
- data.tar.gz: 857df7a209fdef6f8d2ee11823b145bf7f657152
3
+ metadata.gz: e7b1ca5293bcb617700934876a5c43e21c240bac
4
+ data.tar.gz: d6b41b1cf2c6417db165dbf2f58b21ac386e2ffd
5
5
  SHA512:
6
- metadata.gz: ff57dbda09d50cd9561eec04eb621a1d999a836a6afc3f52b2c73f1b98272ddde8056e8b8262439e8ef8138a9bbffd353510db5099c06b0815658ed037ef0ed8
7
- data.tar.gz: 2aade519472fa2d1c89ab8e234121643d8d6b2dfb754d8ef025411aebd2f81d40db948d7b867978553a69616509da3290034157f9e51501195c4e84447c82f7b
6
+ metadata.gz: d9b1b332adc49512ffd7e74316c5840613f98190b4328f081d34602dfdef61b1c04bcc7a66282b3826a2a245c3a8c32554581bab9fd0e455490e19dcf089df44
7
+ data.tar.gz: e08416826e7554d3a32b43ea400b3df576f7c33761e42e7dac8b8b77d2d86951a60e3aa60617089ba30cd40b8353500b79d56cfc7e5cdd3a582f74e66a779d34
@@ -7,9 +7,9 @@ module FriendsLabeledFormHelper
7
7
 
8
8
  def label_tag_for(object_name, method, options = {})
9
9
  label_name = (options[:label].blank? ? method.to_label : options[:label])
10
-
10
+
11
11
  label_name += options[:append] unless options[:append].nil?
12
-
12
+
13
13
  label_text = "<span class='label-text'>#{label_name}</span>"
14
14
 
15
15
  if options[:errors]
@@ -20,13 +20,13 @@ module FriendsLabeledFormHelper
20
20
  # Setting Tooltip format for display in Browsertooltip
21
21
  # line breaks in unicode
22
22
  tooltip = tooltip.gsub(/\n|\<br(\ )?(\/)?\>/, "&#xA;")
23
- # single to double quotes
23
+ # single to double quotes
24
24
  tooltip = tooltip.gsub("'", '"')
25
25
  label_text << tooltip_box(tooltip)
26
- end
27
- end
28
-
29
-
26
+ end
27
+ end
28
+
29
+
30
30
  label_options = {}
31
31
  label_options.merge!(:class => options[:class]) unless options[:class].blank?
32
32
  label_options.merge!(:for => options[:for]) unless options[:for].blank?
@@ -36,26 +36,26 @@ module FriendsLabeledFormHelper
36
36
  end
37
37
 
38
38
  def labeled_text_field(object_name, method, options={})
39
-
39
+
40
40
  if options[:id]
41
41
  label_options = options.merge(:id => "label-#{options[:id]}")
42
42
  else
43
43
  label_options = options
44
- end
45
-
44
+ end
45
+
46
46
  html = label_tag_for(object_name, method, label_options)
47
47
  if options[:password] && options.delete(:password)
48
48
  html += password_field(object_name, method, options)
49
- else
49
+ else
50
50
  html += text_field(object_name, method, options)
51
- end
51
+ end
52
52
  return html.html_safe
53
53
  end
54
54
 
55
55
  def labeled_check_box(object_name, method, options={}, checked_value=1, unchecked_value=0)
56
56
  method = method.to_s.to_sym
57
57
  box_id = object_name.to_s+"_"+method.to_s
58
-
58
+
59
59
  html = "<div class='cf labeled-check-box'>"
60
60
  html += "<div class='checkbox-container'>#{check_box(object_name, method, options.merge!(:id => box_id), checked_value, unchecked_value)}</div>"
61
61
  html += "<div class='checkbox-label-container'>#{label_tag_for(object_name, method, :label => options[:label], :tooltip => options[:tooltip], :class => "checkbox-label", :for => box_id, :errors => options[:errors])}</div>"
@@ -75,20 +75,24 @@ module FriendsLabeledFormHelper
75
75
  html << label_tag_for(object_name, method, {:label => options[:label], :for => options[:id]})
76
76
  html << "</div>"
77
77
  return raw(html)
78
- end
78
+ end
79
79
 
80
80
  end
81
81
 
82
82
  module FriendsLabeledFormBuilder
83
-
83
+
84
84
  def label_tag_for(method, options = {})
85
+ options[:label] ||= object.class.try(:human_attribute_name, method)
85
86
  @template.label_tag_for(@object_name, method, options)
86
- end
87
-
87
+ end
88
+
88
89
 
89
90
  def labeled_radio_button(method, value, options ={})
90
91
  options[:checked] = (object.send(method) == value) if options[:checked].nil?
91
92
 
93
+ # try auto-setting label
94
+ options[:label] ||= object.class.try(:human_attribute_name, method)
95
+
92
96
  options[:class] ||= ""
93
97
  options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )
94
98
  options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )
@@ -100,25 +104,29 @@ module FriendsLabeledFormBuilder
100
104
  def labeled_check_box(method, options = {}, checked_value=1, unchecked_value=0)
101
105
 
102
106
  options[:class] ||= ""
107
+ options[:label] ||= object.class.try(:human_attribute_name, method)
108
+
103
109
  options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )
104
110
  options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )
105
111
 
106
112
  options[:checked] ||= ((object.send(method) rescue false) || options[:checked])
107
113
  @template.labeled_check_box(@object_name, method, options, checked_value, unchecked_value)
108
- end
114
+ end
109
115
 
110
116
 
111
117
  def labeled_text_field(method, options = {})
112
118
 
113
119
  options[:value] ||= (object.send(method) rescue nil )
120
+ options[:label] ||= object.class.try(:human_attribute_name, method)
121
+
114
122
  options[:class] ||= ""
115
123
  options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )
116
124
 
117
125
  options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )
118
126
 
119
127
  @template.labeled_text_field(@object_name, method, options)
120
- end
128
+ end
121
129
 
122
- end
130
+ end
123
131
 
124
132
 
@@ -1,9 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  class FriendsLabel < ActiveRecord::Base
3
-
3
+
4
4
  validates_uniqueness_of :attribute_name
5
-
6
-
7
5
 
8
6
  labels = {}
9
7
 
@@ -11,12 +9,11 @@ class FriendsLabel < ActiveRecord::Base
11
9
  concept_labels = FriendsLabel.all
12
10
  concept_labels.each {|l| labels.merge!(l.attribute_name => {:label => l.label, :tooltip => l.tooltip, :docu_tooltip => l.tooltip_docu})}
13
11
  end
14
-
12
+
15
13
  LABELS = labels
16
-
17
-
14
+
18
15
  def is_unset?
19
16
  return (!(self.attribute_name == self.label)).to_s
20
- end
17
+ end
21
18
 
22
19
  end
@@ -0,0 +1,4 @@
1
+ de:
2
+ friendly_extensions:
3
+ 'is_true': 'Ja'
4
+ 'is_false': 'Nein'
@@ -0,0 +1,4 @@
1
+ en:
2
+ friendly_extensions:
3
+ 'is_true': 'yes'
4
+ 'is_false': 'no'
@@ -0,0 +1,7 @@
1
+ class DropFriendsLabels < ActiveRecord::Migration
2
+
3
+ def change
4
+ drop_table "friends_labels"
5
+ end
6
+
7
+ end
@@ -1,21 +1,17 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # Functions for True/FalseClass
4
1
  module Boolean
5
2
  [TrueClass, FalseClass].each do |bclass|
6
-
7
3
  bclass.class_eval do
8
-
4
+
9
5
  # return string if true/false
10
- def to_real(t = "ja", f = "nein")
6
+ def to_real(t = I18n.t('friendly_extensions.is_true'), f = I18n.t('friendly_extensions.is_false'))
11
7
  case self
12
8
  when TrueClass
13
9
  return t
14
10
  else
15
11
  return f
16
- end
17
- end
18
-
12
+ end
13
+ end
14
+
19
15
  # return integer if true/false
20
16
  def to_i
21
17
  case self
@@ -23,10 +19,9 @@ module Boolean
23
19
  return 1
24
20
  else
25
21
  return 0
26
- end
22
+ end
27
23
  end
28
-
29
- end
30
24
 
31
- end
32
- end
25
+ end
26
+ end
27
+ end
@@ -1,16 +1,16 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module StringAndMore
3
3
  String.class_eval do
4
-
4
+
5
5
  require "chars_2_remove"
6
6
  require 'digest/sha1'
7
-
7
+
8
8
  # List with internation chars and their ASCII replacement
9
9
  CHARS_TO_REMOVE = Chars2Remove::CHARS
10
-
10
+
11
11
  # Characters for creating randdom char combinations
12
12
  String::RANDOM_CHARS = {:upcase => "ABCDEFGHIJKLMNOPQRSTUVWXYZ", :downcase => "abcdefghijklmnopqrstuvwxyz", :numbers => "1234567890"}
13
-
13
+
14
14
  # String charsets used for numeric encryption
15
15
  STRING_CHARSETS = {
16
16
  "a" => String::RANDOM_CHARS[:upcase],
@@ -19,14 +19,14 @@ module StringAndMore
19
19
  "ä" => "äöüÄÖÜß",
20
20
  "!" => '!\"§$%&/()=?+*#@,.-;:_\' ¡“”¶¢[]|{}≠¿^°≤≥∞…–‘’<>'
21
21
  }
22
-
22
+
23
23
  # Array with all strings which can be encrypted
24
24
  STRING_BASE = STRING_CHARSETS.values.join("")
25
-
25
+
26
26
  # Encode String Base with custom secrect key
27
27
  #SHUFFLED_STRING_BASE = STRING_CHARSETS.values.sort_by {|y| STRING_CHARSETS.values.map.with_index {|x,i| STRING_BASE.split("").reverse[i].hex * x.hex }[STRING_CHARSETS.values.index(y)] }
28
-
29
-
28
+
29
+
30
30
  # Returns random String, for Passwords, Captachs etc..
31
31
  # could create :upcase, :downcase, :numbers or :all
32
32
  def self.random_string(l=12, mode = :all)
@@ -36,20 +36,20 @@ module StringAndMore
36
36
  else
37
37
  base = String::RANDOM_CHARS[mode].split("")
38
38
  end
39
-
39
+
40
40
  str = ""
41
-
42
- l.times do
41
+
42
+ l.times do
43
43
  str << base.shuffle[rand(base.size-1)]
44
- end
44
+ end
45
45
  return str
46
46
  end
47
-
47
+
48
48
  def self.email_message_id(mail_domain)
49
49
  "<#{Digest::SHA2.hexdigest(Time.now.to_i.to_s)}@#{mail_domain}>"
50
- end
51
-
52
-
50
+ end
51
+
52
+
53
53
  # Extract boolean status from string
54
54
  def to_boolean
55
55
  if ['true', 'True', 'TRUE', '1'].include?(self)
@@ -58,63 +58,36 @@ module StringAndMore
58
58
  return false
59
59
  end
60
60
  end
61
-
62
- # Create string with german date format to Date
61
+
63
62
  def to_date
64
- # Try German
65
- matched_date = self.match(/((0|1|2|3)[0-9]{1})\.(0[0-9]{1}|10|11|12)\.[0-9]{4}/)
66
-
67
- if !matched_date.nil?
68
- return Date.new(matched_date.to_s.split(".")[2].to_i, matched_date.to_s.split(".")[1].to_i, matched_date.to_s.split(".")[0].to_i)
69
- elsif matched_date.nil?
70
- matched_date = self.match(/[0-9]{4}-(0[0-9]{1}|10|11|12)-((0|1|2|3)[0-9]{1})/)
71
- if !matched_date.nil?
72
- return Date.new(matched_date.to_s.split("-")[0].to_i, matched_date.to_s.split("-")[1].to_i, matched_date.to_s.split("-")[2].to_i)
73
- end
74
- end
75
-
76
- raise ArgumentError, "String has no date like DD.MM.YYYY or YYYY-DD-MM" if matched_date.nil?
63
+ Date.parse(self)
77
64
  end
78
-
79
-
65
+
66
+
80
67
  def to_number(type = :float)
81
68
  extract = self.match(/[0-9\.,]{1,}/).to_s
82
69
  final = extract.gsub(".", "").gsub(",", ".")
83
- case type
70
+ case type
84
71
  when :float
85
72
  return final.to_f
86
73
  else
87
74
  return final.to_i
88
- end
89
- end
90
-
75
+ end
76
+ end
77
+
91
78
  def to_label(options = {:show_tooltip => false})
92
- if FriendsLabel.table_exists?
93
- l = FriendsLabel::LABELS[self]
94
- if l.nil?
95
- FriendsLabel.create(:label => self, :attribute_name => self)
96
- return self
97
- else
98
- unless options[:show_tooltip] == true
99
- return l[:label]
100
- else
101
- return l[:tooltip]
102
- end
103
- end
104
- else
105
- return self
106
- end
79
+ I18n.t("friendly_labels.#{options[:show_tooltip] == true ? 'label_tooltips' : 'labels'}.#{self.downcase}")
107
80
  end
108
-
81
+
109
82
  def shuffle
110
83
  self.split("").sort_by {rand}.join.humanize
111
- end
112
-
113
-
84
+ end
85
+
86
+
114
87
  def to_foldername(sep = "_")
115
88
  # deutsch umlaute ersetzen
116
89
  parameterized_string = self.strip.gsub(/\ {2,}/ , " ").de_2_int
117
-
90
+
118
91
  # Turn unwanted chars into the separator
119
92
  parameterized_string.gsub!(/[^a-zA-Z0-9ÄÖÜöäüß\-_]+/, sep)
120
93
  unless sep.nil? || sep.empty?
@@ -126,99 +99,99 @@ module StringAndMore
126
99
  end
127
100
  return parameterized_string
128
101
  end
129
-
130
-
131
-
102
+
103
+
104
+
132
105
  def de_2_int
133
106
  str = self
134
107
  CHARS_TO_REMOVE.each do |de, int|
135
108
  str = str.gsub(de, int)
136
109
  end
137
110
  str = str.gsub(" ", " ")
138
- return str
111
+ return str
139
112
  end
140
-
113
+
141
114
  def limit(l=20)
142
115
  if self.size > l
143
116
  s = self.size
144
117
  s2 = (((self.size-1)/2).round)
145
118
  first = self.slice(0..s2)
146
119
  last = self.slice(s2+1..-1)
147
-
120
+
148
121
  l1 = (l/2).round
149
-
122
+
150
123
  "#{first.first(l1)}...#{last.last(l1)}"
151
124
  else
152
125
  return self
153
- end
154
- end
155
-
156
-
157
-
158
-
126
+ end
127
+ end
128
+
129
+
130
+
131
+
159
132
  def to_datetime
160
133
  date = self.split(" ").first
161
134
  time = self.split(" ").last.split(":")
162
135
  DateTime.new(date.split(".")[2].to_i, date.split(".")[1].to_i, date.split(".")[0].to_i, time.first.to_i, time.last.to_i)
163
- end
164
-
165
-
136
+ end
137
+
138
+
166
139
  def clear_html(options = {})
167
140
  ActionView::Base.full_sanitizer.sanitize(self, :tags => options[:tags] )
168
141
  end
169
-
142
+
170
143
  def replace_html(from, to)
171
144
  new_text = self
172
145
  new_text = new_text.gsub("<#{from}>", "<#{to}>")
173
146
  new_text = new_text.gsub("</#{from}>", "</#{to}>")
174
147
  return new_text
175
- end
176
-
148
+ end
149
+
177
150
  def to_model
178
151
  self.singularize.camelize.constantize
179
- end
180
-
152
+ end
153
+
181
154
  def to_a
182
155
  return [self]
183
- end
184
-
156
+ end
157
+
185
158
  #== HTML Styling
186
159
  # as the function names say
187
-
160
+
188
161
  def bold
189
162
  "<b>#{self}</b>".html_safe
190
163
  end
191
-
164
+
192
165
  def ital
193
166
  "<i>#{self}</i>".html_safe
194
167
  end
195
-
168
+
196
169
  def span
197
170
  "<span>#{self}</span>".html_safe
198
171
  end
199
-
172
+
200
173
  def uline
201
174
  "<u>#{self}</u>".html_safe
202
- end
203
-
175
+ end
176
+
204
177
  def nbsp
205
178
  self.gsub(" ", "&nbsp;").html_safe
206
- end
207
-
179
+ end
180
+
208
181
  def replace_entities(mode = :html, options = {})
209
182
  str = self
210
183
  Chars2Remove::ENTITIES.each do |orig, rep|
211
184
  str = str.gsub(orig, rep[mode])
212
185
  end
213
- return str.html_safe
186
+ return str.html_safe
214
187
  end
215
-
188
+
216
189
  def add_brs
217
190
  return self.gsub("\n", "<br />")
218
- end
219
-
191
+ end
192
+
220
193
  #== colorization in console
221
-
194
+
222
195
  def colorize(color_code)
223
196
  "\e[#{color_code};40m#{self}\e[0m"
224
197
  end
@@ -238,19 +211,19 @@ module StringAndMore
238
211
  def pink
239
212
  colorize(35)
240
213
  end
241
-
242
-
214
+
215
+
243
216
  #== Numerische encription
244
217
  # cool thing for simple encrypt and decrypt strings
245
-
218
+
246
219
  def numberize(options = {})
247
220
  # Basisarray das alle zeichen enthält die verschlüsselt werden können
248
221
  string_array = STRING_BASE.split("")
249
-
222
+
250
223
  if options[:token]
251
224
  string_array = string_array.sort_by {|x| x.hash*options[:token].inspect.bytes.join("").to_i}
252
- end
253
-
225
+ end
226
+
254
227
  # Nur Zahlen und buchstaben für die verschlüsselung/mix nehmen wg. URLs
255
228
  string_array_filtered = string_array.select {|s| !s.match(/[a-zA-Z0-9\-_]/).nil? }
256
229
  splitted = self.split("")
@@ -261,41 +234,37 @@ module StringAndMore
261
234
  position = string_array.index(s)
262
235
  if !position.nil?
263
236
  numbered_string << (position.to_s.rjust(2, "0")+string_array_filtered[rand(string_array_filtered.size-1)])
264
- end
237
+ end
265
238
  end
266
239
 
267
- return options[:base_64] == true ? Base64.encode64(numbered_string) : numbered_string
268
- end
269
-
240
+ return options[:base_64] == true ? Base64.encode64(numbered_string) : numbered_string
241
+ end
242
+
270
243
  def denumberize(options = {})
271
244
  string_array = STRING_BASE.split("")
272
-
245
+
273
246
  if options[:token]
274
247
  string_array = string_array.sort_by {|x| x.hash*options[:token].inspect.bytes.join("").to_i}
275
- end
276
-
248
+ end
249
+
277
250
  real_string = ""
278
251
  (options[:base_64] == true ? Base64.decode64(self) : self ).scan(/[0-9]{2}.{1}/).each do |s|
279
252
  real_string << string_array[s.first(2).to_i]
280
253
  end
281
- return real_string
254
+ return real_string
282
255
  end
283
-
284
-
285
-
286
-
287
-
256
+
288
257
  end
289
-
258
+
290
259
 
291
260
  Symbol.class_eval do
292
261
 
293
262
  def to_label(options = {})
294
263
  self.to_s.to_label(options)
295
264
  end
296
-
297
- def gsub(old, repl)
265
+
266
+ def gsub(old, repl)
298
267
  self.to_s.gsub(old, repl)
299
- end
300
- end
268
+ end
269
+ end
301
270
  end
@@ -0,0 +1,22 @@
1
+ namespace :friendly_extensions do
2
+
3
+ desc "copy gems from database to yaml file"
4
+ task :migrate_old_labels => :environment do
5
+
6
+ labels_hash = { 'labels' => {}, 'label_tooltips' => {}}
7
+
8
+ FriendsLabel.all.each do |label|
9
+ labels_hash['labels'].merge!(label.attribute_name => label.label)
10
+ labels_hash['label_tooltips'].merge!(label.attribute_name => label.tooltip) unless label.tooltip.blank?
11
+ end
12
+
13
+ yaml_hash = {I18n.default_locale.to_s => { 'friendly_labels' => labels_hash } }
14
+
15
+ yaml_output_path = "#{Rails.root}/config/locales/friendly_labels.#{I18n.default_locale}.yml"
16
+
17
+ File.open(yaml_output_path, 'wb+') do |f|
18
+ f.puts YAML::dump(yaml_hash)
19
+ f.close
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.71
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Eck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-19 00:00:00.000000000 Z
11
+ date: 2016-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -26,7 +26,7 @@ dependencies:
26
26
  version: '0'
27
27
  description: Adds serveral cool features to your Ruby classes. Includes new features
28
28
  for Array, String, Hash, Numeric, Date/Datetime and some more.
29
- email: it-support@friends-systems.de
29
+ email: florian.eck@el-digital.de
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
@@ -35,7 +35,9 @@ files:
35
35
  - app/helpers/friends_labeled_form_helper.rb
36
36
  - app/models/friends_label.rb
37
37
  - config/initializers/values.rb
38
- - db/migrate/20140326005600_create_labels.rb
38
+ - config/locales/friendly_extensions.de.yml
39
+ - config/locales/friendly_extensions.en.yml
40
+ - db/migrate/001_drop_friends_labels.rb
39
41
  - lib/alphanumeric.rb
40
42
  - lib/array.rb
41
43
  - lib/boolean.rb
@@ -48,6 +50,7 @@ files:
48
50
  - lib/numbers.rb
49
51
  - lib/smart_currency.rb
50
52
  - lib/string_and_more.rb
53
+ - lib/tasks/friendly_extentions.rake
51
54
  - test/array_test.rb
52
55
  - test/array_test.rb.orig
53
56
  - test/dummy_class.rb
@@ -74,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
77
  version: '0'
75
78
  requirements: []
76
79
  rubyforge_project:
77
- rubygems_version: 2.2.1
80
+ rubygems_version: 2.4.3
78
81
  signing_key:
79
82
  specification_version: 4
80
83
  summary: Collection of useful features for Ruby/Rails Classes
@@ -1,13 +0,0 @@
1
- class CreateLabels < ActiveRecord::Migration
2
-
3
- def change
4
- create_table "friends_labels", :force => true do |t|
5
- t.string "attribute_name"
6
- t.string "label"
7
- t.text "tooltip"
8
- t.text "tooltip_docu"
9
- t.text "search_tags"
10
- end
11
- end
12
-
13
- end