brick 1.0.131 → 1.0.132

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: 6e9356edd43a6af6120f30bfbcd520383f3ae700e6ff04be11ebdd3493852ef4
4
- data.tar.gz: a099075c53acc9bf29c718043cc619b5ab4f895366f9c7ddd14d53c8f7f432b8
3
+ metadata.gz: '08cc0b19ab0838b667534f4de64f3a7045bf395202a3602981a20ececdc91ab5'
4
+ data.tar.gz: 4b976489a05bb26c3702746700025c6bad3bb930fc129ae897bc9e1596a50901
5
5
  SHA512:
6
- metadata.gz: 9f9df598bad9ce128a88f4fe364d568be8c38eee57e595024866d39a255b42f513a26adc68d64d14cdecd4b5d13fb7424935f17df7dbb41c3bda2ae31057a4c7
7
- data.tar.gz: 845e5747a916a338ee494426e4ef0ac6fd5c65c3579df0210c8a80468887fac12103407acfbaee3659b3b45763f98ef0bd109935d70920b932b4fd41cc15fdc5
6
+ metadata.gz: 580db611d4ab9e2bf7ab0ed62a90940b90a4818619a9a91788802f017845c0aef3c8da1b01ea8a6a87c8e1af8378dc5c0d030396ebebba05d101b46ca0bd4495
7
+ data.tar.gz: fe876de91852b7213fa4d35b378935c7f18e18ae09ff5058f0d34b32dcb3c802a15d1c2cc79f63f7b5eac4177b7bbbeae43603e55499447cfee9e1d3556f64fa
@@ -3,7 +3,7 @@
3
3
  module Brick
4
4
  module Rails
5
5
  class << self
6
- def display_value(col_type, val)
6
+ def display_value(col_type, val, lat_lng = nil)
7
7
  is_mssql_geography = nil
8
8
  # 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)
9
9
  if col_type == :binary && val && val.length < 31 && (val.length - 6) % 8 == 0 && val[0..5].bytes == [230, 16, 0, 0, 1, 12]
@@ -61,14 +61,19 @@ module Brick
61
61
  ::Brick::Rails.display_binary(val)
62
62
  else
63
63
  if col_type
64
- ::Brick::Rails::FormBuilder.hide_bcrypt(val, col_type == :xml)
64
+ if lat_lng
65
+ # Create a link to this style of Google maps URL: https://www.google.com/maps/place/38.7071296+-121.2810649/@38.7071296,-121.2810649,12z
66
+ "<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>"
67
+ else
68
+ ::Brick::Rails::FormBuilder.hide_bcrypt(val, col_type == :xml)
69
+ end
65
70
  else
66
71
  '?'
67
72
  end
68
73
  end
69
74
  end
70
75
 
71
- def display_binary(val)
76
+ def display_binary(val, max_size = 100_000)
72
77
  return unless val
73
78
 
74
79
  @image_signatures ||= { (+"\xFF\xD8\xFF\xEE").force_encoding('ASCII-8BIT') => 'jpeg',
@@ -94,15 +99,12 @@ module Brick
94
99
  val = val[object_start...object_start + real_object_size]
95
100
  end
96
101
 
97
- if (signature = @image_signatures.find { |k, _v| val[0...k.length] == k }) ||
98
- (val[0..3] == 'RIFF' && val[8..11] == 'WEBP' && (signature = 'webp'))
99
- if val.length < 500_000
100
- "<img src=\"data:image/#{signature.last};base64,#{Base64.encode64(val)}\">"
101
- else
102
- "&lt;&nbsp;#{signature.last} image, #{val.length} bytes&nbsp;>"
103
- end
102
+ if ((signature = @image_signatures.find { |k, _v| val[0...k.length] == k }&.last) ||
103
+ (val[0..3] == 'RIFF' && val[8..11] == 'WEBP' && binding.local_variable_set(:signature, 'webp'))) &&
104
+ val.length < max_size
105
+ "<img src=\"data:image/#{signature.last};base64,#{Base64.encode64(val)}\">"
104
106
  else
105
- "&lt;&nbsp;Binary, #{val.length} bytes&nbsp;>"
107
+ "&lt;&nbsp;#{signature ? "#{signature} image" : 'Binary'}, #{val.length} bytes&nbsp;>"
106
108
  end
107
109
  end
108
110
  end
@@ -1636,10 +1638,10 @@ end
1636
1638
  <tr><td colspan=\"2\">(No displayable fields)</td></tr>
1637
1639
  <% end %>
1638
1640
  </table>#{
1639
- "<%= binary = begin
1640
- ::Brick::Rails.display_binary(obj&.blob&.download)&.html_safe
1641
- rescue
1642
- end %>" if model_name == 'ActiveStorage::Attachment'}
1641
+ "<%= begin
1642
+ ::Brick::Rails.display_binary(obj&.blob&.download, 500_000)&.html_safe
1643
+ rescue
1644
+ end %>" if model_name == 'ActiveStorage::Attachment'}
1643
1645
  <% end %>
1644
1646
 
1645
1647
  #{unless args.first == 'new'
@@ -1674,7 +1676,7 @@ end
1674
1676
  collection = collection.instance_exec(&assoc.scopes.first) if assoc.scopes.present?
1675
1677
  if assoc.klass.name == 'ActiveStorage::Attachment'
1676
1678
  br_descrip = begin
1677
- ::Brick::Rails.display_binary(obj.send(assoc.name)&.blob&.download)&.html_safe
1679
+ ::Brick::Rails.display_binary(obj.send(assoc.name)&.blob&.download, 500_000)&.html_safe
1678
1680
  rescue
1679
1681
  end
1680
1682
  end
@@ -139,8 +139,19 @@ module Brick::Rails::FormTags
139
139
  out << if @_brick_monetized_attributes&.include?(col_name)
140
140
  val ? Money.new(val.to_i).format : ''
141
141
  else
142
+ lat_lng = if [:float, :decimal].include?(col.type) &&
143
+ (
144
+ ((col_name == 'latitude' && obj.respond_to?('longitude') && (lng = obj.send('longitude')) && lng.is_a?(Numeric) && (lat = val)) ||
145
+ (col_name == 'longitude' && obj.respond_to?('latitude') && (lat = obj.send('latitude')) && lat.is_a?(Numeric) && (lng = val))
146
+ ) ||
147
+ ((col_name == 'lat' && obj.respond_to?('lng') && (lng = obj.send('lng')) && lng.is_a?(Numeric) && (lat = val)) ||
148
+ (col_name == 'lng' && obj.respond_to?('lat') && (lat = obj.send('lat')) && lat.is_a?(Numeric) && (lng = val))
149
+ )
150
+ )
151
+ [lat, lng]
152
+ end
142
153
  col_type = col&.sql_type == 'geography' ? col.sql_type : col&.type
143
- ::Brick::Rails.display_value(col_type || col&.sql_type, val).to_s
154
+ ::Brick::Rails.display_value(col_type || col&.sql_type, val, lat_lng).to_s
144
155
  end
145
156
  elsif cust_col
146
157
  data = cust_col.first.map { |cc_part| obj.send(cc_part.last) }
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 131
8
+ TINY = 132
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.131
4
+ version: 1.0.132
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-16 00:00:00.000000000 Z
11
+ date: 2023-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord