serum 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Gemfile +2 -0
  2. data/LICENSE +23 -0
  3. data/README.md +55 -0
  4. data/Rakefile +10 -0
  5. data/lib/serum.rb +71 -0
  6. data/lib/serum/core_ext.rb +68 -0
  7. data/lib/serum/errors.rb +4 -0
  8. data/lib/serum/mime.types +84 -0
  9. data/lib/serum/post.rb +177 -0
  10. data/lib/serum/site.rb +116 -0
  11. data/lib/serum/static_file.rb +53 -0
  12. data/serum.gemspec +85 -0
  13. data/test/helper.rb +26 -0
  14. data/test/source/2008-02-02-not-published.textile +8 -0
  15. data/test/source/2008-02-02-published.textile +8 -0
  16. data/test/source/2008-10-18-foo-bar.textile +8 -0
  17. data/test/source/2008-11-21-complex.textile +8 -0
  18. data/test/source/2008-12-03-permalinked-post.textile +9 -0
  19. data/test/source/2008-12-13-include.markdown +8 -0
  20. data/test/source/2009-01-27-array-categories.textile +10 -0
  21. data/test/source/2009-01-27-categories.textile +7 -0
  22. data/test/source/2009-01-27-category.textile +7 -0
  23. data/test/source/2009-01-27-empty-categories.textile +7 -0
  24. data/test/source/2009-01-27-empty-category.textile +7 -0
  25. data/test/source/2009-03-12-hash-#1.markdown +6 -0
  26. data/test/source/2009-05-18-empty-tag.textile +6 -0
  27. data/test/source/2009-05-18-empty-tags.textile +6 -0
  28. data/test/source/2009-05-18-tag.textile +6 -0
  29. data/test/source/2009-05-18-tags.textile +9 -0
  30. data/test/source/2009-05-24-yaml-linebreak.markdown +7 -0
  31. data/test/source/2009-06-22-empty-yaml.textile +3 -0
  32. data/test/source/2009-06-22-no-yaml.textile +1 -0
  33. data/test/source/2010-01-08-triple-dash.markdown +6 -0
  34. data/test/source/2010-01-09-date-override.textile +7 -0
  35. data/test/source/2010-01-09-time-override.textile +7 -0
  36. data/test/source/2010-01-09-timezone-override.textile +7 -0
  37. data/test/source/2010-01-16-override-data.textile +4 -0
  38. data/test/source/2011-04-12-md-extension.md +7 -0
  39. data/test/source/2011-04-12-text-extension.text +0 -0
  40. data/test/source/2013-01-02-post-excerpt.markdown +14 -0
  41. data/test/source/2013-01-12-nil-layout.textile +6 -0
  42. data/test/source/2013-01-12-no-layout.textile +5 -0
  43. data/test/suite.rb +11 -0
  44. data/test/test_core_ext.rb +88 -0
  45. data/test/test_post.rb +138 -0
  46. data/test/test_site.rb +68 -0
  47. metadata +194 -0
@@ -0,0 +1 @@
1
+ No YAML.
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Foo --- Bar
3
+ layout: post
4
+ ---
5
+
6
+ Triple the fun!
@@ -0,0 +1,7 @@
1
+ ---
2
+ date: 2010-01-10
3
+ ---
4
+
5
+ Post with a front matter date
6
+
7
+ {{ page.date | date_to_string }}
@@ -0,0 +1,7 @@
1
+ ---
2
+ date: 2010-01-10 13:07:09
3
+ ---
4
+
5
+ Post with a front matter time
6
+
7
+ {{ page.date | date_to_string }}
@@ -0,0 +1,7 @@
1
+ ---
2
+ date: 2010-01-10 13:07:09 +00:00
3
+ ---
4
+
5
+ Post with a front matter time with timezone
6
+
7
+ {{ page.date | date_to_string }}
@@ -0,0 +1,4 @@
1
+ ---
2
+ date: 2010-01-10 13:07:09
3
+ tags: A string
4
+ ---
@@ -0,0 +1,7 @@
1
+ ---
2
+ date: 2011-04-12 13:07:09
3
+ ---
4
+
5
+ under default configuration, this post should get processed by the identity converter. By changing
6
+ textile extension or markdown extension configuration parameters, you should be able to associate
7
+ it with either of those converters
@@ -0,0 +1,14 @@
1
+ ---
2
+ layout: ~
3
+ title: Post Excerpt
4
+ ---
5
+
6
+ First paragraph with [link ref][link].
7
+
8
+ Second paragraph
9
+
10
+ ---
11
+
12
+ Third paragraph
13
+
14
+ [link]: http://www.jekyllrb.com/
@@ -0,0 +1,6 @@
1
+ ---
2
+ layout: nil
3
+ title: No layout
4
+ ---
5
+
6
+ This post has no layout.
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: I have no layout
3
+ ---
4
+
5
+ This post will be rendered with the "post" layout.
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ gem 'test-unit'
3
+ require 'test/unit'
4
+
5
+ # for some reason these tests fail when run via TextMate
6
+ # but succeed when run on the command line.
7
+
8
+ tests = Dir[File.expand_path("#{File.dirname(__FILE__)}/test_*.rb")]
9
+ tests.each do |file|
10
+ require file
11
+ end
@@ -0,0 +1,88 @@
1
+ require 'helper'
2
+
3
+ class TestCoreExt < Test::Unit::TestCase
4
+ context "hash" do
5
+
6
+ context "pluralized_array" do
7
+
8
+ should "return empty array with no values" do
9
+ data = {}
10
+ assert_equal [], data.pluralized_array('tag', 'tags')
11
+ end
12
+
13
+ should "return empty array with no matching values" do
14
+ data = { 'foo' => 'bar' }
15
+ assert_equal [], data.pluralized_array('tag', 'tags')
16
+ end
17
+
18
+ should "return empty array with matching nil singular" do
19
+ data = { 'foo' => 'bar', 'tag' => nil, 'tags' => ['dog', 'cat'] }
20
+ assert_equal [], data.pluralized_array('tag', 'tags')
21
+ end
22
+
23
+ should "return single value array with matching singular" do
24
+ data = { 'foo' => 'bar', 'tag' => 'dog', 'tags' => ['dog', 'cat'] }
25
+ assert_equal ['dog'], data.pluralized_array('tag', 'tags')
26
+ end
27
+
28
+ should "return single value array with matching singular with spaces" do
29
+ data = { 'foo' => 'bar', 'tag' => 'dog cat', 'tags' => ['dog', 'cat'] }
30
+ assert_equal ['dog cat'], data.pluralized_array('tag', 'tags')
31
+ end
32
+
33
+ should "return empty array with matching nil plural" do
34
+ data = { 'foo' => 'bar', 'tags' => nil }
35
+ assert_equal [], data.pluralized_array('tag', 'tags')
36
+ end
37
+
38
+ should "return empty array with matching empty array" do
39
+ data = { 'foo' => 'bar', 'tags' => [] }
40
+ assert_equal [], data.pluralized_array('tag', 'tags')
41
+ end
42
+
43
+ should "return single value array with matching plural with single string value" do
44
+ data = { 'foo' => 'bar', 'tags' => 'dog' }
45
+ assert_equal ['dog'], data.pluralized_array('tag', 'tags')
46
+ end
47
+
48
+ should "return multiple value array with matching plural with single string value with spaces" do
49
+ data = { 'foo' => 'bar', 'tags' => 'dog cat' }
50
+ assert_equal ['dog', 'cat'], data.pluralized_array('tag', 'tags')
51
+ end
52
+
53
+ should "return single value array with matching plural with single value array" do
54
+ data = { 'foo' => 'bar', 'tags' => ['dog'] }
55
+ assert_equal ['dog'], data.pluralized_array('tag', 'tags')
56
+ end
57
+
58
+ should "return multiple value array with matching plural with multiple value array" do
59
+ data = { 'foo' => 'bar', 'tags' => ['dog', 'cat'] }
60
+ assert_equal ['dog', 'cat'], data.pluralized_array('tag', 'tags')
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ context "enumerable" do
68
+ context "glob_include?" do
69
+ should "return false with no glob patterns" do
70
+ assert ![].glob_include?("a.txt")
71
+ end
72
+
73
+ should "return false with all not match path" do
74
+ data = ["a*", "b?"]
75
+ assert !data.glob_include?("ca.txt")
76
+ assert !data.glob_include?("ba.txt")
77
+ end
78
+
79
+ should "return true with match path" do
80
+ data = ["a*", "b?", "**/a*"]
81
+ assert data.glob_include?("a.txt")
82
+ assert data.glob_include?("ba")
83
+ assert data.glob_include?("c/a/a.txt")
84
+ assert data.glob_include?("c/a/b/a.txt")
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,138 @@
1
+ require 'helper'
2
+
3
+ class TestPost < Test::Unit::TestCase
4
+ def setup_post(file)
5
+ Post.new(@site, source_dir, '', file)
6
+ end
7
+
8
+ context "A Post" do
9
+ setup do
10
+ @site = Site.new(Serum.configuration({'source' => source_dir}))
11
+ end
12
+
13
+ should "ensure valid posts are valid" do
14
+ assert Post.valid?("2008-09-09-foo-bar.textile")
15
+ assert Post.valid?("foo/bar/2008-09-09-foo-bar.textile")
16
+
17
+ assert !Post.valid?("lol2008-09-09-foo-bar.textile")
18
+ assert !Post.valid?("blah")
19
+ end
20
+
21
+ context "processing posts" do
22
+ setup do
23
+ @post = Post.allocate
24
+ @post.site = @site
25
+
26
+ @real_file = "2008-10-18-foo-bar.textile"
27
+ @fake_file = "2008-09-09-foo-bar.textile"
28
+ @source = source_dir('')
29
+ end
30
+
31
+ should "keep date, title, and markup type" do
32
+ @post.process(@fake_file)
33
+
34
+ assert_equal Time.parse("2008-09-09"), @post.date
35
+ assert_equal "foo-bar", @post.slug
36
+ assert_equal ".textile", @post.ext
37
+ end
38
+
39
+ should "raise a good error on invalid post date" do
40
+ assert_raise Serum::FatalException do
41
+ @post.process("2009-27-03-foo-bar.textile")
42
+ end
43
+ end
44
+
45
+ context "with CRLF linebreaks" do
46
+ setup do
47
+ @real_file = "2009-05-24-yaml-linebreak.markdown"
48
+ @source = source_dir('')
49
+ end
50
+ should "read yaml front-matter" do
51
+ @post.read_yaml(@source, @real_file)
52
+
53
+ assert_equal({"title" => "Test title", "layout" => "post", "tag" => "Ruby"}, @post.data)
54
+ end
55
+ end
56
+
57
+ context "with embedded triple dash" do
58
+ setup do
59
+ @real_file = "2010-01-08-triple-dash.markdown"
60
+ end
61
+ should "consume the embedded dashes" do
62
+ @post.read_yaml(@source, @real_file)
63
+
64
+ assert_equal({"title" => "Foo --- Bar", "layout" => "post"}, @post.data)
65
+ end
66
+ end
67
+
68
+ should "read yaml front-matter" do
69
+ @post.read_yaml(@source, @real_file)
70
+
71
+ assert_equal({"title" => "Foo Bar", "layout" => "default"}, @post.data)
72
+ end
73
+
74
+ end
75
+
76
+ context "when in a site" do
77
+ setup do
78
+ @site = Site.new(Serum.configuration({'source' => source_dir}))
79
+ @site.posts = [setup_post('2008-02-02-published.textile'),
80
+ setup_post('2009-01-27-categories.textile')]
81
+ end
82
+
83
+ should "have next post" do
84
+ assert_equal(@site.posts.last, @site.posts.first.next)
85
+ end
86
+
87
+ should "have previous post" do
88
+ assert_equal(@site.posts.first, @site.posts.last.previous)
89
+ end
90
+
91
+ should "not have previous post if first" do
92
+ assert_equal(nil, @site.posts.first.previous)
93
+ end
94
+
95
+ should "not have next post if last" do
96
+ assert_equal(nil, @site.posts.last.next)
97
+ end
98
+ end
99
+
100
+ context "initializing posts" do
101
+ should "publish when published yaml is no specified" do
102
+ post = setup_post("2008-02-02-published.textile")
103
+ assert_equal true, post.published
104
+ end
105
+
106
+ should "not published when published yaml is false" do
107
+ post = setup_post("2008-02-02-not-published.textile")
108
+ assert_equal false, post.published
109
+ end
110
+
111
+ should "recognize date in yaml" do
112
+ post = setup_post("2010-01-09-date-override.textile")
113
+ assert_equal Time, post.date.class
114
+ end
115
+
116
+ should "recognize time in yaml" do
117
+ post = setup_post("2010-01-09-time-override.textile")
118
+ assert_equal Time, post.date.class
119
+ end
120
+
121
+ should "recognize time with timezone in yaml" do
122
+ post = setup_post("2010-01-09-timezone-override.textile")
123
+ assert_equal Time, post.date.class
124
+ end
125
+
126
+ should "allow no yaml" do
127
+ post = setup_post("2009-06-22-no-yaml.textile")
128
+ assert_equal({}, post.data)
129
+ end
130
+
131
+ should "allow empty yaml" do
132
+ post = setup_post("2009-06-22-empty-yaml.textile")
133
+ assert_equal({}, post.data)
134
+ end
135
+ end
136
+ end
137
+
138
+ end
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+
3
+ class TestSite < Test::Unit::TestCase
4
+ context "configuring sites" do
5
+ should "expose default baseurl" do
6
+ site = Site.new(Serum::DEFAULTS.merge({'source' => source_dir}))
7
+ assert_equal Serum::DEFAULTS['baseurl'], site.baseurl
8
+ end
9
+
10
+ should "expose baseurl passed in from config" do
11
+ site = Site.new(Serum::DEFAULTS.merge({'baseurl' => '/blog', 'source' => source_dir}))
12
+ assert_equal '/blog', site.baseurl
13
+ end
14
+ end
15
+ context "creating sites" do
16
+ setup do
17
+ stub(Serum).configuration do
18
+ Serum::DEFAULTS.merge({'source' => source_dir})
19
+ end
20
+ @site = Site.new(Serum.configuration)
21
+ end
22
+
23
+ should "reset data before processing" do
24
+ @site.read_directories
25
+ before_posts = @site.posts.length
26
+ before_static_files = @site.static_files.length
27
+ before_time = @site.time
28
+
29
+ @site.read_directories
30
+ assert_equal before_posts, @site.posts.length
31
+ assert_equal before_static_files, @site.static_files.length
32
+ assert before_time <= @site.time
33
+ end
34
+
35
+ should "read posts" do
36
+ @site.reset
37
+ @site.read_posts('')
38
+ posts = Dir[source_dir('*')]
39
+ assert_equal posts.size - 1, @site.posts.size
40
+ end
41
+
42
+ should "filter entries" do
43
+ ent1 = %w[foo.markdown bar.markdown baz.markdown #baz.markdown#
44
+ .baz.markdow foo.markdown~]
45
+ ent2 = %w[.htaccess _posts _pages bla.bla]
46
+
47
+ assert_equal %w[foo.markdown bar.markdown baz.markdown], @site.filter_entries(ent1)
48
+ assert_equal %w[.htaccess bla.bla], @site.filter_entries(ent2)
49
+ end
50
+
51
+ should "filter entries with exclude" do
52
+ excludes = %w[README TODO]
53
+ files = %w[index.html site.css .htaccess]
54
+
55
+ @site.exclude = excludes + ["exclude*"]
56
+ assert_equal files, @site.filter_entries(excludes + files + ["excludeA"])
57
+ end
58
+
59
+ should "not filter entries within include" do
60
+ includes = %w[_index.html .htaccess include*]
61
+ files = %w[index.html _index.html .htaccess includeA]
62
+
63
+ @site.include = includes
64
+ assert_equal files, @site.filter_entries(files)
65
+ end
66
+
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: serum
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brad Fults
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: safe_yaml
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 10.0.3
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.11'
62
+ - !ruby/object:Gem::Dependency
63
+ name: redgreen
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.2'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.2'
78
+ - !ruby/object:Gem::Dependency
79
+ name: shoulda
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 3.3.2
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 3.3.2
94
+ - !ruby/object:Gem::Dependency
95
+ name: rr
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.0'
110
+ description: Serum is a simple object model on static posts with YAML front matter.
111
+ email: bfults@gmail.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files:
115
+ - README.md
116
+ - LICENSE
117
+ files:
118
+ - Gemfile
119
+ - LICENSE
120
+ - Rakefile
121
+ - lib/serum.rb
122
+ - lib/serum/core_ext.rb
123
+ - lib/serum/errors.rb
124
+ - lib/serum/mime.types
125
+ - lib/serum/post.rb
126
+ - lib/serum/site.rb
127
+ - lib/serum/static_file.rb
128
+ - serum.gemspec
129
+ - test/helper.rb
130
+ - test/source/2008-02-02-not-published.textile
131
+ - test/source/2008-02-02-published.textile
132
+ - test/source/2008-10-18-foo-bar.textile
133
+ - test/source/2008-11-21-complex.textile
134
+ - test/source/2008-12-03-permalinked-post.textile
135
+ - test/source/2008-12-13-include.markdown
136
+ - test/source/2009-01-27-array-categories.textile
137
+ - test/source/2009-01-27-categories.textile
138
+ - test/source/2009-01-27-category.textile
139
+ - test/source/2009-01-27-empty-categories.textile
140
+ - test/source/2009-01-27-empty-category.textile
141
+ - test/source/2009-03-12-hash-#1.markdown
142
+ - test/source/2009-05-18-empty-tag.textile
143
+ - test/source/2009-05-18-empty-tags.textile
144
+ - test/source/2009-05-18-tag.textile
145
+ - test/source/2009-05-18-tags.textile
146
+ - test/source/2009-05-24-yaml-linebreak.markdown
147
+ - test/source/2009-06-22-empty-yaml.textile
148
+ - test/source/2009-06-22-no-yaml.textile
149
+ - test/source/2010-01-08-triple-dash.markdown
150
+ - test/source/2010-01-09-date-override.textile
151
+ - test/source/2010-01-09-time-override.textile
152
+ - test/source/2010-01-09-timezone-override.textile
153
+ - test/source/2010-01-16-override-data.textile
154
+ - test/source/2011-04-12-md-extension.md
155
+ - test/source/2011-04-12-text-extension.text
156
+ - test/source/2013-01-02-post-excerpt.markdown
157
+ - test/source/2013-01-12-nil-layout.textile
158
+ - test/source/2013-01-12-no-layout.textile
159
+ - test/suite.rb
160
+ - test/test_core_ext.rb
161
+ - test/test_post.rb
162
+ - test/test_site.rb
163
+ - README.md
164
+ homepage: http://github.com/h3h/serum
165
+ licenses:
166
+ - MIT
167
+ post_install_message:
168
+ rdoc_options:
169
+ - --charset=UTF-8
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ! '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project: serum
186
+ rubygems_version: 1.8.24
187
+ signing_key:
188
+ specification_version: 2
189
+ summary: A simple object model on static posts with YAML front matter.
190
+ test_files:
191
+ - test/test_core_ext.rb
192
+ - test/test_post.rb
193
+ - test/test_site.rb
194
+ has_rdoc: