serum 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -43,11 +43,11 @@ a simple directory of posts.
43
43
 
44
44
  Maybe more aptly named "deleter" considering this project's origin.
45
45
 
46
- [Brad Fults](http://github.com/h3h) ([bfults@gmail.com][])
46
+ [Brad Fults](http://github.com/h3h) ([bfults@gmail.com](mailto:bfults@gmail.com))
47
47
 
48
48
  ## Acknowledgements
49
49
 
50
- Serum is based entirely on [Jekyll](http://jekyllrb.com/) from Tomm Preston-Werner.
50
+ Serum is based entirely on [Jekyll](http://jekyllrb.com/) from Tom Preston-Werner.
51
51
  Thank you, Tom.
52
52
 
53
53
  ## License
@@ -31,7 +31,7 @@ require 'serum/errors'
31
31
  SafeYAML::OPTIONS[:suppress_warnings] = true
32
32
 
33
33
  module Serum
34
- VERSION = '0.1.0'
34
+ VERSION = '0.2.0'
35
35
 
36
36
  # Default options.
37
37
  # Strings rather than symbols are used for compatability with YAML.
@@ -58,6 +58,10 @@ module Serum
58
58
  else
59
59
  self.published = true
60
60
  end
61
+
62
+ if self.data.has_key?('slug')
63
+ self.slug = self.data['slug']
64
+ end
61
65
  end
62
66
 
63
67
  # Read the YAML frontmatter.
@@ -1,7 +1,7 @@
1
1
  module Serum
2
2
  class Site
3
3
  attr_accessor :config, :posts, :static_files, :exclude, :include, :source
4
- attr_accessor :time, :baseurl
4
+ attr_accessor :time, :baseurl, :slugs_to_posts
5
5
 
6
6
  # Public: Initialize a new Site.
7
7
  #
@@ -29,6 +29,16 @@ module Serum
29
29
  end
30
30
  self.posts = []
31
31
  self.static_files = []
32
+ self.slugs_to_posts = {}
33
+ end
34
+
35
+ # Looks up a post by its slug.
36
+ #
37
+ # slug - A String denoting the slug for the post.
38
+ #
39
+ # Returns the found Post or nil.
40
+ def find_by_slug(slug)
41
+ self.slugs_to_posts[slug]
32
42
  end
33
43
 
34
44
  # Recursively traverse directories to find posts and static files
@@ -73,6 +83,7 @@ module Serum
73
83
 
74
84
  if post.published && post.date <= self.time
75
85
  self.posts << post
86
+ self.slugs_to_posts[post.slug] = post
76
87
  end
77
88
  end
78
89
  end
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'serum'
7
- s.version = '0.1.0'
7
+ s.version = '0.2.0'
8
8
  s.license = 'MIT'
9
9
  s.date = '2013-03-30'
10
10
  s.rubyforge_project = 'serum'
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  layout: ~
3
3
  title: Post Excerpt
4
+ slug: "gray-brains"
4
5
  ---
5
6
 
6
7
  First paragraph with [link ref][link].
@@ -65,6 +65,15 @@ class TestPost < Test::Unit::TestCase
65
65
  end
66
66
  end
67
67
 
68
+ context "with slug specified in YAML front matter" do
69
+ setup do
70
+ @post = setup_post("2013-01-02-post-excerpt.markdown")
71
+ end
72
+ should "allow the slug to be overridden by the YAML" do
73
+ assert_equal("gray-brains", @post.slug)
74
+ end
75
+ end
76
+
68
77
  should "read yaml front-matter" do
69
78
  @post.read_yaml(@source, @real_file)
70
79
 
@@ -64,5 +64,15 @@ class TestSite < Test::Unit::TestCase
64
64
  assert_equal files, @site.filter_entries(files)
65
65
  end
66
66
 
67
+ should "provide a find_by_slug method" do
68
+ post = @site.find_by_slug("complex")
69
+ assert_equal "2008-11-21-complex.textile", post.name
70
+ end
71
+
72
+ should "provide a find_by_slug method when the slug is overridden" do
73
+ post = @site.find_by_slug("gray-brains")
74
+ assert_equal "2013-01-02-post-excerpt.markdown", post.name
75
+ end
76
+
67
77
  end
68
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: