serif 0.5.2 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +58 -21
  4. data/LICENSE +1 -1
  5. data/README.md +11 -13
  6. data/lib/serif.rb +3 -2
  7. data/lib/serif/admin_server.rb +10 -10
  8. data/lib/serif/commands.rb +2 -2
  9. data/lib/serif/config.rb +1 -1
  10. data/lib/serif/content_file.rb +9 -9
  11. data/lib/serif/draft.rb +1 -1
  12. data/lib/serif/errors.rb +1 -1
  13. data/lib/serif/markup_renderer.rb +28 -17
  14. data/lib/serif/post.rb +1 -1
  15. data/lib/serif/server.rb +1 -1
  16. data/lib/serif/site.rb +5 -29
  17. data/rakefile +3 -6
  18. data/serif.gemspec +9 -3
  19. data/statics/assets/js/attachment.js +3 -3
  20. data/statics/skeleton/_config.yml +1 -1
  21. data/statics/skeleton/_layouts/default.html +1 -1
  22. data/statics/skeleton/_templates/archive_page.html +1 -1
  23. data/statics/skeleton/_templates/post.html +1 -1
  24. data/statics/skeleton/archive.html +1 -1
  25. data/statics/skeleton/index.html +1 -1
  26. data/statics/templates/admin/bookmarks.liquid +1 -1
  27. data/statics/templates/admin/edit_draft.liquid +1 -1
  28. data/statics/templates/admin/index.liquid +1 -1
  29. data/statics/templates/admin/layout.liquid +6 -4
  30. data/statics/templates/admin/new_draft.liquid +1 -1
  31. metadata +123 -127
  32. data/test/commands_spec.rb +0 -77
  33. data/test/config_spec.rb +0 -55
  34. data/test/content_file_spec.rb +0 -113
  35. data/test/draft_spec.rb +0 -275
  36. data/test/file_digest_tag_spec.rb +0 -38
  37. data/test/filters_spec.rb +0 -90
  38. data/test/liquid_filter_date_extension_spec.rb +0 -15
  39. data/test/markup_renderer_spec.rb +0 -47
  40. data/test/post_spec.rb +0 -139
  41. data/test/site_dir/_config.yml +0 -18
  42. data/test/site_dir/_drafts/another-sample-draft +0 -3
  43. data/test/site_dir/_drafts/sample-draft +0 -3
  44. data/test/site_dir/_layouts/alt-layout.html +0 -3
  45. data/test/site_dir/_layouts/default.html +0 -8
  46. data/test/site_dir/_posts/2012-01-05-sample-post +0 -4
  47. data/test/site_dir/_posts/2013-01-01-second-post +0 -4
  48. data/test/site_dir/_posts/2013-03-07-post-with-custom-layout +0 -5
  49. data/test/site_dir/_posts/2399-01-01-penultimate-post +0 -4
  50. data/test/site_dir/_posts/2400-01-01-final-post +0 -4
  51. data/test/site_dir/_templates/archive_page.html +0 -9
  52. data/test/site_dir/_templates/post.html +0 -10
  53. data/test/site_dir/archive.html +0 -7
  54. data/test/site_dir/file-digest-test.html +0 -4
  55. data/test/site_dir/index.html +0 -9
  56. data/test/site_dir/page-alt-layout.html +0 -3
  57. data/test/site_dir/page-header-but-no-layout.html +0 -3
  58. data/test/site_dir/test-smarty-filter.html +0 -3
  59. data/test/site_dir/test-stylesheet.css +0 -3
  60. data/test/site_generation_spec.rb +0 -204
  61. data/test/site_spec.rb +0 -189
  62. data/test/test_helper.rb +0 -61
@@ -1,77 +0,0 @@
1
- require "test_helper"
2
-
3
- class Serif::Commands
4
- def exit(code)
5
- "Fake exit with code #{code}"
6
- end
7
- end
8
-
9
- describe Serif::Commands do
10
- def expect_method_call(arg, method)
11
- c = Serif::Commands.new([arg])
12
- c.should_receive(method)
13
- capture_stdout { c.process }
14
- end
15
-
16
- describe "#process" do
17
- it "takes -h and --help and calls print usage" do
18
- %w[-h --help].each do |cmd|
19
- expect_method_call(cmd, :print_help)
20
- end
21
- end
22
-
23
- {
24
- "admin" => :initialize_admin_server,
25
- "dev" => :initialize_dev_server,
26
- "new" => :produce_skeleton,
27
- "generate" => :generate_site
28
- }.each do |command, meth|
29
- it "takes the command '#{command}' and runs #{meth}" do
30
- expect_method_call(command, meth)
31
- end
32
- end
33
-
34
- it "exits on help" do
35
- expect_method_call("-h", :exit)
36
- end
37
- end
38
-
39
- describe "#generate_site" do
40
- it "calls Site#generate" do
41
- Serif::Site.stub(:generation_called)
42
- Serif::Site.any_instance.stub(:generate) { Serif::Site.generation_called }
43
-
44
- # if this is called, it means any instance of Site had #generate called.
45
- Serif::Site.should_receive(:generation_called)
46
-
47
- Serif::Commands.new([]).generate_site("anything")
48
- end
49
-
50
- context "with a conflict" do
51
- def conflicting_generate_command
52
- a = b = double("")
53
- a.stub(:url) { "/foo" }
54
- b.stub(:url) { "/foo" }
55
- a.stub(:path) { "/anything" }
56
- b.stub(:path) { "/anything" }
57
-
58
- # any non-nil value will do
59
- Serif::Site.any_instance.stub(:conflicts) { { "/foo" => [a, b] } }
60
-
61
- command = Serif::Commands.new([])
62
- command.generate_site(testing_dir)
63
- command.should_receive(:exit)
64
- command
65
- end
66
-
67
- it "exits" do
68
- capture_stdout { conflicting_generate_command.process }
69
- end
70
-
71
- it "prints the urls that conflict" do
72
- output = capture_stdout { conflicting_generate_command.process }
73
- output.should match(/Conflicts at:\n\n\/foo\n\t\/anything\n\t\/anything/)
74
- end
75
- end
76
- end
77
- end
@@ -1,55 +0,0 @@
1
- require "test_helper"
2
-
3
- describe Serif::Config do
4
- subject do
5
- Serif::Config.new(testing_dir("_config.yml"))
6
- end
7
-
8
- describe "#admin_username" do
9
- it "is the admin username defined in the config file" do
10
- subject.admin_username.should == "test-changethisusername"
11
- end
12
- end
13
-
14
- describe "#admin_password" do
15
- it "is the admin password defined in the config file" do
16
- subject.admin_password.should == "test-changethispassword"
17
- end
18
- end
19
-
20
- describe "#image_upload_path" do
21
- it "defaults to /images/:timestamp/_name" do
22
- subject.stub(:yaml) { {} }
23
- subject.image_upload_path.should == "/images/:timestamp_:name"
24
- end
25
- end
26
-
27
- describe "#permalink" do
28
- it "is the permalink format defined in the config file" do
29
- subject.permalink.should == "/test-blog/:title"
30
- end
31
-
32
- it "defaults to /:title" do
33
- subject.stub(:yaml) { {} }
34
- subject.permalink.should == "/:title"
35
- end
36
- end
37
-
38
- describe "#archive_url_format" do
39
- it "defaults to /archive/:year/:month" do
40
- subject.stub(:yaml) { {} }
41
- subject.archive_url_format.should == "/archive/:year/:month"
42
- end
43
-
44
- it "is the archive_url_format found in the config file" do
45
- subject.archive_url_format.should == "/test-archive/:year/:month"
46
- end
47
- end
48
-
49
- describe "#archive_enabled?" do
50
- it "defaults to false" do
51
- subject.stub(:yaml) { {} }
52
- subject.archive_enabled?.should be_false
53
- end
54
- end
55
- end
@@ -1,113 +0,0 @@
1
- require "test_helper"
2
-
3
- describe Serif::ContentFile do
4
- subject do
5
- Serif::Site.new(testing_dir)
6
- end
7
-
8
- describe "#basename" do
9
- it "is the basename of the path" do
10
- (subject.drafts + subject.posts).each do |content_file|
11
- content_file.basename.should == File.basename(content_file.path)
12
- end
13
-
14
- draft = Serif::Draft.new(subject)
15
- draft.slug = "foo"
16
- draft.title = "foo"
17
-
18
- # NOTE! Freezing!
19
- Timecop.freeze(Time.parse("2013-04-03"))
20
-
21
- draft.save
22
- draft.publish!
23
- post = Serif::Post.new(subject, draft.path)
24
-
25
- begin
26
- draft.path.should_not be_nil
27
- post.should_not be_nil
28
- draft.basename.should == post.basename
29
-
30
- # NOTE! Time frozen!
31
- post.basename.should == "2013-04-03-foo"
32
- ensure
33
- Timecop.return
34
- FileUtils.rm(post.path)
35
- end
36
- end
37
- end
38
-
39
- describe "draft and published status" do
40
- it "can handle a nil path" do
41
- c = Serif::ContentFile.new(subject)
42
- c.path.should be_nil
43
- c.draft?.should be_true
44
- c.published?.should be_false
45
- end
46
- end
47
-
48
- describe "draft?" do
49
- it "is true if the file is in the _drafts directory" do
50
- subject.drafts.each do |d|
51
- d.draft?.should be_true
52
- d.published?.should be_false
53
- end
54
-
55
- d = subject.drafts.sample
56
- orig_path = d.path
57
- d.stub(:path) { orig_path.gsub(/^#{Regexp.quote(testing_dir("_drafts"))}/, testing_dir("_anything")) }
58
- d.draft?.should be_false
59
- end
60
- end
61
-
62
- describe "published?" do
63
- it "can handle a nil path" do
64
- d = Serif::Post.new(subject)
65
- d.draft?.should be_true
66
- d.published?.should be_false
67
- end
68
-
69
- it "is true if the file is in the _posts directory" do
70
- subject.posts.each do |p|
71
- p.published?.should be_true
72
- p.draft?.should be_false
73
- end
74
-
75
- p = subject.posts.sample
76
- orig_path = p.path
77
- p.stub(:path) { orig_path.gsub(/^#{Regexp.quote(testing_dir("_posts"))}/, testing_dir("_anything")) }
78
- p.published?.should be_false
79
- end
80
- end
81
-
82
- describe "#title=" do
83
- it "sets the underlying header value to the assigned title" do
84
- (subject.drafts + subject.posts).each do |content_file|
85
- content_file.title = "foobar"
86
- content_file.headers[:title].should == "foobar"
87
- end
88
- end
89
- end
90
-
91
- describe "#save(markdown)" do
92
- it "sets the underlying updated time value for posts" do
93
- draft = Serif::Draft.new(subject)
94
- draft.title = "Testing"
95
- draft.slug = "hi"
96
-
97
- begin
98
- draft.save("# Some content")
99
- draft.publish!
100
-
101
- post = Serif::Post.new(subject, draft.path)
102
-
103
- t = Time.now
104
- Timecop.freeze(t + 30) do
105
- post.save("# Heading content")
106
- post.updated.to_i.should == (t + 30).to_i
107
- end
108
- ensure
109
- FileUtils.rm(post.path)
110
- end
111
- end
112
- end
113
- end
@@ -1,275 +0,0 @@
1
- require "test_helper"
2
-
3
- describe Serif::Draft do
4
- before :all do
5
- @site = Serif::Site.new(testing_dir)
6
- D = Serif::Draft
7
- FileUtils.rm_rf(testing_dir("_trash"))
8
- end
9
-
10
- describe "#url" do
11
- it "uses the current time for its placeholder values" do
12
- d = D.new(@site)
13
- d.slug = "my-blar-blar"
14
- orig_headers = d.headers
15
- d.stub(:headers) { orig_headers.merge(:permalink => "/foo/:year/:month/:day/:title") }
16
-
17
- Timecop.freeze(Time.parse("2020-02-09")) do
18
- d.url.should == "/foo/2020/02/09/my-blar-blar"
19
- end
20
- end
21
-
22
- it "can handle nil slug values" do
23
- d = D.new(@site)
24
- d.slug.should be_nil
25
- orig_headers = d.headers
26
- d.stub(:headers) { orig_headers.merge(:permalink => "/foo/:year/:month/:day/:title") }
27
-
28
- Timecop.freeze(Time.parse("2020-02-09")) do
29
- d.url.should == "/foo/2020/02/09/"
30
- end
31
- end
32
-
33
- it "defaults to the config file's permalink value" do
34
- d = D.new(@site)
35
- d.slug = "gablarhgle"
36
- d.url.should == "/test-blog/gablarhgle"
37
- end
38
-
39
- it "uses its permalink header value" do
40
- d = D.new(@site)
41
- d.slug = "anything"
42
- d.stub(:headers) { { :permalink => "testage" } }
43
- d.url.should == "testage"
44
- end
45
- end
46
-
47
- describe ".rename" do
48
- it "moves the draft to a new file" do
49
- draft = D.new(@site)
50
- draft.slug = "test-draft"
51
- draft.title = "Some draft title"
52
- draft.save("some content")
53
-
54
- D.rename(@site, "test-draft", "foo-bar")
55
- d = D.from_slug(@site, "foo-bar")
56
- d.should_not be_nil
57
- File.exist?(testing_dir("_drafts/foo-bar")).should be_true
58
-
59
- d.delete!
60
- end
61
-
62
- it "raises if there is an existing draft" do
63
- draft = D.new(@site)
64
- draft.slug = "test-draft"
65
- draft.title = "Some draft title"
66
- draft.save("some content")
67
-
68
- draft2 = D.new(@site)
69
- draft2.slug = "test-draft-2"
70
- draft2.title = "Some draft title"
71
- draft2.save("some content")
72
-
73
- expect { D.rename(@site, draft2.slug, draft.slug) }.to raise_error
74
-
75
- draft.delete!
76
- draft2.delete!
77
- end
78
- end
79
-
80
- describe "#delete!" do
81
- it "moves the file to _trash" do
82
- draft = D.new(@site)
83
- draft.slug = "test-draft"
84
- draft.title = "Some draft title"
85
- draft.save("some content")
86
- draft.delete!
87
- Dir[testing_dir("_trash/*-test-draft")].length.should == 1
88
- end
89
-
90
- it "creates the _trash directory if it doesn't exist" do
91
- FileUtils.rm_rf(testing_dir("_trash"))
92
-
93
- draft = D.new(@site)
94
- draft.slug = "test-draft"
95
- draft.title = "Some draft title"
96
- draft.save("some content")
97
- draft.delete!
98
-
99
- File.exist?(testing_dir("_trash")).should be_true
100
- end
101
- end
102
-
103
- describe "publish!" do
104
- it "moves the file to the _posts directory" do
105
- draft = D.new(@site)
106
- draft.slug = "test-draft"
107
- draft.title = "Some draft title"
108
- draft.save("some content")
109
- draft.publish!
110
-
111
- published_path = testing_dir("_posts/#{Date.today.to_s}-#{draft.slug}")
112
- File.exist?(published_path).should be_true
113
-
114
- # clean up
115
- FileUtils.rm_f(published_path)
116
- end
117
-
118
- it "creates the posts directory if it doens't already exist" do
119
- draft = D.new(@site)
120
- draft.slug = "test-draft"
121
- draft.title = "Some draft title"
122
- draft.save("some content")
123
-
124
- FileUtils.should_receive(:mkdir_p).with(testing_dir("_posts")).and_call_original
125
-
126
- begin
127
- draft.publish!
128
- ensure
129
- FileUtils.rm(draft.path)
130
- end
131
- end
132
-
133
- it "makes the post available in Site#posts and Site#to_liquid even straight after a generate" do
134
- draft = D.new(@site)
135
- draft.slug = "test-draft-to-go-into-liquid"
136
- draft.title = "Some draft title"
137
- draft.save("some content")
138
- published_path = testing_dir("_posts/#{Date.today.to_s}-#{draft.slug}")
139
-
140
- begin
141
- capture_stdout { @site.generate }
142
- @site.posts.first.slug.should_not == draft.slug
143
- @site.to_liquid["posts"].first.slug.should_not == draft.slug
144
- draft.publish!
145
- capture_stdout { @site.generate }
146
- @site.posts.first.slug.should == draft.slug
147
- @site.to_liquid["posts"].first.slug.should == draft.slug
148
- rescue
149
- # clean up
150
- FileUtils.rm_f(published_path)
151
- end
152
- end
153
-
154
- it "changes the #path to be _posts not _drafts" do
155
- draft = D.new(@site)
156
- draft.slug = "test-draft"
157
- draft.title = "Some draft title"
158
- draft.save("some content")
159
- draft.publish!
160
-
161
- draft.path.should == testing_dir("_posts/#{Date.today.to_s}-#{draft.slug}")
162
- draft.delete! # still deleteable, even though it's been moved
163
- end
164
-
165
- it "does not write out an autopublish header if autopublish? is true" do
166
- draft = D.new(@site)
167
- draft.slug = "autopublish-draft"
168
- draft.title = "Some draft title"
169
- draft.autopublish = true
170
- draft.save("some content")
171
- draft.publish!
172
-
173
- # check the header on the object has been removed
174
- draft.autopublish?.should be_false
175
-
176
- # check the actual file doesn't have the header
177
- Serif::Post.new(@site, draft.path).headers[:publish].should be_nil
178
-
179
- draft.delete!
180
- end
181
- end
182
-
183
- describe "#autopublish=" do
184
- it "sets the 'publish' header to 'now' if truthy assigned value" do
185
- draft = D.new(@site)
186
- draft.slug = "test-draft"
187
- draft.title = "Some draft title"
188
- draft.save("some content")
189
- draft.autopublish = true
190
-
191
- draft.headers[:publish].should == "now"
192
-
193
- draft.delete!
194
- end
195
-
196
- it "removes the 'publish' header entirely if falsey assigned value" do
197
- draft = D.new(@site)
198
- draft.slug = "test-draft"
199
- draft.title = "Some draft title"
200
- draft.save("some content")
201
- draft.autopublish = false
202
-
203
- draft.headers.key?(:publish).should be_false
204
-
205
- draft.delete!
206
- end
207
-
208
- it "carries its value through to #autopublish?" do
209
- draft = D.new(@site)
210
- draft.slug = "test-draft"
211
- draft.title = "Some draft title"
212
- draft.autopublish = false
213
- draft.autopublish?.should be_false
214
-
215
- draft.autopublish = true
216
- draft.autopublish?.should be_true
217
-
218
- draft.autopublish = false
219
- draft.autopublish?.should be_false
220
- end
221
- end
222
-
223
- describe "#autopublish?" do
224
- it "returns true if there is a 'publish: now' header, otherwise false" do
225
- draft = D.new(@site)
226
- draft.autopublish?.should be_false
227
- headers = draft.headers
228
- draft.stub(:headers) { headers.merge(:publish => "now") }
229
- draft.autopublish?.should be_true
230
- end
231
-
232
- it "ignores leading and trailing whitespace around the value of the 'publish' header" do
233
- draft = D.new(@site)
234
- draft.autopublish?.should be_false
235
- headers = draft.headers
236
- draft.stub(:headers) { headers.merge(:publish => " now ") }
237
- draft.autopublish?.should be_true
238
- end
239
- end
240
-
241
- describe "#to_liquid" do
242
- it "contains the relevant keys" do
243
- liq = @site.drafts.sample.to_liquid
244
-
245
- ["title", "content", "slug", "type", "draft", "published", "url"].each do |e|
246
- liq.key?(e).should be_true
247
- end
248
- end
249
-
250
- context "for an initial draft" do
251
- it "works fine" do
252
- expect { Serif::Draft.new(@site).to_liquid }.to_not raise_error
253
- end
254
- end
255
- end
256
-
257
- describe "#save" do
258
- it "saves the file to _drafts" do
259
- draft = D.new(@site)
260
- draft.slug = "test-draft"
261
- draft.title = "Some draft title"
262
-
263
- D.exist?(@site, draft.slug).should be_false
264
- File.exist?(testing_dir("_drafts/test-draft")).should be_false
265
-
266
- draft.save("some content")
267
-
268
- D.exist?(@site, draft.slug).should be_true
269
- File.exist?(testing_dir("_drafts/test-draft")).should be_true
270
-
271
- # clean up the file
272
- draft.delete!
273
- end
274
- end
275
- end