Sha256: 1f16de644a96f6d59e9611f3e2921cd2bbeae15378c5129c6924ce8147f2e371
Contents?: true
Size: 1.85 KB
Versions: 1
Compression:
Stored size: 1.85 KB
Contents
module Jekyll class Engine include Filters attr_reader :site, :page, :content attr_accessor :layout, :content def initialize(payload) @site = OpenStruct.new(payload['site']) @page = OpenStruct.new(payload['page']) @paginator = OpenStruct.new(payload['paginator']) if payload['paginator'] end def erb ERB.new(@layout || @content) end def render erb.result(binding) end def include_file(file) file = file.strip if file !~ /^[a-zA-Z0-9_\/\.-]+$/ || file =~ /\.\// || file =~ /\/\./ return "Include file '#{file}' contains invalid characters or sequences" end Dir.chdir(File.join(@site.source, '_includes')) do choices = Dir['**/*'].reject { |x| File.symlink?(x) } if choices.include?(file) source = File.read(file) ERB.new(source).result(binding) else "Included file '#{@file}' not found in _includes directory" end end end def highlight(text, lang = :ruby) if @site.pygments render_pygments(text, lang) else render_codehighlighter(text, lang) end end def render_pygments(text, lang) output = add_code_tags(Albino.new(text, lang).to_s, lang) case @page.content_type when "markdown" then "\n" + output + "\n" when "textile" then "<notextile>" + output + "</notextile>" else output end end def render_codehighlighter(text, lang) #The div is required because RDiscount blows ass <<-HTML <div> <pre> <code class='#{lang}'>#{h(text).strip}</code> </pre> </div> HTML end def add_code_tags(code, lang) # Add nested <code> tags to code blocks code = code.sub(/<pre>/,'<pre><code class="' + lang.to_s + '">') code = code.sub(/<\/pre>/,"</code></pre>") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
blackwinter-jekyll-0.5.7 | lib/jekyll/engine.rb |