From a2bc6f97627d78d42230061125252f074ce4f4cd Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Sat, 23 Jul 2011 00:23:50 -0400 Subject: 1. Added image tag plugin 2. Removed figure tag plugin 3. Renamed custom_filters to octopress_filters 4. Added styles to support new image tag plugin --- plugins/custom_filters.rb | 84 -------------------------------------------- plugins/figure_tag.rb | 69 ------------------------------------ plugins/image_tag.rb | 41 +++++++++++++++++++++ plugins/octopress_filters.rb | 84 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 153 deletions(-) delete mode 100644 plugins/custom_filters.rb delete mode 100644 plugins/figure_tag.rb create mode 100644 plugins/image_tag.rb create mode 100644 plugins/octopress_filters.rb (limited to 'plugins') diff --git a/plugins/custom_filters.rb b/plugins/custom_filters.rb deleted file mode 100644 index 5b49363b..00000000 --- a/plugins/custom_filters.rb +++ /dev/null @@ -1,84 +0,0 @@ -#custom filters for Octopress - -module OctopressFilters - # Used on the blog index to split posts on the marker - def exerpt(input) - if input.index(//i) - input.split(//i)[0] - else - input - end - 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 - - # Replaces relative urls with full urls - def expand_urls(input, url='') - url ||= '/' - input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]+)/ do - $1+url+$3 - end - 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 - - # replaces primes with smartquotes using RubyPants - def smart_quotes(input) - require 'rubypants' - RubyPants.new(input).to_html - 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 - - # Returns a datetime if the input is a string - def datetime(date) - if date.class == String - date = Time.parse(date) - end - date - end - - # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007 - def ordinalize(date) - date = datetime(date) - "#{date.strftime('%b')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}" - end - - # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc. - def ordinal(number) - if (11..13).include?(number.to_i % 100) - "#{number}th" - else - case number.to_i % 10 - when 1; "#{number}st" - when 2; "#{number}nd" - when 3; "#{number}rd" - else "#{number}th" - end - end - end -end -Liquid::Template.register_filter OctopressFilters diff --git a/plugins/figure_tag.rb b/plugins/figure_tag.rb deleted file mode 100644 index 550e677f..00000000 --- a/plugins/figure_tag.rb +++ /dev/null @@ -1,69 +0,0 @@ -# Title: Simple Image Figure tag for Jekyll -# Author: Brandon Mathis http://brandonmathis.com -# Description: Easily output images in
with an optional
and class names. -# -# Syntax {% figure [class name(s)] url [caption text] %} -# -# Example: -# {% figure left half http://site.com/images/ninja.png Ninja Attack! %} -# -# Output: -#
Ninja Attack!
-# -# Example 2 (image with caption) -# {% figure /images/ninja.png Ninja Attack! %} -# -# Output: -#
Ninja Attack!
-# -# Example 3 (just an image with classes) -# {% figure right /images/ninja.png %} -# -# Output: -#
-# - -module Jekyll - - class FigureImageTag < Liquid::Tag - ClassImgCaption = /(\S[\S\s]*)\s+(https?:\/\/|\/)(\S+)\s+(.+)/i - ClassImg = /(\S[\S\s]*)\s+(https?:\/\/|\/)(\S+)/i - ImgCaption = /^\s*(https?:\/\/|\/)(\S+)\s+(.+)/i - Img = /^\s*(https?:\/\/|\/)(\S+\s)/i - - @img = nil - @caption = nil - @class = '' - - def initialize(tag_name, markup, tokens) - if markup =~ ClassImgCaption - @class = $1 - @img = $2 + $3 - @caption = $4 - elsif markup =~ ClassImg - @class = $1 - @img = $2 + $3 - elsif markup =~ ImgCaption - @img = $1 + $2 - @caption = $3 - elsif markup =~ Img - @img = $1 + $2 - end - super - end - - def render(context) - output = super - if @img - figure = "
" - figure += "" - figure += "
#{@caption}
" if @caption - figure += "
" - else - "Error processing input, expected syntax: {% figure [class name(s)] /url/to/image [caption] %}" - end - end - end -end - -Liquid::Template.register_tag('figure', Jekyll::FigureImageTag) diff --git a/plugins/image_tag.rb b/plugins/image_tag.rb new file mode 100644 index 00000000..d7c85925 --- /dev/null +++ b/plugins/image_tag.rb @@ -0,0 +1,41 @@ +# Title: Simple Image tag for Jekyll +# Author: Brandon Mathis http://brandonmathis.com +# Description: Easily output images with optional class names and title/alt attributes +# +# Syntax {% image [class name(s)] url [title text] %} +# +# Example: +# {% imaeg left half http://site.com/images/ninja.png Ninja Attack! %} +# +# Output: +# Ninja Attack! +# + +module Jekyll + + class ImageTag < Liquid::Tag + @img = nil + @title = nil + @class = '' + + def initialize(tag_name, markup, tokens) + if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+.+)?/i + @class = $1 + @img = $2 + $3 + @title = $4 + end + super + end + + def render(context) + output = super + if @img + figure = "#{@title}" + else + "Error processing input, expected syntax: {% img [class name(s)] /url/to/image [title text] %}" + end + end + end +end + +Liquid::Template.register_tag('img', Jekyll::ImageTag) diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb new file mode 100644 index 00000000..5b49363b --- /dev/null +++ b/plugins/octopress_filters.rb @@ -0,0 +1,84 @@ +#custom filters for Octopress + +module OctopressFilters + # Used on the blog index to split posts on the marker + def exerpt(input) + if input.index(//i) + input.split(//i)[0] + else + input + end + 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 + + # Replaces relative urls with full urls + def expand_urls(input, url='') + url ||= '/' + input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]+)/ do + $1+url+$3 + end + 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 + + # replaces primes with smartquotes using RubyPants + def smart_quotes(input) + require 'rubypants' + RubyPants.new(input).to_html + 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 + + # Returns a datetime if the input is a string + def datetime(date) + if date.class == String + date = Time.parse(date) + end + date + end + + # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007 + def ordinalize(date) + date = datetime(date) + "#{date.strftime('%b')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}" + end + + # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc. + def ordinal(number) + if (11..13).include?(number.to_i % 100) + "#{number}th" + else + case number.to_i % 10 + when 1; "#{number}st" + when 2; "#{number}nd" + when 3; "#{number}rd" + else "#{number}th" + end + end + end +end +Liquid::Template.register_filter OctopressFilters -- cgit v1.2.1