diff options
Diffstat (limited to 'themes/classic')
-rw-r--r-- | themes/classic/_plugins/blockquote.rb | 28 | ||||
-rw-r--r-- | themes/classic/_plugins/gist_tag.rb | 81 | ||||
-rw-r--r-- | themes/classic/_plugins/include_code.rb | 40 | ||||
-rw-r--r-- | themes/classic/_plugins/pygments_cache_patch.rb | 2 |
4 files changed, 101 insertions, 50 deletions
diff --git a/themes/classic/_plugins/blockquote.rb b/themes/classic/_plugins/blockquote.rb index 21ebc5d7..8048f476 100644 --- a/themes/classic/_plugins/blockquote.rb +++ b/themes/classic/_plugins/blockquote.rb @@ -1,21 +1,20 @@ # -# Author: Josediaz Gonzalez - https://github.com/josegonzalez -# Source URL: https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/blockquote.rb -# Modified by Brandon Mathis removed pullquotes and added simple cite paramaters +# Author: Brandon Mathis +# Based on the work of: Josediaz Gonzalez - https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/blockquote.rb # require './_plugins/titlecase.rb' module Jekyll # Outputs a string with a given attribution as a quote # - # {% blockquote John Paul Jones %} - # Monkeys! + # {% blockquote Bobby Willis http://google.com/blah the search for bobby's mom %} + # Wheeee! # {% endblockquote %} # ... # <blockquote> - # Monkeys! - # <br /> - # John Paul Jones + # <p>Wheeee!</p> + # <footer> + # <strong>John Paul Jones</strong><cite><a href="http://google.com/blah">The Search For Bobby's Mom</a> # </blockquote> # class Blockquote < Liquid::Block @@ -42,15 +41,16 @@ module Jekyll def render(context) output = super - if @by.nil? - '<blockquote><p>' + output.join + '</p></blockquote>' - elsif !@title.nil? - '<blockquote><p>' + output.join + '</p>' + '<p><strong>' + @by + '</strong>' + '<cite><a class="source" href="' + @source + '">' + @title + '</a></cite></p></blockquote>' + author = "<strong>#{@by}</strong>" + cite = "<cite><a class='source' href='#{@source}'>#{(@title || 'source')}</a></cite>" + reply = if @by.nil? + "<p>#{output.join.gsub(/\n\n/, '</p><p>')}</p>" elsif !@source.nil? - '<blockquote><p>' + output.join + '</p>' + '<p><strong>' + @by + '</strong>' + '<cite><a class="source" href="' + @source + '">source</a></cite></p></blockquote>' + "<p>#{output.join.gsub(/\n\n/, '</p><p>')}</p><footer>#{author + cite}</footer>" else - '<blockquote><p>' + output.join + '</p>' + '<p><strong>' + @by + '</strong></p></blockquote>' + "<p>#{output.join.gsub(/\n\n/, '</p><p>')}</p><footer>#{author}</footer>" end + "<blockquote>#{reply}</blockquote>" end end end diff --git a/themes/classic/_plugins/gist_tag.rb b/themes/classic/_plugins/gist_tag.rb index 1f37416e..0a8797f8 100644 --- a/themes/classic/_plugins/gist_tag.rb +++ b/themes/classic/_plugins/gist_tag.rb @@ -1,9 +1,11 @@ -# Nicked from Brandon Tilly -# Gist https://gist.github.com/803483 +# A Liquid tag for Jekyll sites that allows embedding Gists and showing code for non-JavaScript enabled browsers and readers. +# by: Brandon Tilly +# Source URL: https://gist.github.com/1027674 # Post http://brandontilley.com/2011/01/31/gist-tag-for-jekyll.html # -# Example usage: {% gist 803483 gist_tag.rb %} //embeds a gist for this plugin +# Example usage: {% gist 1027674 gist_tag.rb %} //embeds a gist for this plugin +require 'cgi' require 'digest/md5' require 'net/https' require 'uri' @@ -12,60 +14,70 @@ module Jekyll class GistTag < Liquid::Tag def initialize(tag_name, text, token) super - system('mkdir -p .gist_cache') - @text = text - @cache = true - @cache_folder = File.expand_path "../.gist_cache", File.dirname(__FILE__) + @text = text + @cache_disabled = false + @cache_folder = File.expand_path "../_gist_cache", File.dirname(__FILE__) + FileUtils.mkdir_p @cache_folder end def render(context) - return "" unless @text =~ /([\d]*) (.*)/ + if parts = @text.match(/([\d]*) (.*)/) + gist, file = parts[1].strip, parts[2].strip + script_url = script_url_for gist, file + code = get_cached_gist(gist, file) || get_gist_from_web(gist, file) + html_output_for script_url, code + else + "" + end + end - gist, file = $1.strip, $2.strip - script_url = "https://gist.github.com/#{gist}.js?file=#{file}" + def html_output_for(script_url, code) + code = CGI.escapeHTML code + <<-HTML +<script src='#{script_url}'></script> +<noscript><pre><code>#{code}</code></pre></noscript> + HTML + end - code = get_cached_gist(gist, file) || get_gist_from_web(gist, file) - code = code.gsub "<", "<" - string = "<script src='#{script_url}'></script>" - string += "<noscript><pre><code>#{code}</code></pre></noscript>" - return string + def script_url_for(gist_id, filename) + "https://gist.github.com/#{gist_id}.js?file=#{filename}" end def get_gist_url_for(gist, file) - "https://gist.github.com/raw/#{gist}/#{file}" + "https://raw.github.com/gist/#{gist}/#{file}" end - def cache_gist(gist, file, data) - file = get_cache_file_for gist, file - File.open(file, "w+") do |f| - f.write(data) + def cache(gist, file, data) + cache_file = get_cache_file_for gist, file + File.open(cache_file, "w") do |io| + io.write data end end def get_cached_gist(gist, file) - return nil if @cache == false - file = get_cache_file_for gist, file - return nil unless File.exist?(file) - return File.new(file).readlines.join + return nil if @cache_disabled + cache_file = get_cache_file_for gist, file + File.read cache_file if File.exist? cache_file end def get_cache_file_for(gist, file) - gist.gsub! /[^a-zA-Z0-9\-_\.]/, '' - file.gsub! /[^a-zA-Z0-9\-_\.]/, '' - md5 = Digest::MD5.hexdigest "#{gist}-#{file}" + bad_chars = /[^a-zA-Z0-9\-_.]/ + gist = gist.gsub bad_chars, '' + file = file.gsub bad_chars, '' + md5 = Digest::MD5.hexdigest "#{gist}-#{file}" File.join @cache_folder, "#{gist}-#{file}-#{md5}.cache" end def get_gist_from_web(gist, file) - gist_url = get_gist_url_for(gist, file) - raw_uri = URI.parse(gist_url) - https = Net::HTTP.new(raw_uri.host, raw_uri.port) + gist_url = get_gist_url_for gist, file + raw_uri = URI.parse gist_url + https = Net::HTTP.new raw_uri.host, raw_uri.port https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE - request = Net::HTTP::Get.new(raw_uri.request_uri) - data = https.request(request) + request = Net::HTTP::Get.new raw_uri.request_uri + data = https.request request data = data.body - cache_gist(gist, file, data) unless @cache == false + cache gist, file, data unless @cache_disabled data end end @@ -73,11 +85,10 @@ module Jekyll class GistTagNoCache < GistTag def initialize(tag_name, text, token) super - @cache = false + @cache_disabled = true end end end Liquid::Template.register_tag('gist', Jekyll::GistTag) Liquid::Template.register_tag('gistnocache', Jekyll::GistTagNoCache) - diff --git a/themes/classic/_plugins/include_code.rb b/themes/classic/_plugins/include_code.rb new file mode 100644 index 00000000..fa5c76ff --- /dev/null +++ b/themes/classic/_plugins/include_code.rb @@ -0,0 +1,40 @@ +require 'pathname' + +module Jekyll + + class IncludeCodeTag < Liquid::Tag + def initialize(tag_name, file, tokens) + super + @file = file.strip + end + + def render(context) + code_dir = (context.registers[:site].config['code_dir'] || 'downloads/code') + code_path = (Pathname.new(context.registers[:site].source) + code_dir).expand_path + file = code_path + @file + + if File.symlink?(code_path) + return "Code directory '#{code_path}' cannot be a symlink" + end + + unless file.file? + return "File #{file} could not be found" + end + + Dir.chdir(code_path) do + code = file.read + file_type = file.extname + url = "#{context.registers[:site].config['url']}/#{code_dir}/#{@file}" + source = "<figure><figcaption><span>#{file.basename}</span><a href='#{url}'>download</a></figcaption>\n" + source += "{% highlight #{file_type} %}\n" + code + "\n{% endhighlight %}</figure>" + partial = Liquid::Template.parse(source) + context.stack do + partial.render(context) + end + end + end + end + +end + +Liquid::Template.register_tag('include_code', Jekyll::IncludeCodeTag) diff --git a/themes/classic/_plugins/pygments_cache_patch.rb b/themes/classic/_plugins/pygments_cache_patch.rb index 36c78d20..09c09840 100644 --- a/themes/classic/_plugins/pygments_cache_patch.rb +++ b/themes/classic/_plugins/pygments_cache_patch.rb @@ -6,7 +6,7 @@ require 'fileutils' require 'digest/md5' -PYGMENTS_CACHE_DIR = File.expand_path('../../_cache', __FILE__) +PYGMENTS_CACHE_DIR = File.expand_path('../../_code_cache', __FILE__) FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) Jekyll::HighlightBlock.class_eval do |