Sha256: 5e67d08dc6efda43b9c60f535be44b4bac200fa0483ad7c05e40bb8d3f0ae582

Contents?: true

Size: 1.5 KB

Versions: 16

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Stepmod
  module Utils
    module Converters
      class Table < ReverseAdoc::Converters::Base
        def convert(node, state = {})
          id = node["id"]
          anchor = id ? "[[#{id}]]\n" : ""
          title = node["caption"].to_s
          title = ".#{title}\n" unless title.empty?
          attrs = style(node)
          "\n\n#{anchor}#{attrs}#{title}|===\n#{treat_children(node,
                                                               state)}\n|===\n"
        end

        def frame(node)
          case node["frame"]
          when "void"
            "frame=none"
          when "hsides"
            "frame=topbot"
          when "vsides"
            "frame=sides"
          when "box", "border"
            "frame=all"
          end
        end

        def rules(node)
          case node["rules"]
          when "all"
            "rules=all"
          when "rows"
            "rules=rows"
          when "cols"
            "rules=cols"
          when "none"
            "rules=none"
          end
        end

        def style(node)
          width = "width=#{node['width']}" if node["width"]
          attrs = []
          frame_attr = frame(node)
          rules_attr = rules(node)
          attrs += width if width
          attrs += frame_attr if frame_attr
          attrs += rules_attr if rules_attr
          return "" if attrs.empty?

          "[#{attrs.join(',')}]\n"
        end
      end

      ReverseAdoc::Converters.register :table, Table.new
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
stepmod-utils-0.3.22 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.21 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.20 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.19 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.18 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.17 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.16 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.15 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.14 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.13 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.12 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.11 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.10 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.9 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.8 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.7 lib/stepmod/utils/converters/table.rb