diff --git a/lib/avo/fields/concerns/has_html_attributes.rb b/lib/avo/fields/concerns/has_html_attributes.rb index 285a16ebb2..2f052f97f8 100644 --- a/lib/avo/fields/concerns/has_html_attributes.rb +++ b/lib/avo/fields/concerns/has_html_attributes.rb @@ -33,11 +33,17 @@ def get_html(name = nil, element:, view:) add_action_data_attributes(attributes, name, element) add_resource_data_attributes(attributes, name, element, view) - attributes + value_or_default name, attributes end private + def value_or_default(name, attributes) + return attributes if attributes.present? + + default_attribute_value name + end + # Returns Hash, HTML::Builder, or nil. def parse_html return if @html.nil? @@ -50,7 +56,7 @@ def parse_html end def default_attribute_value(name) - name == :data ? {} : "" + (name == :data) ? {} : "" end def add_action_data_attributes(attributes, name, element) diff --git a/lib/avo/html/builder.rb b/lib/avo/html/builder.rb index 48d475ac52..376c222e08 100644 --- a/lib/avo/html/builder.rb +++ b/lib/avo/html/builder.rb @@ -47,7 +47,7 @@ def get_stack(name = nil) # We don't have an edit component for new so we should use edit name = :edit if name == :new - send "#{name}_stack" + send :"#{name}_stack" end def dig_stack(*names) @@ -115,17 +115,17 @@ def build self end - protected + private # Capture and parse the blocks for the nested structure def capture_block(property = nil, &block) - send("#{property}_stack=", self.class.parse_block(record: record, resource: resource, &block).build) + send(:"#{property}_stack=", self.class.parse_block(record: record, resource: resource, &block).build) end # Parse the properties and assign them to the blocks def assign_property(property = :data, payload = nil, &block) value = Avo::ExecutionContext.new(target: block || payload, record: record).handle - send("#{property}_stack=", value) + send(:"#{property}_stack=", value) end end diff --git a/lib/tasks/avo_tasks.rake b/lib/tasks/avo_tasks.rake index c1201f5ef1..a094a1069d 100644 --- a/lib/tasks/avo_tasks.rake +++ b/lib/tasks/avo_tasks.rake @@ -1,6 +1,6 @@ desc "Runs the update command for all Avo gems." task "avo:update" do - system "bundle update avo avo-pro avo-advanced avo-dashboards avo_filters avo-menu avo_upgrade" + system "bundle update avo avo-pro avo-advanced avo-dashboards avo_filters avo-menu" end desc "Installs Avo assets and bundles them for when you want to use the GitHub repo in your app" diff --git a/scripts/export-tailwind-safelist.js b/scripts/export-tailwind-safelist.js index b653b7c76a..c5b0f2bcf5 100644 --- a/scripts/export-tailwind-safelist.js +++ b/scripts/export-tailwind-safelist.js @@ -1,9 +1,14 @@ +/** + This command should only be run when updating one of the dynamic components or when we add a suport for a custom class on the docs. + EX: - Avo::ButtonComponent +*/ + /* eslint-disable no-template-curly-in-string */ const fs = require('fs') const kebabCase = require('lodash/kebabCase') const colors = require('tailwindcss/colors') -// Dynamically built buttons need these classes in prod. +// Dynamically-built buttons need these classes in prod. const buttonClasses = [ 'bg-${color}-500', 'border-${color}-500', diff --git a/spec/dummy/app/avo/resources/project.rb b/spec/dummy/app/avo/resources/project.rb index e53b4e4f82..b4ee8d17d0 100644 --- a/spec/dummy/app/avo/resources/project.rb +++ b/spec/dummy/app/avo/resources/project.rb @@ -54,7 +54,11 @@ def fields translation_key: "avo.field_translations.files", view_type: :list, stacked: false, hide_view_type_switcher: false - field :meta, as: :key_value, key_label: "Meta key", value_label: "Meta value", action_text: "New item", delete_text: "Remove item", disable_editing_keys: false, disable_adding_rows: false, disable_deleting_rows: false + field :meta, as: :key_value, key_label: "Meta key", value_label: "Meta value", action_text: "New item", delete_text: "Remove item", disable_editing_keys: false, disable_adding_rows: false, disable_deleting_rows: false, html: -> do + show do + wrapper { classes("spoon") } + end + end field :users, as: :has_and_belongs_to_many field :comments, as: :has_many, searchable: true diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index ba3206d2c8..c1a835c6d1 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -51,7 +51,10 @@ config.factory_bot.definition_file_paths = ["../../db"] - config.log_level = :fatal + if ENV["RAILS_LOG"].blank? + config.logger = Logger.new(nil) + config.log_level = :fatal + end config.i18n.load_path += Dir[Avo::Engine.root.join("lib", "generators", "avo", "templates", "locales", "*.{rb,yml}")]