serif 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.each do |post|
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
- f.puts default_layout.render!("site" => self, "page" => { "title" => ["Posts", "#{post.title}"] }, "content" => Liquid::Template.parse(File.read("_templates/post.html")).render!("post" => post))
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "serif"
3
- s.version = "0.2.1"
3
+ s.version = "0.2.2"
4
4
  s.authors = ["Adam Prescott"]
5
5
  s.email = ["adam@aprescott.com"]
6
6
  s.homepage = "https://github.com/aprescott/serif"
@@ -0,0 +1,4 @@
1
+ title: Second post
2
+ Created: 2013-01-01T00:00:00+00:00
3
+
4
+ Second post.
@@ -5,6 +5,12 @@
5
5
 
6
6
 
7
7
 
8
+ <h1>
9
+ <a href="/test-archive/2013/01">January 2013</a>
10
+ </h1>
11
+
12
+
13
+
8
14
  <h1>
9
15
  <a href="/test-archive/2012/12">December 2012</a>
10
16
  </h1>
@@ -0,0 +1,2 @@
1
+ f8390232f0c354a871f9ba0ed306163c
2
+ .f8390232f0c354a871f9ba0ed306163c
@@ -5,10 +5,12 @@
5
5
 
6
6
  <h2>Posts</h2>
7
7
 
8
- <p>There are 2 posts:</p>
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,14 @@
1
+ <!doctype html>
2
+ <meta charset="UTF-8">
3
+ <title>My site: </title>
4
+ <h1>mysite.com</h1>
5
+
6
+ <h1>Jan 2013 (1)</h1>
7
+
8
+ <ul>
9
+
10
+ <li>
11
+ <a href="/test-blog/second-post">Second post</a>
12
+ </li>
13
+
14
+ </ul>
@@ -8,3 +8,6 @@
8
8
  <p>some content</p>
9
9
 
10
10
  <p><a href="http://twitter.com/share?text=Some+draft+title&amp;url=http%3A%2F%2Fwww.mysite.com%2Ftest-blog%2Fpost-to-be-published-on-generate">Submit this to Twitter.</p>
11
+
12
+ Previous post: Sample post
13
+ Next post: Second post
@@ -8,3 +8,6 @@
8
8
  <p>Just a sample post.</p>
9
9
 
10
10
  <p><a href="http://twitter.com/share?text=Sample+post&amp;url=http%3A%2F%2Fwww.mysite.com%2Ftest-blog%2Fsample-post">Submit this to Twitter.</p>
11
+
12
+
13
+ Next post: Some draft title
@@ -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&amp;url=http%3A%2F%2Fwww.mysite.com%2Ftest-blog%2Fsecond-post">Submit this to Twitter.</p>
11
+
12
+ Previous post: Some draft title
@@ -0,0 +1,3 @@
1
+ #foo {
2
+ bar: baz;
3
+ }
@@ -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 }}&amp;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 }}&amp;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 %}
@@ -1,4 +1,4 @@
1
1
  title: Some draft title
2
- Created: 2013-01-30T22:09:58+00:00
2
+ Created: 2013-02-09T23:02:08+00:00
3
3
 
4
4
  some content
@@ -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 = D.new(subject)
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
@@ -13,7 +13,7 @@ describe Serif::Site do
13
13
 
14
14
  describe "#posts" do
15
15
  it "is the number of posts in the site" do
16
- subject.posts.length.should == 1
16
+ subject.posts.length.should == 2
17
17
  end
18
18
  end
19
19
 
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.1
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-05 00:00:00.000000000 Z
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/1359583798-test-draft
266
- - test/site_dir/_trash/1359583798-autopublish-draft
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