Sha256: f81a08ac13b2b6fbc386ce1e93d1556b6724355f43caf27bb0248451f75aa461

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module Slacken::Filters
  # Public: Sanitize not allowed tags in table.
  class SanitizeTable < Slacken::Filter
    def call(component)
      if component.type.member_of?(:table)
        component.derive(component.children.map(&method(:sanitize_table)))
      else
        component.derive(component.children.map(&method(:call)))
      end
    end

    def valid?(component)
      if component.type.member_of?(:table)
        component.children.all?(&method(:table_sanitized?))
      else
        component.children.all?(&method(:valid?))
      end
    end

    private

    def sanitize_table(component)
      if component.type.allowed_in_table?
        component.derive(
          component.children.map(&method(:sanitize_table))
        )
      else
        # No block tags are allowed.
        component.derive(
          component.children.map(&method(:sanitize_table)),
          type: :span
        )
      end
    end

    def table_sanitized?(component)
      if component.type.allowed_in_table?
        component.children.all?(&method(:table_sanitized?))
      else
        false
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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