Sha256: 8d813e42019b6d758ca3451b8004594a83a392843474ceb2a7658d0d5422dbf4

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require "uv"
require "liquid"
# Psych can't parse some of the syntax/theme files
YAML::ENGINE.yamler = "syck"

module Jekyll
  module Ultraviolet
    class << self; attr_accessor :theme end

    class Block < Liquid::Block
      include Liquid::StandardFilters

      def initialize(tag, lang, tokens)
        super
        @theme = "twilight"
        @lang  = lang.empty? ? "ruby" : lang.strip
      end

      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

      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

      def theme
        Jekyll::Ultraviolet.theme || @theme
      end
    end
  end
end

Liquid::Template.register_tag('uv', Jekyll::Ultraviolet::Block)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-ultraviolet-0.0.3 lib/jekyll/ultraviolet.rb