Sha256: 7b0852d08029556816436511aedc7440de9753f19b731f96846cbb5f2881f344

Contents?: true

Size: 950 Bytes

Versions: 2

Compression:

Stored size: 950 Bytes

Contents

module GrapeDoc
  class ApiDocParts

    module TOC
      class << self

        def add_header(header_obj)
          if [H1,H2].include? header_obj.class
            (@headers ||= []).push(header_obj)
          end
        end

        def create_toc
          @headers.map { |header_obj|
            [
                '*' * header_obj.markdown.scan(/\d+$/)[0].to_i,
                " \"#{header_obj.to_s}\":##{header_obj.instance_variable_get(:@opts)['id']}"
            ].join
          }.join("\n") + "\n\n"
        end

      end
    end

    class H1 < StringObject

      def initialize(*args)
        super
        @opts['id']= SecureRandom.uuid
        TOC.add_header(self)
      end

    end

    class H2 < H1
    end

    class H3 < H1
    end

    class H4 < H1
    end

    class H5 < H1
    end

    class H6 < H1
    end

    class Block < StringObject
      self.markdown = "bq"
    end

    class Br < StringBasic
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-doc-0.5.1 lib/grape/doc/doc_class/header.rb
grape-doc-0.5.0 lib/grape/doc/doc_class/header.rb