Class: PreTag::PreTagBlock

Inherits:
Liquid::Block
  • Object
show all
Defined in:
pre.rb

Overview

""" {% pre %} Content here {% endpre %}

{% pre copyButton %} Content here {% endpre %}"""

Constant Summary collapse

@@prefix =
"<button class='copyBtn' data-clipboard-target="
@@suffix =
" title='Copy to clipboard'><img src='/assets/images/clippy.svg' " \
"alt='Copy to clipboard' style='width: 13px'></button>"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ void

Constructor.

Parameters:

  • tag_name (String)

    is the name of the tag, which we already know.

  • text (Hash, String, Liquid::Tag::Parser)

    the arguments from the web page.

  • tokens (Liquid::ParseContext)

    tokenized command line



37
38
39
40
41
# File 'pre.rb', line 37

def initialize(tag_name, text, tokens)
  super(tag_name, text, tokens)
  text = '' if text.nil?
  @make_copy_button = text.strip! == 'copyButton'
end

Class Method Details

.make_copy_button(pre_id) ⇒ Object



22
23
24
# File 'pre.rb', line 22

def self.make_copy_button(pre_id)
  "#{@@prefix}'##{pre_id}'#{@@suffix}"
end

.make_pre(make_copy_button, content) ⇒ Object



26
27
28
29
30
# File 'pre.rb', line 26

def self.make_pre(make_copy_button, content)
  pre_id = 'id${SecureRandom.hex(6)}'
  copy_button = make_copy_button ? PreTagBlock.make_copy_button(pre_id) : ''
  "<pre data-lt-active='false' class='maxOneScreenHigh copyContainer' id='#{pre_id}'>#{copy_button}#{content}</pre>"
end

Instance Method Details

#render(context) ⇒ String

Method prescribed by the Jekyll plugin lifecycle.

Returns:

  • (String)


45
46
47
48
# File 'pre.rb', line 45

def render(context)
  content = super
  PreTagBlock.make_pre(@make_copy_button, content)
end