Skip to content

Commit 6deb05a

Browse files
committed
Initial import from old notes
0 parents  commit 6deb05a

File tree

108 files changed

+21530
-0
lines changed

Some content is hidden

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

108 files changed

+21530
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_site/
2+
_gh-pages/

Rakefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace :site do
2+
desc "Commit the local site to the gh-pages branch and publish to GitHub Pages"
3+
task :publish do
4+
# Ensure the gh-pages dir exists so we can generate into it.
5+
puts "Checking for gh-pages dir..."
6+
unless File.exist?("./_gh-pages")
7+
puts "No gh-pages directory found. Run the following commands first:"
8+
puts " `git clone [email protected]:mojombo/jekyll gh-pages"
9+
puts " `cd gh-pages"
10+
puts " `git checkout gh-pages`"
11+
exit(1)
12+
end
13+
14+
# Ensure gh-pages branch is up to date.
15+
Dir.chdir('_gh-pages') do
16+
sh "git pull origin gh-pages"
17+
end
18+
19+
# Copy to gh-pages dir.
20+
puts "Removing everything except .gitignore"
21+
Dir.glob("_gh-pages/*") do |path|
22+
next if path == ".gitignore"
23+
sh "rm -rf #{path}"
24+
end
25+
sh "cp -R _site/* _gh-pages"
26+
27+
# Commit and push.
28+
puts "Committing and pushing to GitHub Pages..."
29+
sha = `git log`.match(/[a-z0-9]{40}/)[0]
30+
Dir.chdir('_gh-pages') do
31+
sh "git add ."
32+
sh "git add -u"
33+
sh "git commit -m 'Updating to #{sha}.'"
34+
sh "git push origin gh-pages"
35+
end
36+
puts 'Done.'
37+
end
38+
end

_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: Learn to Code
2+
pygments: true

_includes/exercise.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="exercise">
2+
{{ exercise }}
3+
</div>

_layouts/default.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6+
<title>{{ page.title }}</title>
7+
<meta name="viewport" content="width=device-width">
8+
<!-- Twitter bootstrap basic styles -->
9+
<link rel="stylesheet" href="/bootstrap/css/bootstrap.css">
10+
<link rel="stylesheet" href="/bootstrap/css/bootstrap-responsive.css">
11+
12+
<!-- syntax highlighting CSS -->
13+
<link rel="stylesheet" href="/css/syntax.css">
14+
<!-- Google webfont link -->
15+
<link href='http://fonts.googleapis.com/css?family=Arvo:700|Titillium+Web:900' rel='stylesheet' type='text/css'>
16+
17+
18+
<!-- Custom CSS -->
19+
<link rel="stylesheet" href="/css/main.css">
20+
21+
<script src="/assets/jquery-1.10.0.js"></script>
22+
23+
<script type="text/javascript" src='/bootstrap/js/bootstrap.js'></script>
24+
<script type="text/javascript" src='/assets/custom.js'></script>
25+
26+
</head>
27+
<body class="{{ page.cssclass }}">
28+
29+
<div class="container">
30+
31+
{{ content }}
32+
33+
34+
</div> <!-- /container -->
35+
36+
</body>
37+
</html>

_layouts/post.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
layout: default
3+
---
4+
<h2>{{ page.title }}</h2>
5+
<p class="meta">{{ page.date | date_to_string }}</p>
6+
7+
<div id="post">
8+
{{ content }}
9+
</div>

_layouts/session.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
layout: default
3+
---
4+
5+
<div class="page-header">
6+
<h1>{{page.title }} <small>{{ page.strapline}}</small></h1>
7+
</div>
8+
9+
<div class="tabbable tabs-left">
10+
<ul class="nav nav-tabs" id="myTab">
11+
{% for task in page.tasks %}
12+
{% if forloop.first %}
13+
<li class="active"><a href="#{{ task.name }}" data-toggle="tab">{{ task.title }} </a></li>
14+
{% else %}
15+
<li><a href="#{{ task.name }}" data-toggle="tab">{{ task.title }} </a></li>
16+
{% endif %}
17+
{% endfor %}
18+
</ul>
19+
20+
<div class="tab-content">
21+
{% for task in page.tasks %}
22+
{% if forloop.first %}
23+
<div class="tab-pane active" id="{{ task.name }}">
24+
{% else %}
25+
<div class="tab-pane " id="{{ task.name }}">
26+
{% endif %}
27+
28+
<h2>{{ task.title }}</h2>
29+
{{ task.output }}
30+
</div>
31+
{% endfor %}
32+
</div>
33+
34+
</div>
35+

_layouts/task.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: none
3+
---
4+
5+
{{content}}

_plugins/highlight_in_list.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Jekyll
2+
module Tags
3+
class HighlightBlock < Liquid::Block
4+
alias_method :old_render, :render
5+
6+
def render(context)
7+
output = old_render(context)
8+
if @options['inlist']
9+
output.lines.map {|l| " "*8 + l }
10+
else
11+
output
12+
end
13+
end
14+
end
15+
end
16+
end

_plugins/sessions.rb

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
module Jekyll
2+
3+
class SessionPage < Page
4+
def initialize(site, base, dir)
5+
@site = site
6+
@base = base
7+
@dir = dir
8+
@name = 'index.html'
9+
10+
self.process(@name)
11+
self.read_yaml(File.join(base, '_layouts'), 'session.html')
12+
self.data['tasks'] = get_tasks
13+
# load other options
14+
if File.exists?(File.join(base, '_sessions', dir, 'info.yml'))
15+
self.data.merge!(YAML.load_file(File.join(base, '_sessions', dir, 'info.yml')))
16+
end
17+
18+
self.data['title'] ||= dir
19+
end
20+
21+
def get_tasks
22+
Dir.entries(File.join(@base, '_sessions', @dir)).reject{|x| %w{. .. info.yml}.include?(x)}.reject{|x| x[0]=='_'}.sort.map do |n|
23+
t = TaskPage.new(@site, @base, @dir, n)
24+
#t.render
25+
t
26+
end
27+
end
28+
def render(*args)
29+
self.data['tasks'].each {|t| t.data['output'] = t.tap {|t| t.render(*args)}.output }
30+
super
31+
end
32+
33+
end
34+
35+
class SessionPageGenerator < Generator
36+
safe true
37+
38+
def generate(site)
39+
# if we have a session template
40+
if site.layouts.key? 'session'
41+
# put in top level directory
42+
if Dir.exists?('_sessions')
43+
subdirs = Dir.entries('_sessions').reject{|x| %w{. ..}.include?(x)}
44+
subdirs.each do |dir_name|
45+
46+
site.pages << SessionPage.new(site, site.source, dir_name)
47+
end
48+
end
49+
end
50+
end
51+
end
52+
53+
# In some ways I want a TaskPage. In others I don't.
54+
# I definitely want something to read in individual task files and render them.
55+
# But in a way more akin to a blog page summary than individual pages
56+
57+
# Plan: make TaskPages. Don't have a TaskPage generator. Attach TaskPages to relevant SessionPage.
58+
# Render them using TaskPage.content ?? Or does the content get passed in in a different way.
59+
# You don't call post.content ... :( ... Actually it's ok. Content does seem to be passed to liquid.
60+
# When does it get put into the template though? https://github.com/mojombo/jekyll/blob/master/lib/jekyll/site.rb#L225
61+
# But that just calls page.render: https://github.com/mojombo/jekyll/blob/master/lib/jekyll/page.rb#L105
62+
# But that just goes here: https://github.com/mojombo/jekyll/blob/master/lib/jekyll/convertible.rb#L90
63+
# The only bit I don't want is Convertible.write https://github.com/mojombo/jekyll/blob/master/lib/jekyll/convertible.rb#L141
64+
# Which is called for pages, posts etc. here: https://github.com/mojombo/jekyll/blob/master/lib/jekyll/site.rb#L292
65+
# So what I really want it to do is allow it to render, but not be placed in the list of pages.
66+
# But then that has to be done manually anyway, so we're fine!
67+
68+
# This doesn't seem to work. I have problems rendering the TaskPages at the right time.
69+
# Maybe I should merge the TaskPages into the SessionPage's payload
70+
# Actually I didn't have to do this. The above worked.
71+
72+
class TaskPage < Page
73+
def initialize(site, base, dir, name)
74+
@site = site
75+
@base = base
76+
@dir = dir
77+
@name = name # won't be used
78+
79+
self.process(@name) # separates into @basename and @ext
80+
self.read_yaml(File.join(base,'_sessions', dir), name)
81+
82+
self.data['name'] = @basename
83+
84+
# self.data['title'] = "#{category_title_prefix}#{category}" # should have title already
85+
end
86+
end
87+
88+
89+
90+
class ExerciseTag < Liquid::Block
91+
# somehow access converter
92+
93+
def render(context)
94+
# content = super
95+
# parsed_content = Liquid::Template.parse(content)
96+
# output = context.stack do
97+
# parsed_content.render(context)
98+
# end
99+
# how do I convert this thing???
100+
"<div class='exercise alert alert-info' markdown='1'><strong>Task:</strong> " + super + "</div>"
101+
end
102+
end
103+
104+
105+
end
106+
107+
Liquid::Template.register_tag('exercise', Jekyll::ExerciseTag)

0 commit comments

Comments
 (0)