Skip to content

Commit ab09fa4

Browse files
committed
Add Gemfile, Rakefile and Rackup file for local dev
1 parent cd4b90a commit ab09fa4

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source :rubygems
2+
3+
gem "jekyll"
4+
gem "rack"
5+
gem "jruby-openssl", :platform => "jruby"

Gemfile.lock

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
albino (1.3.3)
5+
posix-spawn (>= 0.3.6)
6+
bouncy-castle-java (1.5.0146.1)
7+
classifier (1.3.3)
8+
fast-stemmer (>= 1.0.0)
9+
directory_watcher (1.4.1)
10+
fast-stemmer (1.0.0)
11+
jekyll (0.11.0)
12+
albino (>= 1.3.2)
13+
classifier (>= 1.3.1)
14+
directory_watcher (>= 1.1.1)
15+
kramdown (>= 0.13.2)
16+
liquid (>= 1.9.0)
17+
maruku (>= 0.5.9)
18+
jruby-openssl (0.7.4)
19+
bouncy-castle-java
20+
kramdown (0.13.3)
21+
liquid (2.2.2)
22+
maruku (0.6.0)
23+
syntax (>= 1.0.0)
24+
posix-spawn (0.3.6)
25+
rack (1.3.2)
26+
syntax (1.0.0)
27+
28+
PLATFORMS
29+
java
30+
ruby
31+
32+
DEPENDENCIES
33+
jekyll
34+
jruby-openssl
35+
rack

Rakefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
begin
2+
require 'bundler/setup'
3+
rescue LoadError
4+
puts "Please install Bundler and run 'bundle install' to ensure you have all dependencies"
5+
end
6+
7+
desc "Clean the site"
8+
task :clean do
9+
rm_rf "_site"
10+
end
11+
12+
desc "Generate the site using Jekyll"
13+
task :generate => :check_pygments do
14+
ruby "-S bundle exec jekyll"
15+
end
16+
task :gen => :generate
17+
task :default => :generate
18+
19+
desc "Run a file server that serves and regenerates the files"
20+
task :server do
21+
ruby "-S bundle exec rackup"
22+
end
23+
24+
task :check_pygments do
25+
`pygmentize -V`
26+
$?.success? or raise "Pygments not installed, see http://pygments.org/docs/installation/"
27+
end

config.ru

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# -*- ruby -*-
2+
#
3+
# This rackup file runs the equivalent of jekyll --server --auto, but
4+
# uses Rack to add a couple of rewrite rules to make it equivalent to the
5+
# Apache configuration.
6+
7+
### This section copied from bin/jekyll file
8+
require 'jekyll'
9+
10+
options = Jekyll.configuration({})
11+
source = options['source']
12+
destination = options['destination']
13+
14+
# Files to watch
15+
def globs(source)
16+
Dir.chdir(source) do
17+
dirs = Dir['*'].select { |x| File.directory?(x) }
18+
dirs -= ['_site']
19+
dirs = dirs.map { |x| "#{x}/**/*" }
20+
dirs += ['*']
21+
end
22+
end
23+
24+
# Create the Site
25+
site = Jekyll::Site.new(options)
26+
27+
# Watch for updates
28+
require 'directory_watcher'
29+
30+
puts "Auto-regenerating enabled: #{source} -> #{destination}"
31+
32+
dw = DirectoryWatcher.new(source)
33+
dw.interval = 1
34+
dw.glob = globs(source)
35+
36+
dw.add_observer do |*args|
37+
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
38+
puts "[#{t}] regeneration: #{args.size} files changed"
39+
site.process
40+
end
41+
42+
dw.start
43+
44+
### Rackup server stuff starts here
45+
46+
# Emulate the following Apache config:
47+
# * / => /index.html
48+
# * RewriteRule ([^.]+)$ $1.html
49+
# * ErrorDocument 404 /404.html
50+
class DotHtmlRewriter
51+
def initialize(app, fourohfour)
52+
@app = app
53+
@fourohfour = fourohfour
54+
end
55+
56+
def call(env)
57+
env["PATH_INFO"] += "index.html" if env["PATH_INFO"] =~ /\/$/
58+
result = @app.call(env)
59+
if result[0] == 404 && env["PATH_INFO"] !~ /\.html$/
60+
env["PATH_INFO"] += ".html"
61+
second_result = @app.call(env)
62+
if second_result[0] != 404
63+
result = second_result
64+
else
65+
result[2] = [File.read(@fourohfour)]
66+
result[1]["Content-Type"] = "text/html"
67+
result[1]["Content-Length"] = result[2][0].length.to_s
68+
end
69+
end
70+
result
71+
end
72+
end
73+
74+
puts "Server running on http://localhost:9292"
75+
use DotHtmlRewriter, "#{destination}/404.html"
76+
run Rack::File.new(destination)

0 commit comments

Comments
 (0)