Class: Jekyll::RunTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
run.rb

Overview

Executes a program and returns the output from STDOUT.

Class Attribute Summary collapse

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



23
24
25
26
27
28
# File 'run.rb', line 23

def initialize(tag_name, command_line, tokens)
  super
  @command = command_line
  @command = '' if @command.nil? || @command.empty?
  RunTag.logger = nil
end

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



15
16
17
# File 'run.rb', line 15

def logger
  @logger
end

Instance Method Details

#render(context) ⇒ String

Method prescribed by the Jekyll plugin lifecycle.

Returns:

  • (String)


32
33
34
35
36
37
# File 'run.rb', line 32

def render(context)
  RunTag.logger = Jekyll::LoggerFactory.new('run', context.config, :warn)
  RunTag.logger.info "Running #{@command}".green
  output = `#{@command}`.rstrip
  "<span class='unselectable'>$ </span>#{@command}\n<span class='unselectable'>#{output}</span>"
end