Sha256: 37867cda90d2e1431ffc97b3427b397b9af4f1aebe70857d88675211cd5bf293
Contents?: true
Size: 1.42 KB
Versions: 19
Compression:
Stored size: 1.42 KB
Contents
module Scrivito class UiObjClassesJsonFormatter < Struct.new(:lookup_context) def format(obj_class) data = base_obj_class_data(obj_class) if obj_class.ancestors.include?(Scrivito::BasicWidget) data[:embeds] = obj_class.embeds? data[:embeddingAttribute] = obj_class.embeds? ? obj_class.embedding_attribute.name.camelcase(:lower) : nil data[:validContainerClasses] = convert_classes_array(obj_class.valid_container_classes) end data[:hasServerDetailsTemplate] = details_view?(obj_class.name) data end private def base_obj_class_data(obj_class) { name: obj_class.name, type: obj_class.ancestors.include?(Scrivito::BasicWidget) ? 'Widget' : 'Obj', title: obj_class.description_for_editor, attributes: obj_class.attribute_definitions.map { |attr| convert_attribute(attr) }, usesServerCallbacks: true, hideFromEditor: obj_class.hide_from_editor?, } end def convert_attribute(attribute) attribute_json = attribute.as_json attribute_json[:name] = attribute_json[:name].camelcase(:lower) attribute_json end def details_view?(obj_class_name) lookup_context.find("#{obj_class_name.underscore}/details").present? rescue ActionView::MissingTemplate false end def convert_classes_array(arr) if arr arr.map(&:name) end end end end
Version data entries
19 entries across 19 versions & 1 rubygems