serif 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/serif/admin_server.rb +10 -3
- data/lib/serif/site.rb +12 -2
- data/serif.gemspec +1 -1
- data/statics/templates/admin/edit_draft.liquid +1 -1
- data/statics/templates/admin/index.liquid +4 -0
- data/statics/templates/admin/layout.liquid +1 -1
- data/test/markup_renderer_spec.rb +8 -0
- data/test/site_dir/_posts/2013-03-07-post-with-custom-layout +5 -0
- data/test/site_dir/_posts/2399-01-01-penultimate-post +4 -0
- data/test/site_dir/_posts/2400-01-01-final-post +4 -0
- data/test/site_dir/_site/drafts/another-sample-draft/{f340ff2dd6aa78f819d547ee908fe7410e6153559b47265dcbc58598bb4a.html → 5d169443ff5dbaf4a7514382e2c71464053230c7c42b96abbe2005e8a731.html} +0 -0
- data/test/site_dir/_site/drafts/sample-draft/{ed883ce827f757888e2900ce0e155a960cb45f832fcc24791c054013b71c.html → 8877b6abe287fd4492604cc67c6d138f02edb0e05f32b0c95c0521055dc2.html} +0 -0
- data/test/site_dir/_trash/1362280744-autopublish-draft +5 -0
- data/test/site_dir/_trash/{1361224983-test-draft → 1362280744-test-draft} +1 -1
- data/test/site_generation_spec.rb +10 -2
- data/test/site_spec.rb +1 -1
- metadata +9 -6
- data/test/site_dir/_trash/1361224983-autopublish-draft +0 -5
data/lib/serif/admin_server.rb
CHANGED
@@ -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.
|
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,
|
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(
|
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
|
-
|
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
|
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
@@ -15,7 +15,7 @@
|
|
15
15
|
</h2>
|
16
16
|
|
17
17
|
<h2 id="private-url">
|
18
|
-
<code><span>preview:</span> <a href="{{ private_url }}">{
|
18
|
+
<code><span>preview:</span> <a href="{{ private_url }}">{% assign parts = private_url | split:"/" %}/{{ parts[1] }}/{{ parts[2] }}/{{ parts[3] | truncate: 10, '' }}…</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>
|
@@ -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 “very” sentence's structure “isn't” necessary.</p>
|
33
41
|
END_OUTPUT
|
34
42
|
end
|
35
43
|
end
|
File without changes
|
File without changes
|
@@ -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’s for a “heading’s” `with code` in it…/
|
@@ -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/
|
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 == "
|
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
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:
|
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-
|
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/
|
281
|
-
- test/site_dir/_site/drafts/sample-draft/
|
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/
|
293
|
-
- test/site_dir/_trash/
|
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
|