diff options
author | Brandon Mathis <brandon@imathis.com> | 2011-05-30 00:30:16 -0400 |
---|---|---|
committer | Brandon Mathis <brandon@imathis.com> | 2011-05-30 00:30:16 -0400 |
commit | 8698a276f937cb1cd6f67f7f213e2ea438500d7e (patch) | |
tree | 3963ed8f9750cd565087ce54fe8de38d9f5c606d /_plugins | |
parent | c7d5365f81552cae16bbb91696ca3e67b4a0a2e9 (diff) | |
download | my_new_personal_website-8698a276f937cb1cd6f67f7f213e2ea438500d7e.tar.xz my_new_personal_website-8698a276f937cb1cd6f67f7f213e2ea438500d7e.zip |
Cleaned out public from repository, updated gitignore, added syntax
highlighting tests, improved syntax highlighting and styling of pre
blocks.
Overriding dynamic gist styling.
Added a plugin for pygments caching which should speed things up
terrifically.
added ender.js as a lightweight way of scripting the DOM, events, etc.
Some general typography and semantic html improvements.
Diffstat (limited to '_plugins')
-rw-r--r-- | _plugins/blockquote.rb | 109 | ||||
-rw-r--r-- | _plugins/category.rb | 65 | ||||
-rw-r--r-- | _plugins/custom_filters.rb | 7 | ||||
-rw-r--r-- | _plugins/iterator.rb | 49 | ||||
-rw-r--r-- | _plugins/pygments_cache_patch.rb | 30 |
5 files changed, 259 insertions, 1 deletions
diff --git a/_plugins/blockquote.rb b/_plugins/blockquote.rb new file mode 100644 index 00000000..7a885175 --- /dev/null +++ b/_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) + + diff --git a/_plugins/category.rb b/_plugins/category.rb new file mode 100644 index 00000000..b9accdec --- /dev/null +++ b/_plugins/category.rb @@ -0,0 +1,65 @@ +module Jekyll + + class CategoryIndex < Page + def initialize(site, base, dir, category) + @site = site + @base = base + @dir = dir + @name = 'index.html' + + self.process(@name) + self.read_yaml(File.join(base, '_layouts'), 'category_index.html') + self.data['category'] = category + + category_title_prefix = site.config['category_title_prefix'] || 'Category: ' + self.data['title'] = "#{category_title_prefix}#{category}" + end + end + + class CategoryList < Page + def initialize(site, base, dir, categories) + @site = site + @base = base + @dir = dir + @name = 'index.html' + + self.process(@name) + self.read_yaml(File.join(base, '_layouts'), 'category_list.html') + self.data['categories'] = categories + end + end + + class CategoryGenerator < Generator + safe true + + def generate(site) + if site.layouts.key? 'category_index' + dir = site.config['category_dir'] || 'categories' + site.categories.keys.each do |category| + write_category_index(site, File.join(dir, category.gsub(/\s/, "-").gsub(/[^\w-]/, '').downcase), category) + end + end + + if site.layouts.key? 'category_list' + dir = site.config['category_dir'] || 'categories' + write_category_list(site, dir, site.categories.keys.sort) + end + end + + def write_category_index(site, dir, category) + index = CategoryIndex.new(site, site.source, dir, category) + index.render(site.layouts, site.site_payload) + index.write(site.dest) + site.static_files << index + end + + def write_category_list(site, dir, categories) + index = CategoryList.new(site, site.source, dir, categories) + index.render(site.layouts, site.site_payload) + index.write(site.dest) + site.static_files << index + end + end + +end + diff --git a/_plugins/custom_filters.rb b/_plugins/custom_filters.rb index 84f1caa0..1ee39fa8 100644 --- a/_plugins/custom_filters.rb +++ b/_plugins/custom_filters.rb @@ -50,6 +50,11 @@ module OctopressFilters end end end + #YearlyPost = Struct.new('YearlyPost', :year, :posts) + def yearly_posts(site) + #site.posts.reverse.group_by { |p| p.date.strftime("%Y") }.map { |k,v| YearlyPost.new(k,v) } + site + end end - Liquid::Template.register_filter OctopressFilters + diff --git a/_plugins/iterator.rb b/_plugins/iterator.rb new file mode 100644 index 00000000..da0b5f0a --- /dev/null +++ b/_plugins/iterator.rb @@ -0,0 +1,49 @@ +## +## Author: Jose Gonzalez - https://github.com/josegonzalez +## Source URL: https://github.com/josegonzalez/josediazgonzalez.com/blob/master/_plugins/iterator.rb +## + +#module Jekyll + #class Site + #alias_method :orig_site_payload, :site_payload + + ## Constuct an array of hashes that will allow the user, using Liquid, to + ## iterate through the keys of _kv_hash_ and be able to iterate through the + ## elements under each key. + ## + ## Example: + ## categories = { 'Ruby' => [<Post>, <Post>] } + ## make_iterable(categories, :index => 'name', :items => 'posts') + ## Will allow the user to iterate through all categories and then iterate + ## though each post in the current category like so: + ## {% for category in site.categories %} + ## h1. {{ category.name }} + ## <ul> + ## {% for post in category.posts %} + ## <li>{{ post.title }}</li> + ## {% endfor %} + ## </ul> + ## {% endfor %} + ## + ## Returns [ {<index> => <kv_hash_key>, <items> => kv_hash[<kv_hash_key>]}, ... ] + + #def make_iterable(kv_hash, options) + #options = {:index => 'name', :items => 'items'}.merge(options) + #result = [] + #kv_hash.sort.each do |key, value| + #result << { options[:index] => key, options[:items] => value } + #end + #result + #end + + #def site_payload + #payload = orig_site_payload + #payload['site']['iterable'].merge!({ + #'categories' => make_iterable(self.categories, :index => 'name', :items => 'posts'), + #'tags' => make_iterable(self.tags, :index => 'name', :items => 'posts') + #}) + #payload + #end + + #end +#end diff --git a/_plugins/pygments_cache_patch.rb b/_plugins/pygments_cache_patch.rb new file mode 100644 index 00000000..36c78d20 --- /dev/null +++ b/_plugins/pygments_cache_patch.rb @@ -0,0 +1,30 @@ +# +# Author: Raimonds Simanovskis, http://blog.rayapps.com/ +# Source URL: https://github.com/rsim/blog.rayapps.com/blob/master/_plugins/pygments_cache_patch.rb +# + +require 'fileutils' +require 'digest/md5' + +PYGMENTS_CACHE_DIR = File.expand_path('../../_cache', __FILE__) +FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) + +Jekyll::HighlightBlock.class_eval do + def render_pygments(context, code) + if defined?(PYGMENTS_CACHE_DIR) + path = File.join(PYGMENTS_CACHE_DIR, "#{@lang}-#{Digest::MD5.hexdigest(code)}.html") + if File.exist?(path) + highlighted_code = File.read(path) + else + highlighted_code = Albino.new(code, @lang).to_s(@options) + File.open(path, 'w') {|f| f.print(highlighted_code) } + end + else + highlighted_code = Albino.new(code, @lang).to_s(@options) + end + output = add_code_tags(highlighted_code, @lang) + output = context["pygments_prefix"] + output if context["pygments_prefix"] + output = output + context["pygments_suffix"] if context["pygments_suffix"] + output + end +end |