Class: Jekyll::Terminal::CommandsBlock
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Jekyll::Terminal::CommandsBlock
- Defined in:
- lib/jekyll-terminal.rb
Instance Method Summary collapse
- #esc(line) ⇒ Object
-
#initialize(tag_name, text, tokens) ⇒ CommandsBlock
constructor
A new instance of CommandsBlock.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ CommandsBlock
Returns a new instance of CommandsBlock.
54 55 56 57 |
# File 'lib/jekyll-terminal.rb', line 54 def initialize(tag_name, text, tokens) super @text = text end |
Instance Method Details
#esc(line) ⇒ Object
90 91 92 |
# File 'lib/jekyll-terminal.rb', line 90 def esc(line) CGI.escapeHTML(line.strip) end |
#render(context) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 |