serif 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- serif (0.1.6)
4
+ serif (0.2.1)
5
5
  liquid (~> 2.4)
6
6
  pygments.rb (~> 0.3)
7
7
  rack (~> 1.0)
@@ -18,13 +18,13 @@ GEM
18
18
  liquid (2.4.1)
19
19
  multi_json (1.5.0)
20
20
  posix-spawn (0.3.6)
21
- pygments.rb (0.3.3)
21
+ pygments.rb (0.3.7)
22
22
  posix-spawn (~> 0.3.6)
23
23
  yajl-ruby (~> 1.1.0)
24
- rack (1.4.1)
24
+ rack (1.4.4)
25
25
  rack-protection (1.3.2)
26
26
  rack
27
- rack-rewrite (1.3.2)
27
+ rack-rewrite (1.3.3)
28
28
  rake (0.9.2.2)
29
29
  redcarpet (2.2.2)
30
30
  redhead (0.0.8)
@@ -44,7 +44,7 @@ GEM
44
44
  rack (~> 1.3, >= 1.3.6)
45
45
  rack-protection (~> 1.2)
46
46
  tilt (~> 1.3, >= 1.3.3)
47
- slop (3.3.3)
47
+ slop (3.4.3)
48
48
  tilt (1.3.3)
49
49
  timecop (0.5.5)
50
50
  yajl-ruby (1.1.0)
data/README.md CHANGED
@@ -4,6 +4,23 @@
4
4
 
5
5
  Serif is a file-based blogging engine intended for simple sites. It compiles Markdown content to static files, and there is a web interface for editing and publishing ([simple video demo](https://docs.google.com/open?id=0BxPQpxGSOOyKS1J4MmlnM3JIaXM)), because managing everything with `ssh` and `git` can be a pain, compared to having a more universally accessible editing interface.
6
6
 
7
+ # Changes and what's new
8
+
9
+ See `CHANGELOG` for what's new.
10
+
11
+ # Contents of this README
12
+
13
+ * [Intro](#intro)
14
+ * [License and contributing](#license-and-contributing)
15
+ * [Basic usage](#basics)
16
+ * [Content and site structure](#content-and-site-structure)
17
+ * [Publishing drafts](#publishing-drafts)
18
+ * [Archive pages](#archive-pages)
19
+ * [Configuration](#configuration)
20
+ * [Deploying](#deploying)
21
+ * [Customising the admin interface](#customising-the-admin-interface)
22
+ * [Custom tags](#custom-tags)
23
+
7
24
  # Intro
8
25
 
9
26
  Serif is a lot like Jekyll with a few extra moving parts, although it didn't start that way. It went through two reworkings before being converted into something based on generated Markdown files. The aim for Serif is to provide two things:
@@ -11,7 +28,7 @@ Serif is a lot like Jekyll with a few extra moving parts, although it didn't sta
11
28
  1. Simplicity: the source and generated content are just files that can be served by any web server.
12
29
  2. Ease of publishing, wherever you are: having everything based on files that you edit in a text editor is a nice idea, but what if you're on a machine that doesn't give you ssh access to your server? What if you need to edit creation timestamps? What about editing drafts without having to make commits and push to git repos?
13
30
 
14
- With this in mind, you might think of Serif's aim as to merge Jekyll, [Second Crack](https://github.com/marcoarment/secondcrack) and ideas from [Svbtle](http://dcurt.is/codename-svbtle). There should be many ways of editing and publishing, such as using the web interface, `rsync`ing from a remote machine, or editing a draft file on the remote server and having everything happen for you. (This last feature doesn't quite exist as planned yet.)
31
+ With this in mind, you might think of Serif's aim as to merge Jekyll, [Second Crack](https://github.com/marcoarment/secondcrack) and ideas from [Svbtle](http://dcurt.is/codename-svbtle). There should be many ways of editing and publishing, such as using the web interface, `rsync`ing from a remote machine, or editing a draft file on the remote server and having everything happen for you.
15
32
 
16
33
  ## Planned features
17
34
 
@@ -37,6 +54,23 @@ The quickest way to get changes contributed:
37
54
 
38
55
  # Basics
39
56
 
57
+ ## First time use
58
+
59
+ To get started with Serif based on a site skeleton:
60
+
61
+ ```bash
62
+ gem install serif # install serif
63
+ cd path/to/some/place # go to where you'll be creating your site directory
64
+ serif new # create an initial site skeleton
65
+
66
+ # ... edit your files how you want them ...
67
+
68
+ serif generate # generate the site based on the source files
69
+ serif dev # serve up the site for local testing purposes
70
+ ```
71
+
72
+ Now visit <http://localhost:8000/> to view the site.
73
+
40
74
  ## Installing
41
75
 
42
76
  Installation is via [RubyGems](https://rubygems.org/). If you don't have Ruby installed, I recommend using [RVM](https://rvm.io/).
@@ -302,6 +336,10 @@ location @not_found_page {
302
336
  }
303
337
  ```
304
338
 
339
+ ## Generating the site
340
+
341
+ Use `ENV=production serif generate` to regenerate the site for production.
342
+
305
343
  ## Admin interface
306
344
 
307
345
  The admin server can be started on the live server the same way it's started locally (with `ENV=production`). To access it from anywhere on the web, you will need to proxy/forward `/admin` HTTP requests to port 4567 to let the admin web server handle it. As an alternative, you could forward a local port with SSH --- you might use this if you didn't want to rely on just HTTP basic auth, which isn't very secure over non-HTTPS connections.
@@ -318,3 +356,21 @@ The admin interface is intended to be a minimal place to focus on writing conten
318
356
 
319
357
  /* more customisation below */
320
358
  ```
359
+
360
+ # Custom tags
361
+
362
+ These tags can be used in templates. For example:
363
+
364
+ ```
365
+ {% file_digest foo.css prefix:- %}
366
+ ```
367
+
368
+ ## List of tags
369
+
370
+ * `file_digest <path> [prefix:<prefix>]`
371
+
372
+ (Note: For this tag to return anything, `ENV=production` must be set as an environment variable.)
373
+
374
+ Computes a hex digest of the contents of `<path>`, optionally prefixed with `<prefix>`. `<path>` is delimited by whitespace.
375
+
376
+ Useful for URL fingerprinting for long-lived caching.
data/lib/serif/site.rb CHANGED
@@ -37,9 +37,51 @@ module Filters
37
37
  input.xmlschema
38
38
  end
39
39
  end
40
+
41
+ class FileDigest < Liquid::Tag
42
+ DIGEST_CACHE = {}
43
+
44
+ # file_digest "file.css" [prefix:.]
45
+ Syntax = /^\s*(\S+)\s*(?:(prefix\s*:\s*\S+)\s*)?/
46
+
47
+ def initialize(tag_name, markup, tokens)
48
+ super
49
+
50
+ if markup =~ Syntax
51
+ @path = $1
52
+
53
+ if $2
54
+ @prefix = $2.gsub(/\s*prefix\s*:\s*/, "")
55
+ else
56
+ @prefix = ""
57
+ end
58
+ else
59
+ raise SyntaxError.new("Syntax error for file_digest")
60
+ end
61
+ end
62
+
63
+ # Takes the given path and returns the MD5
64
+ # hex digest of the file's contents.
65
+ #
66
+ # The path argument is first stripped, and any leading
67
+ # "/" has no effect.
68
+ def render(context)
69
+ return "" unless ENV["ENV"] == "production"
70
+
71
+ full_path = File.join(context["site"]["directory"], @path.strip)
72
+
73
+ return @prefix + DIGEST_CACHE[full_path] if DIGEST_CACHE[full_path]
74
+
75
+ digest = Digest::MD5.hexdigest(File.read(full_path))
76
+ DIGEST_CACHE[full_path] = digest
77
+
78
+ @prefix + digest
79
+ end
80
+ end
40
81
  end
41
82
 
42
83
  Liquid::Template.register_filter(Serif::Filters)
84
+ Liquid::Template.register_tag("file_digest", Serif::FileDigest)
43
85
 
44
86
  module Serif
45
87
  class Site
@@ -169,7 +211,8 @@ class Site
169
211
  {
170
212
  "posts" => posts,
171
213
  "latest_update_time" => latest_update_time,
172
- "archive" => self.class.stringify_keys(archives)
214
+ "archive" => self.class.stringify_keys(archives),
215
+ "directory" => directory
173
216
  }
174
217
  end
175
218
 
@@ -219,7 +262,7 @@ class Site
219
262
  else
220
263
  layout_file = File.join(self.directory, "_layouts", "#{layout_option}.html")
221
264
  layout = Liquid::Template.parse(File.read(layout_file))
222
- f.puts layout.render!("page" => { "title" => [title].compact }, "content" => Liquid::Template.parse(file.to_s).render!("site" => self))
265
+ f.puts layout.render!("site" => self, "page" => { "title" => [title].compact }, "content" => Liquid::Template.parse(file.to_s).render!("site" => self))
223
266
  end
224
267
  end
225
268
  end
@@ -231,7 +274,7 @@ class Site
231
274
  FileUtils.mkdir_p(tmp_path(File.dirname(post.url)))
232
275
 
233
276
  File.open(tmp_path(post.url + ".html"), "w") do |f|
234
- f.puts default_layout.render!("page" => { "title" => ["Posts", "#{post.title}"] }, "content" => Liquid::Template.parse(File.read("_templates/post.html")).render!("post" => post))
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))
235
278
  end
236
279
  end
237
280
 
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"
3
+ s.version = "0.2.1"
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,34 @@
1
+ require "test_helper"
2
+
3
+ describe Serif::FileDigest do
4
+ def file_digest(markup)
5
+ Serif::FileDigest.new("file_digest", markup, "no tokens needed")
6
+ end
7
+
8
+ before :each do
9
+ site = Serif::Site.new(testing_dir)
10
+ @context = { "site" => { "directory" => site.directory }}
11
+ end
12
+
13
+ describe "#render" do
14
+ it "returns the md5 hex digest of the finally deployed site path" do
15
+ file_digest("test-stylesheet.css").render(@context).should == "f8390232f0c354a871f9ba0ed306163c"
16
+ end
17
+
18
+ it "ignores leading slashes" do
19
+ file_digest("/test-stylesheet.css").render(@context).should == "f8390232f0c354a871f9ba0ed306163c"
20
+ end
21
+
22
+ it "ignores surrounding whitespace" do
23
+ file_digest(" test-stylesheet.css ").render(@context).should == "f8390232f0c354a871f9ba0ed306163c"
24
+ end
25
+
26
+ it "includes a prefix if one is specified" do
27
+ file_digest("test-stylesheet.css prefix:.").render(@context).should == ".f8390232f0c354a871f9ba0ed306163c"
28
+ end
29
+
30
+ it "ignores trailing whitespace on the prefix" do
31
+ file_digest("test-stylesheet.css prefix:. ").render(@context).should == ".f8390232f0c354a871f9ba0ed306163c"
32
+ end
33
+ end
34
+ end
data/test/filters_spec.rb CHANGED
@@ -44,7 +44,7 @@ describe Serif::Filters do
44
44
  end
45
45
  end
46
46
  end
47
-
47
+
48
48
  describe "#xmlschema" do
49
49
  it "calls xmlschema on its input" do
50
50
  d = double("")
@@ -1,4 +1,4 @@
1
1
  title: Some draft title
2
- Created: 2013-01-02T14:34:37+00:00
2
+ Created: 2013-01-30T22:09:58+00:00
3
3
 
4
4
  some content
@@ -0,0 +1,4 @@
1
+ layout: none
2
+
3
+ {% file_digest test-stylesheet.css %}
4
+ {% file_digest test-stylesheet.css prefix:. %}
@@ -0,0 +1,3 @@
1
+ #foo {
2
+ bar: baz;
3
+ }
@@ -23,6 +23,12 @@ 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 "correctly handles file_digest calls" do
27
+ subject.generate
28
+
29
+ File.read("_site/file-digest-test.html").strip.should == "f8390232f0c354a871f9ba0ed306163c\n.f8390232f0c354a871f9ba0ed306163c"
30
+ end
31
+
26
32
  context "for drafts with a publish: now header" do
27
33
  before :all do
28
34
  @time = Time.utc(2012, 12, 21, 15, 30, 00)
data/test/test_helper.rb CHANGED
@@ -3,6 +3,9 @@ SimpleCov.start do
3
3
  add_filter "/test/"
4
4
  end
5
5
 
6
+ # run tests in production mode so that file digests are enabled
7
+ ENV["ENV"] = "production"
8
+
6
9
  require "serif"
7
10
  require "fileutils"
8
11
  require "pathname"
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.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-01-02 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -212,62 +212,65 @@ executables:
212
212
  extensions: []
213
213
  extra_rdoc_files: []
214
214
  files:
215
- - lib/serif.rb
216
- - lib/serif/post.rb
217
- - lib/serif/admin_server.rb
215
+ - lib/serif/content_file.rb
218
216
  - lib/serif/server.rb
217
+ - lib/serif/markup_renderer.rb
218
+ - lib/serif/post.rb
219
219
  - lib/serif/config.rb
220
+ - lib/serif/admin_server.rb
220
221
  - lib/serif/draft.rb
221
- - lib/serif/markup_renderer.rb
222
222
  - lib/serif/site.rb
223
- - lib/serif/content_file.rb
223
+ - lib/serif.rb
224
+ - statics/templates/admin/new_draft.liquid
225
+ - statics/templates/admin/edit_draft.liquid
226
+ - statics/templates/admin/layout.liquid
227
+ - statics/templates/admin/index.liquid
228
+ - statics/templates/admin/edit_post.liquid
224
229
  - statics/skeleton/index.html
225
- - statics/skeleton/_templates/post.html
226
230
  - statics/skeleton/_templates/archive_page.html
231
+ - statics/skeleton/_templates/post.html
232
+ - statics/skeleton/_drafts/sample-draft
227
233
  - statics/skeleton/_config.yml
228
- - statics/skeleton/_layouts/default.html
229
234
  - statics/skeleton/_posts/2012-01-05-sample-post
230
- - statics/skeleton/_drafts/sample-draft
235
+ - statics/skeleton/_layouts/default.html
231
236
  - statics/skeleton/archive.html
232
- - statics/templates/admin/new_draft.liquid
233
- - statics/templates/admin/edit_draft.liquid
234
- - statics/templates/admin/layout.liquid
235
- - statics/templates/admin/edit_post.liquid
236
- - statics/templates/admin/index.liquid
237
237
  - statics/assets/js/mousetrap.min.js
238
238
  - statics/assets/js/jquery.autosize.js
239
239
  - bin/serif
240
240
  - test/test_helper.rb
241
- - test/post_spec.rb
241
+ - test/filters_spec.rb
242
+ - test/config_spec.rb
243
+ - test/liquid_filter_date_extension_spec.rb
242
244
  - test/site_spec.rb
243
245
  - test/draft_spec.rb
244
- - test/config_spec.rb
246
+ - test/markup_renderer_spec.rb
245
247
  - test/site_dir/index.html
246
- - test/site_dir/_templates/post.html
247
248
  - test/site_dir/_templates/archive_page.html
248
- - test/site_dir/_config.yml
249
- - test/site_dir/_layouts/default.html
250
- - test/site_dir/_layouts/alt-layout.html
251
- - test/site_dir/_posts/2012-01-05-sample-post
252
- - test/site_dir/page-alt-layout.html
249
+ - test/site_dir/_templates/post.html
253
250
  - test/site_dir/_drafts/another-sample-draft
254
251
  - test/site_dir/_drafts/sample-draft
255
- - test/site_dir/_site/test-blog/sample-post.html
256
- - test/site_dir/_site/test-blog/post-to-be-published-on-generate.html
252
+ - test/site_dir/file-digest-test.html
253
+ - test/site_dir/page-alt-layout.html
254
+ - test/site_dir/page-header-but-no-layout.html
255
+ - test/site_dir/test-stylesheet.css
256
+ - test/site_dir/_config.yml
257
+ - test/site_dir/_site/test-archive/2012/12/index.html
258
+ - test/site_dir/_site/test-archive/2012/11/index.html
257
259
  - test/site_dir/_site/index.html
258
260
  - test/site_dir/_site/page-alt-layout.html
259
- - test/site_dir/_site/test-archive/2012/11/index.html
260
- - test/site_dir/_site/test-archive/2012/12/index.html
261
261
  - test/site_dir/_site/page-header-but-no-layout.html
262
+ - test/site_dir/_site/test-blog/post-to-be-published-on-generate.html
263
+ - test/site_dir/_site/test-blog/sample-post.html
262
264
  - test/site_dir/_site/archive.html
263
- - test/site_dir/_trash/1357137277-autopublish-draft
264
- - test/site_dir/_trash/1357137277-test-draft
265
- - test/site_dir/page-header-but-no-layout.html
265
+ - test/site_dir/_trash/1359583798-test-draft
266
+ - test/site_dir/_trash/1359583798-autopublish-draft
267
+ - test/site_dir/_posts/2012-01-05-sample-post
268
+ - test/site_dir/_layouts/alt-layout.html
269
+ - test/site_dir/_layouts/default.html
266
270
  - test/site_dir/archive.html
267
- - test/markup_renderer_spec.rb
268
- - test/liquid_filter_date_extension_spec.rb
271
+ - test/file_digest_tag_spec.rb
269
272
  - test/site_generation_spec.rb
270
- - test/filters_spec.rb
273
+ - test/post_spec.rb
271
274
  - serif.gemspec
272
275
  - rakefile
273
276
  - LICENSE
@@ -300,11 +303,12 @@ specification_version: 3
300
303
  summary: Simple file-based blogging system.
301
304
  test_files:
302
305
  - test/test_helper.rb
303
- - test/post_spec.rb
306
+ - test/filters_spec.rb
307
+ - test/config_spec.rb
308
+ - test/liquid_filter_date_extension_spec.rb
304
309
  - test/site_spec.rb
305
310
  - test/draft_spec.rb
306
- - test/config_spec.rb
307
311
  - test/markup_renderer_spec.rb
308
- - test/liquid_filter_date_extension_spec.rb
312
+ - test/file_digest_tag_spec.rb
309
313
  - test/site_generation_spec.rb
310
- - test/filters_spec.rb
314
+ - test/post_spec.rb