codeslinger-jekyll 0.3.0
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.
- data/History.txt +86 -0
- data/Manifest.txt +40 -0
- data/README.textile +459 -0
- data/Rakefile +29 -0
- data/bin/jekyll +132 -0
- data/jekyll.gemspec +51 -0
- data/lib/jekyll/albino.rb +116 -0
- data/lib/jekyll/converters/csv.rb +26 -0
- data/lib/jekyll/converters/mephisto.rb +79 -0
- data/lib/jekyll/converters/mt.rb +59 -0
- data/lib/jekyll/converters/textpattern.rb +50 -0
- data/lib/jekyll/converters/typo.rb +49 -0
- data/lib/jekyll/converters/wordpress.rb +54 -0
- data/lib/jekyll/convertible.rb +71 -0
- data/lib/jekyll/core_ext.rb +22 -0
- data/lib/jekyll/filters.rb +39 -0
- data/lib/jekyll/layout.rb +33 -0
- data/lib/jekyll/page.rb +64 -0
- data/lib/jekyll/post.rb +174 -0
- data/lib/jekyll/site.rb +161 -0
- data/lib/jekyll/tags/highlight.rb +41 -0
- data/lib/jekyll/tags/include.rb +31 -0
- data/lib/jekyll.rb +64 -0
- data/test/helper.rb +13 -0
- data/test/source/_includes/sig.markdown +3 -0
- data/test/source/_layouts/default.html +27 -0
- data/test/source/_layouts/simple.html +1 -0
- data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
- data/test/source/_posts/2008-11-21-complex.textile +8 -0
- data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
- data/test/source/_posts/2008-12-13-include.markdown +8 -0
- data/test/source/css/screen.css +76 -0
- data/test/source/index.html +22 -0
- data/test/suite.rb +9 -0
- data/test/test_filters.rb +37 -0
- data/test/test_generated_site.rb +21 -0
- data/test/test_jekyll.rb +0 -0
- data/test/test_post.rb +107 -0
- data/test/test_site.rb +30 -0
- data/test/test_tags.rb +31 -0
- metadata +162 -0
@@ -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,39 @@
|
|
1
|
+
module Jekyll
|
2
|
+
|
3
|
+
module Filters
|
4
|
+
def date_to_string(date)
|
5
|
+
date.strftime("%d %b %Y")
|
6
|
+
end
|
7
|
+
|
8
|
+
def date_to_long_string(date)
|
9
|
+
date.strftime("%d %B %Y")
|
10
|
+
end
|
11
|
+
|
12
|
+
def date_to_xmlschema(date)
|
13
|
+
date.xmlschema
|
14
|
+
end
|
15
|
+
|
16
|
+
def xml_escape(input)
|
17
|
+
input.gsub("&", "&").gsub("<", "<").gsub(">", ">")
|
18
|
+
end
|
19
|
+
|
20
|
+
def number_of_words(input)
|
21
|
+
input.split.length
|
22
|
+
end
|
23
|
+
|
24
|
+
def array_to_sentence_string(array)
|
25
|
+
connector = "and"
|
26
|
+
case array.length
|
27
|
+
when 0
|
28
|
+
""
|
29
|
+
when 1
|
30
|
+
array[0].to_s
|
31
|
+
when 2
|
32
|
+
"#{array[0]} #{connector} #{array[1]}"
|
33
|
+
else
|
34
|
+
"#{array[0...-1].join(', ')}, #{connector} #{array[-1]}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/jekyll/page.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module Jekyll
|
2
|
+
|
3
|
+
class Page
|
4
|
+
include Convertible
|
5
|
+
|
6
|
+
attr_accessor :ext
|
7
|
+
attr_accessor :data, :content, :output
|
8
|
+
|
9
|
+
# Initialize a new Page.
|
10
|
+
# +base+ is the String path to the <source>
|
11
|
+
# +dir+ is the String path between <source> and the file
|
12
|
+
# +name+ is the String filename of the file
|
13
|
+
#
|
14
|
+
# Returns <Page>
|
15
|
+
def initialize(base, dir, name)
|
16
|
+
@base = base
|
17
|
+
@dir = dir
|
18
|
+
@name = name
|
19
|
+
|
20
|
+
self.data = {}
|
21
|
+
|
22
|
+
self.process(name)
|
23
|
+
self.read_yaml(File.join(base, dir), name)
|
24
|
+
#self.transform
|
25
|
+
end
|
26
|
+
|
27
|
+
# Extract information from the page filename
|
28
|
+
# +name+ is the String filename of the page file
|
29
|
+
#
|
30
|
+
# Returns nothing
|
31
|
+
def process(name)
|
32
|
+
self.ext = File.extname(name)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Add any necessary layouts to this post
|
36
|
+
# +layouts+ is a Hash of {"name" => "layout"}
|
37
|
+
# +site_payload+ is the site payload hash
|
38
|
+
#
|
39
|
+
# Returns nothing
|
40
|
+
def render(layouts, site_payload)
|
41
|
+
payload = {"page" => self.data}.deep_merge(site_payload)
|
42
|
+
do_layout(payload, layouts)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Write the generated page file to the destination directory.
|
46
|
+
# +dest+ is the String path to the destination dir
|
47
|
+
#
|
48
|
+
# Returns nothing
|
49
|
+
def write(dest)
|
50
|
+
FileUtils.mkdir_p(File.join(dest, @dir))
|
51
|
+
|
52
|
+
name = @name
|
53
|
+
if self.ext != ""
|
54
|
+
name = @name.split(".")[0..-2].join('.') + self.ext
|
55
|
+
end
|
56
|
+
|
57
|
+
path = File.join(dest, @dir, name)
|
58
|
+
File.open(path, 'w') do |f|
|
59
|
+
f.write(self.output)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/lib/jekyll/post.rb
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
module Jekyll
|
2
|
+
|
3
|
+
class Post
|
4
|
+
include Comparable
|
5
|
+
include Convertible
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :lsi
|
9
|
+
end
|
10
|
+
|
11
|
+
MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
|
12
|
+
|
13
|
+
# Post name validator. Post filenames must be like:
|
14
|
+
# 2008-11-05-my-awesome-post.textile
|
15
|
+
#
|
16
|
+
# Returns <Bool>
|
17
|
+
def self.valid?(name)
|
18
|
+
name =~ MATCHER
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :date, :slug, :ext, :categories, :topics
|
22
|
+
attr_accessor :data, :content, :output
|
23
|
+
|
24
|
+
# Initialize this Post instance.
|
25
|
+
# +base+ is the String path to the dir containing the post file
|
26
|
+
# +name+ is the String filename of the post file
|
27
|
+
# +categories+ is an Array of Strings for the categories for this post
|
28
|
+
#
|
29
|
+
# Returns <Post>
|
30
|
+
def initialize(source, dir, name)
|
31
|
+
@base = File.join(source, dir, '_posts')
|
32
|
+
@name = name
|
33
|
+
|
34
|
+
self.categories = dir.split('/').reject { |x| x.empty? }
|
35
|
+
|
36
|
+
parts = name.split('/')
|
37
|
+
self.topics = parts.size > 1 ? parts[0..-2] : []
|
38
|
+
|
39
|
+
self.process(name)
|
40
|
+
self.read_yaml(@base, name)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Spaceship is based on Post#date
|
44
|
+
#
|
45
|
+
# Returns -1, 0, 1
|
46
|
+
def <=>(other)
|
47
|
+
self.date <=> other.date
|
48
|
+
end
|
49
|
+
|
50
|
+
# Extract information from the post filename
|
51
|
+
# +name+ is the String filename of the post file
|
52
|
+
#
|
53
|
+
# Returns nothing
|
54
|
+
def process(name)
|
55
|
+
m, cats, date, slug, ext = *name.match(MATCHER)
|
56
|
+
self.date = Time.parse(date)
|
57
|
+
self.slug = slug
|
58
|
+
self.ext = ext
|
59
|
+
end
|
60
|
+
|
61
|
+
# The generated directory into which the post will be placed
|
62
|
+
# upon generation. This is derived from the permalink or, if
|
63
|
+
# permalink is absent, set to the default date
|
64
|
+
# e.g. "/2008/11/05/" if the permalink style is :date, otherwise nothing
|
65
|
+
#
|
66
|
+
# Returns <String>
|
67
|
+
def dir
|
68
|
+
if permalink
|
69
|
+
permalink.to_s.split("/")[0..-2].join("/") + '/'
|
70
|
+
else
|
71
|
+
prefix = self.categories.empty? ? '' : '/' + self.categories.join('/')
|
72
|
+
if Jekyll.permalink_style == :date
|
73
|
+
prefix + date.strftime("/%Y/%m/%d/")
|
74
|
+
else
|
75
|
+
prefix + '/'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# The full path and filename of the post.
|
81
|
+
# Defined in the YAML of the post body
|
82
|
+
# (Optional)
|
83
|
+
#
|
84
|
+
# Returns <String>
|
85
|
+
def permalink
|
86
|
+
self.data && self.data['permalink']
|
87
|
+
end
|
88
|
+
|
89
|
+
# The generated relative url of this post
|
90
|
+
# e.g. /2008/11/05/my-awesome-post.html
|
91
|
+
#
|
92
|
+
# Returns <String>
|
93
|
+
def url
|
94
|
+
permalink || self.dir + self.slug + ".html"
|
95
|
+
end
|
96
|
+
|
97
|
+
# The UID for this post (useful in feeds)
|
98
|
+
# e.g. /2008/11/05/my-awesome-post
|
99
|
+
#
|
100
|
+
# Returns <String>
|
101
|
+
def id
|
102
|
+
self.dir + self.slug
|
103
|
+
end
|
104
|
+
|
105
|
+
# Calculate related posts.
|
106
|
+
#
|
107
|
+
# Returns [<Post>]
|
108
|
+
def related_posts(posts)
|
109
|
+
return [] unless posts.size > 1
|
110
|
+
|
111
|
+
if Jekyll.lsi
|
112
|
+
self.class.lsi ||= begin
|
113
|
+
puts "Running the classifier... this could take a while."
|
114
|
+
lsi = Classifier::LSI.new
|
115
|
+
posts.each { |x| $stdout.print(".");$stdout.flush;lsi.add_item(x) }
|
116
|
+
puts ""
|
117
|
+
lsi
|
118
|
+
end
|
119
|
+
|
120
|
+
related = self.class.lsi.find_related(self.content, 11)
|
121
|
+
related - [self]
|
122
|
+
else
|
123
|
+
(posts - [self])[0..9]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Add any necessary layouts to this post
|
128
|
+
# +layouts+ is a Hash of {"name" => "layout"}
|
129
|
+
# +site_payload+ is the site payload hash
|
130
|
+
#
|
131
|
+
# Returns nothing
|
132
|
+
def render(layouts, site_payload)
|
133
|
+
# construct payload
|
134
|
+
payload =
|
135
|
+
{
|
136
|
+
"site" => { "related_posts" => related_posts(site_payload["site"]["posts"]) },
|
137
|
+
"page" => self.to_liquid
|
138
|
+
}
|
139
|
+
payload = payload.deep_merge(site_payload)
|
140
|
+
|
141
|
+
do_layout(payload, layouts)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Write the generated post file to the destination directory.
|
145
|
+
# +dest+ is the String path to the destination dir
|
146
|
+
#
|
147
|
+
# Returns nothing
|
148
|
+
def write(dest)
|
149
|
+
FileUtils.mkdir_p(File.join(dest, dir))
|
150
|
+
|
151
|
+
path = File.join(dest, self.url)
|
152
|
+
File.open(path, 'w') do |f|
|
153
|
+
f.write(self.output)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Convert this post into a Hash for use in Liquid templates.
|
158
|
+
#
|
159
|
+
# Returns <Hash>
|
160
|
+
def to_liquid
|
161
|
+
{ "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
|
162
|
+
"url" => self.url,
|
163
|
+
"date" => self.date,
|
164
|
+
"id" => self.id,
|
165
|
+
"topics" => self.topics,
|
166
|
+
"content" => self.content }.deep_merge(self.data)
|
167
|
+
end
|
168
|
+
|
169
|
+
def inspect
|
170
|
+
"<Post: #{self.id}>"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
data/lib/jekyll/site.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
module Jekyll
|
2
|
+
|
3
|
+
class Site
|
4
|
+
attr_accessor :source, :dest
|
5
|
+
attr_accessor :layouts, :posts
|
6
|
+
|
7
|
+
# Initialize the site
|
8
|
+
# +source+ is String path to the source directory containing
|
9
|
+
# the proto-site
|
10
|
+
# +dest+ is the String path to the directory where the generated
|
11
|
+
# site should be written
|
12
|
+
#
|
13
|
+
# Returns <Site>
|
14
|
+
def initialize(source, dest)
|
15
|
+
self.source = source
|
16
|
+
self.dest = dest
|
17
|
+
self.layouts = {}
|
18
|
+
self.posts = []
|
19
|
+
end
|
20
|
+
|
21
|
+
# Do the actual work of processing the site and generating the
|
22
|
+
# real deal.
|
23
|
+
#
|
24
|
+
# Returns nothing
|
25
|
+
def process
|
26
|
+
self.read_layouts
|
27
|
+
self.transform_pages
|
28
|
+
self.write_posts
|
29
|
+
end
|
30
|
+
|
31
|
+
# Read all the files in <source>/_layouts except backup files
|
32
|
+
# (end with "~") into memory for later use.
|
33
|
+
#
|
34
|
+
# Returns nothing
|
35
|
+
def read_layouts
|
36
|
+
base = File.join(self.source, "_layouts")
|
37
|
+
entries = Dir.entries(base)
|
38
|
+
entries = entries.reject { |e| e[-1..-1] == '~' }
|
39
|
+
entries = entries.reject { |e| File.directory?(File.join(base, e)) }
|
40
|
+
|
41
|
+
entries.each do |f|
|
42
|
+
name = f.split(".")[0..-2].join(".")
|
43
|
+
self.layouts[name] = Layout.new(base, f)
|
44
|
+
end
|
45
|
+
rescue Errno::ENOENT => e
|
46
|
+
# ignore missing layout dir
|
47
|
+
end
|
48
|
+
|
49
|
+
# Read all the files in <base>/_posts except backup files (end with "~")
|
50
|
+
# and create a new Post object with each one.
|
51
|
+
#
|
52
|
+
# Returns nothing
|
53
|
+
def read_posts(dir)
|
54
|
+
base = File.join(self.source, dir, '_posts')
|
55
|
+
|
56
|
+
entries = []
|
57
|
+
Dir.chdir(base) { entries = Dir['**/*'] }
|
58
|
+
entries = entries.reject { |e| e[-1..-1] == '~' }
|
59
|
+
entries = entries.reject { |e| File.directory?(File.join(base, e)) }
|
60
|
+
|
61
|
+
# first pass processes, but does not yet render post content
|
62
|
+
entries.each do |f|
|
63
|
+
if Post.valid?(f)
|
64
|
+
post = Post.new(self.source, dir, f)
|
65
|
+
self.posts << post
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# second pass renders each post now that full site payload is available
|
70
|
+
self.posts.each do |post|
|
71
|
+
post.render(self.layouts, site_payload)
|
72
|
+
end
|
73
|
+
|
74
|
+
self.posts.sort!
|
75
|
+
rescue Errno::ENOENT => e
|
76
|
+
# ignore missing layout dir
|
77
|
+
end
|
78
|
+
|
79
|
+
# Write each post to <dest>/<year>/<month>/<day>/<slug>
|
80
|
+
#
|
81
|
+
# Returns nothing
|
82
|
+
def write_posts
|
83
|
+
self.posts.each do |post|
|
84
|
+
post.write(self.dest)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Copy all regular files from <source> to <dest>/ ignoring
|
89
|
+
# any files/directories that are hidden or backup files (start
|
90
|
+
# with "." or end with "~") or contain site content (start with "_")
|
91
|
+
# unless they are "_posts" directories or web server files such as
|
92
|
+
# '.htaccess'
|
93
|
+
# The +dir+ String is a relative path used to call this method
|
94
|
+
# recursively as it descends through directories
|
95
|
+
#
|
96
|
+
# Returns nothing
|
97
|
+
def transform_pages(dir = '')
|
98
|
+
base = File.join(self.source, dir)
|
99
|
+
entries = Dir.entries(base)
|
100
|
+
entries = entries.reject { |e| e[-1..-1] == '~' }
|
101
|
+
entries = entries.reject do |e|
|
102
|
+
(e != '_posts') and ['.', '_'].include?(e[0..0]) unless ['.htaccess'].include?(e)
|
103
|
+
end
|
104
|
+
|
105
|
+
# we need to make sure to process _posts *first* otherwise they
|
106
|
+
# might not be available yet to other templates as {{ site.posts }}
|
107
|
+
if entries.include?('_posts')
|
108
|
+
entries.delete('_posts')
|
109
|
+
read_posts(dir)
|
110
|
+
end
|
111
|
+
|
112
|
+
entries.each do |f|
|
113
|
+
if File.directory?(File.join(base, f))
|
114
|
+
next if self.dest.sub(/\/$/, '') == File.join(base, f)
|
115
|
+
transform_pages(File.join(dir, f))
|
116
|
+
else
|
117
|
+
first3 = File.open(File.join(self.source, dir, f)) { |fd| fd.read(3) }
|
118
|
+
|
119
|
+
if first3 == "---"
|
120
|
+
# file appears to have a YAML header so process it as a page
|
121
|
+
page = Page.new(self.source, dir, f)
|
122
|
+
page.render(self.layouts, site_payload)
|
123
|
+
page.write(self.dest)
|
124
|
+
else
|
125
|
+
# otherwise copy the file without transforming it
|
126
|
+
FileUtils.mkdir_p(File.join(self.dest, dir))
|
127
|
+
FileUtils.cp(File.join(self.source, dir, f), File.join(self.dest, dir, f))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Constructs a hash map of Posts indexed by the specified Post attribute
|
134
|
+
#
|
135
|
+
# Returns {post_attr => [<Post>]}
|
136
|
+
def post_attr_hash(post_attr)
|
137
|
+
# Build a hash map based on the specified post attribute ( post attr => array of posts )
|
138
|
+
# then sort each array in reverse order
|
139
|
+
hash = Hash.new { |hash, key| hash[key] = Array.new }
|
140
|
+
self.posts.each { |p| p.send(post_attr.to_sym).each { |t| hash[t] << p } }
|
141
|
+
hash.values.map { |sortme| sortme.sort! { |a, b| b <=> a} }
|
142
|
+
return hash
|
143
|
+
end
|
144
|
+
|
145
|
+
# The Hash payload containing site-wide data
|
146
|
+
#
|
147
|
+
# Returns {"site" => {"time" => <Time>,
|
148
|
+
# "posts" => [<Post>],
|
149
|
+
# "categories" => [<Post>],
|
150
|
+
# "topics" => [<Post>] }}
|
151
|
+
def site_payload
|
152
|
+
{"site" => {
|
153
|
+
"time" => Time.now,
|
154
|
+
"posts" => self.posts.sort { |a,b| b <=> a },
|
155
|
+
"categories" => post_attr_hash('categories'),
|
156
|
+
"topics" => post_attr_hash('topics')
|
157
|
+
}}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Jekyll
|
2
|
+
|
3
|
+
class HighlightBlock < Liquid::Block
|
4
|
+
include Liquid::StandardFilters
|
5
|
+
|
6
|
+
def initialize(tag_name, lang, tokens)
|
7
|
+
super
|
8
|
+
@lang = lang.strip
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(context)
|
12
|
+
if Jekyll.pygments
|
13
|
+
render_pygments(context, super.to_s)
|
14
|
+
else
|
15
|
+
render_codehighlighter(context, super.to_s)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def render_pygments(context, code)
|
20
|
+
if Jekyll.content_type == :markdown
|
21
|
+
return "\n" + Albino.new(code, @lang).to_s + "\n"
|
22
|
+
else
|
23
|
+
"<notextile>" + Albino.new(code, @lang).to_s + "</notextile>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_codehighlighter(context, code)
|
28
|
+
#The div is required because RDiscount blows ass
|
29
|
+
<<-HTML
|
30
|
+
<div>
|
31
|
+
<pre>
|
32
|
+
<code class='#{@lang}'>#{h(code).strip}</code>
|
33
|
+
</pre>
|
34
|
+
</div>
|
35
|
+
HTML
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
Liquid::Template.register_tag('highlight', Jekyll::HighlightBlock)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Jekyll
|
2
|
+
|
3
|
+
class IncludeTag < Liquid::Tag
|
4
|
+
def initialize(tag_name, file, tokens)
|
5
|
+
super
|
6
|
+
@file = file.strip
|
7
|
+
end
|
8
|
+
|
9
|
+
def render(context)
|
10
|
+
if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./
|
11
|
+
return "Include file '#{@file}' contains invalid characters or sequences"
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir.chdir(File.join(Jekyll.source, '_includes')) do
|
15
|
+
choices = Dir['**/*'].reject { |x| File.symlink?(x) }
|
16
|
+
if choices.include?(@file)
|
17
|
+
source = File.read(@file)
|
18
|
+
partial = Liquid::Template.parse(source)
|
19
|
+
context.stack do
|
20
|
+
partial.render(context)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
"Included file '#{@file}' not found in _includes directory"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
Liquid::Template.register_tag('include', Jekyll::IncludeTag)
|
data/lib/jekyll.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
|
2
|
+
|
3
|
+
# rubygems
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
# core
|
7
|
+
require 'fileutils'
|
8
|
+
require 'time'
|
9
|
+
require 'yaml'
|
10
|
+
|
11
|
+
# stdlib
|
12
|
+
|
13
|
+
# 3rd party
|
14
|
+
require 'liquid'
|
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
|
+
|
33
|
+
# internal requires
|
34
|
+
require 'jekyll/core_ext'
|
35
|
+
require 'jekyll/site'
|
36
|
+
require 'jekyll/convertible'
|
37
|
+
require 'jekyll/layout'
|
38
|
+
require 'jekyll/page'
|
39
|
+
require 'jekyll/post'
|
40
|
+
require 'jekyll/filters'
|
41
|
+
require 'jekyll/tags/highlight'
|
42
|
+
require 'jekyll/tags/include'
|
43
|
+
require 'jekyll/albino'
|
44
|
+
|
45
|
+
module Jekyll
|
46
|
+
VERSION = '0.3.0'
|
47
|
+
|
48
|
+
class << self
|
49
|
+
attr_accessor :source, :dest, :lsi, :pygments, :markdown_proc, :content_type, :permalink_style
|
50
|
+
end
|
51
|
+
|
52
|
+
Jekyll.lsi = false
|
53
|
+
Jekyll.pygments = false
|
54
|
+
Jekyll.markdown_proc = Proc.new { |x| Maruku.new(x).to_html }
|
55
|
+
Jekyll.permalink_style = :date
|
56
|
+
|
57
|
+
def self.process(source, dest)
|
58
|
+
require 'classifier' if Jekyll.lsi
|
59
|
+
|
60
|
+
Jekyll.source = source
|
61
|
+
Jekyll.dest = dest
|
62
|
+
Jekyll::Site.new(source, dest).process
|
63
|
+
end
|
64
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
7
|
+
<title>{{ page.title }}</title>
|
8
|
+
<meta name="author" content="<%= @page.author %>" />
|
9
|
+
|
10
|
+
<!-- CodeRay syntax highlighting CSS -->
|
11
|
+
<link rel="stylesheet" href="/css/coderay.css" type="text/css" />
|
12
|
+
|
13
|
+
<!-- Homepage CSS -->
|
14
|
+
<link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen, projection" />
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
|
18
|
+
<div class="site">
|
19
|
+
<div class="title">
|
20
|
+
Tom Preston-Werner
|
21
|
+
</div>
|
22
|
+
|
23
|
+
{{ content }}
|
24
|
+
</div>
|
25
|
+
|
26
|
+
</body>
|
27
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<<< {{ content }} >>>
|