Sha256: 81da5bdf5663b9a35674386b130370d0f397a5348349ee060ed502786f69b03d

Contents?: true

Size: 1.47 KB

Versions: 113

Compression:

Stored size: 1.47 KB

Contents

require 'tilt/template'
require 'commonmarker'

module Tilt
  class CommonMarkerTemplate < Template
    self.default_mime_type = 'text/html'

    OPTION_ALIAS = {
      :smartypants => :SMART
    }
    PARSE_OPTIONS = [
      :SMART,
      :smartypants,
    ].freeze
    RENDER_OPTIONS = [
      :GITHUB_PRE_LANG,
      :HARDBREAKS,
      :NOBREAKS,
      :SAFE,
      :SOURCEPOS,
    ].freeze
    EXTENSIONS = [
      :autolink,
      :strikethrough,
      :table,
      :tagfilter,
    ].freeze

    def extensions
      EXTENSIONS.select do |extension|
        options[extension]
      end
    end

    def parse_options
      raw_options = PARSE_OPTIONS.select do |option|
        options[option]
      end
      actual_options = raw_options.map do |option|
        OPTION_ALIAS[option] || option
      end

      if actual_options.any?
        actual_options
      else
        :DEFAULT
      end
    end

    def render_options
      raw_options = RENDER_OPTIONS.select do |option|
        options[option]
      end
      actual_options = raw_options.map do |option|
        OPTION_ALIAS[option] || option
      end
      if actual_options.any?
        actual_options
      else
        :DEFAULT
      end
    end

    def prepare
      @engine = nil
      @output = nil
    end

    def evaluate(scope, locals, &block)
      doc = CommonMarker.render_doc(data, parse_options, extensions)
      doc.to_html(render_options, extensions)
    end

    def allows_script?
      false
    end
  end
end

Version data entries

113 entries across 79 versions & 11 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
brakeman-5.2.3 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
brakeman-5.2.2 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
brakeman-5.2.1 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
brakeman-5.2.0 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
brakeman-5.1.2 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/commonmarker.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/commonmarker.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/commonmarker.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/commonmarker.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/commonmarker.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/commonmarker.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/commonmarker.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/commonmarker.rb