Class: JekyllBlockTagPlugin::MyBlock

Inherits:
JekyllSupport::JekyllBlock
  • Object
show all
Includes:
JekyllPluginTemplateVersion
Defined in:
lib/jekyll_block_tag_plugin.rb

Overview

This class implements the Jekyll block tag functionality

Constant Summary collapse

REJECTED_ATTRIBUTES =
%w[content excerpt next previous].freeze

Constants included from JekyllPluginTemplateVersion

JekyllPluginTemplateVersion::VERSION

Instance Method Summary collapse

Instance Method Details

#render_impl(content) ⇒ String

Method prescribed by the Jekyll support plugin.

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/jekyll_block_tag_plugin.rb', line 30

def render_impl(content)
  @helper.gem_file __FILE__ # This enables attribution

  @param1  = @helper.keys_values['param1'] # Obtain the value of parameter param1
  @param2  = @helper.keys_values['param2']
  @param3  = @helper.keys_values['param3']
  @param4  = @helper.keys_values['param4']
  @param5  = @helper.keys_values['param5']
  @param_x = @helper.keys_values['not_present'] # The value of parameters that are present is nil, but displays as the empty string

  @logger.debug do
    <<~HEREDOC
      tag_name = '#{@helper.tag_name}'
      argument_string = '#{@helper.argument_string}'
      @param1 = '#{@param1}'
      @param2 = '#{@param2}'
      @param3 = '#{@param3}'
      @param4 = '#{@param4}'
      @param5 = '#{@param5}'
      @param_x = '#{@param_x}'
      params =
        #{@helper.keys_values.map { |k, v| "#{k} = #{v}" }.join("\n  ")}
    HEREDOC
  end

  @layout_hash = @envs['layout']

  @logger.debug do
    <<~HEREDOC
      mode="#{@mode}"
      page attributes:
        #{@page.sort
               .reject { |k, _| REJECTED_ATTRIBUTES.include? k }
               .map { |k, v| "#{k}=#{v}" }
               .join("\n  ")}
    HEREDOC
  end

  # Compute the return value of this Jekyll tag
  <<~HEREDOC
    <p style='color: green; background-color: yellow; padding: 1em; border: solid thin grey;'>
      #{content} #{@param1}
      #{@helper.attribute if @helper.attribution}
    </p>
  HEREDOC
rescue StandardError => e
  @logger.error { "#{self.class} died with a #{e.full_message}" }
  exit 3
end