Sha256: 0660934dd58244848581ed952521fbb8f62ebcfbf5d2eb952cef462149134651

Contents?: true

Size: 1.12 KB

Versions: 171

Compression:

Stored size: 1.12 KB

Contents

module Expressir
  module Express
    # Formatter module - format references as hyperlinks
    # @example Include into Formatter subclass
    #   formatter = Class.new(Expressir::Express::Formatter) do
    #     include Expressir::Express::HyperlinkFormatter
    #   end
    module HyperlinkFormatter
      # @!visibility private
      def self.included(mod)
        if !mod.superclass.private_method_defined? :format_references_simple_reference
          raise 'Missing method'
        end
      end

      private

      def format_references_simple_reference(node)
        return node.id unless node.base_path

        # find closest node with path
        current_node = node
        while !current_node.path
          current_node = current_node.parent
        end

        # skip if this reference and target node are in the same node with path
        node_base_path_parts = node.base_path.split(".")
        current_node_path_parts = current_node.path.split(".")
        return node.id if node_base_path_parts[0..1] == current_node_path_parts[0..1]

        "{{{<<express:#{node.base_path},#{node.id}>>}}}"
      end
    end
  end
end

Version data entries

171 entries across 171 versions & 1 rubygems

Version Path
expressir-1.2.4-arm64-darwin lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.4-aarch64-linux lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.3 lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.3-x86_64-linux lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.3-x86_64-darwin lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.3-x86-mingw32 lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.3-x86-linux lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.3-x64-mingw32 lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.3-arm64-darwin lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.3-aarch64-linux lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.1 lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.1-x86_64-linux lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.1-x86_64-darwin lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.1-x86-mingw32 lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.1-x86-linux lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.1-x64-mingw32 lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.1-arm64-darwin lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.0 lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.0-x86_64-linux lib/expressir/express/hyperlink_formatter.rb
expressir-1.2.0-x86_64-darwin lib/expressir/express/hyperlink_formatter.rb