jsjohnst-jekyll 0.4.1.999.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/History.txt +106 -0
  2. data/README.textile +555 -0
  3. data/VERSION.yml +4 -0
  4. data/bin/jekyll +146 -0
  5. data/lib/jekyll.rb +81 -0
  6. data/lib/jekyll/albino.rb +121 -0
  7. data/lib/jekyll/converters/csv.rb +26 -0
  8. data/lib/jekyll/converters/mephisto.rb +79 -0
  9. data/lib/jekyll/converters/mt.rb +59 -0
  10. data/lib/jekyll/converters/rss.rb +44 -0
  11. data/lib/jekyll/converters/textpattern.rb +50 -0
  12. data/lib/jekyll/converters/typo.rb +49 -0
  13. data/lib/jekyll/converters/wordpress.rb +55 -0
  14. data/lib/jekyll/convertible.rb +71 -0
  15. data/lib/jekyll/core_ext.rb +22 -0
  16. data/lib/jekyll/filters.rb +87 -0
  17. data/lib/jekyll/layout.rb +47 -0
  18. data/lib/jekyll/page.rb +64 -0
  19. data/lib/jekyll/post.rb +232 -0
  20. data/lib/jekyll/site.rb +221 -0
  21. data/lib/jekyll/tags/highlight.rb +53 -0
  22. data/lib/jekyll/tags/include.rb +49 -0
  23. data/lib/jekyll/tasks.rb +68 -0
  24. data/test/helper.rb +14 -0
  25. data/test/source/_includes/sig.markdown +3 -0
  26. data/test/source/_layouts/default.html +27 -0
  27. data/test/source/_layouts/simple.html +1 -0
  28. data/test/source/_posts/2008-02-02-not-published.textile +8 -0
  29. data/test/source/_posts/2008-02-02-published.textile +8 -0
  30. data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
  31. data/test/source/_posts/2008-11-21-complex.textile +8 -0
  32. data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
  33. data/test/source/_posts/2008-12-13-include.markdown +8 -0
  34. data/test/source/_posts/2009-01-27-categories.textile +7 -0
  35. data/test/source/_posts/2009-01-27-category.textile +7 -0
  36. data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
  37. data/test/source/category_test.html +13 -0
  38. data/test/source/css/screen.css +76 -0
  39. data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
  40. data/test/source/index.html +22 -0
  41. data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
  42. data/test/suite.rb +9 -0
  43. data/test/test_filters.rb +49 -0
  44. data/test/test_generated_site.rb +37 -0
  45. data/test/test_jekyll.rb +0 -0
  46. data/test/test_post.rb +174 -0
  47. data/test/test_site.rb +51 -0
  48. data/test/test_tags.rb +52 -0
  49. metadata +186 -0
@@ -0,0 +1,59 @@
1
+ # Created by Nick Gerakines, open source and publically available under the
2
+ # MIT license. Use this module at your own risk.
3
+ # I'm an Erlang/Perl/C++ guy so please forgive my dirty ruby.
4
+
5
+ require 'rubygems'
6
+ require 'sequel'
7
+ require 'fileutils'
8
+
9
+ # NOTE: This converter requires Sequel and the MySQL gems.
10
+ # The MySQL gem can be difficult to install on OS X. Once you have MySQL
11
+ # installed, running the following commands should work:
12
+ # $ sudo gem install sequel
13
+ # $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
14
+
15
+ module Jekyll
16
+ module MT
17
+ # This query will pull blog posts from all entries across all blogs. If
18
+ # you've got unpublished, deleted or otherwise hidden posts please sift
19
+ # through the created posts to make sure nothing is accidently published.
20
+ QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_created_on, entry_title FROM mt_entry"
21
+
22
+ def self.process(dbname, user, pass, host = 'localhost')
23
+ db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
24
+
25
+ FileUtils.mkdir_p "_posts"
26
+
27
+ db[QUERY].each do |post|
28
+ title = post[:entry_title]
29
+ slug = post[:entry_basename]
30
+ date = post[:entry_created_on]
31
+ content = post[:entry_text]
32
+ more_content = post[:entry_text_more]
33
+
34
+ # Be sure to include the body and extended body.
35
+ if more_content != nil
36
+ content = content + " \n" + more_content
37
+ end
38
+
39
+ # Ideally, this script would determine the post format (markdown, html
40
+ # , etc) and create files with proper extensions. At this point it
41
+ # just assumes that markdown will be acceptable.
42
+ name = [date.year, date.month, date.day, slug].join('-') + ".markdown"
43
+
44
+ data = {
45
+ 'layout' => 'post',
46
+ 'title' => title.to_s,
47
+ 'mt_id' => post[:entry_id],
48
+ }.delete_if { |k,v| v.nil? || v == ''}.to_yaml
49
+
50
+ File.open("_posts/#{name}", "w") do |f|
51
+ f.puts data
52
+ f.puts "---"
53
+ f.puts content
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,44 @@
1
+ module Jekyll
2
+
3
+ require 'rexml/document'
4
+ require 'time'
5
+ require "YAML"
6
+
7
+ module RSS
8
+ #Reads posts from an RSS feed.
9
+ #It creates a post file for each entry in the RSS.
10
+ def self.process(source = "rss.xml")
11
+ #FileUtils.mkdir_p "_posts"
12
+ content = ""
13
+ open(source, "r") { |f| content << f.read }
14
+ doc = REXML::Document.new(content)
15
+ posts = 0
16
+ doc.elements.each("rss/channel/item") do |item|
17
+ link = item.elements["link"].text
18
+ name = link.split("/")[-1]
19
+ name = $1 if name =~ /(.*)\.html/
20
+ name = $1 if name =~ /\d+\-(.*)/
21
+
22
+ #title = item.elements["title"].text
23
+ content = item.elements["content:encoded"].text
24
+ timestamp = Time.parse(item.elements["pubDate"].text)
25
+ filename = "_posts/#{timestamp.strftime("%Y-%m-%d")}-#{name}.html"
26
+ puts "#{link} -> #{filename}"
27
+ File.open(filename, "w") do |f|
28
+ YAML.dump(
29
+ {
30
+ "layout" => "post",
31
+ "name" => name,
32
+ "title" => item.elements["title"].text,
33
+ "time" => timestamp,
34
+ },
35
+ f
36
+ )
37
+ f.puts "---\n#{content}"
38
+ end
39
+ posts += 1
40
+ end
41
+ puts "Created #{posts} posts!"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'sequel'
3
+ require 'fileutils'
4
+
5
+ # NOTE: This converter requires Sequel and the MySQL gems.
6
+ # The MySQL gem can be difficult to install on OS X. Once you have MySQL
7
+ # installed, running the following commands should work:
8
+ # $ sudo gem install sequel
9
+ # $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
10
+
11
+ module Jekyll
12
+ module TextPattern
13
+ # Reads a MySQL database via Sequel and creates a post file for each post.
14
+ # The only posts selected are those with a status of 4 or 5, which means "live"
15
+ # and "sticky" respectively.
16
+ # Other statuses is 1 => draft, 2 => hidden and 3 => pending
17
+ QUERY = "select Title, url_title, Posted, Body, Keywords from textpattern where Status = '4' or Status = '5'"
18
+
19
+ def self.process(dbname, user, pass, host = 'localhost')
20
+ db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
21
+
22
+ FileUtils.mkdir_p "_posts"
23
+
24
+ db[QUERY].each do |post|
25
+ # Get required fields and construct Jekyll compatible name
26
+ title = post[:Title]
27
+ slug = post[:url_title]
28
+ date = post[:Posted]
29
+ content = post[:Body]
30
+
31
+ name = [date.strftime("%Y-%m-%d"), slug].join('-') + ".textile"
32
+
33
+ # Get the relevant fields as a hash, delete empty fields and convert
34
+ # to YAML for the header
35
+ data = {
36
+ 'layout' => 'post',
37
+ 'title' => title.to_s,
38
+ 'tags' => post[:Keywords].split(',')
39
+ }.delete_if { |k,v| v.nil? || v == ''}.to_yaml
40
+
41
+ # Write out the data and content to file
42
+ File.open("_posts/#{name}", "w") do |f|
43
+ f.puts data
44
+ f.puts "---"
45
+ f.puts content
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,49 @@
1
+ # Author: Toby DiPasquale <toby@cbcg.net>
2
+ require 'fileutils'
3
+ require 'rubygems'
4
+ require 'sequel'
5
+
6
+ module Jekyll
7
+ module Typo
8
+ # this SQL *should* work for both MySQL and PostgreSQL, but I haven't
9
+ # tested PostgreSQL yet (as of 2008-12-16)
10
+ SQL = <<-EOS
11
+ SELECT c.id id,
12
+ c.title title,
13
+ c.permalink slug,
14
+ c.body body,
15
+ c.published_at date,
16
+ c.state state,
17
+ COALESCE(tf.name, 'html') filter
18
+ FROM contents c
19
+ LEFT OUTER JOIN text_filters tf
20
+ ON c.text_filter_id = tf.id
21
+ EOS
22
+
23
+ def self.process dbname, user, pass, host='localhost'
24
+ FileUtils.mkdir_p '_posts'
25
+ db = Sequel.mysql dbname, :user => user, :password => pass, :host => host
26
+ db[SQL].each do |post|
27
+ next unless post[:state] =~ /Published/
28
+
29
+ name = [ sprintf("%.04d", post[:date].year),
30
+ sprintf("%.02d", post[:date].month),
31
+ sprintf("%.02d", post[:date].day),
32
+ post[:slug].strip ].join('-')
33
+ # Can have more than one text filter in this field, but we just want
34
+ # the first one for this
35
+ name += '.' + post[:filter].split(' ')[0]
36
+
37
+ File.open("_posts/#{name}", 'w') do |f|
38
+ f.puts({ 'layout' => 'post',
39
+ 'title' => post[:title].to_s,
40
+ 'typo_id' => post[:id]
41
+ }.delete_if { |k, v| v.nil? || v == '' }.to_yaml)
42
+ f.puts '---'
43
+ f.puts post[:body].delete("\r")
44
+ end
45
+ end
46
+ end
47
+
48
+ end # module Typo
49
+ end # module Jekyll
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'sequel'
3
+ require 'fileutils'
4
+
5
+ # NOTE: This converter requires Sequel and the MySQL gems.
6
+ # The MySQL gem can be difficult to install on OS X. Once you have MySQL
7
+ # installed, running the following commands should work:
8
+ # $ sudo gem install sequel
9
+ # $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
10
+
11
+ module Jekyll
12
+ module WordPress
13
+
14
+ # Reads a MySQL database via Sequel and creates a post file for each
15
+ # post in wp_posts that has post_status = 'publish'.
16
+ # This restriction is made because 'draft' posts are not guaranteed to
17
+ # have valid dates.
18
+ QUERY = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from wp_posts where post_status = 'publish' and post_type = 'post'"
19
+
20
+ def self.process(dbname, user, pass, host = 'localhost')
21
+ db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
22
+
23
+ FileUtils.mkdir_p "_posts"
24
+
25
+ db[QUERY].each do |post|
26
+ # Get required fields and construct Jekyll compatible name
27
+ title = post[:post_title]
28
+ slug = post[:post_name]
29
+ date = post[:post_date]
30
+ content = post[:post_content]
31
+
32
+ name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day,
33
+ slug]
34
+
35
+ # Get the relevant fields as a hash, delete empty fields and convert
36
+ # to YAML for the header
37
+ data = {
38
+ 'layout' => 'post',
39
+ 'title' => title.to_s,
40
+ 'excerpt' => post[:post_excerpt].to_s,
41
+ 'wordpress_id' => post[:ID],
42
+ 'wordpress_url' => post[:guid]
43
+ }.delete_if { |k,v| v.nil? || v == ''}.to_yaml
44
+
45
+ # Write out the data and content to file
46
+ File.open("_posts/#{name}", "w") do |f|
47
+ f.puts data
48
+ f.puts "---"
49
+ f.puts content
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,71 @@
1
+ module Jekyll
2
+ module Convertible
3
+ # Return the contents as a string
4
+ def to_s
5
+ self.content || ''
6
+ end
7
+
8
+ # Read the YAML frontmatter
9
+ # +base+ is the String path to the dir containing the file
10
+ # +name+ is the String filename of the file
11
+ #
12
+ # Returns nothing
13
+ def read_yaml(base, name)
14
+ self.content = File.read(File.join(base, name))
15
+
16
+ if self.content =~ /^(---\s*\n.*?)\n---\s*\n/m
17
+ self.content = self.content[($1.size + 5)..-1]
18
+
19
+ self.data = YAML.load($1)
20
+ end
21
+ end
22
+
23
+ # Transform the contents based on the file extension.
24
+ #
25
+ # Returns nothing
26
+ def transform
27
+ case Jekyll.content_type
28
+ when :textile
29
+ self.ext = ".html"
30
+ self.content = RedCloth.new(self.content).to_html
31
+ when :markdown
32
+ self.ext = ".html"
33
+ self.content = Jekyll.markdown_proc.call(self.content)
34
+ end
35
+ end
36
+
37
+ def determine_content_type
38
+ case self.ext[1..-1]
39
+ when /textile/i
40
+ return :textile
41
+ when /markdown/i, /mkdn/i, /md/i
42
+ return :markdown
43
+ end
44
+ return :unknown
45
+ end
46
+
47
+ # Add any necessary layouts to this convertible document
48
+ # +layouts+ is a Hash of {"name" => "layout"}
49
+ # +site_payload+ is the site payload hash
50
+ #
51
+ # Returns nothing
52
+ def do_layout(payload, layouts)
53
+ # render and transform content (this becomes the final content of the object)
54
+ Jekyll.content_type = self.determine_content_type
55
+ self.content = Liquid::Template.parse(self.content).render(payload, [Jekyll::Filters])
56
+ self.transform
57
+
58
+ # output keeps track of what will finally be written
59
+ self.output = self.content
60
+
61
+ # recursively render layouts
62
+ layout = layouts[self.data["layout"]]
63
+ while layout
64
+ payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
65
+ self.output = Liquid::Template.parse(layout.content).render(payload, [Jekyll::Filters])
66
+
67
+ layout = layouts[layout.data["layout"]]
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,22 @@
1
+ class Hash
2
+ # Merges self with another hash, recursively.
3
+ #
4
+ # This code was lovingly stolen from some random gem:
5
+ # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
6
+ #
7
+ # Thanks to whoever made it.
8
+ def deep_merge(hash)
9
+ target = dup
10
+
11
+ hash.keys.each do |key|
12
+ if hash[key].is_a? Hash and self[key].is_a? Hash
13
+ target[key] = target[key].deep_merge(hash[key])
14
+ next
15
+ end
16
+
17
+ target[key] = hash[key]
18
+ end
19
+
20
+ target
21
+ end
22
+ end
@@ -0,0 +1,87 @@
1
+ module Jekyll
2
+
3
+ module Filters
4
+ def textilize(input)
5
+ RedCloth.new(input).to_html
6
+ end
7
+
8
+ def date_to_rfc2822(date)
9
+ date.rfc2822
10
+ end
11
+
12
+ def date_to_string(date)
13
+ date.strftime("%d %b %Y")
14
+ end
15
+
16
+ def date_to_long_string(date)
17
+ date.strftime("%d %B %Y")
18
+ end
19
+
20
+ def date_to_xmlschema(date)
21
+ date.xmlschema
22
+ end
23
+
24
+ def xml_escape(input)
25
+ input.gsub("&", "&amp;").gsub("<", "&lt;").gsub(">", "&gt;")
26
+ end
27
+
28
+ def number_of_words(input)
29
+ input.split.length
30
+ end
31
+
32
+ # Returns all content before the first-encountered <hr /> tag.
33
+ # Allows authors to mark the fold with an hr in their drafts.
34
+ # e.g. {{ content | before_fold }}
35
+ def before_fold(input)
36
+ input.split("<hr").first
37
+ end
38
+
39
+ def array_to_sentence_string(array)
40
+ connector = "and"
41
+ case array.length
42
+ when 0
43
+ ""
44
+ when 1
45
+ array[0].to_s
46
+ when 2
47
+ "#{array[0]} #{connector} #{array[1]}"
48
+ else
49
+ "#{array[0...-1].join(', ')}, #{connector} #{array[-1]}"
50
+ end
51
+ end
52
+
53
+ def html_truncatewords(input, words = 15, truncate_string = "...")
54
+ doc = Hpricot.parse(input)
55
+ (doc/:"text()").to_s.split[0..words].join(' ') + truncate_string
56
+ end
57
+
58
+
59
+ def strip_html_suffix(input)
60
+ input.gsub(/\.html$/, '')
61
+ end
62
+
63
+ def gist(id)
64
+ js = open("http://gist.github.com/#{id}.js").read
65
+ js.match(/document.write\('(<div.+)'\)/)[1].gsub(/\\"/, '"').gsub(/\\\//, '/').gsub(/\\n/, '')
66
+ end
67
+
68
+ def educate(input)
69
+ Smartypants.educate_string(input)
70
+ end
71
+
72
+ def markdown(input)
73
+ Maruku.new(input).to_html
74
+ end
75
+ end
76
+
77
+ # Maruku, inexplicably, offers no way to access its Smartypants
78
+ # implementation outside of the Markdown interface. So here's a hack.
79
+ class Smartypants; end
80
+ class << Smartypants
81
+ include MaRuKu::In::Markdown::SpanLevelParser
82
+ include MaRuKu::Helpers
83
+ def educate_string(s)
84
+ educate([s]).map{ |x| x.to_html_entity rescue x }.join
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,47 @@
1
+ module Jekyll
2
+
3
+ class Layout
4
+ include Convertible
5
+
6
+ attr_accessor :ext
7
+ attr_accessor :data, :content
8
+
9
+ # Initialize a new Layout.
10
+ # +base+ is the String path to the <source>
11
+ # +name+ is the String filename of the post file
12
+ #
13
+ # Returns <Page>
14
+ def initialize(base, name)
15
+ @base = base
16
+ @name = name
17
+
18
+ self.data = {}
19
+
20
+ self.process(name)
21
+ self.read_yaml(base, name)
22
+ end
23
+
24
+ # Extract information from the layout filename
25
+ # +name+ is the String filename of the layout file
26
+ #
27
+ # Returns nothing
28
+ def process(name)
29
+ self.ext = File.extname(name)
30
+ end
31
+
32
+ # Add any necessary layouts to this post
33
+ # +layouts+ is a Hash of {"name" => "layout"}
34
+ # +site_payload+ is the site payload hash
35
+ #
36
+ # Returns nothing
37
+ def add_layout(layouts, site_payload)
38
+ payload = {"page" => self.data}.deep_merge(site_payload)
39
+ self.content = Liquid::Template.parse(self.content).render(payload, [Jekyll::Filters])
40
+
41
+ layout = layouts[self.data["layout"]] || self.content
42
+ payload = {"content" => self.content, "page" => self.data}
43
+
44
+ self.content = Liquid::Template.parse(layout).render(payload, [Jekyll::Filters])
45
+ end
46
+ end
47
+ end