Class: Jekyll::Ultraviolet::Block
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Jekyll::Ultraviolet::Block
- Includes:
- Liquid::StandardFilters
- Defined in:
- lib/jekyll/ultraviolet.rb
Instance Method Summary collapse
-
#initialize(tag, lang, tokens) ⇒ Block
constructor
A new instance of Block.
- #render(context) ⇒ Object
- #theme ⇒ Object
- #trim(text) ⇒ Object
Constructor Details
#initialize(tag, lang, tokens) ⇒ Block
Returns a new instance of Block.
13 14 15 16 17 |
# File 'lib/jekyll/ultraviolet.rb', line 13 def initialize(tag, lang, tokens) super @theme = "twilight" @lang = lang.empty? ? "ruby" : lang.strip end |
Instance Method Details
#render(context) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/jekyll/ultraviolet.rb', line 19 def render(context) output = [] output << context["pygments_prefix"] output << Uv.parse(trim(super.join), "xhtml", @lang, false, theme) output << context["pygments_suffix"] output.join rescue LoadError raise "Ultraviolet not installed." end |
#theme ⇒ Object
35 36 37 |
# File 'lib/jekyll/ultraviolet.rb', line 35 def theme Jekyll::Ultraviolet.theme || @theme end |
#trim(text) ⇒ Object
29 30 31 32 33 |
# File 'lib/jekyll/ultraviolet.rb', line 29 def trim(text) padding = text.match(/\n?(\s+)/)[1] return text.rstrip if padding == "\n" text.each_line.map { |l| l.gsub(/^#{padding}/, "") }.join.rstrip end |