Created
January 17, 2013 03:21
-
-
Save meirish/4553290 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jekyll | |
class PjaxFile | |
def initialize(site, base, dir, obj) | |
@output = obj.output | |
@base = base | |
@dir = dir | |
@url = obj.url | |
#print obj + "\n" | |
write(@url) | |
end | |
def destination(dest) | |
print @output + "\n" | |
print dest + "\n" | |
File.join(@base, @dir ,CGI.unescape(dest)) | |
end | |
def write(dest) | |
path = destination(dest) | |
FileUtils.mkdir_p(File.dirname(path)) | |
File.open(path, 'w') do |f| | |
f.write(@output) | |
end | |
end | |
end | |
class PjaxGenerator < Generator | |
safe true | |
def generate(site) | |
@site = site | |
process_pages | |
process_posts | |
end | |
def process_posts | |
@site.posts.each do |post| | |
generate_pjax_file(post) | |
end | |
end | |
def process_pages | |
@site.pages.each do |page| | |
generate_pjax_file(page) | |
end | |
end | |
def generate_pjax_file(obj) | |
@site.static_files << Jekyll::PjaxFile.new(@site, @site.dest, 'pjax', obj) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment