Sha256: b20d7f357f2d0a26905112fdd7bd9e0b2766a6371da72299c7976036ac3df44b

Contents?: true

Size: 1.32 KB

Versions: 24

Compression:

Stored size: 1.32 KB

Contents

require 'erb'
require 'redcarpet'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/array'
require 'redcarpet/render_strip'

module JSONAPIonify
  class Documentation
    using JSONAPIonify::IndentedString
    STRIPPER = Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
    RENDERER = Redcarpet::Markdown.new(
      Redcarpet::Render::HTML,
      autolink:                     true,
      tables:                       true,
      fenced_code_blocks:           true,
      strikethrough:                true,
      disable_indented_code_blocks: true,
      no_intra_emphasis:            true,
      space_after_headers:          true,
      underline:                    true,
      highlight:                    true,
      quote:                        true
    )

    def self.render_markdown(string)
      RENDERER.render(string.deindent)
    end

    def self.onelinify_markdown(string)
      strip_markdown(string).gsub(/[\r\n\t]/, ' ').strip
    end

    def self.strip_markdown(string)
      STRIPPER.render(string.deindent)
    end

    attr_reader :api

    def initialize(api, template: nil)
      template ||= File.join(__dir__, 'documentation/template.erb')
      @api     = api
      @erb     = ERB.new File.read(template)
    end

    def result
      @erb.result(binding)
    end

  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
jsonapionify-0.12.10 lib/jsonapionify/documentation.rb
jsonapionify-0.12.9 lib/jsonapionify/documentation.rb
jsonapionify-0.12.8 lib/jsonapionify/documentation.rb
jsonapionify-0.12.7 lib/jsonapionify/documentation.rb
jsonapionify-0.12.5 lib/jsonapionify/documentation.rb
jsonapionify-0.12.4 lib/jsonapionify/documentation.rb
jsonapionify-0.12.3 lib/jsonapionify/documentation.rb
jsonapionify-0.12.2 lib/jsonapionify/documentation.rb
jsonapionify-0.12.1 lib/jsonapionify/documentation.rb
jsonapionify-0.12.0 lib/jsonapionify/documentation.rb
jsonapionify-0.11.11 lib/jsonapionify/documentation.rb
jsonapionify-0.11.10 lib/jsonapionify/documentation.rb
jsonapionify-0.11.9 lib/jsonapionify/documentation.rb
jsonapionify-0.11.8 lib/jsonapionify/documentation.rb
jsonapionify-0.11.7 lib/jsonapionify/documentation.rb
jsonapionify-0.11.6 lib/jsonapionify/documentation.rb
jsonapionify-0.11.5 lib/jsonapionify/documentation.rb
jsonapionify-0.11.0 lib/jsonapionify/documentation.rb
jsonapionify-0.10.2 lib/jsonapionify/documentation.rb
jsonapionify-0.10.1 lib/jsonapionify/documentation.rb