Newer
Older
def self.has_string(property)
has_field property, :string
end
def self.has_text(property)
has_field property, :text
end
def self.has_select(property, **args)
has_field property, :select
end
has_field "#{property}_alt".to_sym, :string
has_field "#{property}_credit".to_sym, :string
self.fields ||= []
self.fields << { name: property, type: kind }
Communication::Block::Component::#{kind.classify}.new(property, self).value
Communication::Block::Component::#{kind.classify}.new(property, self).value = value
json = JSON.parse value
self.class.fields.each do |field|
update_field field, json
build_git_dependencies
@git_dependencies.uniq!
end
@git_dependencies
def update_field(field, json)
name = field[:name]
value = json["#{name}"]
public_send "#{name}=", value
end
def build_git_dependencies
end
def add_dependency(dependency)
if dependency.is_a? Array
@git_dependencies += dependency
else
@git_dependencies += [dependency]
end
end
def find_blob(object, key)
id = object.dig(key, 'id')
return if id.blank?
university.active_storage_blobs.find id
end
def extract_image_alt_and_credit(source, variable)
blob = find_blob source, variable
return if blob.nil?
alt = source["alt"] || source["#{variable}_alt"]
credit = source["credit"] || source["#{variable}_credit"]
text = source["text"] || source["#{variable}_text"]
{
blob: blob,
alt: alt,
credit: credit,
text: text
}.to_dot
end