Sha256: 2f0a07da666768a997c9140be80f2541c68771962650501e3f49559c6151ef0a

Contents?: true

Size: 772 Bytes

Versions: 6

Compression:

Stored size: 772 Bytes

Contents

module Slacken::Filters
  # Public: Wrap child content nodes of each li or dd node with an indent node.
  class GroupIndent < Slacken::Filter
    def call(component)
      if component.type.member_of?(%i(li dd))
        head, *tails = component.children.map(&method(:call))
        component.derive([head, component.class.new(:indent, tails)])
      else
        component.derive(
          component.children.map(&method(:call))
        )
      end
    end

    def valid?(component)
      if component.type.member_of?(%i(li dd))
        head, tail = component.children
        if tail
          tail.type.member_of?(:indent) && valid?(tail)
        else
          true
        end
      else
        component.children.all?(&method(:valid?))
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
slacken-0.1.6 lib/slacken/filters/group_indent.rb
slacken-0.1.5 lib/slacken/filters/group_indent.rb
slacken-0.1.4 lib/slacken/filters/group_indent.rb
slacken-0.1.3 lib/slacken/filters/group_indent.rb
slacken-0.1.2 lib/slacken/filters/group_indent.rb
slacken-0.1.1 lib/slacken/filters/group_indent.rb