brick 1.0.207 → 1.0.208

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: 585c18ee97a6ecead8dec67a3bd9ad7ef765524bb109c72c5550f9f0dbd3b98f
4
- data.tar.gz: a0ff5371aef56af539e2022349c0b07c0cdad0bdc93dcbb35aa54a1a8ef3ae4f
3
+ metadata.gz: b119de0df1fa94e7c3a07315295c2d5fcf2871ec01e44986db6ddee784b82cf3
4
+ data.tar.gz: ba567e471502273780baeb78ed456e3b81319ce63560ccd7eaaf7ec15cb0ea21
5
5
  SHA512:
6
- metadata.gz: 73f5772ef3b440025b50c62b727a58e63392b7642f326d43e63be64f5c2d68eb9fcc1e8a0d77279f0491a284e51cdeb3ca1db90a67bf2b79d1a4f62371575c71
7
- data.tar.gz: 9c068ca26a463307b7f931ca7dcd3c4c12bb06dcc313b284a286aa509ef039b5e4efea1108be9f83839bdb84de47249b9c93a4418dcfc51fe507fd85dba0a6dd
6
+ metadata.gz: 6f0e173346e205727f94e1e33d182f2a783cc20d3496a8acb7592da9c931a1c4a9e6f32da540d78647f75b00b504df03845e17816cfd589a6dc69d73a81f56b5
7
+ data.tar.gz: 02b36babcf6958b35cf38ad8caf2147fffaf5a438f2674a541f46f0b9813ec46df05a5fe1fafcbaba96ad63a654db429d4dc245d1a1cb688b1e20070b197a374
data/lib/brick/config.rb CHANGED
@@ -258,6 +258,18 @@ module Brick
258
258
  @mutex.synchronize { @json_columns = cols }
259
259
  end
260
260
 
261
+ # Restrict all Carrierwave images when set to +true+,
262
+ # or limit to the first n number if set to an Integer
263
+ def limit_carrierwave
264
+ # When not set then by default just do a max of 50 images so that
265
+ # a grid of say 1000 things won't bring the page to its knees
266
+ @mutex.synchronize { @limit_carrierwave ||= 50 }
267
+ end
268
+
269
+ def limit_carrierwave=(num)
270
+ @mutex.synchronize { @limit_carrierwave = num }
271
+ end
272
+
261
273
  def sidescroll
262
274
  @mutex.synchronize { @sidescroll ||= {} }
263
275
  end
@@ -1,7 +1,8 @@
1
1
  module Brick::Rails::FormBuilder
2
2
  DT_PICKERS = { datetime: 'datetimepicker', timestamp: 'datetimepicker', time: 'timepicker', date: 'datepicker' }
3
3
 
4
- # When this field is one of the appropriate types, will set one of these instance variables accordingly:
4
+ # Render an editable field
5
+ # When it's one of these types, will set an appropriate instance variable truthy accordingly:
5
6
  # @_text_fields_present - To include trix editor
6
7
  # @_date_fields_present - To include flatpickr date / time editor
7
8
  # @_json_fields_present - To include JSONEditor
@@ -37,7 +38,7 @@ module Brick::Rails::FormBuilder
37
38
  "<span class=\"orphan\">Orphaned ID: #{val}</span>".html_safe
38
39
  end
39
40
  out << bt_link if bt_link
40
- elsif @_brick_monetized_attributes&.include?(method)
41
+ elsif model._brick_monetized_attributes&.include?(method)
41
42
  out << self.text_field(method.to_sym, html_options.merge({ value: Money.new(val.to_i).format }))
42
43
  else
43
44
  col_type = if model.json_column?(col) || val.is_a?(Array)
@@ -51,12 +52,12 @@ module Brick::Rails::FormBuilder
51
52
  when :string, :text, :citext,
52
53
  :enum # Support for the activerecord-mysql-enum gem
53
54
  spit_out_text_field = nil
54
- if ::Brick::Rails::FormBuilder.is_bcrypt?(val) # || .readonly?
55
+ if ::Brick::Rails.is_bcrypt?(val) # || .readonly?
55
56
  is_revert = false
56
- out << ::Brick::Rails::FormBuilder.hide_bcrypt(val, nil, 1000)
57
+ out << ::Brick::Rails.hide_bcrypt(val, nil, 1000)
57
58
  elsif col_type == :string
58
59
  if model.respond_to?(:uploaders) && model.uploaders.key?(col.name&.to_sym) &&
59
- (url = self.object.send(col.name)&.url) # Carrierwave image?
60
+ (url = self.object.send(col.name)&.url) # Carrierwave image?
60
61
  out << "<img src=\"#{url}\" title=\"#{val}\">"
61
62
  elsif model.respond_to?(:enumerized_attributes) && (opts = (attr = model.enumerized_attributes[method])&.options).present?
62
63
  enum_html_options = attr.kind_of?(Enumerize::Multiple) ? html_options.merge({ multiple: true, size: opts.length + 1 }) : html_options
@@ -139,74 +140,4 @@ module Brick::Rails::FormBuilder
139
140
  "
140
141
  out.html_safe
141
142
  end # brick_field
142
-
143
- # --- CLASS METHODS ---
144
-
145
- def self.is_bcrypt?(val)
146
- val.is_a?(String) && val.length == 60 && val.start_with?('$2a$')
147
- end
148
-
149
- def self.hide_bcrypt(val, is_xml = nil, max_len = 200)
150
- if ::Brick::Rails::FormBuilder.is_bcrypt?(val)
151
- '(hidden)'
152
- else
153
- if val.is_a?(String)
154
- return ::Brick::Rails.display_binary(val) unless (val_utf8 = val.dup.force_encoding('UTF-8')).valid_encoding?
155
-
156
- val = val_utf8.strip
157
- return CGI.escapeHTML(val) if is_xml
158
-
159
- if val.length > max_len
160
- if val[0] == '<' # Seems to be HTML?
161
- cur_len = 0
162
- cur_idx = 0
163
- # Find which HTML tags we might be inside so we can apply ending tags to balance
164
- element_name = nil
165
- in_closing = nil
166
- elements = []
167
- val.each_char do |ch|
168
- case ch
169
- when '<'
170
- element_name = +''
171
- when '/' # First character of tag is '/'?
172
- in_closing = true if element_name == ''
173
- when '>'
174
- if element_name
175
- if in_closing
176
- if (idx = elements.index { |tag| tag.downcase == element_name.downcase })
177
- elements.delete_at(idx)
178
- end
179
- elsif (tag_name = element_name.split.first).present?
180
- elements.unshift(tag_name)
181
- end
182
- element_name = nil
183
- in_closing = nil
184
- end
185
- else
186
- element_name << ch if element_name
187
- end
188
- cur_idx += 1
189
- # Unless it's inside wickets then this is real text content, and see if we're at the limit
190
- break if element_name.nil? && ((cur_len += 1) > max_len)
191
- end
192
- val = val[0..cur_idx]
193
- # Somehow still in the middle of an opening tag right at the end? (Should never happen)
194
- if !in_closing && (tag_name = element_name&.split&.first)&.present?
195
- elements.unshift(tag_name)
196
- val << '>'
197
- end
198
- elements.each do |closing_tag|
199
- val << "</#{closing_tag}>"
200
- end
201
- else # Not HTML, just cut it at the length
202
- val = val[0...max_len]
203
- end
204
- val = "#{val}..."
205
- end
206
- val
207
- else
208
- val.to_s
209
- end
210
- end
211
- end
212
143
  end
@@ -229,11 +229,18 @@ module Brick::Rails::FormTags
229
229
  end
230
230
  end
231
231
  elsif (col = cols[col_name]).is_a?(ActiveRecord::ConnectionAdapters::Column)
232
- # binding.pry if col.is_a?(Array)
233
232
  out << if klass._brick_monetized_attributes&.include?(col_name)
234
233
  val ? Money.new(val.to_i).format : ''
235
234
  elsif klass.respond_to?(:uploaders) && klass.uploaders.key?(col_name.to_sym) &&
236
- (url = obj.send(col_name)&.url) # Carrierwave image?
235
+ (url = obj.send(col.name)&.url) && # Carrierwave image?
236
+ # And either not restricting Carrierwave, or under the defined Carrierwave image limit?
237
+ (!(limit_carrierwave = ::Brick.config.limit_carrierwave) ||
238
+ (limit_carrierwave.is_a?(Numeric) &&
239
+ (carrierwave_count = instance_variable_get(:@_carrierwave_count) || 0) &&
240
+ ((carrierwave_count += 1) < limit_carrierwave) &&
241
+ instance_variable_set(:@_carrierwave_count, carrierwave_count)
242
+ )
243
+ )
237
244
  "<img class=\"thumbImg\" src=\"#{url}\" title=\"#{val}\">"
238
245
  else
239
246
  lat_lng = if [:float, :decimal].include?(col.type) &&
@@ -663,6 +670,7 @@ btnAddCol.addEventListener(\"click\", function () {
663
670
 
664
671
  private
665
672
 
673
+ # Dig through all instance variables with hopes to find any that appear related to ActiveRecord
666
674
  def _brick_resource_from_iv(trim_ampersand = false)
667
675
  instance_variables.each_with_object(Hash.new { |h, k| h[k] = [] }) do |name, s|
668
676
  iv_name = trim_ampersand ? name.to_s[1..-1] : name
@@ -5,6 +5,9 @@ require 'brick/frameworks/rails/engine'
5
5
 
6
6
  module ::Brick::Rails
7
7
  class << self
8
+ # Low-level way to render read-only data for a field based on its data type.
9
+ # Used by both brick_grid and brick_form_for (which gets down to this low-level
10
+ # implementation from brick_field).
8
11
  def display_value(col_type, val, lat_lng = nil)
9
12
  is_mssql_geography = nil
10
13
  # Some binary thing that really looks like a Microsoft-encoded WGS84 point? (With the first two bytes, E6 10, indicating an EPSG code of 4326)
@@ -68,10 +71,10 @@ module ::Brick::Rails
68
71
  "<a href=\"https://www.google.com/maps/place/#{lat_lng.first}+#{lat_lng.last}/@#{lat_lng.first},#{lat_lng.last},12z\" target=\"blank\">#{val}</a>"
69
72
  elsif val.is_a?(Numeric) && ::ActiveSupport.const_defined?(:NumberHelper)
70
73
  ::ActiveSupport::NumberHelper.number_to_delimited(val, delimiter: ',')
71
- else
72
- ::Brick::Rails::FormBuilder.hide_bcrypt(val, col_type == :xml)
74
+ else # Text or HTML based content
75
+ ::Brick::Rails.hide_bcrypt(val, col_type == :xml)
73
76
  end
74
- else
77
+ else # Don't take chances if we can't figure out the data type
75
78
  '?'
76
79
  end
77
80
  end
@@ -172,7 +175,7 @@ erDiagram
172
175
  def dt_lookup(dt)
173
176
  { 'integer' => 'int', }[dt] || dt&.tr(' ', '_') || 'int'
174
177
  end
175
- callbacks.merge({#{model_short_name} => #{model.name}}).each do |cb_k, cb_class|
178
+ callbacks.merge({#{model_short_name.inspect} => #{model.name}}).each do |cb_k, cb_class|
176
179
  cb_relation = ::Brick.relations[cb_class.table_name]
177
180
  pkeys = cb_relation[:pkey]&.first&.last
178
181
  fkeys = cb_relation[:fks]&.values&.each_with_object([]) { |fk, s| s << fk[:fk] if fk.fetch(:is_bt, nil) }
@@ -201,8 +204,80 @@ erDiagram
201
204
  </div>
202
205
  "
203
206
  end
207
+
208
+ # Render text or HTML without exposing password details
209
+ def hide_bcrypt(val, is_xml = nil, max_len = 200)
210
+ if ::Brick::Rails.is_bcrypt?(val)
211
+ '(hidden)'
212
+ else
213
+ if val.is_a?(String)
214
+ return ::Brick::Rails.display_binary(val) unless (val_utf8 = val.dup.force_encoding('UTF-8')).valid_encoding?
215
+
216
+ val = val_utf8.strip
217
+ return CGI.escapeHTML(val) if is_xml
218
+
219
+ if val.length > max_len
220
+ if val[0] == '<' # Seems to be HTML?
221
+ cur_len = 0
222
+ cur_idx = 0
223
+ # Find which HTML tags we might be inside so we can apply ending tags to balance
224
+ element_name = nil
225
+ in_closing = nil
226
+ elements = []
227
+ val.each_char do |ch|
228
+ case ch
229
+ when '<'
230
+ element_name = +''
231
+ when '/' # First character of tag is '/'?
232
+ in_closing = true if element_name == ''
233
+ when '>'
234
+ if element_name
235
+ if in_closing
236
+ if (idx = elements.index { |tag| tag.downcase == element_name.downcase })
237
+ elements.delete_at(idx)
238
+ end
239
+ elsif (tag_name = element_name.split.first).present?
240
+ elements.unshift(tag_name)
241
+ end
242
+ element_name = nil
243
+ in_closing = nil
244
+ end
245
+ else
246
+ element_name << ch if element_name
247
+ end
248
+ cur_idx += 1
249
+ # Unless it's inside wickets then this is real text content, and see if we're at the limit
250
+ break if element_name.nil? && ((cur_len += 1) > max_len)
251
+ end
252
+ val = val[0..cur_idx]
253
+ # Somehow still in the middle of an opening tag right at the end? (Should never happen)
254
+ if !in_closing && (tag_name = element_name&.split&.first)&.present?
255
+ elements.unshift(tag_name)
256
+ val << '>'
257
+ end
258
+ elements.each do |closing_tag|
259
+ val << "</#{closing_tag}>"
260
+ end
261
+ else # Not HTML, just cut it at the length
262
+ val = val[0...max_len]
263
+ end
264
+ val = "#{val}..."
265
+ end
266
+ val
267
+ else
268
+ val.to_s
269
+ end
270
+ end
271
+ end
272
+
273
+ # Password type data?
274
+ def is_bcrypt?(val)
275
+ val.is_a?(String) && val.length == 60 && val.start_with?('$2a$')
276
+ end
204
277
  end
205
278
 
279
+ # CONSTANTS
280
+
206
281
  AVO_SVG = "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 84 90\" height=\"30\" fill=\"#3096F7\">
207
282
  <path d=\"M83.8304 81.0201C83.8343 82.9343 83.2216 84.7996 82.0822 86.3423C80.9427 87.8851 79.3363 89.0244 77.4984 89.5931C75.6606 90.1618 73.6878 90.1302 71.8694 89.5027C70.0509 88.8753 68.4823 87.6851 67.3935 86.1065L67.0796 85.6029C66.9412 85.378 66.8146 85.1463 66.6998 84.9079L66.8821 85.3007C64.1347 81.223 60.419 77.8817 56.0639 75.5723C51.7087 73.263 46.8484 72.057 41.9129 72.0609C31.75 72.0609 22.372 77.6459 16.9336 85.336C17.1412 84.7518 17.7185 83.6137 17.9463 83.0446L19.1059 80.5265L19.1414 80.456C25.2533 68.3694 37.7252 59.9541 52.0555 59.9541C53.1949 59.9541 54.3241 60.0095 55.433 60.1102C60.748 60.6134 65.8887 62.2627 70.4974 64.9433C75.1061 67.6238 79.0719 71.2712 82.1188 75.6314C82.1188 75.6314 82.1441 75.6717 82.1593 75.6868C82.1808 75.717 82.1995 75.749 82.215 75.7825C82.2821 75.8717 82.3446 75.9641 82.4024 76.0595C82.4682 76.1653 82.534 76.4221 82.5999 76.5279C82.6657 76.6336 82.772 76.82 82.848 76.9711L83.1822 77.7063C83.6094 78.7595 83.8294 79.8844 83.8304 81.0201V81.0201Z\" fill=\"currentColor\" fill-opacity=\"0.22\"></path>
208
283
  <path opacity=\"0.25\" d=\"M83.8303 81.015C83.8354 82.9297 83.2235 84.7956 82.0844 86.3393C80.9453 87.8829 79.339 89.0229 77.5008 89.5923C75.6627 90.1617 73.6895 90.1304 71.8706 89.5031C70.0516 88.8758 68.4826 87.6854 67.3935 86.1065L67.0796 85.6029C66.9412 85.3746 66.8146 85.1429 66.6998 84.9079L66.8821 85.3007C64.1353 81.222 60.4199 77.8797 56.0647 75.5695C51.7095 73.2593 46.8488 72.0524 41.9129 72.0558C31.75 72.0558 22.372 77.6408 16.9336 85.3309C17.1412 84.7467 17.7185 83.6086 17.9463 83.0395L19.1059 80.5214L19.1414 80.4509C22.1906 74.357 26.8837 69.2264 32.6961 65.6326C38.5086 62.0387 45.2114 60.1232 52.0555 60.1001C53.1949 60.1001 54.3241 60.1555 55.433 60.2562C60.7479 60.7594 65.8887 62.4087 70.4974 65.0893C75.1061 67.7698 79.0719 71.4172 82.1188 75.7775C82.1188 75.7775 82.1441 75.8177 82.1593 75.8328C82.1808 75.863 82.1995 75.895 82.215 75.9285C82.2821 76.0177 82.3446 76.1101 82.4024 76.2055L82.5999 76.5228C82.6859 76.6638 82.772 76.8149 82.848 76.966L83.1822 77.7012C83.6093 78.7544 83.8294 79.8793 83.8303 81.015Z\" fill=\"currentColor\" fill-opacity=\"0.22\"></path>
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 207
8
+ TINY = 208
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.207
4
+ version: 1.0.208
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
285
  - !ruby/object:Gem::Version
286
286
  version: 1.3.6
287
287
  requirements: []
288
- rubygems_version: 3.2.33
288
+ rubygems_version: 3.1.6
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: Create a Rails app from data alone