cduruk-jekyll 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +115 -0
- data/README.textile +649 -0
- data/Rakefile +91 -0
- data/VERSION.yml +4 -0
- data/bin/jekyll +156 -0
- data/lib/jekyll.rb +84 -0
- data/lib/jekyll/albino.rb +122 -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 +117 -0
- data/lib/jekyll/core_ext.rb +29 -0
- data/lib/jekyll/filters.rb +47 -0
- data/lib/jekyll/haml_helpers.rb +15 -0
- data/lib/jekyll/layout.rb +37 -0
- data/lib/jekyll/page.rb +67 -0
- data/lib/jekyll/post.rb +305 -0
- data/lib/jekyll/site.rb +300 -0
- data/lib/jekyll/tags/highlight.rb +68 -0
- data/lib/jekyll/tags/include.rb +31 -0
- data/test/helper.rb +24 -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-02-02-not-published.textile +8 -0
- data/test/source/_posts/2008-02-02-published.textile +8 -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/_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/source/category/_posts/2008-9-23-categories.textile +6 -0
- data/test/source/css/screen.css +76 -0
- data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
- data/test/source/index.html +22 -0
- data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
- data/test/suite.rb +9 -0
- data/test/test_filters.rb +41 -0
- data/test/test_generated_site.rb +38 -0
- data/test/test_post.rb +262 -0
- data/test/test_site.rb +57 -0
- data/test/test_tags.rb +51 -0
- metadata +165 -0
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
begin
|
6
|
+
gem 'jeweler', '>= 0.11.0'
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |s|
|
9
|
+
s.name = "jekyll"
|
10
|
+
s.summary = %Q{Jekyll is a simple, blog aware, static site generator.}
|
11
|
+
s.email = "tom@mojombo.com"
|
12
|
+
s.homepage = "http://github.com/mojombo/jekyll"
|
13
|
+
s.description = "Jekyll is a simple, blog aware, static site generator."
|
14
|
+
s.authors = ["Tom Preston-Werner"]
|
15
|
+
s.rubyforge_project = "jekyll"
|
16
|
+
s.files.exclude 'test/dest'
|
17
|
+
s.test_files.exclude 'test/dest'
|
18
|
+
s.add_dependency('RedCloth', '>= 4.0.4')
|
19
|
+
s.add_dependency('liquid', '>= 1.9.0')
|
20
|
+
s.add_dependency('classifier', '>= 1.3.1')
|
21
|
+
s.add_dependency('maruku', '>= 0.5.9')
|
22
|
+
s.add_dependency('directory_watcher', '>= 1.1.1')
|
23
|
+
s.add_dependency('open4', '>= 0.9.6')
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler --version '>= 0.11.0'"
|
27
|
+
exit(1)
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::TestTask.new do |t|
|
31
|
+
t.libs << 'lib'
|
32
|
+
t.pattern = 'test/**/test_*.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
rdoc.rdoc_dir = 'rdoc'
|
38
|
+
rdoc.title = 'jekyll'
|
39
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
40
|
+
rdoc.rdoc_files.include('README*')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
end
|
43
|
+
|
44
|
+
begin
|
45
|
+
require 'rcov/rcovtask'
|
46
|
+
Rcov::RcovTask.new do |t|
|
47
|
+
t.libs << 'test'
|
48
|
+
t.test_files = FileList['test/**/test_*.rb']
|
49
|
+
t.verbose = true
|
50
|
+
end
|
51
|
+
rescue LoadError
|
52
|
+
end
|
53
|
+
|
54
|
+
task :default => [:test, :features]
|
55
|
+
|
56
|
+
# console
|
57
|
+
|
58
|
+
desc "Open an irb session preloaded with this library"
|
59
|
+
task :console do
|
60
|
+
sh "irb -rubygems -I lib -r jekyll.rb"
|
61
|
+
end
|
62
|
+
|
63
|
+
# converters
|
64
|
+
|
65
|
+
namespace :convert do
|
66
|
+
desc "Migrate from mephisto in the current directory"
|
67
|
+
task :mephisto do
|
68
|
+
sh %q(ruby -r './lib/jekyll/converters/mephisto' -e 'Jekyll::Mephisto.postgres(:database => "#{ENV["DB"]}")')
|
69
|
+
end
|
70
|
+
desc "Migrate from Movable Type in the current directory"
|
71
|
+
task :mt do
|
72
|
+
sh %q(ruby -r './lib/jekyll/converters/mt' -e 'Jekyll::MT.process("#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")')
|
73
|
+
end
|
74
|
+
desc "Migrate from Typo in the current directory"
|
75
|
+
task :typo do
|
76
|
+
sh %q(ruby -r './lib/jekyll/converters/typo' -e 'Jekyll::Typo.process("#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
begin
|
81
|
+
require 'cucumber/rake/task'
|
82
|
+
|
83
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
84
|
+
t.cucumber_opts = "--format pretty"
|
85
|
+
end
|
86
|
+
rescue LoadError
|
87
|
+
desc 'Cucumber rake task not available'
|
88
|
+
task :features do
|
89
|
+
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
|
90
|
+
end
|
91
|
+
end
|
data/VERSION.yml
ADDED
data/bin/jekyll
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
4
|
+
|
5
|
+
help = <<HELP
|
6
|
+
Jekyll is a blog-aware, static site generator.
|
7
|
+
|
8
|
+
Basic Command Line Usage:
|
9
|
+
jekyll # . -> ./_site
|
10
|
+
jekyll <path to write generated site> # . -> <path>
|
11
|
+
jekyll <path to source> <path to write generated site> # <path> -> <path>
|
12
|
+
|
13
|
+
Configuration is read from '<source>/_config.yml' but can be overriden
|
14
|
+
using the following options:
|
15
|
+
|
16
|
+
HELP
|
17
|
+
|
18
|
+
require 'optparse'
|
19
|
+
require 'jekyll'
|
20
|
+
|
21
|
+
exec = {}
|
22
|
+
options = {}
|
23
|
+
opts = OptionParser.new do |opts|
|
24
|
+
opts.banner = help
|
25
|
+
|
26
|
+
opts.on("--auto", "Auto-regenerate") do
|
27
|
+
options['auto'] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("--no-auto", "No auto-regenerate") do
|
31
|
+
options['auto'] = false
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("--server [PORT]", "Start web server (default port 4000)") do |port|
|
35
|
+
options['server'] = true
|
36
|
+
options['server_port'] = port unless port.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("--lsi", "Use LSI for better related posts") do
|
40
|
+
options['lsi'] = true
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("--pygments", "Use pygments to highlight code") do
|
44
|
+
options['pygments'] = true
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("--pygments-cache", "Path to cache pygments output in, for faster re-rendering") do |path|
|
48
|
+
options['pygments_cache'] = path
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("--rdiscount", "Use rdiscount gem for Markdown") do
|
52
|
+
options['markdown'] = 'rdiscount'
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("--permalink [TYPE]", "Use 'date' (default) for YYYY/MM/DD") do |style|
|
56
|
+
options['permalink'] = style unless style.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on("--multiviews", "Don't use .html in links since Apache has 'Options +MultiViews'") do |style|
|
60
|
+
options['multiviews'] = true
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on("--sass", "Use Sass from haml gem for CSS generation") do
|
64
|
+
options['sass'] = true
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on("--haml", "Enable using Haml for posts and pages") do
|
68
|
+
options['haml'] = true
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on("--version", "Display current version") do
|
72
|
+
puts "Jekyll " + Jekyll.version
|
73
|
+
exit 0
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Read command line options into `options` hash
|
78
|
+
opts.parse!
|
79
|
+
|
80
|
+
# Get source and destintation from command line
|
81
|
+
case ARGV.size
|
82
|
+
when 0
|
83
|
+
when 1
|
84
|
+
options['destination'] = ARGV[0]
|
85
|
+
when 2
|
86
|
+
options['source'] = ARGV[0]
|
87
|
+
options['destination'] = ARGV[1]
|
88
|
+
else
|
89
|
+
puts "Invalid options. Run `jekyll --help` for assistance."
|
90
|
+
exit(1)
|
91
|
+
end
|
92
|
+
|
93
|
+
options = Jekyll.configuration(options)
|
94
|
+
|
95
|
+
# Get source and destination directories (possibly set by config file)
|
96
|
+
source = options['source']
|
97
|
+
destination = options['destination']
|
98
|
+
|
99
|
+
# Files to watch
|
100
|
+
def globs(source)
|
101
|
+
Dir.chdir(source) do
|
102
|
+
dirs = Dir['*'].select { |x| File.directory?(x) }
|
103
|
+
dirs -= ['_site']
|
104
|
+
dirs = dirs.map { |x| "#{x}/**/*" }
|
105
|
+
dirs += ['*']
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Create the Site
|
110
|
+
site = Jekyll::Site.new(options)
|
111
|
+
|
112
|
+
# Run the directory watcher for auto-generation, if required
|
113
|
+
if options['auto']
|
114
|
+
require 'directory_watcher'
|
115
|
+
|
116
|
+
puts "Auto-regenerating enabled: #{source} -> #{destination}"
|
117
|
+
|
118
|
+
dw = DirectoryWatcher.new(source)
|
119
|
+
dw.interval = 1
|
120
|
+
dw.glob = globs(source)
|
121
|
+
|
122
|
+
dw.add_observer do |*args|
|
123
|
+
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
124
|
+
puts "[#{t}] regeneration: #{args.size} files changed"
|
125
|
+
site.process
|
126
|
+
end
|
127
|
+
|
128
|
+
dw.start
|
129
|
+
|
130
|
+
unless options['server']
|
131
|
+
loop { sleep 1000 }
|
132
|
+
end
|
133
|
+
else
|
134
|
+
puts "Building site: #{source} -> #{destination}"
|
135
|
+
site.process
|
136
|
+
puts "Successfully generated site: #{source} -> #{destination}"
|
137
|
+
end
|
138
|
+
|
139
|
+
# Run the server on the specified port, if required
|
140
|
+
if options['server']
|
141
|
+
require 'webrick'
|
142
|
+
include WEBrick
|
143
|
+
|
144
|
+
FileUtils.mkdir_p(destination)
|
145
|
+
|
146
|
+
s = HTTPServer.new(
|
147
|
+
:Port => options['server_port'],
|
148
|
+
:DocumentRoot => destination
|
149
|
+
)
|
150
|
+
t = Thread.new {
|
151
|
+
s.start
|
152
|
+
}
|
153
|
+
|
154
|
+
trap("INT") { s.shutdown }
|
155
|
+
t.join()
|
156
|
+
end
|
data/lib/jekyll.rb
ADDED
@@ -0,0 +1,84 @@
|
|
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
|
+
|
17
|
+
# internal requires
|
18
|
+
require 'jekyll/core_ext'
|
19
|
+
require 'jekyll/site'
|
20
|
+
require 'jekyll/convertible'
|
21
|
+
require 'jekyll/layout'
|
22
|
+
require 'jekyll/page'
|
23
|
+
require 'jekyll/post'
|
24
|
+
require 'jekyll/filters'
|
25
|
+
require 'jekyll/tags/highlight'
|
26
|
+
require 'jekyll/tags/include'
|
27
|
+
require 'jekyll/albino'
|
28
|
+
|
29
|
+
module Jekyll
|
30
|
+
# Default options. Overriden by values in _config.yml or command-line opts.
|
31
|
+
# Strings are used instead of symbols for YAML compatibility.
|
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
|
+
'sass' => false,
|
43
|
+
'markdown' => 'maruku',
|
44
|
+
'permalink' => 'date',
|
45
|
+
|
46
|
+
'maruku' => {
|
47
|
+
'use_tex' => false,
|
48
|
+
'use_divs' => false,
|
49
|
+
'png_engine' => 'blahtex',
|
50
|
+
'png_dir' => 'images/latex',
|
51
|
+
'png_url' => '/images/latex'
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
# Generate a Jekyll configuration Hash by merging the default options
|
56
|
+
# with anything in _config.yml, and adding the given options on top
|
57
|
+
# +override+ is a Hash of config directives
|
58
|
+
#
|
59
|
+
# Returns Hash
|
60
|
+
def self.configuration(override)
|
61
|
+
# _config.yml may override default source location, but until
|
62
|
+
# then, we need to know where to look for _config.yml
|
63
|
+
source = override['source'] || Jekyll::DEFAULTS['source']
|
64
|
+
|
65
|
+
# Get configuration from <source>/_config.yml
|
66
|
+
config = {}
|
67
|
+
config_file = File.join(source, '_config.yml')
|
68
|
+
begin
|
69
|
+
config = YAML.load_file(config_file)
|
70
|
+
puts "Configuration from #{config_file}"
|
71
|
+
rescue => err
|
72
|
+
puts "WARNING: Could not read configuration. Using defaults (and options)."
|
73
|
+
puts "\t" + err
|
74
|
+
end
|
75
|
+
|
76
|
+
# Merge DEFAULTS < _config.yml < override
|
77
|
+
Jekyll::DEFAULTS.deep_merge(config).deep_merge(override)
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.version
|
81
|
+
yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
|
82
|
+
"#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
##
|
2
|
+
# Wrapper for the Pygments command line tool, pygmentize.
|
3
|
+
#
|
4
|
+
# Pygments: http://pygments.org/
|
5
|
+
#
|
6
|
+
# Assumes pygmentize is in the path. If not, set its location
|
7
|
+
# with Albino.bin = '/path/to/pygmentize'
|
8
|
+
#
|
9
|
+
# Use like so:
|
10
|
+
#
|
11
|
+
# @syntaxer = Albino.new('/some/file.rb', :ruby)
|
12
|
+
# puts @syntaxer.colorize
|
13
|
+
#
|
14
|
+
# This'll print out an HTMLized, Ruby-highlighted version
|
15
|
+
# of '/some/file.rb'.
|
16
|
+
#
|
17
|
+
# To use another formatter, pass it as the third argument:
|
18
|
+
#
|
19
|
+
# @syntaxer = Albino.new('/some/file.rb', :ruby, :bbcode)
|
20
|
+
# puts @syntaxer.colorize
|
21
|
+
#
|
22
|
+
# You can also use the #colorize class method:
|
23
|
+
#
|
24
|
+
# puts Albino.colorize('/some/file.rb', :ruby)
|
25
|
+
#
|
26
|
+
# Another also: you get a #to_s, for somewhat nicer use in Rails views.
|
27
|
+
#
|
28
|
+
# ... helper file ...
|
29
|
+
# def highlight(text)
|
30
|
+
# Albino.new(text, :ruby)
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# ... view file ...
|
34
|
+
# <%= highlight text %>
|
35
|
+
#
|
36
|
+
# The default lexer is 'text'. You need to specify a lexer yourself;
|
37
|
+
# because we are using STDIN there is no auto-detect.
|
38
|
+
#
|
39
|
+
# To see all lexers and formatters available, run `pygmentize -L`.
|
40
|
+
#
|
41
|
+
# Chris Wanstrath // chris@ozmm.org
|
42
|
+
# GitHub // http://github.com
|
43
|
+
#
|
44
|
+
require 'open4'
|
45
|
+
|
46
|
+
class Albino
|
47
|
+
@@bin = Rails.development? ? 'pygmentize' : '/usr/bin/pygmentize' rescue 'pygmentize'
|
48
|
+
|
49
|
+
def self.bin=(path)
|
50
|
+
@@bin = path
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.colorize(*args)
|
54
|
+
new(*args).colorize
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize(target, lexer = :text, format = :html)
|
58
|
+
@target = File.exists?(target) ? File.read(target) : target rescue target
|
59
|
+
@options = { :l => lexer, :f => format, :O => 'encoding=utf-8' }
|
60
|
+
end
|
61
|
+
|
62
|
+
def execute(command)
|
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
|
71
|
+
end
|
72
|
+
|
73
|
+
def colorize(options = {})
|
74
|
+
html = execute(@@bin + convert_options(options))
|
75
|
+
# Work around an RDiscount bug: http://gist.github.com/97682
|
76
|
+
html.to_s.sub(%r{</pre></div>\Z}, "</pre>\n</div>")
|
77
|
+
end
|
78
|
+
alias_method :to_s, :colorize
|
79
|
+
|
80
|
+
def convert_options(options = {})
|
81
|
+
@options.merge(options).inject('') do |string, (flag, value)|
|
82
|
+
string + " -#{flag} #{value}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
if $0 == __FILE__
|
88
|
+
require 'rubygems'
|
89
|
+
require 'test/spec'
|
90
|
+
require 'mocha'
|
91
|
+
begin require 'redgreen'; rescue LoadError; end
|
92
|
+
|
93
|
+
context "Albino" do
|
94
|
+
setup do
|
95
|
+
@syntaxer = Albino.new(__FILE__, :ruby)
|
96
|
+
end
|
97
|
+
|
98
|
+
specify "defaults to text" do
|
99
|
+
syntaxer = Albino.new(__FILE__)
|
100
|
+
syntaxer.expects(:execute).with('pygmentize -f html -l text').returns(true)
|
101
|
+
syntaxer.colorize
|
102
|
+
end
|
103
|
+
|
104
|
+
specify "accepts options" do
|
105
|
+
@syntaxer.expects(:execute).with('pygmentize -f html -l ruby').returns(true)
|
106
|
+
@syntaxer.colorize
|
107
|
+
end
|
108
|
+
|
109
|
+
specify "works with strings" do
|
110
|
+
syntaxer = Albino.new('class New; end', :ruby)
|
111
|
+
assert_match %r(highlight), syntaxer.colorize
|
112
|
+
end
|
113
|
+
|
114
|
+
specify "aliases to_s" do
|
115
|
+
assert_equal @syntaxer.colorize, @syntaxer.to_s
|
116
|
+
end
|
117
|
+
|
118
|
+
specify "class method colorize" do
|
119
|
+
assert_equal @syntaxer.colorize, Albino.colorize(__FILE__, :ruby)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|