Sha256: ba0d49b4fff178cce6274e84399fe6bbfacafa637eab489e6a3e1f36bfb995af

Contents?: true

Size: 1.4 KB

Versions: 24

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Stepmod
  module Utils
    module Converters
      class ExpressG < ReverseAdoc::Converters::Base
        def convert(node, state = {})
          node.children.map do |child|
            next unless child.name == "imgfile"

            parse_to_svg_reference(child["file"], state)
          end.join("\n")
        end

        private

        def parse_to_svg_reference(file, state)
          return "" unless File.file?(file)

          image_document = Nokogiri::XML(File.read(file))
          svg_path = File.basename(image_document.xpath("//img").first["src"],
                                   ".*")
          <<~SVGMAP

            *)
            (*"#{state.fetch(:schema_name)}.__expressg"
            [.svgmap]
            ====
            image::#{svg_path}.svg[]

            #{image_document.xpath('//img.area').map.with_index(1) { |n, i| schema_reference(n['href'], i) }.join("\n")}
            ====
          SVGMAP
        end

        def schema_reference(xml_path, index)
          if /#/.match?(xml_path)
            _, express_path_part = xml_path.split("#")
            "* <<express:#{express_path_part.strip}>>; #{index}"
          else
            schema_name = File.basename(xml_path, ".*")
            "* <<express:#{schema_name.strip}>>; #{index}"
          end
        end
      end

      ReverseAdoc::Converters.register "express-g", ExpressG.new
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
stepmod-utils-0.3.30 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.29 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.28 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.27 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.26 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.25 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.24 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.23 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.22 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.21 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.20 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.19 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.18 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.17 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.16 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.15 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.14 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.13 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.12 lib/stepmod/utils/converters/express_g.rb
stepmod-utils-0.3.11 lib/stepmod/utils/converters/express_g.rb