brick 1.0.193 → 1.0.195
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 +4 -4
- data/lib/brick/extensions.rb +18 -21
- data/lib/brick/frameworks/rails/engine.rb +10 -6
- data/lib/brick/frameworks/rails/form_builder.rb +6 -2
- data/lib/brick/frameworks/rails/form_tags.rb +3 -0
- data/lib/brick/version_number.rb +1 -1
- data/lib/generators/brick/controllers_generator.rb +3 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48a47a4a4fd18918a7e1b3f90ffb1953afb11c569e19664920d3921e4806b4fe
|
4
|
+
data.tar.gz: 2a50f06d5790c7facfec994693c5f88f747b96825f62cf6b51a81dbf97f88aca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc9840fb52d71e04ef8a899d16289276d11556f55492d9190aaf6387659d520c105c7885c80c65a5ddba5a4294c0f088cbf03adb70969b9f948dd85721865fe2
|
7
|
+
data.tar.gz: 2846f746ad0f325ea5915b8ad68db9bb39d8a81061adf3ca6dfa996bc209d193887eea22b4eb9c6bdf65131c1c82f2ce980eedea9f7be886b0d9084017fcd553
|
data/lib/brick/extensions.rb
CHANGED
@@ -436,12 +436,12 @@ module ActiveRecord
|
|
436
436
|
order_by = ordering&.each_with_object([]) do |ord_part, s| # %%% If a term is also used as an eqi-condition in the WHERE clause, it can be omitted from ORDER BY
|
437
437
|
case ord_part
|
438
438
|
when String
|
439
|
-
if ord_part.index('^^^')
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
439
|
+
ord_expr = if ord_part.index('^^^')
|
440
|
+
ord_part.gsub('^^^', _br_quoted_name(table_name))
|
441
|
+
else
|
442
|
+
_br_quoted_name(ord_part)
|
443
|
+
end
|
444
|
+
s << Arel.sql(ord_expr)
|
445
445
|
order_by_txt&.<<("Arel.sql(#{ord_expr.inspect})")
|
446
446
|
else # Expecting only Symbol
|
447
447
|
ord_part = ord_part.to_s
|
@@ -1860,14 +1860,14 @@ class Object
|
|
1860
1860
|
end
|
1861
1861
|
end
|
1862
1862
|
|
1863
|
-
def default_ordering(table_name, pk)
|
1863
|
+
def default_ordering(table_name, pk, omit_table_name = nil)
|
1864
1864
|
case (order_tbl = ::Brick.config.order[table_name]) && (order_default = order_tbl[:_brick_default])
|
1865
1865
|
when Array
|
1866
1866
|
order_default.map { |od_part| order_tbl[od_part] || od_part }
|
1867
1867
|
when Symbol
|
1868
1868
|
order_tbl[order_default] || order_default
|
1869
1869
|
else
|
1870
|
-
pk.map { |part| "#{table_name}
|
1870
|
+
pk.map { |part| "#{"#{table_name}." unless omit_table_name}#{part}"} # If it's not a custom ORDER BY, just use the key
|
1871
1871
|
end
|
1872
1872
|
end
|
1873
1873
|
|
@@ -1917,7 +1917,7 @@ class Object
|
|
1917
1917
|
cspd.select! { |val| val == "'self'" }
|
1918
1918
|
cspd << style_value
|
1919
1919
|
else
|
1920
|
-
cspd << "'sha256-
|
1920
|
+
cspd << "'sha256-ZMGrNwNigXBkvHBZrPrNurCVlJycGWtt2uvoEigUowg='"
|
1921
1921
|
end
|
1922
1922
|
cspd << 'https://cdn.jsdelivr.net'
|
1923
1923
|
end
|
@@ -2035,6 +2035,7 @@ class Object
|
|
2035
2035
|
end
|
2036
2036
|
|
2037
2037
|
self.protect_from_forgery unless: -> { self.request.format.js? }
|
2038
|
+
plural_table_name = table_name.split('.').last.pluralize
|
2038
2039
|
unless is_avo
|
2039
2040
|
self.define_method :index do
|
2040
2041
|
request_ver = request.path.split('/')[-2]
|
@@ -2220,7 +2221,7 @@ class Object
|
|
2220
2221
|
end
|
2221
2222
|
end
|
2222
2223
|
ar_select = ar_relation.respond_to?(:_select!) ? ar_relation.dup._select!(*selects, *counts) : ar_relation.select(selects + counts)
|
2223
|
-
instance_variable_set("@#{
|
2224
|
+
instance_variable_set("@#{plural_table_name}".to_sym, ar_select)
|
2224
2225
|
table_name_no_schema = singular_table_name.pluralize
|
2225
2226
|
if namespace && (idx = lookup_context.prefixes.index(table_name_no_schema))
|
2226
2227
|
lookup_context.prefixes[idx] = "#{namespace.name.underscore}/#{lookup_context.prefixes[idx]}"
|
@@ -2259,10 +2260,10 @@ class Object
|
|
2259
2260
|
end
|
2260
2261
|
end
|
2261
2262
|
|
2262
|
-
_, order_by_txt = model._brick_calculate_ordering(default_ordering(table_name, pk)) if pk
|
2263
|
+
_, order_by_txt = model._brick_calculate_ordering(default_ordering(table_name, pk, true)) if pk
|
2263
2264
|
code << " def index\n"
|
2264
|
-
code << " @#{
|
2265
|
-
code << " @#{
|
2265
|
+
code << " @#{plural_table_name} = #{model.name}#{pk&.present? ? ".order(#{order_by_txt.join(', ')})" : '.all'}\n"
|
2266
|
+
code << " @#{plural_table_name}.brick_select(params)\n"
|
2266
2267
|
code << " end\n"
|
2267
2268
|
|
2268
2269
|
is_pk_string = nil
|
@@ -2562,12 +2563,8 @@ class Object
|
|
2562
2563
|
assoc_name = assoc_parts.join('.')
|
2563
2564
|
else
|
2564
2565
|
class_name_parts = ::Brick.namify(hm_assoc[:inverse_table], :underscore).split('.')
|
2565
|
-
|
2566
|
-
class_name_parts[last_idx] = class_name_parts[last_idx].singularize
|
2567
|
-
real_name = class_name_parts.map(&:camelize).join('::')
|
2568
|
-
needs_class = (real_name != hm_assoc[:inverse_table].camelize)
|
2566
|
+
needs_class = assoc_name.singularize.camelize != class_name_parts.last.singularize.camelize
|
2569
2567
|
end
|
2570
|
-
# hm_assoc[:assoc_name] = assoc_name
|
2571
2568
|
[assoc_name, needs_class]
|
2572
2569
|
end
|
2573
2570
|
# Already have the HM class around?
|
@@ -2616,7 +2613,7 @@ end.class_exec do
|
|
2616
2613
|
# https://discuss.rubyonrails.org/t/failed-write-transaction-upgrades-in-sqlite3/81480/2
|
2617
2614
|
if ActiveRecord::Base.connection.adapter_name == 'SQLite'
|
2618
2615
|
arca = ::ActiveRecord::ConnectionAdapters
|
2619
|
-
db_statements = arca::SQLite3::DatabaseStatements
|
2616
|
+
db_statements = arca::SQLite3.const_defined?('DatabaseStatements') ? arca::SQLite3::DatabaseStatements : arca::SQLite3::SchemaStatements
|
2620
2617
|
# Rails 7.1 and later
|
2621
2618
|
if arca::AbstractAdapter.private_instance_methods.include?(:with_raw_connection)
|
2622
2619
|
db_statements.define_method(:begin_db_transaction) do
|
@@ -3084,7 +3081,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
3084
3081
|
INNER JOIN pg_class child ON pg_inherits.inhrelid = child.oid
|
3085
3082
|
INNER JOIN pg_catalog.pg_namespace n ON n.oid = parent.relnamespace#{
|
3086
3083
|
if schema
|
3087
|
-
params
|
3084
|
+
params << schema
|
3088
3085
|
"
|
3089
3086
|
WHERE n.nspname = COALESCE(?, 'public')"
|
3090
3087
|
end}
|
@@ -3099,7 +3096,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
3099
3096
|
FROM pg_class
|
3100
3097
|
INNER JOIN pg_catalog.pg_namespace n ON n.oid = pg_class.relnamespace#{
|
3101
3098
|
if schema
|
3102
|
-
params
|
3099
|
+
params << schema
|
3103
3100
|
"
|
3104
3101
|
WHERE n.nspname = COALESCE(?, 'public')"
|
3105
3102
|
end}
|
@@ -1002,6 +1002,10 @@ a.big-arrow {
|
|
1002
1002
|
color: red;
|
1003
1003
|
white-space: nowrap;
|
1004
1004
|
}
|
1005
|
+
.thumbImg {
|
1006
|
+
max-width: 96px;
|
1007
|
+
max-height: 96px;
|
1008
|
+
}
|
1005
1009
|
.danger {
|
1006
1010
|
background-color: red;
|
1007
1011
|
color: white;
|
@@ -1376,7 +1380,7 @@ end %>#{"
|
|
1376
1380
|
end
|
1377
1381
|
\"<tr><td colspan=\\\"#\{td_count}\\\">Children: #\{child_links.join(' ')}</tr>\".html_safe
|
1378
1382
|
end
|
1379
|
-
%><%= if (page_num = @#{table_name}._brick_page_num)
|
1383
|
+
%><%= if (page_num = @#{res_name = table_name.pluralize}._brick_page_num)
|
1380
1384
|
\"<tr><td colspan=\\\"#\{td_count}\\\">Page #\{page_num}</td></tr>\".html_safe
|
1381
1385
|
end %></table>#{template_link}<%
|
1382
1386
|
if description.present? %><span class=\"__brick\"><%=
|
@@ -1418,19 +1422,19 @@ end
|
|
1418
1422
|
|
1419
1423
|
<%= # Consider getting the name from the association -- hm.first.name -- if a more \"friendly\" alias should be used for a screwy table name
|
1420
1424
|
# If the resource is missing, has the user simply created an inappropriately pluralised name for a table?
|
1421
|
-
@#{
|
1425
|
+
@#{res_name} ||= if (dym_list = instance_variables.reject do |entry|
|
1422
1426
|
entry.to_s.start_with?('@_') ||
|
1423
1427
|
['@cache_hit', '@marked_for_same_origin_verification', '@view_renderer', '@view_flow', '@output_buffer', '@virtual_path'].include?(entry.to_s)
|
1424
1428
|
end).present?
|
1425
|
-
msg = +\"Can't find resource \\\"#{
|
1429
|
+
msg = +\"Can't find resource \\\"#{res_name}\\\".\"
|
1426
1430
|
# Can't be sure otherwise of what is up, so check DidYouMean and offer a suggestion.
|
1427
|
-
if (dym = DidYouMean::SpellChecker.new(dictionary: dym_list).correct('@#{
|
1431
|
+
if (dym = DidYouMean::SpellChecker.new(dictionary: dym_list).correct('@#{res_name}')).present?
|
1428
1432
|
msg << \"\nIf you meant \\\"#\{found_dym = dym.first[1..-1]}\\\" then to avoid this message add this entry into inflections.rb:\n\"
|
1429
1433
|
msg << \" inflect.irregular '#{obj_name}', '#\{found_dym}'\"
|
1430
1434
|
puts
|
1431
1435
|
puts \"WARNING: #\{msg}\"
|
1432
1436
|
puts
|
1433
|
-
@#{
|
1437
|
+
@#{res_name} = instance_variable_get(dym.first.to_sym)
|
1434
1438
|
else
|
1435
1439
|
raise ActiveRecord::RecordNotFound.new(msg)
|
1436
1440
|
end
|
@@ -1450,7 +1454,7 @@ end
|
|
1450
1454
|
# Rails.application.reloader.to_prepare do ... end
|
1451
1455
|
self.class.class_exec { include ::Brick::Rails::FormTags } unless respond_to?(:brick_grid)
|
1452
1456
|
# Write out the mega-grid
|
1453
|
-
brick_grid(@#{
|
1457
|
+
brick_grid(@#{res_name}, @_brick_sequence, @_brick_incl, @_brick_excl,
|
1454
1458
|
cols, bt_descrip: @_brick_bt_descrip, poly_cols: poly_cols, bts: bts, hms_keys: #{hms_keys.inspect}, hms_cols: {#{hms_columns.join(', ')}}) %>
|
1455
1459
|
|
1456
1460
|
#{"<hr><%= link_to(\"New #{new_path_name = "new_#{path_obj_name}_path"
|
@@ -55,7 +55,10 @@ module Brick::Rails::FormBuilder
|
|
55
55
|
is_revert = false
|
56
56
|
out << ::Brick::Rails::FormBuilder.hide_bcrypt(val, nil, 1000)
|
57
57
|
elsif col_type == :string
|
58
|
-
if model.respond_to?(:
|
58
|
+
if model.respond_to?(:uploaders) && model.uploaders.key?(col.name&.to_sym) &&
|
59
|
+
(url = self.object.send(col.name)&.url) # Carrierwave image?
|
60
|
+
out << "<img src=\"#{url}\" title=\"#{val}\">"
|
61
|
+
elsif model.respond_to?(:enumerized_attributes) && (opts = (attr = model.enumerized_attributes[method])&.options).present?
|
59
62
|
enum_html_options = attr.kind_of?(Enumerize::Multiple) ? html_options.merge({ multiple: true, size: opts.length + 1 }) : html_options
|
60
63
|
out << self.select(method.to_sym, [["(No #{method} chosen)", '^^^brick_NULL^^^']] + opts, { value: val || '^^^brick_NULL^^^' }, enum_html_options)
|
61
64
|
else
|
@@ -149,9 +152,10 @@ module Brick::Rails::FormBuilder
|
|
149
152
|
else
|
150
153
|
if val.is_a?(String)
|
151
154
|
return ::Brick::Rails.display_binary(val) unless (val_utf8 = val.dup.force_encoding('UTF-8')).valid_encoding?
|
155
|
+
|
152
156
|
val = val_utf8.strip
|
153
157
|
return CGI.escapeHTML(val) if is_xml
|
154
|
-
|
158
|
+
|
155
159
|
if val.length > max_len
|
156
160
|
if val[0] == '<' # Seems to be HTML?
|
157
161
|
cur_len = 0
|
@@ -229,6 +229,9 @@ module Brick::Rails::FormTags
|
|
229
229
|
# binding.pry if col.is_a?(Array)
|
230
230
|
out << if @_brick_monetized_attributes&.include?(col_name)
|
231
231
|
val ? Money.new(val.to_i).format : ''
|
232
|
+
elsif klass.respond_to?(:uploaders) && klass.uploaders.key?(col_name.to_sym) &&
|
233
|
+
(url = obj.send(col_name)&.url) # Carrierwave image?
|
234
|
+
"<img class=\"thumbImg\" src=\"#{url}\" title=\"#{val}\">"
|
232
235
|
else
|
233
236
|
lat_lng = if [:float, :decimal].include?(col.type) &&
|
234
237
|
(
|
data/lib/brick/version_number.rb
CHANGED
@@ -27,7 +27,7 @@ module Brick
|
|
27
27
|
model_info = Hash.new { |h, k| h[k] = {} }
|
28
28
|
tableless = Hash.new { |h, k| h[k] = [] }
|
29
29
|
existing_controllers = ActionController::Base.descendants.reject do |c|
|
30
|
-
c.name.start_with?('Turbo::Native::')
|
30
|
+
c.name.nil? || c.name&.start_with?('Turbo::Native::')
|
31
31
|
end.map(&:name)
|
32
32
|
controllers = ::Brick.relations.each_with_object([]) do |rel, s|
|
33
33
|
next if rel.first.is_a?(Symbol)
|
@@ -64,7 +64,8 @@ module Brick
|
|
64
64
|
else
|
65
65
|
Object
|
66
66
|
end
|
67
|
-
|
67
|
+
controller_parts[controller_parts.length - 1] = (controller_name = "#{controller_parts.last.pluralize}Controller")
|
68
|
+
_built_controller, code = Object.send(:build_controller, namespace, controller_name, controller_name, controller_option.model, relations)
|
68
69
|
path = ['controllers']
|
69
70
|
path.concat(controller_parts.map(&:underscore))
|
70
71
|
dir = +"#{::Rails.root}/app"
|
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.
|
4
|
+
version: 1.0.195
|
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-12-
|
11
|
+
date: 2023-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -284,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
284
|
- !ruby/object:Gem::Version
|
285
285
|
version: 1.3.6
|
286
286
|
requirements: []
|
287
|
-
rubygems_version: 3.
|
287
|
+
rubygems_version: 3.1.6
|
288
288
|
signing_key:
|
289
289
|
specification_version: 4
|
290
290
|
summary: Create a Rails app from data alone
|