2011-05-30 04:30:16 +00:00
|
|
|
#
|
2011-06-15 22:31:22 +00:00
|
|
|
# Author: Brandon Mathis
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# {% blockquote Bobby Willis http://google.com/blah the search for bobby's mom %}
|
|
|
|
# Wheeee!
|
|
|
|
# {% endblockquote %}
|
|
|
|
# ...
|
|
|
|
# <blockquote>
|
|
|
|
# <p>Wheeee!</p>
|
|
|
|
# <footer>
|
2011-06-22 22:53:17 +00:00
|
|
|
# <strong>Bobby Willis</strong><cite><a href="http://google.com/blah">The Search For Bobby's Mom</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
|
|
|
|
FullCiteWithTitle = /([\w\s]+)(https?:\/\/)(\S+\s)([\w\s]+)/i
|
|
|
|
FullCite = /([\w\s]+)(https?:\/\/)(\S+)/i
|
|
|
|
Author = /([\w\s]+)/
|
|
|
|
|
|
|
|
def initialize(tag_name, markup, tokens)
|
|
|
|
@by = nil
|
|
|
|
@source = nil
|
|
|
|
@title = nil
|
|
|
|
if markup =~ FullCiteWithTitle
|
|
|
|
@by = $1
|
|
|
|
@source = $2 + $3
|
|
|
|
@title = $4.titlecase
|
|
|
|
elsif markup =~ FullCite
|
|
|
|
@by = $1
|
|
|
|
@source = $2 + $3
|
|
|
|
elsif markup =~ Author
|
|
|
|
@by = $1
|
|
|
|
end
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def render(context)
|
2011-06-22 22:53:17 +00:00
|
|
|
output = paragraphize(super.map(&:strip).join)
|
|
|
|
author = "<strong>#{@by.strip}</strong>"
|
|
|
|
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
|
|
|
|
cite = "<cite><a href='#{@source}'>#{(@title || source)}</a></cite>"
|
2011-06-15 22:31:22 +00:00
|
|
|
reply = if @by.nil?
|
2011-06-22 22:53:17 +00:00
|
|
|
output
|
2011-05-30 04:30:16 +00:00
|
|
|
elsif !@source.nil?
|
2011-06-22 22:53:17 +00:00
|
|
|
"#{output}<footer>#{author + cite}</footer>"
|
2011-05-30 04:30:16 +00:00
|
|
|
else
|
2011-06-22 22:53:17 +00:00
|
|
|
"#{output}<footer>#{author}</footer>"
|
2011-05-30 04:30:16 +00:00
|
|
|
end
|
2011-06-15 22:31:22 +00:00
|
|
|
"<blockquote>#{reply}</blockquote>"
|
2011-05-30 04:30:16 +00:00
|
|
|
end
|
2011-06-22 22:53:17 +00:00
|
|
|
|
|
|
|
def paragraphize(input)
|
|
|
|
"<p>#{input.gsub(/\n\n/, '</p><p>').gsub(/\n/, '<br/>')}</p>"
|
|
|
|
end
|
2011-05-30 04:30:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Liquid::Template.register_tag('blockquote', Jekyll::Blockquote)
|