Move logic from key definition to views
Before this change, two important things depend on the format of each key, where to render it in the administration panel and which kind of interface to use for each setting. Following this strategy led us to a very complex code, very difficult to maintain or modify. So, we do not want to depend on the setting key structure anymore to decide how or where to render each setting. With this commit, we get rid of the key format-based rules. Now we render each setting explicitly passing to it the type and the tab where it belongs.
This commit is contained in:
committed by
Javi Martín
parent
91c3bde36b
commit
f8835debae
22
app/components/admin/settings/row_component.rb
Normal file
22
app/components/admin/settings/row_component.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class Admin::Settings::RowComponent < ApplicationComponent
|
||||
attr_reader :key, :tab, :type
|
||||
delegate :dom_id, to: :helpers
|
||||
|
||||
def initialize(key, type: :text, tab: nil)
|
||||
@key = key
|
||||
@type = type
|
||||
@tab = tab
|
||||
end
|
||||
|
||||
def setting
|
||||
@setting ||= Setting.find_by!(key: key)
|
||||
end
|
||||
|
||||
def content_type_setting?
|
||||
type == :content_type
|
||||
end
|
||||
|
||||
def featured_setting?
|
||||
type == :feature
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user