# # 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 %} # ... #
#

Wheeee!

#
# 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.strip =~ FullCiteWithTitle @by = $1 @source = $2 + $3 @title = $4.titlecase.strip elsif markup.strip =~ FullCite @by = $1 @source = $2 + $3 elsif markup.strip =~ AuthorTitle @by = $1 @title = $2.titlecase.strip elsif markup.strip =~ Author @by = $1 end super end def render(context) quote = paragraphize(super) author = "#{@by.strip}" 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 = " #{(@title || source)}" elsif !@title.nil? cite = " #{@title}" end blockquote = if @by.nil? quote elsif cite "#{quote}" else "#{quote}" end "
#{blockquote}
" end def paragraphize(input) "

#{input.lstrip.rstrip.gsub(/\n\n/, '

').gsub(/\n/, '
')}

" end end end Liquid::Template.register_tag('blockquote', Jekyll::Blockquote)