aboutsummaryrefslogtreecommitdiff
path: root/.themes/classic/plugins/blockquote.rb
diff options
context:
space:
mode:
authorBrandon Mathis <brandon@imathis.com>2011-07-11 11:17:15 -0400
committerBrandon Mathis <brandon@imathis.com>2011-07-11 11:17:15 -0400
commitee7b9dd9581a048cee17e89181cba94254033fb2 (patch)
tree42c7d47ebfcaf9faf68a302a39a4815ef2e8f5ec /.themes/classic/plugins/blockquote.rb
parentd4139e394ec9f70acfcb35f25340bdb541d0d7ee (diff)
downloadmy_new_personal_website-ee7b9dd9581a048cee17e89181cba94254033fb2.tar.xz
my_new_personal_website-ee7b9dd9581a048cee17e89181cba94254033fb2.zip
Changed _plugins folder to plugins and updated rake tasks accordingly
Diffstat (limited to '.themes/classic/plugins/blockquote.rb')
-rw-r--r--.themes/classic/plugins/blockquote.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/.themes/classic/plugins/blockquote.rb b/.themes/classic/plugins/blockquote.rb
new file mode 100644
index 00000000..2f0712bd
--- /dev/null
+++ b/.themes/classic/plugins/blockquote.rb
@@ -0,0 +1,73 @@
+#
+# Author: Brandon Mathis
+# 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/blah the search for bobby's mom %}
+# Wheeee!
+# {% endblockquote %}
+# ...
+# <blockquote>
+# <p>Wheeee!</p>
+# <footer>
+# <strong>Bobby Willis</strong><cite><a href="http://google.com/blah">The Search For Bobby's Mom</a>
+# </blockquote>
+#
+require './_plugins/titlecase.rb'
+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)
+ 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 << '/&hellip;' unless source == @source
+ end
+ cite = "<cite><a href='#{@source}'>#{(@title || source)}</a></cite>"
+ reply = if @by.nil?
+ output
+ elsif !@source.nil?
+ "#{output}<footer>#{author + cite}</footer>"
+ else
+ "#{output}<footer>#{author}</footer>"
+ end
+ "<blockquote>#{reply}</blockquote>"
+ end
+
+ def paragraphize(input)
+ "<p>#{input.gsub(/\n\n/, '</p><p>').gsub(/\n/, '<br/>')}</p>"
+ end
+ end
+end
+
+Liquid::Template.register_tag('blockquote', Jekyll::Blockquote)