class Jekyll::Terminal::CommandsBlock

Public Class Methods

new(tag_name, text, tokens) click to toggle source
Calls superclass method
# File lib/jekyll-terminal.rb, line 54
def initialize(tag_name, text, tokens)
  super
  @text = text
end

Public Instance Methods

esc(line) click to toggle source
# File lib/jekyll-terminal.rb, line 90
def esc(line)
  CGI.escapeHTML(line.strip)
end
render(context) click to toggle source
Calls superclass method
# File lib/jekyll-terminal.rb, line 59
      def render(context)
        site = context.registers[:site]
        terminal_config = site.config[:terminal] || {}
        tag_name = terminal_config[:tag_name] || 'h3'
        continuation_string = terminal_config[:continuation_string] || '/'
        continuation_string = '/' if continuation_string == '$'
        content = super(context).strip.lines.map do |line|
          # Test the continuation string first, because it may start with '$'.
          # Note that it can't be '$' thanks to the guard above.
          if line.start_with?(continuation_string)
             "<span class='continuation'>#{esc line[continuation_string.size..-1]}</span>"          
          elsif line.start_with?("$")
             "<span class='command'>#{esc line[1..-1]}</span>"
          else
             "<span class='output'>#{esc line}</span>"
          end
        end.join("\n")
        %{
<div class="terminal">
  <nav>
    <a href="#" class="close">close</a>
    <a href="#" class="minimize">minimize</a>
    <a href="#" class="deactivate">deactivate</a>
  </nav>
  <#{tag_name} class="title">Terminal</#{tag_name}>
  <pre>
#{content}
  </pre>
</div>}
      end