serif 0.3 → 0.3.1

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.
@@ -30,7 +30,7 @@ class AdminServer
30
30
 
31
31
  get "/admin/?" do
32
32
  posts = site.posts.sort_by { |p| p.created }.reverse
33
- drafts = site.drafts.sort_by { |p| p.slug }.reverse
33
+ drafts = site.drafts.sort_by { |p| File.mtime(p.path) }.reverse
34
34
 
35
35
  liquid :index, locals: { posts: posts, drafts: drafts }
36
36
  end
@@ -185,11 +185,18 @@ class AdminServer
185
185
  FileUtils.mkdir_p(File.join(site.directory, File.dirname(filename)))
186
186
  FileUtils.mkdir_p(File.dirname(site.site_path(filename)))
187
187
 
188
+ source_file = File.join(site.directory, filename)
189
+ deployed_file = site.site_path(filename)
190
+
188
191
  # move to the source directory
189
- FileUtils.mv(tempfile.path, File.join(site.directory, filename))
192
+ FileUtils.mv(tempfile.path, source_file)
190
193
 
191
194
  # copy to production to avoid the need to generate right now
192
- FileUtils.copy(File.join(site.directory, filename), site.site_path(filename))
195
+ FileUtils.copy(source_file, deployed_file)
196
+
197
+ # no executable permissions, and whatever the umask is
198
+ perms = 0777 & ~0111 & ~File.umask
199
+ File.chmod(perms, source_file, deployed_file)
193
200
 
194
201
  "File uploaded"
195
202
  end
data/lib/serif/site.rb CHANGED
@@ -2,7 +2,11 @@ class StandardFilterCheck
2
2
  include Liquid::StandardFilters
3
3
 
4
4
  def date_supports_now?
5
- date("now", "%Y") == Time.now.year
5
+ begin
6
+ date("now", "%Y") == Time.now.year
7
+ rescue
8
+ false
9
+ end
6
10
  end
7
11
  end
8
12
 
@@ -305,6 +309,12 @@ class Site
305
309
 
306
310
  FileUtils.mkdir_p(tmp_path(File.dirname(post.url)))
307
311
 
312
+ post_layout = default_layout
313
+
314
+ if post.headers[:layout]
315
+ post_layout = Liquid::Template.parse(File.read(File.join(self.directory, "_layouts", "#{post.headers[:layout]}.html")))
316
+ end
317
+
308
318
  File.open(tmp_path(post.url + ".html"), "w") do |f|
309
319
  # variables available in the post template
310
320
  post_template_variables = {
@@ -313,7 +323,7 @@ class Site
313
323
  "next_post" => next_post
314
324
  }
315
325
 
316
- f.puts default_layout.render!(
326
+ f.puts post_layout.render!(
317
327
  "site" => self,
318
328
  "page" => { "title" => ["Posts", "#{post.title}"] },
319
329
  "content" => Liquid::Template.parse(File.read("_templates/post.html")).render!(post_template_variables)
data/serif.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "serif"
3
- s.version = "0.3"
3
+ s.version = "0.3.1"
4
4
  s.authors = ["Adam Prescott"]
5
5
  s.email = ["adam@aprescott.com"]
6
6
  s.homepage = "https://github.com/aprescott/serif"
@@ -15,7 +15,7 @@
15
15
  </h2>
16
16
 
17
17
  <h2 id="private-url">
18
- <code><span>preview:</span> <a href="{{ private_url }}">{{ private_url | escape }}</a></code>
18
+ <code><span>preview:</span> <a href="{{ private_url }}">{% assign parts = private_url | split:"/" %}/{{ parts[1] }}/{{ parts[2] }}/{{ parts[3] | truncate: 10, '' }}&hellip;</a></code>
19
19
  </h2>
20
20
 
21
21
  <div class="post{% if post.draft %} draft{% endif %}">
@@ -1,5 +1,7 @@
1
1
  <h1>Drafts</h1>
2
2
 
3
+ <p>(Most recently modified first.)</p>
4
+
3
5
  <ul>
4
6
  {% for draft in drafts %}
5
7
  <li><a href="/admin/edit/drafts/{{ draft.slug }}">{% if draft.slug != empty %}{{ draft.slug }}{% else %}<em>(untitled)</em>{% endif %}</a></li>
@@ -8,6 +10,8 @@
8
10
 
9
11
  <h1>Posts</h1>
10
12
 
13
+ <p>(Most recently published first.)</p>
14
+
11
15
  <ul>
12
16
  {% for post in posts %}
13
17
  <li><a href="/admin/edit/posts/{{ post.slug }}">{% if post.title != empty %}{{ post.title }}{% else %}<em>(untitled)</em>{% endif %}</a></li>
@@ -369,7 +369,7 @@ body > nav ul li:last-child {
369
369
  setDepartureCheck(false);
370
370
 
371
371
  $(function() {
372
- $("input, textarea").change(function(event) {
372
+ $("input, textarea").keyup(function(event) {
373
373
  setDepartureCheck(true);
374
374
  });
375
375
  });
@@ -30,6 +30,14 @@ END_SOURCE
30
30
  <p>foo</p>
31
31
  <pre class="highlight"><code><span class="n">foo</span>
32
32
  </code></pre>
33
+ END_OUTPUT
34
+ end
35
+
36
+ it "renders quote marks properly" do
37
+ subject.render(<<END_SOURCE).should == <<END_OUTPUT
38
+ This "very" sentence's structure "isn't" necessary.
39
+ END_SOURCE
40
+ <p>This &ldquo;very&rdquo; sentence&#39;s structure &ldquo;isn&#39;t&rdquo; necessary.</p>
33
41
  END_OUTPUT
34
42
  end
35
43
  end
@@ -0,0 +1,5 @@
1
+ title: Custom layout
2
+ Created: 2013-03-07T00:00:00+00:00
3
+ layout: alt-layout
4
+
5
+ Second post.
@@ -0,0 +1,4 @@
1
+ title: Penultimate post
2
+ Created: 2399-01-01T00:00:00+00:00
3
+
4
+ Penultimate post
@@ -0,0 +1,4 @@
1
+ title: Final post
2
+ Created: 2400-01-01T00:00:00+00:00
3
+
4
+ The final post in the blog
@@ -0,0 +1,5 @@
1
+ title: Some draft title
2
+ Updated: 2013-03-03T03:19:04+00:00
3
+ Created: 2013-03-03T03:19:04+00:00
4
+
5
+ some content
@@ -1,4 +1,4 @@
1
1
  title: Some draft title
2
- Updated: 2013-02-18T22:03:03+00:00
2
+ Updated: 2013-03-03T03:19:04+00:00
3
3
 
4
4
  some content
@@ -23,6 +23,14 @@ describe Serif::Site do
23
23
  File.read("_site/page-alt-layout.html").lines.first.should =~ /<h1.+?>Alternate layout<\/h1>/
24
24
  end
25
25
 
26
+ it "reads the layout header for a post file and uses the appropriate layout file" do
27
+ subject.generate
28
+
29
+ # check it actually got generated
30
+ File.exist?(testing_dir("_site/test-blog/post-with-custom-layout.html")).should be_true
31
+ File.read("_site/test-blog/post-with-custom-layout.html").lines.first.should =~ /<h1.+?>Alternate layout<\/h1>/
32
+ end
33
+
26
34
  it "supports a smarty filter" do
27
35
  subject.generate
28
36
  File.read("_site/test-smarty-filter.html").should =~ /testing&rsquo;s for a &ldquo;heading&rsquo;s&rdquo; `with code` in it&hellip;/
@@ -45,13 +53,13 @@ describe Serif::Site do
45
53
  next_title.should_not be_nil
46
54
  next_title[/(?<=: ).+/].should == "Second post"
47
55
 
48
- contents = File.read("_site/test-blog/second-post.html")
56
+ contents = File.read("_site/test-blog/final-post.html")
49
57
  previous_title = contents[/Previous post: .+?$/]
50
58
  next_title = contents[/Next post: .+?$/]
51
59
 
52
60
  previous_title.should_not be_nil
53
61
  next_title.should be_nil
54
- previous_title[/(?<=: ).+/].should == "Sample post"
62
+ previous_title[/(?<=: ).+/].should == "Penultimate post"
55
63
  end
56
64
 
57
65
  it "sets a draft_preview flag for preview urls" do
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 == 2
16
+ subject.posts.length.should == 5
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.3'
4
+ version: 0.3.1
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-18 00:00:00.000000000 Z
12
+ date: 2013-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -277,8 +277,8 @@ files:
277
277
  - test/site_dir/_site/test-archive/2013/01/index.html
278
278
  - test/site_dir/_site/test-archive/2012/12/index.html
279
279
  - test/site_dir/_site/test-archive/2012/11/index.html
280
- - test/site_dir/_site/drafts/another-sample-draft/f340ff2dd6aa78f819d547ee908fe7410e6153559b47265dcbc58598bb4a.html
281
- - test/site_dir/_site/drafts/sample-draft/ed883ce827f757888e2900ce0e155a960cb45f832fcc24791c054013b71c.html
280
+ - test/site_dir/_site/drafts/another-sample-draft/5d169443ff5dbaf4a7514382e2c71464053230c7c42b96abbe2005e8a731.html
281
+ - test/site_dir/_site/drafts/sample-draft/8877b6abe287fd4492604cc67c6d138f02edb0e05f32b0c95c0521055dc2.html
282
282
  - test/site_dir/_site/index.html
283
283
  - test/site_dir/_site/file-digest-test.html
284
284
  - test/site_dir/_site/page-alt-layout.html
@@ -289,9 +289,12 @@ files:
289
289
  - test/site_dir/_site/test-blog/sample-post.html
290
290
  - test/site_dir/_site/test-smarty-filter.html
291
291
  - test/site_dir/_site/archive.html
292
- - test/site_dir/_trash/1361224983-test-draft
293
- - test/site_dir/_trash/1361224983-autopublish-draft
292
+ - test/site_dir/_trash/1362280744-autopublish-draft
293
+ - test/site_dir/_trash/1362280744-test-draft
294
+ - test/site_dir/_posts/2013-03-07-post-with-custom-layout
294
295
  - test/site_dir/_posts/2012-01-05-sample-post
296
+ - test/site_dir/_posts/2400-01-01-final-post
297
+ - test/site_dir/_posts/2399-01-01-penultimate-post
295
298
  - test/site_dir/_posts/2013-01-01-second-post
296
299
  - test/site_dir/test-smarty-filter.html
297
300
  - test/site_dir/_layouts/alt-layout.html
@@ -1,5 +0,0 @@
1
- title: Some draft title
2
- Updated: 2013-02-18T22:03:03+00:00
3
- Created: 2013-02-18T22:03:03+00:00
4
-
5
- some content