Class: JekyllPreModule::ExecTag

Inherits:
JekyllSupport::JekyllTag
  • Object
show all
Includes:
JekyllPreVersion
Defined in:
lib/exec_tag.rb

Constant Summary

Constants included from JekyllPreVersion

JekyllPreVersion::VERSION

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.remove_html_tags(string) ⇒ Object



18
19
20
# File 'lib/exec_tag.rb', line 18

def self.remove_html_tags(string)
  string.gsub(/<[^>]*>/, '')
end

Instance Method Details

#render_implObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/exec_tag.rb', line 22

def render_impl
  parse_args
  @original_command = @helper.remaining_markup_original
  command = ::JekyllSupport::JekyllPluginHelper.expand_env @original_command
  if command.strip.empty?
    msg = "Command is empty on on line #{@line_number} (after front matter) of #{@page['path']}"
    unless @die_if_error
      @logger.warn { msg }
      return ''
    end
    raise PreError, msg, []
  end

  response = run_command(command)
  response = if @child_status.success?
               JekyllPreModule.compress(response, @no_strip)
             else
               handle_error(command)
             end

  <<~END_OUTPUT
    #{Rack::Utils.escape_html(@original_command)}
    <span class='unselectable'>#{response}</span>
  END_OUTPUT
rescue PreError => e
  raise PreError, e.message, []
rescue StandardError => e
  msg = self.class.remove_html_tags(e.message) +
        " from executing '#{@original_command}' on line #{@line_number} (after front matter) of #{@page['path']}"
  raise PreError, msg.red, [] if @die_if_error
end