diff options
author | Brandon Mathis <brandon@imathis.com> | 2011-06-11 15:58:53 -0400 |
---|---|---|
committer | Brandon Mathis <brandon@imathis.com> | 2011-06-11 15:58:53 -0400 |
commit | 913fa105c4a6793e6522ca45b85d8f06c803c6b9 (patch) | |
tree | 8047baaf313f6a0966b03c8a26a8988cdfa3c172 /themes/classic/_plugins/blockquote.rb | |
parent | 814be44c151088dfb90d6a01281c9206151b0a88 (diff) | |
download | my_new_personal_website-913fa105c4a6793e6522ca45b85d8f06c803c6b9.tar.xz my_new_personal_website-913fa105c4a6793e6522ca45b85d8f06c803c6b9.zip |
1. Moved _plugins into themes/classic/_plugins
I think it's probably better to ship plugins with themes to make it
easier to update them.
2. Improved 'install' rake task and made nicer output
Diffstat (limited to 'themes/classic/_plugins/blockquote.rb')
-rw-r--r-- | themes/classic/_plugins/blockquote.rb | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/themes/classic/_plugins/blockquote.rb b/themes/classic/_plugins/blockquote.rb new file mode 100644 index 00000000..7a885175 --- /dev/null +++ b/themes/classic/_plugins/blockquote.rb @@ -0,0 +1,109 @@ +# +# Author: Josediaz Gonzalez - https://github.com/josegonzalez +# Source URL: https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/blockquote.rb +# Modified by Brandon Mathis +# +require './_plugins/titlecase.rb' +module Jekyll + + # Outputs a string with a given attribution as a quote + # + # {% blockquote John Paul Jones %} + # Monkeys! + # {% endblockquote %} + # ... + # <blockquote> + # Monkeys! + # <br /> + # John Paul Jones + # </blockquote> + # + 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 = super + if @by.nil? + '<blockquote><p>' + output.join + '</p></blockquote>' + elsif !@title.nil? + '<blockquote><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong>' + '<a class="source" href="' + @source + '">' + @title + '</a></cite></p>' + elsif !@source.nil? + '<blockquote><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong>' + '<a class="source" href="' + @source + '">source</a></cite></p>' + else + '<blockquote><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong></cite></p>' + end + end + end + + # Outputs a string with a given attribution as a pullquote + # + # {% blockquote John Paul Jones %} + # Monkeys! + # {% endblockquote %} + # ... + # <blockquote class="pullquote"> + # Monkeys! + # <br /> + # John Paul Jones + # </blockquote> + # + class Pullquote < Liquid::Block + FullCiteWithTitle = /([\w\s]+)(http:\/\/|https:\/\/)(\S+)([\w\s]+)/i + FullCite = /([\w\s]+)(http:\/\/|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 + elsif markup =~ FullCite + @by = $1 + @source = $2 + $3 + elsif markup =~ Author + @by = $1 + end + super + end + + def render(context) + output = super + if @by.nil? + '<blockquote class="pullquote"><p>' + output.join + '</p></blockquote>' + elsif @title + '<blockquote class="pullquote"><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong>' + ' <a class="source" href="' + @source + '">' + @title + '</a></cite></p>' + elsif @source + '<blockquote class="pullquote"><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong>' + ' <a class="source" href="' + @source + '">source</a></cite></p>' + elsif @by + '<blockquote class="pullquote"><p>' + output.join + '</p></blockquote>' + '<p><cite><strong>' + @by + '</strong></cite></p>' + end + end + end +end + +Liquid::Template.register_tag('blockquote', Jekyll::Blockquote) +Liquid::Template.register_tag('pullquote', Jekyll::Pullquote) + + |