codeslinger-jekyll 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +19 -1
- data/README.textile +75 -5
- data/Rakefile +91 -0
- data/VERSION.yml +2 -2
- data/bin/jekyll +60 -56
- data/lib/jekyll.rb +48 -32
- data/lib/jekyll/albino.rb +9 -5
- data/lib/jekyll/converters/mephisto.rb +8 -8
- data/lib/jekyll/converters/mt.rb +8 -8
- data/lib/jekyll/converters/textpattern.rb +4 -4
- data/lib/jekyll/converters/typo.rb +8 -8
- data/lib/jekyll/converters/wordpress.rb +1 -2
- data/lib/jekyll/convertible.rb +33 -22
- data/lib/jekyll/core_ext.rb +5 -5
- data/lib/jekyll/filters.rb +10 -6
- data/lib/jekyll/layout.rb +9 -6
- data/lib/jekyll/page.rb +13 -10
- data/lib/jekyll/post.rb +58 -27
- data/lib/jekyll/site.rb +121 -50
- data/lib/jekyll/tags/highlight.rb +12 -9
- data/lib/jekyll/tags/include.rb +5 -5
- data/test/helper.rb +17 -6
- data/test/source/_posts/2008-02-02-not-published.textile +8 -0
- data/test/source/_posts/2008-02-02-published.textile +8 -0
- data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
- data/test/source/_posts/2009-01-27-categories.textile +7 -0
- data/test/source/_posts/2009-01-27-category.textile +7 -0
- data/test/test_filters.rb +31 -27
- data/test/test_generated_site.rb +32 -16
- data/test/test_post.rb +134 -102
- data/test/test_site.rb +52 -28
- data/test/test_tags.rb +17 -13
- metadata +19 -67
- data/test/test_jekyll.rb +0 -0
data/lib/jekyll.rb
CHANGED
@@ -13,22 +13,6 @@ require 'yaml'
|
|
13
13
|
# 3rd party
|
14
14
|
require 'liquid'
|
15
15
|
require 'redcloth'
|
16
|
-
begin
|
17
|
-
require 'maruku'
|
18
|
-
require 'maruku/ext/math'
|
19
|
-
# Switch off MathML output
|
20
|
-
MaRuKu::Globals[:html_math_output_mathml] = false
|
21
|
-
MaRuKu::Globals[:html_math_engine] = 'none'
|
22
|
-
|
23
|
-
# Turn on math to PNG support with blahtex
|
24
|
-
# Resulting PNGs stored in `images/latex`
|
25
|
-
MaRuKu::Globals[:html_math_output_png] = true
|
26
|
-
MaRuKu::Globals[:html_png_engine] = 'blahtex'
|
27
|
-
MaRuKu::Globals[:html_png_dir] = 'images/latex'
|
28
|
-
MaRuKu::Globals[:html_png_url] = '/images/latex/'
|
29
|
-
rescue LoadError
|
30
|
-
puts "The maruku gem is required for markdown support!"
|
31
|
-
end
|
32
16
|
|
33
17
|
# internal requires
|
34
18
|
require 'jekyll/core_ext'
|
@@ -43,23 +27,55 @@ require 'jekyll/tags/include'
|
|
43
27
|
require 'jekyll/albino'
|
44
28
|
|
45
29
|
module Jekyll
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
30
|
+
# Default options. Overriden by values in _config.yaml or command-line opts.
|
31
|
+
# (Strings rather symbols used for compatability with YAML)
|
32
|
+
DEFAULTS = {
|
33
|
+
'auto' => false,
|
34
|
+
'server' => false,
|
35
|
+
'server_port' => 4000,
|
36
|
+
|
37
|
+
'source' => '.',
|
38
|
+
'destination' => File.join('.', '_site'),
|
39
|
+
|
40
|
+
'lsi' => false,
|
41
|
+
'pygments' => false,
|
42
|
+
'markdown' => 'maruku',
|
43
|
+
'permalink' => 'date',
|
44
|
+
|
45
|
+
'maruku' => {
|
46
|
+
'use_tex' => false,
|
47
|
+
'use_divs' => false,
|
48
|
+
'png_engine' => 'blahtex',
|
49
|
+
'png_dir' => 'images/latex',
|
50
|
+
'png_url' => '/images/latex'
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
# Generate a Jekyll configuration Hash by merging the default options
|
55
|
+
# with anything in _config.yml, and adding the given options on top
|
56
|
+
# +override+ is a Hash of config directives
|
57
|
+
#
|
58
|
+
# Returns Hash
|
59
|
+
def self.configuration(override)
|
60
|
+
# _config.yml may override default source location, but until
|
61
|
+
# then, we need to know where to look for _config.yml
|
62
|
+
source = override['source'] || Jekyll::DEFAULTS['source']
|
63
|
+
|
64
|
+
# Get configuration from <source>/_config.yaml
|
65
|
+
config = {}
|
66
|
+
config_file = File.join(source, '_config.yml')
|
67
|
+
begin
|
68
|
+
config = YAML.load_file(config_file)
|
69
|
+
puts "Configuration from #{config_file}"
|
70
|
+
rescue => err
|
71
|
+
puts "WARNING: Could not read configuration. Using defaults (and options)."
|
72
|
+
puts "\t" + err
|
73
|
+
end
|
74
|
+
|
75
|
+
# Merge DEFAULTS < _config.yml < override
|
76
|
+
Jekyll::DEFAULTS.deep_merge(config).deep_merge(override)
|
61
77
|
end
|
62
|
-
|
78
|
+
|
63
79
|
def self.version
|
64
80
|
yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
|
65
81
|
"#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
|
data/lib/jekyll/albino.rb
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
#
|
39
39
|
# To see all lexers and formatters available, run `pygmentize -L`.
|
40
40
|
#
|
41
|
-
# Chris Wanstrath // chris@ozmm.org
|
41
|
+
# Chris Wanstrath // chris@ozmm.org
|
42
42
|
# GitHub // http://github.com
|
43
43
|
#
|
44
44
|
require 'open4'
|
@@ -60,10 +60,14 @@ class Albino
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def execute(command)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
output = ''
|
64
|
+
Open4.popen4(command) do |pid, stdin, stdout, stderr|
|
65
|
+
stdin.puts @target
|
66
|
+
stdin.close
|
67
|
+
output = stdout.read.strip
|
68
|
+
[stdout, stderr].each { |io| io.close }
|
69
|
+
end
|
70
|
+
output
|
67
71
|
end
|
68
72
|
|
69
73
|
def colorize(options = {})
|
@@ -13,7 +13,7 @@ require File.join(File.dirname(__FILE__),"csv.rb")
|
|
13
13
|
# installed, running the following commands should work:
|
14
14
|
# $ sudo gem install sequel
|
15
15
|
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
16
|
-
|
16
|
+
|
17
17
|
module Jekyll
|
18
18
|
module Mephisto
|
19
19
|
#Accepts a hash with database config variables, exports mephisto posts into a csv
|
@@ -38,24 +38,24 @@ module Jekyll
|
|
38
38
|
# through the created posts to make sure nothing is accidently published.
|
39
39
|
|
40
40
|
QUERY = "SELECT id, permalink, body, published_at, title FROM contents WHERE user_id = 1 AND type = 'Article' AND published_at IS NOT NULL ORDER BY published_at"
|
41
|
-
|
41
|
+
|
42
42
|
def self.process(dbname, user, pass, host = 'localhost')
|
43
43
|
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
44
|
-
|
44
|
+
|
45
45
|
FileUtils.mkdir_p "_posts"
|
46
|
-
|
46
|
+
|
47
47
|
db[QUERY].each do |post|
|
48
48
|
title = post[:title]
|
49
49
|
slug = post[:permalink]
|
50
50
|
date = post[:published_at]
|
51
51
|
content = post[:body]
|
52
52
|
# more_content = ''
|
53
|
-
|
53
|
+
|
54
54
|
# Be sure to include the body and extended body.
|
55
55
|
# if more_content != nil
|
56
56
|
# content = content + " \n" + more_content
|
57
57
|
# end
|
58
|
-
|
58
|
+
|
59
59
|
# Ideally, this script would determine the post format (markdown, html
|
60
60
|
# , etc) and create files with proper extensions. At this point it
|
61
61
|
# just assumes that markdown will be acceptable.
|
@@ -66,14 +66,14 @@ module Jekyll
|
|
66
66
|
'title' => title.to_s,
|
67
67
|
'mt_id' => post[:entry_id],
|
68
68
|
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
69
|
-
|
69
|
+
|
70
70
|
File.open("_posts/#{name}", "w") do |f|
|
71
71
|
f.puts data
|
72
72
|
f.puts "---"
|
73
73
|
f.puts content
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
data/lib/jekyll/converters/mt.rb
CHANGED
@@ -11,31 +11,31 @@ require 'fileutils'
|
|
11
11
|
# installed, running the following commands should work:
|
12
12
|
# $ sudo gem install sequel
|
13
13
|
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
14
|
-
|
14
|
+
|
15
15
|
module Jekyll
|
16
16
|
module MT
|
17
17
|
# This query will pull blog posts from all entries across all blogs. If
|
18
18
|
# you've got unpublished, deleted or otherwise hidden posts please sift
|
19
19
|
# through the created posts to make sure nothing is accidently published.
|
20
20
|
QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_created_on, entry_title FROM mt_entry"
|
21
|
-
|
21
|
+
|
22
22
|
def self.process(dbname, user, pass, host = 'localhost')
|
23
23
|
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
24
|
-
|
24
|
+
|
25
25
|
FileUtils.mkdir_p "_posts"
|
26
|
-
|
26
|
+
|
27
27
|
db[QUERY].each do |post|
|
28
28
|
title = post[:entry_title]
|
29
29
|
slug = post[:entry_basename]
|
30
30
|
date = post[:entry_created_on]
|
31
31
|
content = post[:entry_text]
|
32
32
|
more_content = post[:entry_text_more]
|
33
|
-
|
33
|
+
|
34
34
|
# Be sure to include the body and extended body.
|
35
35
|
if more_content != nil
|
36
36
|
content = content + " \n" + more_content
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
# Ideally, this script would determine the post format (markdown, html
|
40
40
|
# , etc) and create files with proper extensions. At this point it
|
41
41
|
# just assumes that markdown will be acceptable.
|
@@ -46,14 +46,14 @@ module Jekyll
|
|
46
46
|
'title' => title.to_s,
|
47
47
|
'mt_id' => post[:entry_id],
|
48
48
|
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
|
49
|
-
|
49
|
+
|
50
50
|
File.open("_posts/#{name}", "w") do |f|
|
51
51
|
f.puts data
|
52
52
|
f.puts "---"
|
53
53
|
f.puts content
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -18,20 +18,20 @@ module Jekyll
|
|
18
18
|
|
19
19
|
def self.process(dbname, user, pass, host = 'localhost')
|
20
20
|
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
21
|
-
|
21
|
+
|
22
22
|
FileUtils.mkdir_p "_posts"
|
23
|
-
|
23
|
+
|
24
24
|
db[QUERY].each do |post|
|
25
25
|
# Get required fields and construct Jekyll compatible name
|
26
26
|
title = post[:Title]
|
27
27
|
slug = post[:url_title]
|
28
28
|
date = post[:Posted]
|
29
29
|
content = post[:Body]
|
30
|
-
|
30
|
+
|
31
31
|
name = [date.strftime("%Y-%m-%d"), slug].join('-') + ".textile"
|
32
32
|
|
33
33
|
# Get the relevant fields as a hash, delete empty fields and convert
|
34
|
-
# to YAML for the header
|
34
|
+
# to YAML for the header
|
35
35
|
data = {
|
36
36
|
'layout' => 'post',
|
37
37
|
'title' => title.to_s,
|
@@ -2,22 +2,22 @@
|
|
2
2
|
require 'fileutils'
|
3
3
|
require 'rubygems'
|
4
4
|
require 'sequel'
|
5
|
-
|
5
|
+
|
6
6
|
module Jekyll
|
7
7
|
module Typo
|
8
|
-
# this SQL *should* work for both MySQL and PostgreSQL, but I haven't
|
8
|
+
# this SQL *should* work for both MySQL and PostgreSQL, but I haven't
|
9
9
|
# tested PostgreSQL yet (as of 2008-12-16)
|
10
10
|
SQL = <<-EOS
|
11
11
|
SELECT c.id id,
|
12
|
-
c.title title,
|
13
|
-
c.permalink slug,
|
12
|
+
c.title title,
|
13
|
+
c.permalink slug,
|
14
14
|
c.body body,
|
15
|
-
c.published_at date,
|
15
|
+
c.published_at date,
|
16
16
|
c.state state,
|
17
17
|
COALESCE(tf.name, 'html') filter
|
18
|
-
FROM contents c
|
18
|
+
FROM contents c
|
19
19
|
LEFT OUTER JOIN text_filters tf
|
20
|
-
ON c.text_filter_id = tf.id
|
20
|
+
ON c.text_filter_id = tf.id
|
21
21
|
EOS
|
22
22
|
|
23
23
|
def self.process dbname, user, pass, host='localhost'
|
@@ -30,7 +30,7 @@ module Jekyll
|
|
30
30
|
sprintf("%.02d", post[:date].month),
|
31
31
|
sprintf("%.02d", post[:date].day),
|
32
32
|
post[:slug].strip ].join('-')
|
33
|
-
# Can have more than one text filter in this field, but we just want
|
33
|
+
# Can have more than one text filter in this field, but we just want
|
34
34
|
# the first one for this
|
35
35
|
name += '.' + post[:filter].split(' ')[0]
|
36
36
|
|
@@ -15,7 +15,7 @@ module Jekyll
|
|
15
15
|
# post in wp_posts that has post_status = 'publish'.
|
16
16
|
# This restriction is made because 'draft' posts are not guaranteed to
|
17
17
|
# have valid dates.
|
18
|
-
QUERY = "select
|
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
19
|
|
20
20
|
def self.process(dbname, user, pass, host = 'localhost')
|
21
21
|
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host)
|
@@ -28,7 +28,6 @@ module Jekyll
|
|
28
28
|
slug = post[:post_name]
|
29
29
|
date = post[:post_date]
|
30
30
|
content = post[:post_content]
|
31
|
-
|
32
31
|
name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day,
|
33
32
|
slug]
|
34
33
|
|
data/lib/jekyll/convertible.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
+
# Convertible provides methods for converting a pagelike item
|
2
|
+
# from a certain type of markup into actual content
|
3
|
+
#
|
4
|
+
# Requires
|
5
|
+
# self.site -> Jekyll::Site
|
1
6
|
module Jekyll
|
2
7
|
module Convertible
|
3
8
|
# Return the contents as a string
|
4
9
|
def to_s
|
5
10
|
self.content || ''
|
6
11
|
end
|
7
|
-
|
12
|
+
|
8
13
|
# Read the YAML frontmatter
|
9
14
|
# +base+ is the String path to the dir containing the file
|
10
15
|
# +name+ is the String filename of the file
|
@@ -12,58 +17,64 @@ module Jekyll
|
|
12
17
|
# Returns nothing
|
13
18
|
def read_yaml(base, name)
|
14
19
|
self.content = File.read(File.join(base, name))
|
15
|
-
|
20
|
+
|
16
21
|
if self.content =~ /^(---\s*\n.*?)\n---\s*\n/m
|
17
22
|
self.content = self.content[($1.size + 5)..-1]
|
18
|
-
|
23
|
+
|
19
24
|
self.data = YAML.load($1)
|
20
25
|
end
|
21
26
|
end
|
22
|
-
|
27
|
+
|
23
28
|
# Transform the contents based on the file extension.
|
24
29
|
#
|
25
30
|
# Returns nothing
|
26
31
|
def transform
|
27
|
-
case
|
28
|
-
when
|
32
|
+
case self.content_type
|
33
|
+
when 'textile'
|
29
34
|
self.ext = ".html"
|
30
|
-
self.content =
|
31
|
-
when
|
35
|
+
self.content = self.site.textile(self.content)
|
36
|
+
when 'markdown'
|
32
37
|
self.ext = ".html"
|
33
|
-
self.content =
|
38
|
+
self.content = self.site.markdown(self.content)
|
34
39
|
end
|
35
40
|
end
|
36
|
-
|
37
|
-
|
41
|
+
|
42
|
+
# Determine which formatting engine to use based on this convertible's
|
43
|
+
# extension
|
44
|
+
#
|
45
|
+
# Returns one of :textile, :markdown or :unknown
|
46
|
+
def content_type
|
38
47
|
case self.ext[1..-1]
|
39
48
|
when /textile/i
|
40
|
-
return
|
49
|
+
return 'textile'
|
41
50
|
when /markdown/i, /mkdn/i, /md/i
|
42
|
-
return
|
43
|
-
end
|
44
|
-
return
|
51
|
+
return 'markdown'
|
52
|
+
end
|
53
|
+
return 'unknown'
|
45
54
|
end
|
46
|
-
|
55
|
+
|
47
56
|
# Add any necessary layouts to this convertible document
|
48
57
|
# +layouts+ is a Hash of {"name" => "layout"}
|
49
58
|
# +site_payload+ is the site payload hash
|
50
59
|
#
|
51
60
|
# Returns nothing
|
52
61
|
def do_layout(payload, layouts)
|
62
|
+
info = { :filters => [Jekyll::Filters], :registers => { :site => self.site } }
|
63
|
+
|
53
64
|
# render and transform content (this becomes the final content of the object)
|
54
|
-
|
55
|
-
self.content = Liquid::Template.parse(self.content).render(payload,
|
65
|
+
payload["content_type"] = self.content_type
|
66
|
+
self.content = Liquid::Template.parse(self.content).render(payload, info)
|
56
67
|
self.transform
|
57
|
-
|
68
|
+
|
58
69
|
# output keeps track of what will finally be written
|
59
70
|
self.output = self.content
|
60
|
-
|
71
|
+
|
61
72
|
# recursively render layouts
|
62
73
|
layout = layouts[self.data["layout"]]
|
63
74
|
while layout
|
64
75
|
payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
|
65
|
-
self.output = Liquid::Template.parse(layout.content).render(payload,
|
66
|
-
|
76
|
+
self.output = Liquid::Template.parse(layout.content).render(payload, info)
|
77
|
+
|
67
78
|
layout = layouts[layout.data["layout"]]
|
68
79
|
end
|
69
80
|
end
|
data/lib/jekyll/core_ext.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
class Hash
|
2
2
|
# Merges self with another hash, recursively.
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# This code was lovingly stolen from some random gem:
|
5
5
|
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# Thanks to whoever made it.
|
8
8
|
def deep_merge(hash)
|
9
9
|
target = dup
|
10
|
-
|
10
|
+
|
11
11
|
hash.keys.each do |key|
|
12
12
|
if hash[key].is_a? Hash and self[key].is_a? Hash
|
13
13
|
target[key] = target[key].deep_merge(hash[key])
|
14
14
|
next
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
target[key] = hash[key]
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
target
|
21
21
|
end
|
22
22
|
end
|