diff options
author | Zhiming Wang <zmwangx@gmail.com> | 2015-05-04 14:55:10 -0700 |
---|---|---|
committer | Zhiming Wang <zmwangx@gmail.com> | 2015-05-04 14:55:10 -0700 |
commit | 301679861a2440a10c9eac746cec86459f445ef9 (patch) | |
tree | 5aad22ead01cf0da226623f603f33867896c0fea /plugins | |
parent | d0a07c64afba47bbe8bfb56ba9893296a73fc7db (diff) | |
download | my_new_personal_website-301679861a2440a10c9eac746cec86459f445ef9.tar.xz my_new_personal_website-301679861a2440a10c9eac746cec86459f445ef9.zip |
remove all Octopress stuff
Diffstat (limited to '')
-rw-r--r-- | plugins/backtick_code_block.rb | 42 | ||||
-rw-r--r-- | plugins/blockquote.rb | 82 | ||||
-rw-r--r-- | plugins/category_generator.rb | 193 | ||||
-rw-r--r-- | plugins/code_block.rb | 92 | ||||
-rw-r--r-- | plugins/config_tag.rb | 44 | ||||
-rw-r--r-- | plugins/gist_tag.rb | 130 | ||||
-rw-r--r-- | plugins/haml.rb | 24 | ||||
-rw-r--r-- | plugins/image_tag.rb | 50 | ||||
-rw-r--r-- | plugins/include_array.rb | 58 | ||||
-rw-r--r-- | plugins/include_code.rb | 71 | ||||
-rw-r--r-- | plugins/jsfiddle.rb | 40 | ||||
-rw-r--r-- | plugins/octopress_filters.rb | 142 | ||||
-rw-r--r-- | plugins/pullquote.rb | 45 | ||||
-rw-r--r-- | plugins/pygments_code.rb | 45 | ||||
-rw-r--r-- | plugins/raw.rb | 40 | ||||
-rw-r--r-- | plugins/render_partial.rb | 69 | ||||
-rw-r--r-- | plugins/rubypants.rb | 489 | ||||
-rw-r--r-- | plugins/titlecase.rb | 36 | ||||
-rw-r--r-- | plugins/video_tag.rb | 56 |
19 files changed, 0 insertions, 1748 deletions
diff --git a/plugins/backtick_code_block.rb b/plugins/backtick_code_block.rb deleted file mode 100644 index ae4a0472..00000000 --- a/plugins/backtick_code_block.rb +++ /dev/null @@ -1,42 +0,0 @@ -require './plugins/pygments_code' - -module BacktickCodeBlock - AllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i - LangCaption = /([^\s]+)\s*(.+)?/i - def self.render_code_block(input) - @options = nil - @caption = nil - @lang = nil - @url = nil - @title = nil - input.gsub(/^`{3} *([^\n]+)?\n(.+?)\n`{3}/m) do - @options = $1 || '' - str = $2 - - if @options =~ AllOptions - @lang = $1 - @caption = "<figcaption><span>#{$2}</span><a href='#{$3}'>#{$4 || 'link'}</a></figcaption>" - elsif @options =~ LangCaption - @lang = $1 - @caption = "<figcaption><span>#{$2}</span></figcaption>" - end - - if str.match(/\A( {4}|\t)/) - str = str.gsub(/^( {4}|\t)/, '') - end - if @lang.nil? || @lang == 'plain' - code = HighlightCode::tableize_code(str.gsub('<','<').gsub('>','>')) - "<figure class='code'>#{@caption}#{code}</figure>" - else - if @lang.include? "-raw" - raw = "``` #{@options.sub('-raw', '')}\n" - raw += str - raw += "\n```\n" - else - code = HighlightCode::highlight(str, @lang) - "<figure class='code'>#{@caption}#{code}</figure>" - end - end - end - end -end diff --git a/plugins/blockquote.rb b/plugins/blockquote.rb deleted file mode 100644 index ebdc0e89..00000000 --- a/plugins/blockquote.rb +++ /dev/null @@ -1,82 +0,0 @@ -# -# Author: Brandon Mathis -# A full rewrite based on the work of: Josediaz Gonzalez - https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/blockquote.rb -# -# Outputs a string with a given attribution as a quote -# -# {% blockquote Bobby Willis http://google.com/search?q=pants the search for bobby's pants %} -# Wheeee! -# {% endblockquote %} -# ... -# <blockquote> -# <p>Wheeee!</p> -# <footer> -# <strong>Bobby Willis</strong><cite><a href="http://google.com/search?q=pants">The Search For Bobby's Pants</a> -# </blockquote> -# -require './plugins/titlecase.rb' - -module Jekyll - - class Blockquote < Liquid::Block - FullCiteWithTitle = /(\S.*)\s+(https?:\/\/)(\S+)\s+(.+)/i - FullCite = /(\S.*)\s+(https?:\/\/)(\S+)/i - AuthorTitle = /([^,]+),([^,]+)/ - Author = /(.+)/ - - def initialize(tag_name, markup, tokens) - @by = nil - @source = nil - @title = nil - if markup =~ FullCiteWithTitle - @by = $1 - @source = $2 + $3 - @title = $4.titlecase.strip - elsif markup =~ FullCite - @by = $1 - @source = $2 + $3 - elsif markup =~ AuthorTitle - @by = $1 - @title = $2.titlecase.strip - elsif markup =~ Author - @by = $1 - end - super - end - - def render(context) - quote = paragraphize(super) - author = "<strong>#{@by.strip}</strong>" if @by - if @source - url = @source.match(/https?:\/\/(.+)/)[1].split('/') - parts = [] - url.each do |part| - if (parts + [part]).join('/').length < 32 - parts << part - end - end - source = parts.join('/') - source << '/…' unless source == @source - end - if !@source.nil? - cite = " <cite><a href='#{@source}'>#{(@title || source)}</a></cite>" - elsif !@title.nil? - cite = " <cite>#{@title}</cite>" - end - blockquote = if @by.nil? - quote - elsif cite - "#{quote}<footer>#{author + cite}</footer>" - else - "#{quote}<footer>#{author}</footer>" - end - "<blockquote>#{blockquote}</blockquote>" - end - - def paragraphize(input) - "<p>#{input.lstrip.rstrip.gsub(/\n\n/, '</p><p>').gsub(/\n/, '<br/>')}</p>" - end - end -end - -Liquid::Template.register_tag('blockquote', Jekyll::Blockquote) diff --git a/plugins/category_generator.rb b/plugins/category_generator.rb deleted file mode 100644 index c55d62f4..00000000 --- a/plugins/category_generator.rb +++ /dev/null @@ -1,193 +0,0 @@ -# encoding: utf-8 -# -# Jekyll category page generator. -# http://recursive-design.com/projects/jekyll-plugins/ -# -# Version: 0.1.4 (201101061053) -# -# Copyright (c) 2010 Dave Perrett, http://recursive-design.com/ -# Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) -# -# A generator that creates category pages for jekyll sites. -# -# Included filters : -# - category_links: Outputs the list of categories as comma-separated <a> links. -# - date_to_html_string: Outputs the post.date as formatted html, with hooks for CSS styling. -# -# Available _config.yml settings : -# - category_dir: The subfolder to build category pages in (default is 'categories'). -# - category_title_prefix: The string used before the category name in the page title (default is -# 'Category: '). - -require 'stringex' - -module Jekyll - - # The CategoryIndex class creates a single category page for the specified category. - class CategoryIndex < Page - - # Initializes a new CategoryIndex. - # - # +base+ is the String path to the <source>. - # +category_dir+ is the String path between <source> and the category folder. - # +category+ is the category currently being processed. - def initialize(site, base, category_dir, category) - @site = site - @base = base - @dir = category_dir - @name = 'index.html' - self.process(@name) - # Read the YAML data from the layout page. - self.read_yaml(File.join(base, '_layouts'), 'category_index.html') - self.data['category'] = category - # Set the title for this page. - title_prefix = site.config['category_title_prefix'] || 'Category: ' - self.data['title'] = "#{title_prefix}#{category}" - # Set the meta-description for this page. - meta_description_prefix = site.config['category_meta_description_prefix'] || 'Category: ' - self.data['description'] = "#{meta_description_prefix}#{category}" - end - - end - - # The CategoryFeed class creates an Atom feed for the specified category. - class CategoryFeed < Page - - # Initializes a new CategoryFeed. - # - # +base+ is the String path to the <source>. - # +category_dir+ is the String path between <source> and the category folder. - # +category+ is the category currently being processed. - def initialize(site, base, category_dir, category) - @site = site - @base = base - @dir = category_dir - @name = 'atom.xml' - self.process(@name) - # Read the YAML data from the layout page. - self.read_yaml(File.join(base, '_includes/custom'), 'category_feed.xml') - self.data['category'] = category - # Set the title for this page. - title_prefix = site.config['category_title_prefix'] || 'Category: ' - self.data['title'] = "#{title_prefix}#{category}" - # Set the meta-description for this page. - meta_description_prefix = site.config['category_meta_description_prefix'] || 'Category: ' - self.data['description'] = "#{meta_description_prefix}#{category}" - - # Set the correct feed URL. - self.data['feed_url'] = "#{category_dir}/#{name}" - end - - end - - # The Site class is a built-in Jekyll class with access to global site config information. - class Site - - # Creates an instance of CategoryIndex for each category page, renders it, and - # writes the output to a file. - # - # +category_dir+ is the String path to the category folder. - # +category+ is the category currently being processed. - def write_category_index(category_dir, category) - index = CategoryIndex.new(self, self.source, category_dir, category) - index.render(self.layouts, site_payload) - index.write(self.dest) - # Record the fact that this page has been added, otherwise Site::cleanup will remove it. - self.pages << index - - # Create an Atom-feed for each index. - feed = CategoryFeed.new(self, self.source, category_dir, category) - feed.render(self.layouts, site_payload) - feed.write(self.dest) - # Record the fact that this page has been added, otherwise Site::cleanup will remove it. - self.pages << feed - end - - # Loops through the list of category pages and processes each one. - def write_category_indexes - if self.layouts.key? 'category_index' - dir = self.config['category_dir'] || 'categories' - self.categories.keys.each do |category| - self.write_category_index(File.join(dir, category.to_url), category) - end - - # Throw an exception if the layout couldn't be found. - else - raise <<-ERR - - -=============================================== - Error for category_generator.rb plugin ------------------------------------------------ - No 'category_index.html' in source/_layouts/ - Perhaps you haven't installed a theme yet. -=============================================== - -ERR - end - end - - end - - - # Jekyll hook - the generate method is called by jekyll, and generates all of the category pages. - class GenerateCategories < Generator - safe true - priority :low - - def generate(site) - site.write_category_indexes - end - - end - - - # Adds some extra filters used during the category creation process. - module Filters - - # Outputs a list of categories as comma-separated <a> links. This is used - # to output the category list for each post on a category page. - # - # +categories+ is the list of categories to format. - # - # Returns string - # - def category_links(categories) - categories = categories.sort!.map { |c| category_link c } - - case categories.length - when 0 - "" - when 1 - categories[0].to_s - else - "#{categories[0...-1].join(', ')}, #{categories[-1]}" - end - end - - # Outputs a single category as an <a> link. - # - # +category+ is a category string to format as an <a> link - # - # Returns string - # - def category_link(category) - dir = @context.registers[:site].config['category_dir'] - "<a class='category' href='/#{dir}/#{category.to_url}/'>#{category}</a>" - end - - # Outputs the post.date as formatted html, with hooks for CSS styling. - # - # +date+ is the date object to format as HTML. - # - # Returns string - def date_to_html_string(date) - result = '<span class="month">' + date.strftime('%b').upcase + '</span> ' - result += date.strftime('<span class="day">%d</span> ') - result += date.strftime('<span class="year">%Y</span> ') - result - end - - end - -end diff --git a/plugins/code_block.rb b/plugins/code_block.rb deleted file mode 100644 index 539a3475..00000000 --- a/plugins/code_block.rb +++ /dev/null @@ -1,92 +0,0 @@ -# Title: Simple Code Blocks for Jekyll -# Author: Brandon Mathis http://brandonmathis.com -# Description: Write codeblocks with semantic HTML5 <figure> and <figcaption> elements and optional syntax highlighting — all with a simple, intuitive interface. -# -# Syntax: -# {% codeblock [title] [url] [link text] %} -# code snippet -# {% endcodeblock %} -# -# For syntax highlighting, put a file extension somewhere in the title. examples: -# {% codeblock file.sh %} -# code snippet -# {% endcodeblock %} -# -# {% codeblock Time to be Awesome! (awesome.rb) %} -# code snippet -# {% endcodeblock %} -# -# Example: -# -# {% codeblock Got pain? painreleif.sh http://site.com/painreleief.sh Download it! %} -# $ rm -rf ~/PAIN -# {% endcodeblock %} -# -# Output: -# -# <figure class='code'> -# <figcaption><span>Got pain? painrelief.sh</span> <a href="http://site.com/painrelief.sh">Download it!</a> -# <div class="highlight"><pre><code class="sh"> -# -- nicely escaped highlighted code -- -# </code></pre></div> -# </figure> -# -# Example 2 (no syntax highlighting): -# -# {% codeblock %} -# <sarcasm>Ooooh, sarcasm... How original!</sarcasm> -# {% endcodeblock %} -# -# <figure class='code'> -# <pre><code><sarcasm> Ooooh, sarcasm... How original!</sarcasm></code></pre> -# </figure> -# -require './plugins/pygments_code' -require './plugins/raw' - -module Jekyll - - class CodeBlock < Liquid::Block - CaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i - Caption = /(\S[\S\s]*)/ - def initialize(tag_name, markup, tokens) - @title = nil - @caption = nil - @filetype = nil - @highlight = true - if markup =~ /\s*lang:(\S+)/i - @filetype = $1 - markup = markup.sub(/\s*lang:(\S+)/i,'') - end - if markup =~ CaptionUrlTitle - @file = $1 - @caption = "<figcaption><span>#{$1}</span><a href='#{$2}'>#{$3 || 'link'}</a></figcaption>" - elsif markup =~ Caption - @file = $1 - @caption = "<figcaption><span>#{$1}</span></figcaption>\n" - end - if @file =~ /\S[\S\s]*\w+\.(\w+)/ && @filetype.nil? - @filetype = $1 - end - super - end - - def render(context) - output = super - code = super - source = "<figure class='code'>" - source += @caption if @caption - if @filetype - source += "#{HighlightCode::highlight(code, @filetype)}</figure>" - else - source += "#{HighlightCode::tableize_code(code.lstrip.rstrip.gsub(/</,'<'))}</figure>" - end - source = TemplateWrapper::safe_wrap(source) - source = context['pygments_prefix'] + source if context['pygments_prefix'] - source = source + context['pygments_suffix'] if context['pygments_suffix'] - source - end - end -end - -Liquid::Template.register_tag('codeblock', Jekyll::CodeBlock) diff --git a/plugins/config_tag.rb b/plugins/config_tag.rb deleted file mode 100644 index 92d1f63c..00000000 --- a/plugins/config_tag.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'json' - -class ConfigTag < Liquid::Tag - def initialize(tag_name, options, tokens) - super - options = options.split(' ').map {|i| i.strip } - @key = options.slice!(0) - @tag = nil - @classname = nil - options.each do |option| - @tag = $1 if option =~ /tag:(\S+)/ - @classname = $1 if option =~ /classname:(\S+)/ - end - end - - def render(context) - config_tag(context.registers[:site].config, @key, @tag, @classname) - end -end - -def config_tag(config, key, tag=nil, classname=nil) - options = key.split('.').map { |k| config[k] }.last #reference objects with dot notation - tag ||= 'div' - classname ||= key.sub(/_/, '-').sub(/\./, '-') - output = "<#{tag} class='#{classname}'" - - if options.respond_to? 'keys' - options.each do |k,v| - unless v.nil? - v = v.join ',' if v.respond_to? 'join' - v = v.to_json if v.respond_to? 'keys' - output += " data-#{k.sub'_','-'}='#{v}'" - end - end - elsif options.respond_to? 'join' - output += " data-value='#{config[key].join(',')}'" - else - output += " data-value='#{config[key]}'" - end - output += "></#{tag}>" -end - -Liquid::Template.register_tag('config_tag', ConfigTag) - diff --git a/plugins/gist_tag.rb b/plugins/gist_tag.rb deleted file mode 100644 index 51201156..00000000 --- a/plugins/gist_tag.rb +++ /dev/null @@ -1,130 +0,0 @@ -# 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 1027674 gist_tag.rb %} //embeds a gist for this plugin - -require 'cgi' -require 'digest/md5' -require 'net/https' -require 'uri' - -module Jekyll - class GistTag < Liquid::Tag - def initialize(tag_name, text, token) - super - @text = text - @cache_disabled = false - @cache_folder = File.expand_path "../.gist-cache", File.dirname(__FILE__) - FileUtils.mkdir_p @cache_folder - end - - def render(context) - if parts = @text.match(/([a-zA-Z\d]*) (.*)/) - gist, file = parts[1].strip, parts[2].strip - else - gist, file = @text.strip, "" - end - if gist.empty? - "" - else - 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 - end - end - - def html_output_for(script_url, code) - code = CGI.escapeHTML code - <<-HTML -<div><script src='#{script_url}'></script> -<noscript><pre><code>#{code}</code></pre></noscript></div> - HTML - end - - def script_url_for(gist_id, filename) - url = "https://gist.github.com/#{gist_id}.js" - url = "#{url}?file=#{filename}" unless filename.nil? or filename.empty? - url - end - - def get_gist_url_for(gist, file) - "https://gist.githubusercontent.com/raw/#{gist}/#{file}" - end - - 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_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) - 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) - data = get_web_content(gist_url) - - locations = Array.new - while (data.code.to_i == 301 || data.code.to_i == 302) - data = handle_gist_redirecting(data) - break if locations.include? data.header['Location'] - locations << data.header['Location'] - end - - if data.code.to_i != 200 - raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}" - end - - cache(gist, file, data.body) unless @cache_disabled - data.body - end - - def handle_gist_redirecting(data) - redirected_url = data.header['Location'] - if redirected_url.nil? || redirected_url.empty? - raise ArgumentError, "GitHub replied with a 302 but didn't provide a location in the response headers." - end - - get_web_content(redirected_url) - end - - def get_web_content(url) - raw_uri = URI.parse url - proxy = ENV['http_proxy'] - if proxy - proxy_uri = URI.parse(proxy) - https = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port).new raw_uri.host, raw_uri.port - else - https = Net::HTTP.new raw_uri.host, raw_uri.port - end - https.use_ssl = true - https.verify_mode = OpenSSL::SSL::VERIFY_NONE - request = Net::HTTP::Get.new raw_uri.request_uri - data = https.request request - end - end - - class GistTagNoCache < GistTag - def initialize(tag_name, text, token) - super - @cache_disabled = true - end - end -end - -Liquid::Template.register_tag('gist', Jekyll::GistTag) -Liquid::Template.register_tag('gistnocache', Jekyll::GistTagNoCache) diff --git a/plugins/haml.rb b/plugins/haml.rb deleted file mode 100644 index 7e548dec..00000000 --- a/plugins/haml.rb +++ /dev/null @@ -1,24 +0,0 @@ -module Jekyll - require 'haml' - class HamlConverter < Converter - safe true - priority :low - - def matches(ext) - ext =~ /haml/i - end - - def output_ext(ext) - ".html" - end - - def convert(content) - begin - engine = Haml::Engine.new(content) - engine.render - rescue StandardError => e - puts "!!! HAML Error: " + e.message - end - end - end -end diff --git a/plugins/image_tag.rb b/plugins/image_tag.rb deleted file mode 100644 index 45670007..00000000 --- a/plugins/image_tag.rb +++ /dev/null @@ -1,50 +0,0 @@ -# Title: Simple Image tag for Jekyll -# Authors: Brandon Mathis http://brandonmathis.com -# Felix Schäfer, Frederic Hemberger -# Description: Easily output images with optional class names, width, height, title and alt attributes -# -# Syntax {% img [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | "title text" ["alt text"]] %} -# -# Examples: -# {% img /images/ninja.png Ninja Attack! %} -# {% img left half http://site.com/images/ninja.png Ninja Attack! %} -# {% img left half http://site.com/images/ninja.png 150 150 "Ninja Attack!" "Ninja in attack posture" %} -# -# Output: -# <img src="/images/ninja.png"> -# <img class="left half" src="http://site.com/images/ninja.png" title="Ninja Attack!" alt="Ninja Attack!"> -# <img class="left half" src="http://site.com/images/ninja.png" width="150" height="150" title="Ninja Attack!" alt="Ninja in attack posture"> -# - -module Jekyll - - class ImageTag < Liquid::Tag - @img = nil - - def initialize(tag_name, markup, tokens) - attributes = ['class', 'src', 'width', 'height', 'title'] - - if markup =~ /(?<class>\S.*\s+)?(?<src>(?:https?:\/\/|\/|\S+\/)\S+)(?:\s+(?<width>\d+))?(?:\s+(?<height>\d+))?(?<title>\s+.+)?/i - @img = attributes.reduce({}) { |img, attr| img[attr] = $~[attr].strip if $~[attr]; img } - if /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/ =~ @img['title'] - @img['title'] = title - @img['alt'] = alt - else - @img['alt'] = @img['title'].gsub!(/"/, '"') if @img['title'] - end - @img['class'].gsub!(/"/, '') if @img['class'] - end - super - end - - def render(context) - if @img - "<img #{@img.collect {|k,v| "#{k}=\"#{v}\"" if v}.join(" ")}>" - else - "Error processing input, expected syntax: {% img [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | \"title text\" [\"alt text\"]] %}" - end - end - end -end - -Liquid::Template.register_tag('img', Jekyll::ImageTag) diff --git a/plugins/include_array.rb b/plugins/include_array.rb deleted file mode 100644 index 000040fb..00000000 --- a/plugins/include_array.rb +++ /dev/null @@ -1,58 +0,0 @@ -# Title: Include Array Tag for Jekyll -# Author: Jason Woodward http://www.woodwardjd.com -# Description: Import files on your filesystem as specified in a configuration variable in _config.yml. Mostly cribbed from Jekyll's include tag. -# Syntax: {% include_array variable_name_from_config.yml %} -# -# Example 1: -# {% include_array asides %} -# -# _config.yml snippet: -# asides: [asides/twitter.html, asides/custom/my_picture.html] -# -module Jekyll - - class IncludeArrayTag < Liquid::Tag - Syntax = /(#{Liquid::QuotedFragment}+)/ - def initialize(tag_name, markup, tokens) - if markup =~ Syntax - @array_name = $1 - else - raise SyntaxError.new("Error in tag 'include_array' - Valid syntax: include_array [array from _config.yml]") - end - - super - end - - def render(context) - includes_dir = File.join(context.registers[:site].source, '_includes') - - if File.symlink?(includes_dir) - return "Includes directory '#{includes_dir}' cannot be a symlink" - end - - rtn = '' - (context.environments.first['site'][@array_name] || []).each do |file| - if file !~ /^[a-zA-Z0-9_\/\.-]+$/ || file =~ /\.\// || file =~ /\/\./ - rtn = rtn + "Include file '#{file}' contains invalid characters or sequences" - end - - Dir.chdir(includes_dir) do - choices = Dir['**/*'].reject { |x| File.symlink?(x) } - if choices.include?(file) - source = File.read(file) - partial = Liquid::Template.parse(source) - context.stack do - rtn = rtn + partial.render(context) - end - else - rtn = rtn + "Included file '#{file}' not found in _includes directory" - end - end - end - rtn - end - end - -end - -Liquid::Template.register_tag('include_array', Jekyll::IncludeArrayTag) diff --git a/plugins/include_code.rb b/plugins/include_code.rb deleted file mode 100644 index a61d06cf..00000000 --- a/plugins/include_code.rb +++ /dev/null @@ -1,71 +0,0 @@ -# Title: Include Code Tag for Jekyll -# Author: Brandon Mathis http://brandonmathis.com -# Description: Import files on your filesystem into any blog post as embedded code snippets with syntax highlighting and a download link. -# Configuration: You can set default import path in _config.yml (defaults to code_dir: downloads/code) -# -# Syntax {% include_code path/to/file %} -# -# Example 1: -# {% include_code javascripts/test.js %} -# -# This will import test.js from source/downloads/code/javascripts/test.js -# and output the contents in a syntax highlighted code block inside a figure, -# with a figcaption listing the file name and download link -# -# Example 2: -# You can also include an optional title for the <figcaption> -# -# {% include_code Example 2 javascripts/test.js %} -# -# will output a figcaption with the title: Example 2 (test.js) -# - -require './plugins/pygments_code' -require './plugins/raw' -require 'pathname' - -module Jekyll - - class IncludeCodeTag < Liquid::Tag - def initialize(tag_name, markup, tokens) - @title = nil - @file = nil - if markup.strip =~ /\s*lang:(\S+)/i - @filetype = $1 - markup = markup.strip.sub(/lang:\S+/i,'') - end - if markup.strip =~ /(.*)?(\s+|^)(\/*\S+)/i - @title = $1 || nil - @file = $3 - end - super - end - - def render(context) - code_dir = (context.registers[:site].config['code_dir'].sub(/^\//,'') || '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 - @filetype = file.extname.sub('.','') if @filetype.nil? - title = @title ? "#{@title} (#{file.basename})" : file.basename - url = "/#{code_dir}/#{@file}" - source = "<figure class='code'><figcaption><span>#{title}</span> <a href='#{url}'>download</a></figcaption>\n" - source += "#{HighlightCode::highlight(code, @filetype)}</figure>" - TemplateWrapper::safe_wrap(source) - end - end - end - -end - -Liquid::Template.register_tag('include_code', Jekyll::IncludeCodeTag) diff --git a/plugins/jsfiddle.rb b/plugins/jsfiddle.rb deleted file mode 100644 index 815910e2..00000000 --- a/plugins/jsfiddle.rb +++ /dev/null @@ -1,40 +0,0 @@ -# Title: jsFiddle tag for Jekyll -# Author: Brian Arnold (@brianarn) -# Description: -# Given a jsFiddle shortcode, outputs the jsFiddle iframe code. -# Using 'default' will preserve defaults as specified by jsFiddle. -# -# Syntax: {% jsfiddle shorttag [tabs] [skin] [height] [width] %} -# -# Examples: -# -# Input: {% jsfiddle ccWP7 %} -# Output: <iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/ccWP7/embedded/js,resources,html,css,result/light/"></iframe> -# -# Input: {% jsfiddle ccWP7 js,html,result %} -# Output: <iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/ccWP7/embedded/js,html,result/light/"></iframe> -# - -module Jekyll - class JsFiddle < Liquid::Tag - def initialize(tag_name, markup, tokens) - if /(?<fiddle>\w+\/?\d?)(?:\s+(?<sequence>[\w,]+))?(?:\s+(?<skin>\w+))?(?:\s+(?<height>\w+))?(?:\s+(?<width>\w+))?/ =~ markup - @fiddle = fiddle - @sequence = (sequence unless sequence == 'default') || 'js,resources,html,css,result' - @skin = (skin unless skin == 'default') || 'light' - @width = width || '100%' - @height = height || '300px' - end - end - - def render(context) - if @fiddle - "<iframe style=\"width: #{@width}; height: #{@height}\" frameborder=\"0\" seamless=\"seamless\" src=\"http://jsfiddle.net/#{@fiddle}/embedded/#{@sequence}/#{@skin}/\"></iframe>" - else - "Error processing input, expected syntax: {% jsfiddle shorttag [tabs] [skin] [height] [width] %}" - end - end - end -end - -Liquid::Template.register_tag('jsfiddle', Jekyll::JsFiddle) diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb deleted file mode 100644 index 9c7fa6c5..00000000 --- a/plugins/octopress_filters.rb +++ /dev/null @@ -1,142 +0,0 @@ -#custom filters for Octopress -require './plugins/backtick_code_block' -require 'octopress-hooks' -require 'jekyll-sitemap' -require 'octopress-date-format' -require './plugins/raw' -require 'rubypants' - -module OctopressFilters - def self.pre_filter(page) - if page.ext.match('html|textile|markdown|md|haml|slim|xml') - input = BacktickCodeBlock::render_code_block(page.content) - page.content = input.gsub /(<figure.+?>.+?<\/figure>)/m do - TemplateWrapper::safe_wrap($1) - end - end - end - def self.post_filter(page) - if page.ext.match('html|textile|markdown|md|haml|slim|xml') - page.output = TemplateWrapper::unwrap(page.output) - end - - page.output = RubyPants.new(page.output).to_html - end - - class PageFilters < Octopress::Hooks::Page - def pre_render(page) - OctopressFilters::pre_filter(page) - end - - def post_render(page) - OctopressFilters::post_filter(page) - end - end - - class PostFilters < Octopress::Hooks::Post - def pre_render(post) - OctopressFilters::pre_filter(post) - end - - def post_render(post) - OctopressFilters::post_filter(post) - end - end -end - - -module OctopressLiquidFilters - - # Used on the blog index to split posts on the <!--more--> marker - def excerpt(input) - if input.index(/<!--\s*more\s*-->/i) - input.split(/<!--\s*more\s*-->/i)[0] - else - input - end - end - - # Checks for excerpts (helpful for template conditionals) - def has_excerpt(input) - input =~ /<!--\s*more\s*-->/i ? true : false - end - - # Summary is used on the Archive pages to return the first block of content from a post. - def summary(input) - if input.index(/\n\n/) - input.split(/\n\n/)[0] - else - input - end - end - - # Extracts raw content DIV from template, used for page description as {{ content }} - # contains complete sub-template code on main page level - def raw_content(input) - /<div class="entry-content">(?<content>[\s\S]*?)<\/div>\s*<(footer|\/article)>/ =~ input - return (content.nil?) ? input : content - end - - # Escapes CDATA sections in post content - def cdata_escape(input) - input.gsub(/<!\[CDATA\[/, '<![CDATA[').gsub(/\]\]>/, ']]>') - end - - # Replaces relative urls with full urls - def expand_urls(input, url='') - url ||= '/' - input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\/>]{1}[^\"'>]*)/ do - $1+url+$3 - end - end - - # Improved version of Liquid's truncate: - # - Doesn't cut in the middle of a word. - # - Uses typographically correct ellipsis (…) insted of '...' - def truncate(input, length) - if input.length > length && input[0..(length-1)] =~ /(.+)\b.+$/im - $1.strip + ' …' - else - input - end - end - - # Improved version of Liquid's truncatewords: - # - Uses typographically correct ellipsis (…) insted of '...' - def truncatewords(input, length) - truncate = input.split(' ') - if truncate.length > length - truncate[0..length-1].join(' ').strip + ' …' - else - input - end - end - - # Condenses multiple spaces and tabs into a single space - def condense_spaces(input) - input.gsub(/\s{2,}/, ' ') - end - - # Removes trailing forward slash from a string for easily appending url segments - def strip_slash(input) - if input =~ /(.+)\/$|^\/$/ - input = $1 - end - input - end - - # Returns a url without the protocol (http://) - def shorthand_url(input) - input.gsub /(https?:\/\/)(\S+)/ do - $2 - end - end - - # Returns a title cased string based on John Gruber's title case http://daringfireball.net/2008/08/title_case_update - def titlecase(input) - input.titlecase - end - -end -Liquid::Template.register_filter OctopressLiquidFilters - diff --git a/plugins/pullquote.rb b/plugins/pullquote.rb deleted file mode 100644 index 3c65e66e..00000000 --- a/plugins/pullquote.rb +++ /dev/null @@ -1,45 +0,0 @@ -# -# Author: Brandon Mathis -# Based on the semantic pullquote technique by Maykel Loomans at http://miekd.com/articles/pull-quotes-with-html5-and-css/ -# -# Outputs a span with a data-pullquote attribute set from the marked pullquote. Example: -# -# {% pullquote %} -# When writing longform posts, I find it helpful to include pullquotes, which help those scanning a post discern whether or not a post is helpful. -# It is important to note, {" pullquotes are merely visual in presentation and should not appear twice in the text. "} That is why it is prefered -# to use a CSS only technique for styling pullquotes. -# {% endpullquote %} -# ...will output... -# <p> -# <span data-pullquote="pullquotes are merely visual in presentation and should not appear twice in the text."> -# When writing longform posts, I find it helpful to include pullquotes, which help those scanning a post discern whether or not a post is helpful. -# It is important to note, pullquotes are merely visual in presentation and should not appear twice in the text. This is why a CSS only approach -# for styling pullquotes is prefered. -# </span> -# </p> -# -# {% pullquote left %} will create a left-aligned pullquote instead. -# -# Note: this plugin now creates pullquotes with the class of pullquote-right by default - -module Jekyll - - class PullquoteTag < Liquid::Block - def initialize(tag_name, markup, tokens) - @align = (markup =~ /left/i) ? "left" : "right" - super - end - - def render(context) - output = super - if output =~ /\{"\s*(.+?)\s*"\}/m - @quote = RubyPants.new($1).to_html - "<span class='pullquote-#{@align}' data-pullquote='#{@quote}'>#{output.gsub(/\{"\s*|\s*"\}/, '')}</span>" - else - return "Surround your pullquote like this {\" text to be quoted \"}" - end - end - end -end - -Liquid::Template.register_tag('pullquote', Jekyll::PullquoteTag) diff --git a/plugins/pygments_code.rb b/plugins/pygments_code.rb deleted file mode 100644 index c0f4de92..00000000 --- a/plugins/pygments_code.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'pygments' -require 'fileutils' -require 'digest/md5' - -PYGMENTS_CACHE_DIR = File.expand_path('../../.pygments-cache', __FILE__) -FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) - -module HighlightCode - def self.highlight(str, lang) - lang = 'ruby' if lang == 'ru' - lang = 'objc' if lang == 'm' - lang = 'perl' if lang == 'pl' - lang = 'yaml' if lang == 'yml' - str = pygments(str, lang).match(/<pre>(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '') #strip out divs <div class="highlight"> - tableize_code(str, lang) - end - - def self.pygments(code, lang) - if defined?(PYGMENTS_CACHE_DIR) - path = File.join(PYGMENTS_CACHE_DIR, "#{lang}-#{Digest::MD5.hexdigest(code)}.html") - if File.exist?(path) - highlighted_code = File.read(path) - else - begin - highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8', :startinline => true}) - rescue MentosError - raise "Pygments can't parse unknown language: #{lang}." - end - File.open(path, 'w') {|f| f.print(highlighted_code) } - end - else - highlighted_code = Pygments.highlight(code, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8', :startinline => true}) - end - highlighted_code - end - def self.tableize_code (str, lang = '') - table = '<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers">' - code = '' - str.lines.each_with_index do |line,index| - table += "<span class='line-number'>#{index+1}</span>\n" - code += "<span class='line'>#{line}</span>" - end - table += "</pre></td><td class='code'><pre><code class='#{lang}'>#{code}</code></pre></td></tr></table></div>" - end -end diff --git a/plugins/raw.rb b/plugins/raw.rb deleted file mode 100644 index e97c9459..00000000 --- a/plugins/raw.rb +++ /dev/null @@ -1,40 +0,0 @@ -# Author: Brandon Mathis -# Description: Provides plugins with a method for wrapping and unwrapping input to prevent Markdown and Textile from parsing it. -# Purpose: This is useful for preventing Markdown and Textile from being too aggressive and incorrectly parsing in-line HTML. -module TemplateWrapper - # Wrap input with a <div> - def self.safe_wrap(input) - "<div class='bogus-wrapper'><notextile>#{input}</notextile></div>" - end - # This must be applied after the - def self.unwrap(input) - input.gsub /<div class='bogus-wrapper'><notextile>(.+?)<\/notextile><\/div>/m do - $1 - end - end -end - -# Author: phaer, https://github.com/phaer -# Source: https://gist.github.com/1020852 -# Description: Raw tag for jekyll. Keeps liquid from parsing text betweeen {% raw %} and {% endraw %} - -module Jekyll - class RawTag < Liquid::Block - def parse(tokens) - @nodelist ||= [] - @nodelist.clear - - while token = tokens.shift - if token =~ FullToken - if block_delimiter == $1 - end_tag - return - end - end - @nodelist << token if not token.empty? - end - end - end -end - -Liquid::Template.register_tag('raw', Jekyll::RawTag) diff --git a/plugins/render_partial.rb b/plugins/render_partial.rb deleted file mode 100644 index b6ebfe8b..00000000 --- a/plugins/render_partial.rb +++ /dev/null @@ -1,69 +0,0 @@ -# Title: Render Partial Tag for Jekyll -# Author: Brandon Mathis http://brandonmathis.com -# Description: Import files on your filesystem into any blog post and render them inline. -# Note: Paths are relative to the source directory, if you import a file with yaml front matter, the yaml will be stripped out. -# -# Syntax {% render_partial path/to/file %} -# -# Example 1: -# {% render_partial about/_bio.markdown %} -# -# This will import source/about/_bio.markdown and render it inline. -# In this example I used an underscore at the beginning of the filename to prevent Jekyll -# from generating an about/bio.html (Jekyll doesn't convert files beginning with underscores) -# -# Example 2: -# {% render_partial ../README.markdown %} -# -# You can use relative pathnames, to include files outside of the source directory. -# This might be useful if you want to have a page for a project's README without having -# to duplicated the contents -# -# - -require 'pathname' -require './plugins/octopress_filters' - -module Jekyll - - class RenderPartialTag < Liquid::Tag - include OctopressFilters - def initialize(tag_name, markup, tokens) - @file = nil - @raw = false - if markup =~ /^(\S+)\s?(\w+)?/ - @file = $1.strip - @raw = $2 == 'raw' - end - super - end - - def render(context) - file_dir = (context.registers[:site].source || 'source') - file_path = Pathname.new(file_dir).expand_path - file = file_path + @file - - unless file.file? - return "File #{file} could not be found" - end - - Dir.chdir(file_path) do - contents = file.read - if contents =~ /\A-{3}.+[^\A]-{3}\n(.+)/m - contents = $1.lstrip - end - contents = pre_filter(contents) - if @raw - contents - else - partial = Liquid::Template.parse(contents) - context.stack do - partial.render(context) - end - end - end - end - end -end - -Liquid::Template.register_tag('render_partial', Jekyll::RenderPartialTag) diff --git a/plugins/rubypants.rb b/plugins/rubypants.rb deleted file mode 100644 index e4f4502f..00000000 --- a/plugins/rubypants.rb +++ /dev/null @@ -1,489 +0,0 @@ -# -# = RubyPants -- SmartyPants ported to Ruby -# -# Ported by Christian Neukirchen <mailto:chneukirchen@gmail.com> -# Copyright (C) 2004 Christian Neukirchen -# -# Incooporates ideas, comments and documentation by Chad Miller -# Copyright (C) 2004 Chad Miller -# -# Original SmartyPants by John Gruber -# Copyright (C) 2003 John Gruber -# - -# -# = RubyPants -- SmartyPants ported to Ruby -# -# == Synopsis -# -# RubyPants is a Ruby port of the smart-quotes library SmartyPants. -# -# The original "SmartyPants" is a free web publishing plug-in for -# Movable Type, Blosxom, and BBEdit that easily translates plain ASCII -# punctuation characters into "smart" typographic punctuation HTML -# entities. -# -# -# == Description -# -# RubyPants can perform the following transformations: -# -# * Straight quotes (<tt>"</tt> and <tt>'</tt>) into "curly" quote -# HTML entities -# * Backticks-style quotes (<tt>``like this''</tt>) into "curly" quote -# HTML entities -# * Dashes (<tt>--</tt> and <tt>---</tt>) into en- and em-dash -# entities -# * Three consecutive dots (<tt>...</tt> or <tt>. . .</tt>) into an -# ellipsis entity -# -# This means you can write, edit, and save your posts using plain old -# ASCII straight quotes, plain dashes, and plain dots, but your -# published posts (and final HTML output) will appear with smart -# quotes, em-dashes, and proper ellipses. -# -# RubyPants does not modify characters within <tt><pre></tt>, -# <tt><code></tt>, <tt><kbd></tt>, <tt><math></tt> or -# <tt><script></tt> tag blocks. Typically, these tags are used to -# display text where smart quotes and other "smart punctuation" would -# not be appropriate, such as source code or example markup. -# -# -# == Backslash Escapes -# -# If you need to use literal straight quotes (or plain hyphens and -# periods), RubyPants accepts the following backslash escape sequences -# to force non-smart punctuation. It does so by transforming the -# escape sequence into a decimal-encoded HTML entity: -# -# \\ \" \' \. \- \` -# -# This is useful, for example, when you want to use straight quotes as -# foot and inch marks: 6'2" tall; a 17" iMac. (Use <tt>6\'2\"</tt> -# resp. <tt>17\"</tt>.) -# -# -# == Algorithmic Shortcomings -# -# One situation in which quotes will get curled the wrong way is when -# apostrophes are used at the start of leading contractions. For -# example: -# -# 'Twas the night before Christmas. -# -# In the case above, RubyPants will turn the apostrophe into an -# opening single-quote, when in fact it should be a closing one. I -# don't think this problem can be solved in the general case--every -# word processor I've tried gets this wrong as well. In such cases, -# it's best to use the proper HTML entity for closing single-quotes -# ("<tt>’</tt>") by hand. -# -# -# == Bugs -# -# To file bug reports or feature requests (except see above) please -# send email to: mailto:chneukirchen@gmail.com -# -# If the bug involves quotes being curled the wrong way, please send -# example text to illustrate. -# -# -# == Authors -# -# John Gruber did all of the hard work of writing this software in -# Perl for Movable Type and almost all of this useful documentation. -# Chad Miller ported it to Python to use with Pyblosxom. -# -# Christian Neukirchen provided the Ruby port, as a general-purpose -# library that follows the *Cloth API. -# -# -# == Copyright and License -# -# === SmartyPants license: -# -# Copyright (c) 2003 John Gruber -# (http://daringfireball.net) -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# * Neither the name "SmartyPants" nor the names of its contributors -# may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# This software is provided by the copyright holders and contributors -# "as is" and any express or implied warranties, including, but not -# limited to, the implied warranties of merchantability and fitness -# for a particular purpose are disclaimed. In no event shall the -# copyright owner or contributors be liable for any direct, indirect, -# incidental, special, exemplary, or consequential damages (including, -# but not limited to, procurement of substitute goods or services; -# loss of use, data, or profits; or business interruption) however -# caused and on any theory of liability, whether in contract, strict -# liability, or tort (including negligence or otherwise) arising in -# any way out of the use of this software, even if advised of the -# possibility of such damage. -# -# === RubyPants license -# -# RubyPants is a derivative work of SmartyPants and smartypants.py. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# This software is provided by the copyright holders and contributors -# "as is" and any express or implied warranties, including, but not -# limited to, the implied warranties of merchantability and fitness -# for a particular purpose are disclaimed. In no event shall the -# copyright owner or contributors be liable for any direct, indirect, -# incidental, special, exemplary, or consequential damages (including, -# but not limited to, procurement of substitute goods or services; -# loss of use, data, or profits; or business interruption) however -# caused and on any theory of liability, whether in contract, strict -# liability, or tort (including negligence or otherwise) arising in -# any way out of the use of this software, even if advised of the -# possibility of such damage. -# -# -# == Links -# -# John Gruber:: http://daringfireball.net -# SmartyPants:: http://daringfireball.net/projects/smartypants -# -# Chad Miller:: http://web.chad.org -# -# Christian Neukirchen:: http://kronavita.de/chris -# - - -class RubyPants < String - - # Create a new RubyPants instance with the text in +string+. - # - # Allowed elements in the options array: - # - # 0 :: do nothing - # 1 :: enable all, using only em-dash shortcuts - # 2 :: enable all, using old school en- and em-dash shortcuts (*default*) - # 3 :: enable all, using inverted old school en and em-dash shortcuts - # -1 :: stupefy (translate HTML entities to their ASCII-counterparts) - # - # If you don't like any of these defaults, you can pass symbols to change - # RubyPants' behavior: - # - # <tt>:quotes</tt> :: quotes - # <tt>:backticks</tt> :: backtick quotes (``double'' only) - # <tt>:allbackticks</tt> :: backtick quotes (``double'' and `single') - # <tt>:dashes</tt> :: dashes - # <tt>:oldschool</tt> :: old school dashes - # <tt>:inverted</tt> :: inverted old school dashes - # <tt>:ellipses</tt> :: ellipses - # <tt>:convertquotes</tt> :: convert <tt>"</tt> entities to - # <tt>"</tt> for Dreamweaver users - # <tt>:stupefy</tt> :: translate RubyPants HTML entities - # to their ASCII counterparts. - # - def initialize(string, options=[2]) - super string - @options = [*options] - end - - # Apply SmartyPants transformations. - def to_html - do_quotes = do_backticks = do_dashes = do_ellipses = do_stupify = nil - convert_quotes = false - - if @options.include? 0 - # Do nothing. - return self - elsif @options.include? 1 - # Do everything, turn all options on. - do_quotes = do_backticks = do_ellipses = true - do_dashes = :normal - elsif @options.include? 2 - # Do everything, turn all options on, use old school dash shorthand. - do_quotes = do_backticks = do_ellipses = true - do_dashes = :oldschool - elsif @options.include? 3 - # Do everything, turn all options on, use inverted old school - # dash shorthand. - do_quotes = do_backticks = do_ellipses = true - do_dashes = :inverted - elsif @options.include?(-1) - do_stupefy = true - else - do_quotes = @options.include? :quotes - do_backticks = @options.include? :backticks - do_backticks = :both if @options.include? :allbackticks - do_dashes = :normal if @options.include? :dashes - do_dashes = :oldschool if @options.include? :oldschool - do_dashes = :inverted if @options.include? :inverted - do_ellipses = @options.include? :ellipses - convert_quotes = @options.include? :convertquotes - do_stupefy = @options.include? :stupefy - end - - # Parse the HTML - tokens = tokenize - - # Keep track of when we're inside <pre> or <code> tags. - in_pre = false - - # Here is the result stored in. - result = "" - - # This is a cheat, used to get some context for one-character - # tokens that consist of just a quote char. What we do is remember - # the last character of the previous text token, to use as context - # to curl single- character quote tokens correctly. - prev_token_last_char = nil - - tokens.each { |token| - if token.first == :tag - result << token[1] - if token[1] =~ %r!<(/?)(?:pre|code|kbd|script|math)[\s>]! - in_pre = ($1 != "/") # Opening or closing tag? - end - else - t = token[1] - - # Remember last char of this token before processing. - last_char = t[-1].chr - - unless in_pre - t = process_escapes t - - t.gsub!(/"/, '"') if convert_quotes - - if do_dashes - t = educate_dashes t if do_dashes == :normal - t = educate_dashes_oldschool t if do_dashes == :oldschool - t = educate_dashes_inverted t if do_dashes == :inverted - end - - t = educate_ellipses t if do_ellipses - - # Note: backticks need to be processed before quotes. - if do_backticks - t = educate_backticks t - t = educate_single_backticks t if do_backticks == :both - end - - if do_quotes - if t == "'" - # Special case: single-character ' token - if prev_token_last_char =~ /\S/ - t = "’" - else - t = "‘" - end - elsif t == '"' - # Special case: single-character " token - if prev_token_last_char =~ /\S/ - t = "”" - else - t = "“" - end - else - # Normal case: - t = educate_quotes t - end - end - - t = stupefy_entities t if do_stupefy - end - - prev_token_last_char = last_char - result << t - end - } - - # Done - result - end - - protected - - # Return the string, with after processing the following backslash - # escape sequences. This is useful if you want to force a "dumb" quote - # or other character to appear. - # - # Escaped are: - # \\ \" \' \. \- \` - # - def process_escapes(str) - str.gsub('\\\\', '\'). - gsub('\"', '"'). - gsub("\\\'", '''). - gsub('\.', '.'). - gsub('\-', '-'). - gsub('\`', '`') - end - - # The string, with each instance of "<tt>--</tt>" translated to an - # em-dash HTML entity. - # - def educate_dashes(str) - str.gsub(/--/, '—') - end - - # The string, with each instance of "<tt>--</tt>" translated to an - # en-dash HTML entity, and each "<tt>---</tt>" translated to an - # em-dash HTML entity. - # - def educate_dashes_oldschool(str) - str.gsub(/---/, '—').gsub(/--/, '–') - end - - # Return the string, with each instance of "<tt>--</tt>" translated - # to an em-dash HTML entity, and each "<tt>---</tt>" translated to - # an en-dash HTML entity. Two reasons why: First, unlike the en- and - # em-dash syntax supported by +educate_dashes_oldschool+, it's - # compatible with existing entries written before SmartyPants 1.1, - # back when "<tt>--</tt>" was only used for em-dashes. Second, - # em-dashes are more common than en-dashes, and so it sort of makes - # sense that the shortcut should be shorter to type. (Thanks to - # Aaron Swartz for the idea.) - # - def educate_dashes_inverted(str) - str.gsub(/---/, '–').gsub(/--/, '—') - end - - # Return the string, with each instance of "<tt>...</tt>" translated - # to an ellipsis HTML entity. Also converts the case where there are - # spaces between the dots. - # - def educate_ellipses(str) - str.gsub('...', '…').gsub('. . .', '…') - end - - # Return the string, with "<tt>``backticks''</tt>"-style single quotes - # translated into HTML curly quote entities. - # - def educate_backticks(str) - str.gsub("``", '“').gsub("''", '”') - end - - # Return the string, with "<tt>`backticks'</tt>"-style single quotes - # translated into HTML curly quote entities. - # - def educate_single_backticks(str) - str.gsub("`", '‘').gsub("'", '’') - end - - # Return the string, with "educated" curly quote HTML entities. - # - def educate_quotes(str) - punct_class = '[!"#\$\%\'()*+,\-.\/:;<=>?\@\[\\\\\]\^_`{|}~]' - - str = str.dup - - # Special case if the very first character is a quote followed by - # punctuation at a non-word-break. Close the quotes by brute - # force: - str.gsub!(/^'(?=#{punct_class}\B)/, '’') - str.gsub!(/^"(?=#{punct_class}\B)/, '”') - - # Special case for double sets of quotes, e.g.: - # <p>He said, "'Quoted' words in a larger quote."</p> - str.gsub!(/"'(?=\w)/, '“‘') - str.gsub!(/'"(?=\w)/, '‘“') - - # Special case for decade abbreviations (the '80s): - str.gsub!(/'(?=\d\ds)/, '’') - - close_class = %![^\ \t\r\n\\[\{\(\-]! - dec_dashes = '–|—' - - # Get most opening single quotes: - str.gsub!(/(\s| |--|&[mn]dash;|#{dec_dashes}|ȁ[34];)'(?=\w)/, - '\1‘') - # Single closing quotes: - str.gsub!(/(#{close_class})'/, '\1’') - str.gsub!(/'(\s|s\b|$)/, '’\1') - # Any remaining single quotes should be opening ones: - str.gsub!(/'/, '‘') - - # Get most opening double quotes: - str.gsub!(/(\s| |--|&[mn]dash;|#{dec_dashes}|ȁ[34];)"(?=\w)/, - '\1“') - # Double closing quotes: - str.gsub!(/(#{close_class})"/, '\1”') - str.gsub!(/"(\s|s\b|$)/, '”\1') - # Any remaining quotes should be opening ones: - str.gsub!(/"/, '“') - - str - end - - # Return the string, with each RubyPants HTML entity translated to - # its ASCII counterpart. - # - # Note: This is not reversible (but exactly the same as in SmartyPants) - # - def stupefy_entities(str) - str. - gsub(/–/, '-'). # en-dash - gsub(/—/, '--'). # em-dash - - gsub(/‘/, "'"). # open single quote - gsub(/’/, "'"). # close single quote - - gsub(/“/, '"'). # open double quote - gsub(/”/, '"'). # close double quote - - gsub(/…/, '...') # ellipsis - end - - # Return an array of the tokens comprising the string. Each token is - # either a tag (possibly with nested, tags contained therein, such - # as <tt><a href="<MTFoo>"></tt>, or a run of text between - # tags. Each element of the array is a two-element array; the first - # is either :tag or :text; the second is the actual value. - # - # Based on the <tt>_tokenize()</tt> subroutine from Brad Choate's - # MTRegex plugin. <http://www.bradchoate.com/past/mtregex.php> - # - # This is actually the easier variant using tag_soup, as used by - # Chad Miller in the Python port of SmartyPants. - # - def tokenize - tag_soup = /([^<]*)(<[^>]*>)/ - - tokens = [] - - prev_end = 0 - scan(tag_soup) { - tokens << [:text, $1] if $1 != "" - tokens << [:tag, $2] - - prev_end = $~.end(0) - } - - if prev_end < size - tokens << [:text, self[prev_end..-1]] - end - - tokens - end -end diff --git a/plugins/titlecase.rb b/plugins/titlecase.rb deleted file mode 100644 index 7648932c..00000000 --- a/plugins/titlecase.rb +++ /dev/null @@ -1,36 +0,0 @@ -class String - def titlecase - small_words = %w(a an and as at but by en for if in of on or the to v v. via vs vs.) - - x = split(" ").map do |word| - # note: word could contain non-word characters! - # downcase all small_words, capitalize the rest - small_words.include?(word.gsub(/\W/, "").downcase) ? word.downcase! : word.smart_capitalize! - word - end - # capitalize first and last words - x.first.to_s.smart_capitalize! - x.last.to_s.smart_capitalize! - # small words are capitalized after colon, period, exclamation mark, question mark - x.join(" ").gsub(/(:|\.|!|\?)\s?(\W*#{small_words.join("|")}\W*)\s/) { "#{$1} #{$2.smart_capitalize} " } - end - - def titlecase! - replace(titlecase) - end - - def smart_capitalize - # ignore any leading crazy characters and capitalize the first real character - if self =~ /^['"\(\[']*([a-z])/ - i = index($1) - x = self[i,self.length] - # word with capitals and periods mid-word are left alone - self[i,1] = self[i,1].upcase unless x =~ /[A-Z]/ or x =~ /\.\w+/ - end - self - end - - def smart_capitalize! - replace(smart_capitalize) - end -end diff --git a/plugins/video_tag.rb b/plugins/video_tag.rb deleted file mode 100644 index c6e67b77..00000000 --- a/plugins/video_tag.rb +++ /dev/null @@ -1,56 +0,0 @@ -# Title: Simple Video tag for Jekyll -# Author: Brandon Mathis http://brandonmathis.com -# Description: Easily output MPEG4 HTML5 video with a flash backup. -# -# Syntax {% video url/to/video [width height] [url/to/poster] %} -# -# Example: -# {% video http://site.com/video.mp4 720 480 http://site.com/poster-frame.jpg %} -# -# Output: -# <video width='720' height='480' preload='none' controls poster='http://site.com/poster-frame.jpg'> -# <source src='http://site.com/video.mp4' type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'/> -# </video> -# - -module Jekyll - - class VideoTag < Liquid::Tag - @video = nil - @poster = '' - @height = '' - @width = '' - - def initialize(tag_name, markup, tokens) - if markup =~ /(https?:\S+)(\s+(https?:\S+))?(\s+(https?:\S+))?(\s+(\d+)\s(\d+))?(\s+(https?:\S+))?/i - @video = [$1, $3, $5].compact - @width = $7 - @height = $8 - @poster = $10 - end - super - end - - def render(context) - output = super - type = { - 'mp4' => "type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'", - 'ogv' => "type='video/ogg; codecs=theora, vorbis'", - 'webm' => "type='video/webm; codecs=vp8, vorbis'" - } - if @video.size > 0 - video = "<video width='#{@width}' height='#{@height}' preload='none' controls poster='#{@poster}'>" - @video.each do |v| - t = v.match(/([^\.]+)$/)[1] - video += "<source src='#{v}' #{type[t]}>" - end - video += "</video>" - else - "Error processing input, expected syntax: {% video url/to/video [url/to/video] [url/to/video] [width height] [url/to/poster] %}" - end - end - end -end - -Liquid::Template.register_tag('video', Jekyll::VideoTag) - |