Class: RunTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll_run.rb

Overview

Jekyll tag plugin that executes a program and returns the output from STDOUT. Because the output includes the command that was executed, and is contains unselectable span tags, this plugin is intended to be embedded within a pre tag. Executes a program and returns the output from STDOUT.

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, command_line, tokens) ⇒ void

Constructor.

Parameters:

  • tag_name (String) —

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

  • command_line (Hash, String, Liquid::Tag::Parser) —

    the arguments from the web page.

  • tokens (Liquid::ParseContext) —

    tokenized command line



18
19
20
21
22
23
# File 'lib/jekyll_run.rb', line 18

def initialize(tag_name, command_line, tokens)
  super
  @command = command_line
  @command = "" if @command.nil? || @command.empty?
  @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
end

Instance Method Details

#render(_context) ⇒ String

Method prescribed by the Jekyll plugin lifecycle.

Returns:

  • (String)


27
28
29
30
31
# File 'lib/jekyll_run.rb', line 27

def render(_context)
  @logger.debug "Running #{@command}"
  output = `#{@command}`.rstrip
  "<span class='unselectable'>$ </span>#{@command}\n<span class='unselectable'>#{output}</span>"
end