Class: Jekyll::MyBlock
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Jekyll::MyBlock
- Defined in:
- lib/jekyll_block_tag_plugin_template.rb
Overview
This class implements the Jekyll tag functionality
Instance Method Summary collapse
- #initialize(tag_name, argument_string, _parse_context) ⇒ void constructor
-
#render(context) ⇒ String
Method prescribed by the Jekyll plugin lifecycle.
Constructor Details
#initialize(tag_name, argument_string, _parse_context) ⇒ void
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jekyll_block_tag_plugin_template.rb', line 34 def initialize(tag_name, argument_string, _parse_context) super @logger = PluginMetaLogger.instance.new_logger(self) argv = Shellwords.split argument_string # Scans name/value arguments params = KeyValueParser.new.parse(argv) # Extracts key/value pairs, default value for non-existant keys is nil @param1 = params[:param1] # Example of obtaining the value of parameter param1 @param_x = params[:not_present] # The value of parameters that are present is nil, but displays as the empty string @logger.debug do <<~HEREDOC tag_name = '#{tag_name}' argument_string = '#{argument_string}' @param1 = '#{@param1}' @param_x = '#{@param_x}' params = #{params.map { |k, v| "#{k} = #{v}" }.join("\n ")} HEREDOC end end |
Instance Method Details
#render(context) ⇒ String
Method prescribed by the Jekyll plugin lifecycle.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jekyll_block_tag_plugin_template.rb', line 57 def render(context) content = super # This underdocumented assignment returns the text within the block. @site = context.registers[:site] @config = @site.config @mode = @config["env"]["JEKYLL_ENV"] @page = context.registers[:page] @logger.debug <<~HEREDOC mode="#{@mode}" page.path="#{@page.path}" page.url="#{@page.url}" HEREDOC # Compute the return value of this Jekyll tag <<~HEREDOC <p style="color: green; background-color: yellow; padding: 1em; border: solid thin grey;"> #{content} #{@param1} </p> HEREDOC end |