Class: ContentBlock
Overview
Public ContentBlock model exposed to the host app.
Defined Under Namespace
Modules: Publishable, Searchable, Versionable
Constant Summary
collapse
- CONTENT_TYPES =
%w[text rich_text image link list].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
#current_version_number, #rollback_to_version!
#publish, #published?, #unpublish
Class Method Details
.accessible_by(_user) ⇒ Object
79
80
81
|
# File 'lib/generators/ruby_cms/templates/models/content_block.rb', line 79
def self.accessible_by(_user)
all
end
|
.action_text_available? ⇒ Boolean
19
20
21
22
23
24
25
26
|
# File 'lib/generators/ruby_cms/templates/models/content_block.rb', line 19
def self.action_text_available?
return false unless defined?(::ActionText::RichText)
ActiveRecord::Base.connection.data_source_exists?("action_text_rich_texts")
rescue ActiveRecord::ConnectionNotEstablished, ActiveRecord::NoDatabaseError,
ActiveRecord::StatementInvalid
false
end
|
.active_storage_available? ⇒ Boolean
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/generators/ruby_cms/templates/models/content_block.rb', line 28
def self.active_storage_available?
return false unless defined?(::ActiveStorage::Blob)
c = ActiveRecord::Base.connection
c.data_source_exists?("active_storage_blobs") &&
c.data_source_exists?("active_storage_attachments")
rescue ActiveRecord::ConnectionNotEstablished, ActiveRecord::NoDatabaseError,
ActiveRecord::StatementInvalid
false
end
|
.by_key ⇒ Object
83
84
85
|
# File 'lib/generators/ruby_cms/templates/models/content_block.rb', line 83
def self.by_key
alphabetically
end
|
.find_by_key_and_locale(key, locale: nil, default_locale: nil) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/generators/ruby_cms/templates/models/content_block.rb', line 108
def self.find_by_key_and_locale(key, locale: nil, default_locale: nil)
locale ||= I18n.locale.to_s
default_locale ||= begin
I18n.default_locale.to_s
rescue StandardError
"en"
end
block = find_by(key: key.to_s, locale: locale.to_s)
return block if block
return nil if locale.to_s == default_locale.to_s
find_by(key: key.to_s, locale: default_locale.to_s)
end
|
Instance Method Details
#can_delete?(user) ⇒ Boolean
91
92
93
|
# File 'lib/generators/ruby_cms/templates/models/content_block.rb', line 91
def can_delete?(user)
user&.can?(:manage_content_blocks, record: self)
end
|
#can_edit?(user) ⇒ Boolean
87
88
89
|
# File 'lib/generators/ruby_cms/templates/models/content_block.rb', line 87
def can_edit?(user)
user&.can?(:manage_content_blocks, record: self)
end
|
#content_body ⇒ Object
99
100
101
102
103
104
105
106
|
# File 'lib/generators/ruby_cms/templates/models/content_block.rb', line 99
def content_body
if content_type == "rich_text" && self.class.action_text_available? &&
respond_to?(:rich_content)
rich_content.to_s
else
content.to_s
end
end
|
#record_update_by(user) ⇒ Object
95
96
97
|
# File 'lib/generators/ruby_cms/templates/models/content_block.rb', line 95
def record_update_by(user)
self.updated_by = user if user
end
|