Sha256: fc8ad0679505ce138072f670939d3c5095566ac356c9d9f9098719a22ed7e8e6

Contents?: true

Size: 861 Bytes

Versions: 3

Compression:

Stored size: 861 Bytes

Contents

module Panda
  module CMS
    module EditorJs
      module Blocks
        class List < Base
          def render
            list_type = (data["style"] == "ordered") ? "ol" : "ul"
            html_safe(
              "<#{list_type}>" \
              "#{render_items(data["items"])}" \
              "</#{list_type}>"
            )
          end

          private

          def render_items(items)
            items.map do |item|
              content = item.is_a?(Hash) ? item["content"] : item
              nested = (item.is_a?(Hash) && item["items"].present?) ? render_nested(item["items"]) : ""
              "<li>#{sanitize(content)}#{nested}</li>"
            end.join
          end

          def render_nested(items)
            self.class.new({"items" => items, "style" => data["style"]}).render
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
panda-cms-0.7.3 lib/panda/cms/editor_js/blocks/list.rb
panda-cms-0.7.2 lib/panda/cms/editor_js/blocks/list.rb
panda-cms-0.7.0 lib/panda/cms/editor_js/blocks/list.rb