Skip to content

Commit 8215274

Browse files
committed
Migrate pages to use includes. Created Sublime project
Sublime: Project == single-page-apps folder Add new build tool to start Jekyll (Tools > Build System > Jekell), and then Meta-B to (re)start Jekyll server.
1 parent 01a9f40 commit 8215274

13 files changed

+7492
-57
lines changed

Rakefile

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

_includes/footer.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!-- ########## _includes/footer.html ########## -->
2+
<div class="footer">
3+
<div>
4+
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/deed.en_US">
5+
<img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by/3.0/80x15.png" />
6+
</a>
7+
<br />
8+
This work by
9+
<a xmlns:cc="http://creativecommons.org/ns#" href="http://csantanapr.github.io/single-page-apps" property="cc:attributionName" rel="cc:attributionURL">http://csantanapr.github.io/single-page-apps/
10+
</a>
11+
is licensed under a
12+
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/deed.en_US">Creative Commons Attribution 3.0 Unported License
13+
</a>.
14+
</div>
15+
<div class="contact">
16+
<p>
17+
Carlos Santana<br />
18+
Open Source Developer<br />
19+
20+
</p>
21+
</div>
22+
<div class="contact">
23+
<p>
24+
<a href="http://github.com/csantanapr/">github.com/csantanapr</a><br />
25+
<a href="http://twitter.com/csantanapr/">twitter.com/csantanapr</a><br />
26+
</p>
27+
</div>
28+
29+
</div> <!-- /footer -->

_includes/header.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- ########## _includes/header.html ########## -->
2+
<div class="header">
3+
<h1 class="title">
4+
<a href="{{ site.baseurl }}/"><i class="icon-home icon-large"></i> {{ site.name }}</a>
5+
</h1>
6+
<a class="extra" href="{{ site.baseurl }}/pages/ideas.html">
7+
<i class="icon-lightbulb"></i>
8+
ideas</a>
9+
</div>

_includes/html_head.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- ########## _includes/head.html ########## -->
2+
<meta charset="utf-8">
3+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
4+
<title>{{ page.title }}</title>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
7+
<!-- Add Bootstrap and Font awesome styles -->
8+
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
9+
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
10+
11+
<!-- syntax highlighting CSS -->
12+
<link rel="stylesheet" href="{{ site.baseurl }}/css/syntax.css">
13+
14+
<!-- Custom CSS -->
15+
<link rel="stylesheet" href="{{ site.baseurl }}/css/main.css">

0 commit comments

Comments
 (0)