Sha256: 932018775f67a5424875245ca043dfc31e5cc23a449dfc0ebc25cec3dd1f89e5

Contents?: true

Size: 1.89 KB

Versions: 22

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

module Stepmod
  module Utils
    module Converters
      class Table < ReverseAdoc::Converters::Base

        def self.pattern(state, id)
          if state[:schema_and_entity].nil?
            raise StandardError.new("[table]: no state given, #{id}")
          end

          schema = state[:schema_and_entity].split(".").first
          "table-#{schema}-#{id}"
        end

        def convert(node, state = {})
          # If we want to skip this node
          return "" if state[:no_notes_examples]

          id = node["id"]
          anchor = id ? "[[table-#{self.class.pattern(state, 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

22 entries across 22 versions & 1 rubygems

Version Path
stepmod-utils-0.4.8 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.4.7 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.4.6 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.4.5 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.4.2 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.4.1 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.4.0 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.37 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.36 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.35 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.34 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.33 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.32 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.31 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.30 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.29 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.28 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.27 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.26 lib/stepmod/utils/converters/table.rb
stepmod-utils-0.3.25 lib/stepmod/utils/converters/table.rb