Skip to content

Commit

Permalink
Add css_class to action links, to avoid changing name, it may result …
Browse files Browse the repository at this point in the history
…confusing

deprecate changing name
  • Loading branch information
scambra committed Oct 23, 2024
1 parent 8b285f4 commit b4de4dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Add css_class to action links, to avoid changing name, it may result confusing, deprecate name setter

= 3.7.8
- Rollback previous behaviour when submitting empty values, broken when default_value was added. Default value set in column is not used when trying to save empty value, DB default is used in that case, and save NULL when string is empty, as before.
- Support operators =, null and not null for :select search_ui, so it's possible to search for NULL with :select search UI.
Expand Down
15 changes: 11 additions & 4 deletions lib/active_scaffold/data_structures/action_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ class ActionLinks
include Enumerable
attr_accessor :default_type

def initialize
def initialize(name = :root)
@set = []
@name = :root
@name = name
@css_class = name.to_s.downcase
@weight = 0
end

Expand Down Expand Up @@ -130,8 +131,8 @@ def subgroup(name, label = nil)

if group.nil?
group = ActiveScaffold::DataStructures::ActionLinks.new
group = ActiveScaffold::DataStructures::ActionLinks.new(name)
group.label = label || name
group.name = name
group.default_type = self.name == :root ? (name.to_sym if %w[member collection].include?(name.to_s)) : default_type
add_to_set group
end
Expand Down Expand Up @@ -166,8 +167,14 @@ def respond_to_missing?(name, *)
name !~ /[!?]$/
end

attr_accessor :name
attr_reader :name
attr_accessor :weight
attr_accessor :css_class

def name=(value)
ActiveSupport::Deprecation.warn "Changing name is deprecated, use css_class to change the class html attribute"
self.css_class = value
end

protected

Expand Down
2 changes: 1 addition & 1 deletion lib/active_scaffold/helpers/action_link_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def display_action_link(link, content, record, options)
group_tag = :li
end
content = content_tag(group_tag, :class => html_classes.presence, :onclick => ('' if hover_via_click?)) do
content_tag(:div, as_(link.label(record)), :class => link.name.to_s.downcase) << content_tag(:ul, content)
content_tag(:div, as_(link.label(record)), :class => link.css_class) << content_tag(:ul, content)
end
else
content = render_action_link(link, record, options)
Expand Down

0 comments on commit b4de4dd

Please sign in to comment.