serif 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/lib/serif/site.rb +20 -2
- data/serif.gemspec +1 -1
- data/test/site_dir/_posts/2013-01-01-second-post +4 -0
- data/test/site_dir/_site/archive.html +6 -0
- data/test/site_dir/_site/file-digest-test.html +2 -0
- data/test/site_dir/_site/index.html +3 -1
- data/test/site_dir/_site/test-archive/2013/01/index.html +14 -0
- data/test/site_dir/_site/test-blog/post-to-be-published-on-generate.html +3 -0
- data/test/site_dir/_site/test-blog/sample-post.html +3 -0
- data/test/site_dir/_site/test-blog/second-post.html +12 -0
- data/test/site_dir/_site/test-stylesheet.css +3 -0
- data/test/site_dir/_templates/post.html +4 -1
- data/test/site_dir/_trash/{1359583798-autopublish-draft → 1360450928-autopublish-draft} +1 -1
- data/test/site_dir/_trash/{1359583798-test-draft → 1360450928-test-draft} +0 -0
- data/test/site_generation_spec.rb +21 -1
- data/test/site_spec.rb +1 -1
- metadata +9 -4
data/README.md
CHANGED
@@ -20,6 +20,7 @@ See `CHANGELOG` for what's new.
|
|
20
20
|
* [Deploying](#deploying)
|
21
21
|
* [Customising the admin interface](#customising-the-admin-interface)
|
22
22
|
* [Custom tags](#custom-tags)
|
23
|
+
* [Template variables](#template-variables)
|
23
24
|
|
24
25
|
# Intro
|
25
26
|
|
@@ -374,3 +375,15 @@ These tags can be used in templates. For example:
|
|
374
375
|
Computes a hex digest of the contents of `<path>`, optionally prefixed with `<prefix>`. `<path>` is delimited by whitespace.
|
375
376
|
|
376
377
|
Useful for URL fingerprinting for long-lived caching.
|
378
|
+
|
379
|
+
# Template variables
|
380
|
+
|
381
|
+
In addition to those mentioned above, such as the archive page variables, there are others. *This is not exhaustive.*
|
382
|
+
|
383
|
+
## Post template variables
|
384
|
+
|
385
|
+
These are available on individual post pages.
|
386
|
+
|
387
|
+
* `{{ post }}` --- the post being processed. Allows access to variables like `post.url`, `post.title`, `post.slug`, `post.created` and `post.content`.
|
388
|
+
* `{{ prev_post }}` --- the post published chronologically before `post`.
|
389
|
+
* `{{ next_post }}` --- the post published chronologically after `post`.
|
data/lib/serif/site.rb
CHANGED
@@ -268,14 +268,32 @@ class Site
|
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
271
|
-
posts
|
271
|
+
# the posts are iterated over in reverse chrological order
|
272
|
+
next_post = nil
|
273
|
+
|
274
|
+
# run through the posts + nil so we can keep |a, b| such that a hits every element
|
275
|
+
# while iterating.
|
276
|
+
[*posts, nil].each_cons(2) do |post, prev_post|
|
272
277
|
puts "Processing post: #{post.path}"
|
273
278
|
|
274
279
|
FileUtils.mkdir_p(tmp_path(File.dirname(post.url)))
|
275
280
|
|
276
281
|
File.open(tmp_path(post.url + ".html"), "w") do |f|
|
277
|
-
|
282
|
+
# variables available in the post template
|
283
|
+
post_template_variables = {
|
284
|
+
"post" => post,
|
285
|
+
"prev_post" => prev_post,
|
286
|
+
"next_post" => next_post
|
287
|
+
}
|
288
|
+
|
289
|
+
f.puts default_layout.render!(
|
290
|
+
"site" => self,
|
291
|
+
"page" => { "title" => ["Posts", "#{post.title}"] },
|
292
|
+
"content" => Liquid::Template.parse(File.read("_templates/post.html")).render!(post_template_variables)
|
293
|
+
)
|
278
294
|
end
|
295
|
+
|
296
|
+
next_post = post
|
279
297
|
end
|
280
298
|
|
281
299
|
generate_archives(default_layout)
|
data/serif.gemspec
CHANGED
@@ -5,10 +5,12 @@
|
|
5
5
|
|
6
6
|
<h2>Posts</h2>
|
7
7
|
|
8
|
-
<p>There are
|
8
|
+
<p>There are 3 posts:</p>
|
9
9
|
|
10
10
|
<ul>
|
11
11
|
|
12
|
+
<li><a href="/test-blog/second-post">Second post</a> (posted 2013-01-01T00:00:00+00:00)</li>
|
13
|
+
|
12
14
|
<li><a href="/test-blog/post-to-be-published-on-generate">Some draft title</a> (posted 2012-12-21T15:30:00+00:00)</li>
|
13
15
|
|
14
16
|
<li><a href="/test-blog/sample-post">Sample post</a> (posted 2012-11-21T17:07:09+00:00)</li>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<meta charset="UTF-8">
|
3
|
+
<title>My site: Posts - Second post</title>
|
4
|
+
<h1>mysite.com</h1>
|
5
|
+
|
6
|
+
<h2>Second post</h2>
|
7
|
+
|
8
|
+
<p>Second post.</p>
|
9
|
+
|
10
|
+
<p><a href="http://twitter.com/share?text=Second+post&url=http%3A%2F%2Fwww.mysite.com%2Ftest-blog%2Fsecond-post">Submit this to Twitter.</p>
|
11
|
+
|
12
|
+
Previous post: Some draft title
|
@@ -2,4 +2,7 @@
|
|
2
2
|
|
3
3
|
{{ post.content | markdown }}
|
4
4
|
|
5
|
-
<p><a href="http://twitter.com/share?text={{ post.title | encode_uri_component }}&url={{ 'http://www.mysite.com' | encode_uri_component }}{{ post.url | encode_uri_component }}">Submit this to Twitter.</p>
|
5
|
+
<p><a href="http://twitter.com/share?text={{ post.title | encode_uri_component }}&url={{ 'http://www.mysite.com' | encode_uri_component }}{{ post.url | encode_uri_component }}">Submit this to Twitter.</p>
|
6
|
+
|
7
|
+
{% if prev_post %}Previous post: {{ prev_post.title }}{% endif %}
|
8
|
+
{% if next_post %}Next post: {{ next_post.title }}{% endif %}
|
File without changes
|
@@ -29,11 +29,31 @@ describe Serif::Site do
|
|
29
29
|
File.read("_site/file-digest-test.html").strip.should == "f8390232f0c354a871f9ba0ed306163c\n.f8390232f0c354a871f9ba0ed306163c"
|
30
30
|
end
|
31
31
|
|
32
|
+
it "makes the previous and next posts available" do
|
33
|
+
subject.generate
|
34
|
+
|
35
|
+
contents = File.read("_site/test-blog/sample-post.html")
|
36
|
+
previous_title = contents[/^Previous post: .+?$/]
|
37
|
+
next_title = contents[/^Next post: .+?$/]
|
38
|
+
|
39
|
+
previous_title.should be_nil
|
40
|
+
next_title.should_not be_nil
|
41
|
+
next_title[/(?<=: ).+/].should == "Second post"
|
42
|
+
|
43
|
+
contents = File.read("_site/test-blog/second-post.html")
|
44
|
+
previous_title = contents[/Previous post: .+?$/]
|
45
|
+
next_title = contents[/Next post: .+?$/]
|
46
|
+
|
47
|
+
previous_title.should_not be_nil
|
48
|
+
next_title.should be_nil
|
49
|
+
previous_title[/(?<=: ).+/].should == "Sample post"
|
50
|
+
end
|
51
|
+
|
32
52
|
context "for drafts with a publish: now header" do
|
33
53
|
before :all do
|
34
54
|
@time = Time.utc(2012, 12, 21, 15, 30, 00)
|
35
55
|
|
36
|
-
draft =
|
56
|
+
draft = Serif::Draft.new(subject)
|
37
57
|
draft.slug = "post-to-be-published-on-generate"
|
38
58
|
draft.title = "Some draft title"
|
39
59
|
draft.autopublish = true
|
data/test/site_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -254,17 +254,22 @@ files:
|
|
254
254
|
- test/site_dir/page-header-but-no-layout.html
|
255
255
|
- test/site_dir/test-stylesheet.css
|
256
256
|
- test/site_dir/_config.yml
|
257
|
+
- test/site_dir/_site/test-archive/2013/01/index.html
|
257
258
|
- test/site_dir/_site/test-archive/2012/12/index.html
|
258
259
|
- test/site_dir/_site/test-archive/2012/11/index.html
|
259
260
|
- test/site_dir/_site/index.html
|
261
|
+
- test/site_dir/_site/file-digest-test.html
|
260
262
|
- test/site_dir/_site/page-alt-layout.html
|
261
263
|
- test/site_dir/_site/page-header-but-no-layout.html
|
264
|
+
- test/site_dir/_site/test-stylesheet.css
|
262
265
|
- test/site_dir/_site/test-blog/post-to-be-published-on-generate.html
|
266
|
+
- test/site_dir/_site/test-blog/second-post.html
|
263
267
|
- test/site_dir/_site/test-blog/sample-post.html
|
264
268
|
- test/site_dir/_site/archive.html
|
265
|
-
- test/site_dir/_trash/
|
266
|
-
- test/site_dir/_trash/
|
269
|
+
- test/site_dir/_trash/1360450928-autopublish-draft
|
270
|
+
- test/site_dir/_trash/1360450928-test-draft
|
267
271
|
- test/site_dir/_posts/2012-01-05-sample-post
|
272
|
+
- test/site_dir/_posts/2013-01-01-second-post
|
268
273
|
- test/site_dir/_layouts/alt-layout.html
|
269
274
|
- test/site_dir/_layouts/default.html
|
270
275
|
- test/site_dir/archive.html
|