Sha256: cbd8c32c9175e59eef0bb3d19d18a7f703f6eac6930ed7f4b6805136652aae7f

Contents?: true

Size: 1.29 KB

Versions: 8

Compression:

Stored size: 1.29 KB

Contents

# ------------------------------------------------------------------------------
#  ~/_plugins/asciidoctor-extensions/twitter-emoji-inline.rb
#  Asciidoctor extension for J1 Template
#
#  Product/Info:
#  https://jekyll.one
#
#  Copyright (C) 2019 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

SIZE_MAP = {'1x' => 18, 'lg' => 24, '2x' => 34, '3x' => 50, '4x' => 68, '5x' => 85}
SIZE_MAP.default = 24

Asciidoctor::Extensions.register do
  class EmojiInlineMacro < Extensions::InlineMacroProcessor
    use_dsl
    named :emoji
    name_positional_attributes 'size', 'modifier'
    default_attrs 'size' => '1x', 'modifier' => 'no-modifier'

    def process parent, target, attributes
      doc = parent.document
      # Use twemoji only
      size_class = (size = attributes['size']) ? %( twa-#{size}) : nil
      modifier_class = (modifier = attributes['modifier']) ? %( twa-#{modifier}) : nil
      emoji_name = target.tr '_', '-'
      %(<i class="twa#{size_class} twa-#{emoji_name} twa-#{modifier}"></i>)
    end
  end
  inline_macro EmojiInlineMacro
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
j1_template-2019.4.12 lib/starter_web/_plugins/asciidoctor-extensions/twitter-emoji-inline.rb
j1_template-2019.4.11 lib/starter_web/_plugins/asciidoctor-extensions/twitter-emoji-inline.rb
j1_template-2019.4.10 lib/starter_web/_plugins/asciidoctor-extensions/twitter-emoji-inline.rb
j1_template-2019.4.8 lib/starter_web/_plugins/asciidoctor-extensions/twitter-emoji-inline.rb
j1_template-2019.4.7 lib/starter_web/_plugins/asciidoctor-extensions/twitter-emoji-inline.rb
j1_template-2019.4.5 lib/starter_web/_plugins/asciidoctor-extensions/twitter-emoji-inline.rb
j1_template-2019.4.4 lib/starter_web/_plugins/asciidoctor-extensions/twitter-emoji-inline.rb
j1_template-2019.4.1 lib/starter_web/_plugins/asciidoctor-extensions/twitter-emoji-inline.rb