Sha256: c0abe6696358248d0c9ba2b165ea0aac0adaf7a9fa22e2b79ba5bdb35b968cde

Contents?: true

Size: 1.32 KB

Versions: 26

Compression:

Stored size: 1.32 KB

Contents

# ------------------------------------------------------------------------------
# ~/_plugins/asciidoctor-extensions/gist-block.rb
# Asciidoctor extension for J1 Template
#
# Product/Info:
# https://jekyll.one
#
# Copyright (C) 2020 Juergen Adams
#
# J1 Template is licensed under the MIT License.
# See: https://github.com/jekyll-one-org/J1 Template/blob/master/LICENSE
#
# ------------------------------------------------------------------------------
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
include Asciidoctor

# A block macro that embeds a Gist into the output document
#
# Usage
#
#   gist::12345[]
#
# Example:
#
#   .Guard setup to live preview AsciiDoc output
#   gist::mojavelinux/5546622[]
#
Asciidoctor::Extensions.register do

  class GistBlockMacro < Extensions::BlockMacroProcessor
    use_dsl

    named :gist

    def process parent, target, attrs
      title_html = (attrs.has_key? 'title') ?
          %(<div class="title">#{attrs['title']}</div>\n) : nil

      html = %(<div class="openblock gist mt-4 mb-5">
                 #{title_html}
                 <div class="content">
                   <script src="https://gist.github.com/#{target}.js"></script>
                 </div>
               </div>)

      create_pass_block parent, html, attrs, subs: nil
    end
  end

  block_macro GistBlockMacro

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
j1-template-2021.0.0 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.25 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.24 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.22 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.21 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.20 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.19 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.18 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.17 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.16 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.15 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.14 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.13 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.12 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.11 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.10 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.9 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.8 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.7 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb
j1-template-2020.0.6 lib/starter_web/_plugins/asciidoctor-extensions/gist-block.rb