Sha256: d82280790fa713834430c60d7b0b94b48ce4db466e5940699ebed898a0631600

Contents?: true

Size: 888 Bytes

Versions: 58

Compression:

Stored size: 888 Bytes

Contents

module Para
  module Markup
    class ResourceTree < Para::Markup::Component
      def tree_list(resources, options = {}, &block)
        options[:class] ||= ''
        options[:class] << ' tree-list'

        content_tag(:ul, options) do
          resources.each do |resource|
            block.call(resource)
          end
        end
      end

      def tree_node(resource: nil, label: nil, children: [], **options, &block)
        options[:class] ||= ''
        options[:class] << ' node'

        content_tag(:li, options) do
          node_row(resource, label) + 
          node_children(children, &block)
        end
      end

      def node_row(resource, label)
        content_tag(:div, class: 'node-row') do
          label
        end
      end

      def node_children(children, &block)
        tree_list(children, &block) if children.length > 0
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
para-0.12.4 lib/para/markup/resources_tree.rb
para-0.12.3 lib/para/markup/resources_tree.rb
para-0.12.2 lib/para/markup/resources_tree.rb
para-0.12.1 lib/para/markup/resources_tree.rb
para-0.12.0 lib/para/markup/resources_tree.rb
para-0.11.4 lib/para/markup/resources_tree.rb
para-0.11.3 lib/para/markup/resources_tree.rb
para-0.11.2 lib/para/markup/resources_tree.rb
para-0.11.1 lib/para/markup/resources_tree.rb
para-0.11.0 lib/para/markup/resources_tree.rb
para-0.10.0 lib/para/markup/resources_tree.rb
para-0.9.4 lib/para/markup/resources_tree.rb
para-0.9.3.3 lib/para/markup/resources_tree.rb
para-0.9.3.2 lib/para/markup/resources_tree.rb
para-0.9.3.1 lib/para/markup/resources_tree.rb
para-0.9.2 lib/para/markup/resources_tree.rb
para-0.9.0 lib/para/markup/resources_tree.rb
para-0.8.15 lib/para/markup/resources_tree.rb
para-0.8.14 lib/para/markup/resources_tree.rb
para-0.8.13 lib/para/markup/resources_tree.rb