module Scrivito class ChildListTag < Struct.new(:tag_name, :obj, :field_name, :view) include TagRenderer def initialize(tag_name, obj, field_name, view) unless field_name == 'toclist' raise "#{field_name} is not (yet) supported. Currently only toclist is supported." end super end def options return {} unless user_present? || obj.path.nil? options = { 'private-child-list-allowed-classes' => Obj.valid_page_classes_beneath(obj.path).to_json, 'private-child-list-path' => obj.path, 'private-obj-description-for-editor' => obj.description_for_editor, } if obj.has_attribute?(:child_order) options['private-child-list-order-obj-id'] = obj.id modification = comparison.modification_for_attribute(obj, :child_order) if modification == Modification::EDITED options['private-child-list-modification'] = modification end end options end def content(&block) return unless block_given? is_sortable = obj.has_attribute?(:child_order) && user_present? rendered_children = sorted_children.map do |child| obj_tag = ObjTag.new(child, is_sortable, comparison.modification(child), view) yield obj_tag, child obj_tag.rendered end view.safe_join(rendered_children) end # # This is a helper class for {ScrivitoHelper#scrivito_tag_list}. # @api public # class ObjTag < Struct.new(:obj, :is_sortable, :modification, :view) include TagRenderer attr_reader :tag_name, :rendered # # @api public # # @param tag_name [String, Symbol] Name of the html tag (e.g. +:div+ or +:span+). # @param html_options [Hash] Additional options, which are passed to +content_tag+. # Use them to add HTML attributes to the tag. # # @return [String] The rendered html tag # # @example Render a