Skip to content

Commit dff1f4f

Browse files
committed
Merge pull request #4 from sigint-ctf/bootstrap
Jekyll Bootstrap version of the website
2 parents c996779 + b5f1aa1 commit dff1f4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2128
-960
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
_site/*
2+
_theme_packages/*
3+
4+
Thumbs.db
5+
.DS_Store
6+
7+
!.gitkeep
8+
9+
.rbenv-version
10+
.rvmrc
11+
*.swp

404.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sorry this page does not exist =(

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Jekyll-Bootstrap
2+
3+
The quickest way to start and publish your Jekyll powered blog. 100% compatible with GitHub pages
4+
5+
## Usage
6+
7+
For all usage and documentation please see: <http://jekyllbootstrap.com>
8+
9+
## Version
10+
11+
0.3.0 - stable and versioned using [semantic versioning](http://semver.org/).
12+
13+
**NOTE:** 0.3.0 introduces a new theme which is not backwards compatible in the sense it won't _look_ like the old version.
14+
However, the actual API has not changed at all.
15+
You might want to run 0.3.0 in a branch to make sure you are ok with the theme design changes.
16+
17+
## Contributing
18+
19+
20+
To contribute to the framework please make sure to checkout your branch based on `jb-development`!!
21+
This is very important as it allows me to accept your pull request without having to publish a public version release.
22+
23+
Small, atomic Features, bugs, etc.
24+
Use the `jb-development` branch but note it will likely change fast as pull requests are accepted.
25+
Please rebase as often as possible when working.
26+
Work on small, atomic features/bugs to avoid upstream commits affecting/breaking your development work.
27+
28+
For Big Features or major API extensions/edits:
29+
This is the one case where I'll accept pull-requests based off the master branch.
30+
This allows you to work in isolation but it means I'll have to manually merge your work into the next public release.
31+
Translation : it might take a bit longer so please be patient! (but sincerely thank you).
32+
33+
**Jekyll-Bootstrap Documentation Website.**
34+
35+
The documentation website at <http://jekyllbootstrap.com> is maintained at https://github.com/plusjade/jekyllbootstrap.com
36+
37+
38+
## License
39+
40+
[MIT](http://opensource.org/licenses/MIT)

Rakefile

+311
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
require "rubygems"
2+
require 'rake'
3+
require 'yaml'
4+
require 'time'
5+
6+
SOURCE = "."
7+
CONFIG = {
8+
'version' => "0.3.0",
9+
'themes' => File.join(SOURCE, "_includes", "themes"),
10+
'layouts' => File.join(SOURCE, "_layouts"),
11+
'posts' => File.join(SOURCE, "_posts"),
12+
'post_ext' => "md",
13+
'theme_package_version' => "0.1.0"
14+
}
15+
16+
# Path configuration helper
17+
module JB
18+
class Path
19+
SOURCE = "."
20+
Paths = {
21+
:layouts => "_layouts",
22+
:themes => "_includes/themes",
23+
:theme_assets => "assets/themes",
24+
:theme_packages => "_theme_packages",
25+
:posts => "_posts"
26+
}
27+
28+
def self.base
29+
SOURCE
30+
end
31+
32+
# build a path relative to configured path settings.
33+
def self.build(path, opts = {})
34+
opts[:root] ||= SOURCE
35+
path = "#{opts[:root]}/#{Paths[path.to_sym]}/#{opts[:node]}".split("/")
36+
path.compact!
37+
File.__send__ :join, path
38+
end
39+
40+
end #Path
41+
end #JB
42+
43+
# Usage: rake post title="A Title" [date="2012-02-09"] [tags=[tag1,tag2]] [category="category"]
44+
desc "Begin a new post in #{CONFIG['posts']}"
45+
task :post do
46+
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
47+
title = ENV["title"] || "new-post"
48+
tags = ENV["tags"] || "[]"
49+
category = ENV["category"] || ""
50+
category = "\"#{category.gsub(/-/,' ')}\"" if !category.empty?
51+
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
52+
begin
53+
date = (ENV['date'] ? Time.parse(ENV['date']) : Time.now).strftime('%Y-%m-%d')
54+
rescue => e
55+
puts "Error - date format must be YYYY-MM-DD, please check you typed it correctly!"
56+
exit -1
57+
end
58+
filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}")
59+
if File.exist?(filename)
60+
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
61+
end
62+
63+
puts "Creating new post: #{filename}"
64+
open(filename, 'w') do |post|
65+
post.puts "---"
66+
post.puts "layout: post"
67+
post.puts "title: \"#{title.gsub(/-/,' ')}\""
68+
post.puts 'description: ""'
69+
post.puts "category: #{category}"
70+
post.puts "tags: #{tags}"
71+
post.puts "---"
72+
post.puts "{% include JB/setup %}"
73+
end
74+
end # task :post
75+
76+
# Usage: rake page name="about.html"
77+
# You can also specify a sub-directory path.
78+
# If you don't specify a file extention we create an index.html at the path specified
79+
desc "Create a new page."
80+
task :page do
81+
name = ENV["name"] || "new-page.md"
82+
filename = File.join(SOURCE, "#{name}")
83+
filename = File.join(filename, "index.html") if File.extname(filename) == ""
84+
title = File.basename(filename, File.extname(filename)).gsub(/[\W\_]/, " ").gsub(/\b\w/){$&.upcase}
85+
if File.exist?(filename)
86+
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
87+
end
88+
89+
mkdir_p File.dirname(filename)
90+
puts "Creating new page: #{filename}"
91+
open(filename, 'w') do |post|
92+
post.puts "---"
93+
post.puts "layout: page"
94+
post.puts "title: \"#{title}\""
95+
post.puts 'description: ""'
96+
post.puts "---"
97+
post.puts "{% include JB/setup %}"
98+
end
99+
end # task :page
100+
101+
desc "Launch preview environment"
102+
task :preview do
103+
system "jekyll serve -w"
104+
end # task :preview
105+
106+
# Public: Alias - Maintains backwards compatability for theme switching.
107+
task :switch_theme => "theme:switch"
108+
109+
namespace :theme do
110+
111+
# Public: Switch from one theme to another for your blog.
112+
#
113+
# name - String, Required. name of the theme you want to switch to.
114+
# The theme must be installed into your JB framework.
115+
#
116+
# Examples
117+
#
118+
# rake theme:switch name="the-program"
119+
#
120+
# Returns Success/failure messages.
121+
desc "Switch between Jekyll-bootstrap themes."
122+
task :switch do
123+
theme_name = ENV["name"].to_s
124+
theme_path = File.join(CONFIG['themes'], theme_name)
125+
settings_file = File.join(theme_path, "settings.yml")
126+
non_layout_files = ["settings.yml"]
127+
128+
abort("rake aborted: name cannot be blank") if theme_name.empty?
129+
abort("rake aborted: '#{theme_path}' directory not found.") unless FileTest.directory?(theme_path)
130+
abort("rake aborted: '#{CONFIG['layouts']}' directory not found.") unless FileTest.directory?(CONFIG['layouts'])
131+
132+
Dir.glob("#{theme_path}/*") do |filename|
133+
next if non_layout_files.include?(File.basename(filename).downcase)
134+
puts "Generating '#{theme_name}' layout: #{File.basename(filename)}"
135+
136+
open(File.join(CONFIG['layouts'], File.basename(filename)), 'w') do |page|
137+
if File.basename(filename, ".html").downcase == "default"
138+
page.puts "---"
139+
page.puts File.read(settings_file) if File.exist?(settings_file)
140+
page.puts "---"
141+
else
142+
page.puts "---"
143+
page.puts "layout: default"
144+
page.puts "---"
145+
end
146+
page.puts "{% include JB/setup %}"
147+
page.puts "{% include themes/#{theme_name}/#{File.basename(filename)} %}"
148+
end
149+
end
150+
151+
puts "=> Theme successfully switched!"
152+
puts "=> Reload your web-page to check it out =)"
153+
end # task :switch
154+
155+
# Public: Install a theme using the theme packager.
156+
# Version 0.1.0 simple 1:1 file matching.
157+
#
158+
# git - String, Optional path to the git repository of the theme to be installed.
159+
# name - String, Optional name of the theme you want to install.
160+
# Passing name requires that the theme package already exist.
161+
#
162+
# Examples
163+
#
164+
# rake theme:install git="https://github.com/jekyllbootstrap/theme-twitter.git"
165+
# rake theme:install name="cool-theme"
166+
#
167+
# Returns Success/failure messages.
168+
desc "Install theme"
169+
task :install do
170+
if ENV["git"]
171+
manifest = theme_from_git_url(ENV["git"])
172+
name = manifest["name"]
173+
else
174+
name = ENV["name"].to_s.downcase
175+
end
176+
177+
packaged_theme_path = JB::Path.build(:theme_packages, :node => name)
178+
179+
abort("rake aborted!
180+
=> ERROR: 'name' cannot be blank") if name.empty?
181+
abort("rake aborted!
182+
=> ERROR: '#{packaged_theme_path}' directory not found.
183+
=> Installable themes can be added via git. You can find some here: http://github.com/jekyllbootstrap
184+
=> To download+install run: `rake theme:install git='[PUBLIC-CLONE-URL]'`
185+
=> example : rake theme:install git='[email protected]:jekyllbootstrap/theme-the-program.git'
186+
") unless FileTest.directory?(packaged_theme_path)
187+
188+
manifest = verify_manifest(packaged_theme_path)
189+
190+
# Get relative paths to packaged theme files
191+
# Exclude directories as they'll be recursively created. Exclude meta-data files.
192+
packaged_theme_files = []
193+
FileUtils.cd(packaged_theme_path) {
194+
Dir.glob("**/*.*") { |f|
195+
next if ( FileTest.directory?(f) || f =~ /^(manifest|readme|packager)/i )
196+
packaged_theme_files << f
197+
}
198+
}
199+
200+
# Mirror each file into the framework making sure to prompt if already exists.
201+
packaged_theme_files.each do |filename|
202+
file_install_path = File.join(JB::Path.base, filename)
203+
if File.exist? file_install_path and ask("#{file_install_path} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
204+
next
205+
else
206+
mkdir_p File.dirname(file_install_path)
207+
cp_r File.join(packaged_theme_path, filename), file_install_path
208+
end
209+
end
210+
211+
puts "=> #{name} theme has been installed!"
212+
puts "=> ---"
213+
if ask("=> Want to switch themes now?", ['y', 'n']) == 'y'
214+
system("rake switch_theme name='#{name}'")
215+
end
216+
end
217+
218+
# Public: Package a theme using the theme packager.
219+
# The theme must be structured using valid JB API.
220+
# In other words packaging is essentially the reverse of installing.
221+
#
222+
# name - String, Required name of the theme you want to package.
223+
#
224+
# Examples
225+
#
226+
# rake theme:package name="twitter"
227+
#
228+
# Returns Success/failure messages.
229+
desc "Package theme"
230+
task :package do
231+
name = ENV["name"].to_s.downcase
232+
theme_path = JB::Path.build(:themes, :node => name)
233+
asset_path = JB::Path.build(:theme_assets, :node => name)
234+
235+
abort("rake aborted: name cannot be blank") if name.empty?
236+
abort("rake aborted: '#{theme_path}' directory not found.") unless FileTest.directory?(theme_path)
237+
abort("rake aborted: '#{asset_path}' directory not found.") unless FileTest.directory?(asset_path)
238+
239+
## Mirror theme's template directory (_includes)
240+
packaged_theme_path = JB::Path.build(:themes, :root => JB::Path.build(:theme_packages, :node => name))
241+
mkdir_p packaged_theme_path
242+
cp_r theme_path, packaged_theme_path
243+
244+
## Mirror theme's asset directory
245+
packaged_theme_assets_path = JB::Path.build(:theme_assets, :root => JB::Path.build(:theme_packages, :node => name))
246+
mkdir_p packaged_theme_assets_path
247+
cp_r asset_path, packaged_theme_assets_path
248+
249+
## Log packager version
250+
packager = {"packager" => {"version" => CONFIG["theme_package_version"].to_s } }
251+
open(JB::Path.build(:theme_packages, :node => "#{name}/packager.yml"), "w") do |page|
252+
page.puts packager.to_yaml
253+
end
254+
255+
puts "=> '#{name}' theme is packaged and available at: #{JB::Path.build(:theme_packages, :node => name)}"
256+
end
257+
258+
end # end namespace :theme
259+
260+
# Internal: Download and process a theme from a git url.
261+
# Notice we don't know the name of the theme until we look it up in the manifest.
262+
# So we'll have to change the folder name once we get the name.
263+
#
264+
# url - String, Required url to git repository.
265+
#
266+
# Returns theme manifest hash
267+
def theme_from_git_url(url)
268+
tmp_path = JB::Path.build(:theme_packages, :node => "_tmp")
269+
abort("rake aborted: system call to git clone failed") if !system("git clone #{url} #{tmp_path}")
270+
manifest = verify_manifest(tmp_path)
271+
new_path = JB::Path.build(:theme_packages, :node => manifest["name"])
272+
if File.exist?(new_path) && ask("=> #{new_path} theme package already exists. Override?", ['y', 'n']) == 'n'
273+
remove_dir(tmp_path)
274+
abort("rake aborted: '#{manifest["name"]}' already exists as theme package.")
275+
end
276+
277+
remove_dir(new_path) if File.exist?(new_path)
278+
mv(tmp_path, new_path)
279+
manifest
280+
end
281+
282+
# Internal: Process theme package manifest file.
283+
#
284+
# theme_path - String, Required. File path to theme package.
285+
#
286+
# Returns theme manifest hash
287+
def verify_manifest(theme_path)
288+
manifest_path = File.join(theme_path, "manifest.yml")
289+
manifest_file = File.open( manifest_path )
290+
abort("rake aborted: repo must contain valid manifest.yml") unless File.exist? manifest_file
291+
manifest = YAML.load( manifest_file )
292+
manifest_file.close
293+
manifest
294+
end
295+
296+
def ask(message, valid_options)
297+
if valid_options
298+
answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
299+
else
300+
answer = get_stdin(message)
301+
end
302+
answer
303+
end
304+
305+
def get_stdin(message)
306+
print message
307+
STDIN.gets.chomp
308+
end
309+
310+
#Load custom rake scripts
311+
Dir['_rake/*.rake'].each { |r| load r }

0 commit comments

Comments
 (0)