Sha256: ac24724f835d66171718632bd2f1662734675d779aaf80502ad81d9de686b209

Contents?: true

Size: 1.5 KB

Versions: 8

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"
          else
            nil
          end
        end

        def rules(node)
          case node["rules"]
          when "all"
            "rules=all"
          when "rows"
            "rules=rows"
          when "cols"
            "rules=cols"
          when "none"
            "rules=none"
          else
            nil
          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

8 entries across 8 versions & 1 rubygems

Version Path
stepmod-utils-0.3.5 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.4 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.2 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.1 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.0 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.2.7 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.2.6 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.2.5 lib/stepmod/utils/converters/table.rb