2011-05-30 04:30:16 +00:00
|
|
|
#
|
2011-06-15 22:31:22 +00:00
|
|
|
# Author: Brandon Mathis
|
2011-07-17 21:23:41 +00:00
|
|
|
# A full rewrite based on the work of: Josediaz Gonzalez - https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/blockquote.rb
|
2011-05-30 04:30:16 +00:00
|
|
|
#
|
2011-06-19 19:14:01 +00:00
|
|
|
# Outputs a string with a given attribution as a quote
|
|
|
|
#
|
2011-07-17 21:23:41 +00:00
|
|
|
# {% blockquote Bobby Willis http://google.com/search?q=pants the search for bobby's pants %}
|
2011-06-19 19:14:01 +00:00
|
|
|
# Wheeee!
|
|
|
|
# {% endblockquote %}
|
|
|
|
# ...
|
|
|
|
# <blockquote>
|
|
|
|
# <p>Wheeee!</p>
|
|
|
|
# <footer>
|
2011-07-17 21:23:41 +00:00
|
|
|
# <strong>Bobby Willis</strong><cite><a href="http://google.com/search?q=pants">The Search For Bobby's Pants</a>
|
2011-06-19 19:14:01 +00:00
|
|
|
# </blockquote>
|
|
|
|
#
|
2011-07-11 15:37:38 +00:00
|
|
|
require './plugins/titlecase.rb'
|
|
|
|
|
2011-05-30 04:30:16 +00:00
|
|
|
module Jekyll
|
|
|
|
|
|
|
|
class Blockquote < Liquid::Block
|
2011-07-22 15:47:23 +00:00
|
|
|
FullCiteWithTitle = /(\S.*)\s+(https?:\/\/)(\S+)\s+(.+)/i
|
|
|
|
FullCite = /(\S.*)\s+(https?:\/\/)(\S+)/i
|
2013-01-09 14:24:43 +00:00
|
|
|
AuthorTitle = /([^,]+),([^,]+)/
|
2011-07-22 15:47:23 +00:00
|
|
|
Author = /(.+)/
|
2011-05-30 04:30:16 +00:00
|
|
|
|
|
|
|
def initialize(tag_name, markup, tokens)
|
|
|
|
@by = nil
|
|
|
|
@source = nil
|
|
|
|
@title = nil
|
|
|
|
if markup =~ FullCiteWithTitle
|
|
|
|
@by = $1
|
|
|
|
@source = $2 + $3
|
2013-01-12 22:36:15 +00:00
|
|
|
@title = $4.titlecase.strip
|
2011-05-30 04:30:16 +00:00
|
|
|
elsif markup =~ FullCite
|
|
|
|
@by = $1
|
|
|
|
@source = $2 + $3
|
2013-01-09 14:24:43 +00:00
|
|
|
elsif markup =~ AuthorTitle
|
|
|
|
@by = $1
|
2013-01-12 22:36:15 +00:00
|
|
|
@title = $2.titlecase.strip
|
2011-05-30 04:30:16 +00:00
|
|
|
elsif markup =~ Author
|
2013-01-09 14:24:43 +00:00
|
|
|
@by = $1
|
2011-05-30 04:30:16 +00:00
|
|
|
end
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def render(context)
|
2012-05-24 15:28:32 +00:00
|
|
|
quote = paragraphize(super)
|
2011-07-19 20:32:57 +00:00
|
|
|
author = "<strong>#{@by.strip}</strong>" if @by
|
2011-06-22 22:53:17 +00:00
|
|
|
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
|
2011-07-22 15:47:23 +00:00
|
|
|
if !@source.nil?
|
2011-12-11 22:24:32 +00:00
|
|
|
cite = " <cite><a href='#{@source}'>#{(@title || source)}</a></cite>"
|
2011-07-22 15:47:23 +00:00
|
|
|
elsif !@title.nil?
|
2011-12-11 22:24:32 +00:00
|
|
|
cite = " <cite>#{@title}</cite>"
|
2011-07-22 15:47:23 +00:00
|
|
|
end
|
|
|
|
blockquote = if @by.nil?
|
2011-07-19 20:32:57 +00:00
|
|
|
quote
|
2011-07-22 15:47:23 +00:00
|
|
|
elsif cite
|
2011-07-19 20:32:57 +00:00
|
|
|
"#{quote}<footer>#{author + cite}</footer>"
|
2011-05-30 04:30:16 +00:00
|
|
|
else
|
2011-07-19 20:32:57 +00:00
|
|
|
"#{quote}<footer>#{author}</footer>"
|
2011-05-30 04:30:16 +00:00
|
|
|
end
|
2011-07-22 15:47:23 +00:00
|
|
|
"<blockquote>#{blockquote}</blockquote>"
|
2011-05-30 04:30:16 +00:00
|
|
|
end
|
2011-06-22 22:53:17 +00:00
|
|
|
|
|
|
|
def paragraphize(input)
|
2012-05-24 15:28:32 +00:00
|
|
|
"<p>#{input.lstrip.rstrip.gsub(/\n\n/, '</p><p>').gsub(/\n/, '<br/>')}</p>"
|
2011-06-22 22:53:17 +00:00
|
|
|
end
|
2011-05-30 04:30:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Liquid::Template.register_tag('blockquote', Jekyll::Blockquote)
|