rollin 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +66 -12
- data/VERSION +1 -1
- data/lib/rollin/article.rb +39 -12
- data/lib/rollin/blog.rb +15 -0
- data/lib/rollin/metatag_key.rb +7 -0
- data/lib/rollin/metatag_value.rb +7 -0
- data/lib/rollin.rb +2 -0
- data/spec/fixtures/2013_05_01_My_first_post.mk +5 -0
- data/spec/fixtures/2013_06_01_My_third_post.mk +0 -1
- data/spec/fixtures/2014_01_01_My_fourth_post.mk +7 -1
- data/spec/rollin_spec.rb +61 -32
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2c32191bfacf8a3806320873f8616bcd527ac8c
|
4
|
+
data.tar.gz: f00eddf1f6e960db06dbb6c854a46fbb9be0e3f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6585b788143321aa37e98ad8d80530fc3733464439c0f0134fdab205d05798c1dc17dc11b5b0f7eb4e2536cf96ea48951931df1792a97d2c3632f75f4983ea51
|
7
|
+
data.tar.gz: 17803515ff2bf385fb0740b1bdbce0531c62df2a412a585f5f2e487ca56b5b7b5e114c0cf56ca686b56b0c2b59c5f5839611b11ed7d9be13c4d5abd91fe241b2
|
data/README.md
CHANGED
@@ -25,18 +25,72 @@ First you will need to have the following structure in your filesystem.
|
|
25
25
|
|
26
26
|
blog = Rollin::Blog.new({articles_folder: "posts"}) # Defaults to "articles"
|
27
27
|
|
28
|
-
|
28
|
+
article = blog.articles.first
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
article.id # => "2013_05_01_My_first_post"
|
31
|
+
article.title # => "My first post"
|
32
|
+
article.body # => "<h3>My first post!</h3>\n<p>blah blah blah</p>"
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
article.date # => #<Date: 2013-05-01 ((2456414j,0s,0n),+0s,2299161j)>
|
35
|
+
article.year # => 2013
|
36
|
+
article.month # => 05
|
37
|
+
article.day # => 01
|
38
38
|
|
39
|
-
###
|
39
|
+
### Metatags
|
40
|
+
|
41
|
+
You may define articles metatags at the begging of your article with the format:
|
42
|
+
|
43
|
+
---
|
44
|
+
author: Zé
|
45
|
+
title: My new awesome blog!
|
46
|
+
tags: development, fun
|
47
|
+
---
|
48
|
+
|
49
|
+
This is how you access the tag information.
|
50
|
+
|
51
|
+
article.metatags # => { 'title' => 'My new awesome blog!',
|
52
|
+
'author' => 'Zé',
|
53
|
+
'tags' => [ 'development', 'fun' ] }
|
54
|
+
|
55
|
+
|
56
|
+
It is YAML snippet and follows a similar format to Jekyll's [yaml front matter](https://github.com/mojombo/jekyll/wiki/yaml-front-matter). Except that our special variables are different:
|
57
|
+
|
58
|
+
| Metatag | Description |
|
59
|
+
|:------- |:----------- |
|
60
|
+
| title | The article title. It overrides the on extracted from the file name. |
|
61
|
+
|
62
|
+
### Inquiring metatags
|
63
|
+
|
64
|
+
blog.metatags # => A list of metatag objects
|
65
|
+
|
66
|
+
author_metatag = blog.metatags.first
|
67
|
+
|
68
|
+
author_metatag.label # => "tags"
|
69
|
+
author_metatag.values # => A list of metatag value objects
|
70
|
+
|
71
|
+
author_metatag_value = metatag.values.fist
|
72
|
+
author_metatag_value.content # => "Zé"
|
73
|
+
author_metatag_value.articles # => A list of articles containing that metatag value
|
74
|
+
|
75
|
+
### Finding a articles
|
76
|
+
|
77
|
+
#### By article id
|
78
|
+
|
79
|
+
blog.article('2013_05_01_My_first_post') # => #Rollin::Article(:title => "My first post" ...)
|
80
|
+
|
81
|
+
#### By tag
|
82
|
+
|
83
|
+
blog.articles(:tags => "development") # => A list of articles tagged with development
|
84
|
+
|
85
|
+
#### By date
|
86
|
+
|
87
|
+
blog.articles(:year => 2013) # => A list of articles for that year
|
88
|
+
blog.articles(:year => 2013, :month => 5) # => A list of articles for that month
|
89
|
+
blog.articles(:year => 2013, :month => 5, :day => 1) # => A list of articles for that day
|
90
|
+
|
91
|
+
### Archive
|
92
|
+
|
93
|
+
#### Monthly
|
40
94
|
|
41
95
|
may_archive = blog.monthly_archive.first
|
42
96
|
|
@@ -44,7 +98,7 @@ First you will need to have the following structure in your filesystem.
|
|
44
98
|
may_archive.month # => 5
|
45
99
|
may_archive.articles # => [ Rollin::Article(:title => "My first post" ...) ]
|
46
100
|
|
47
|
-
|
101
|
+
#### Annual
|
48
102
|
|
49
103
|
twenty_thirteen_archive = blog.annual_archive.first
|
50
104
|
|
@@ -52,9 +106,9 @@ First you will need to have the following structure in your filesystem.
|
|
52
106
|
twenty_thirteen_archive.articles # => [ Rollin::Article(:title => "My first post" ...) ]
|
53
107
|
twenty_thirteen_archive.monthly_archive # => [ Rollin::MonthArchive(:year => 2013, :month => 5 ...) ]
|
54
108
|
|
55
|
-
###
|
109
|
+
### More datailed documentation
|
56
110
|
|
57
|
-
|
111
|
+
You can find a more detailed documentation at the [rollin_spec.rb](https://github.com/marano/rollin/blob/master/spec/rollin_spec.rb) file.
|
58
112
|
|
59
113
|
## Build status
|
60
114
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/rollin/article.rb
CHANGED
@@ -12,13 +12,14 @@ class Rollin::Article
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def title
|
15
|
-
metatags[
|
15
|
+
metatags['title'] || @title_from_filename
|
16
16
|
end
|
17
17
|
|
18
18
|
def matches?(search)
|
19
|
-
search = search.clone
|
20
|
-
|
21
19
|
return true if @id == search
|
20
|
+
return false if @searh.is_a? String
|
21
|
+
|
22
|
+
search = search.clone
|
22
23
|
|
23
24
|
if search.has_key?(:year)
|
24
25
|
return false if search.delete(:year) != @year
|
@@ -30,6 +31,8 @@ class Rollin::Article
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
34
|
+
search = search.inject({}) { |memo, (k,v)| memo[k.to_s] = v; memo }
|
35
|
+
|
33
36
|
if search.keys.empty?
|
34
37
|
return true
|
35
38
|
else
|
@@ -41,20 +44,15 @@ class Rollin::Article
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def metatags
|
44
|
-
|
47
|
+
file = read_from_file
|
48
|
+
return {} unless file.has_front_matter?
|
45
49
|
begin
|
46
|
-
|
47
|
-
|
48
|
-
if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
49
|
-
content = $POSTMATCH
|
50
|
-
return YAML.safe_load($1).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
51
|
-
end
|
50
|
+
return YAML.safe_load(file.yaml_front_matter)
|
52
51
|
rescue SyntaxError => e
|
53
52
|
puts "YAML Exception reading #{File.join(@source_file)}: #{e.message}"
|
54
53
|
rescue Exception => e
|
55
54
|
puts "Error reading file #{File.join(@source_file)}: #{e.message}"
|
56
55
|
end
|
57
|
-
|
58
56
|
return {}
|
59
57
|
end
|
60
58
|
|
@@ -67,6 +65,35 @@ class Rollin::Article
|
|
67
65
|
autolink: true,
|
68
66
|
space_after_headers: true,
|
69
67
|
hard_wrap: true)
|
70
|
-
redcarpet.render(
|
68
|
+
redcarpet.render(read_from_file.content)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def read_from_file
|
74
|
+
raw = File.read(@source_file)
|
75
|
+
|
76
|
+
# Stolen from Jekyll
|
77
|
+
if raw =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
78
|
+
content = $POSTMATCH
|
79
|
+
yaml_front_matter = $1
|
80
|
+
content = raw[yaml_front_matter.size + 3, raw.size - 1]
|
81
|
+
FileContent.new(yaml_front_matter, content)
|
82
|
+
else
|
83
|
+
FileContent.new(nil, raw)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class FileContent
|
89
|
+
attr_reader :yaml_front_matter, :content
|
90
|
+
|
91
|
+
def initialize(yaml_front_matter, content)
|
92
|
+
@yaml_front_matter = yaml_front_matter
|
93
|
+
@content = content
|
94
|
+
end
|
95
|
+
|
96
|
+
def has_front_matter?
|
97
|
+
!yaml_front_matter.nil?
|
71
98
|
end
|
72
99
|
end
|
data/lib/rollin/blog.rb
CHANGED
@@ -15,6 +15,21 @@ class Rollin::Blog
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def metatags
|
19
|
+
metatag_labels = articles.map do |article|
|
20
|
+
article.metatags.keys
|
21
|
+
end.flatten.uniq
|
22
|
+
|
23
|
+
metatag_labels.map do |metatag_label|
|
24
|
+
values = articles.select { |article| article.metatags.has_key?(metatag_label) }.map do |article|
|
25
|
+
article.metatags[metatag_label]
|
26
|
+
end.flatten.uniq.map do |metatag_content|
|
27
|
+
Rollin::MetatagValue.new(metatag_content, articles(metatag_label => metatag_content))
|
28
|
+
end
|
29
|
+
Rollin::MetatagKey.new(metatag_label, values)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
18
33
|
def annual_archive
|
19
34
|
monthly_archive.map { |month_archive| month_archive.year }.uniq.map do |year|
|
20
35
|
Rollin::YearArchive.new(year, monthly_archive.select { |aMonth| aMonth.year == year })
|
data/lib/rollin.rb
CHANGED
data/spec/rollin_spec.rb
CHANGED
@@ -11,10 +11,18 @@ describe 'how rollin works' do
|
|
11
11
|
|
12
12
|
subject (:blog) { Rollin::Blog.new(articles_folder: 'spec/fixtures') }
|
13
13
|
|
14
|
+
let (:first_article) { blog.articles.first }
|
15
|
+
let (:second_article) { blog.articles[1] }
|
16
|
+
let (:third_article) { blog.articles[2] }
|
17
|
+
let (:fourth_article) { blog.articles[3] }
|
18
|
+
|
19
|
+
let (:article_with_single_tag_metatag) { blog.articles[0] }
|
20
|
+
let (:article_with_title_metatag) { blog.articles[1] }
|
21
|
+
let (:article_with_multiple_tag_metatag) { blog.articles[2] }
|
22
|
+
let (:article_with_published_metatag) { blog.articles[3] }
|
23
|
+
|
14
24
|
context 'article content' do
|
15
25
|
let (:article) { blog.articles.first }
|
16
|
-
let (:article_with_title_metatag) { blog.articles[1] }
|
17
|
-
let (:article_with_custom_metatags) { blog.articles[2] }
|
18
26
|
|
19
27
|
it 'exposes article information and content' do
|
20
28
|
article.id.should == '2013_05_01_My_first_post'
|
@@ -24,7 +32,7 @@ describe 'how rollin works' do
|
|
24
32
|
article.day.should == 1
|
25
33
|
article.date.should == Date.new(2013, 5, 1)
|
26
34
|
article.body.should == "<h2>This is my first post</h2>\n\n<p>And here we go!</p>\n"
|
27
|
-
article.metatags.should
|
35
|
+
article.metatags.should == { 'tags' => [ 'manero' ] }
|
28
36
|
end
|
29
37
|
|
30
38
|
it 'allows article title definition with metatag' do
|
@@ -32,32 +40,34 @@ describe 'how rollin works' do
|
|
32
40
|
end
|
33
41
|
|
34
42
|
it 'exposes the list of defined metatags' do
|
35
|
-
|
43
|
+
article_with_multiple_tag_metatag.metatags.should == { 'tags' => ['manero', 'massa', 'bacana'] }
|
44
|
+
article_with_published_metatag.metatags.should == { 'published' => false }
|
36
45
|
end
|
37
46
|
end
|
38
47
|
|
39
48
|
context 'searching for articles' do
|
40
|
-
let (:first_article) { blog.articles.first }
|
41
|
-
let (:second_article) { blog.articles[1] }
|
42
|
-
let (:third_article) { blog.articles[2] }
|
43
|
-
let (:article_with_custom_metatags) { blog.articles[2] }
|
44
|
-
|
45
49
|
it 'searches by article id' do
|
46
50
|
blog.article('2013_05_01_My_first_post').should == first_article
|
47
51
|
end
|
48
52
|
|
49
53
|
it 'searches by metatags' do
|
50
|
-
blog.article(tags
|
51
|
-
blog.
|
54
|
+
blog.article(:tags => 'manero').should == article_with_single_tag_metatag
|
55
|
+
blog.article('tags' => 'manero').should == article_with_single_tag_metatag
|
56
|
+
|
57
|
+
blog.articles(:tags => 'manero').should == [ article_with_single_tag_metatag, article_with_multiple_tag_metatag ]
|
58
|
+
blog.articles('tags' => 'manero').should == [ article_with_single_tag_metatag, article_with_multiple_tag_metatag ]
|
59
|
+
|
60
|
+
blog.article(:published => false).should == article_with_published_metatag
|
61
|
+
blog.article('published' => false).should == article_with_published_metatag
|
52
62
|
|
53
|
-
blog.
|
54
|
-
blog.articles(published
|
63
|
+
blog.articles(:published => false).should == [ article_with_published_metatag ]
|
64
|
+
blog.articles('published' => false).should == [ article_with_published_metatag ]
|
55
65
|
end
|
56
66
|
|
57
67
|
it 'searches by date' do
|
58
|
-
blog.articles(year: 2013).should
|
59
|
-
blog.articles(year: 2013, month: 5).should
|
60
|
-
blog.articles(year: 2013, month: 5, day: 1).should
|
68
|
+
blog.articles(year: 2013).should == [ first_article, second_article, third_article ]
|
69
|
+
blog.articles(year: 2013, month: 5).should == [first_article, second_article ]
|
70
|
+
blog.articles(year: 2013, month: 5, day: 1).should == [ first_article ]
|
61
71
|
end
|
62
72
|
|
63
73
|
it 'narrows search by date when searching for metatags' do
|
@@ -66,6 +76,31 @@ describe 'how rollin works' do
|
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
79
|
+
context 'inquiring metatags' do
|
80
|
+
it 'shows a list of existent metatags' do
|
81
|
+
blog.should have(3).metatags
|
82
|
+
|
83
|
+
blog.metatags[0].label.should == 'tags'
|
84
|
+
blog.metatags[0].should have(3).values
|
85
|
+
blog.metatags[0].values[0].content.should == 'manero'
|
86
|
+
blog.metatags[0].values[0].articles.should == [ article_with_single_tag_metatag, article_with_multiple_tag_metatag ]
|
87
|
+
blog.metatags[0].values[1].content.should == 'massa'
|
88
|
+
blog.metatags[0].values[1].articles.should == [ article_with_multiple_tag_metatag ]
|
89
|
+
blog.metatags[0].values[2].content.should == 'bacana'
|
90
|
+
blog.metatags[0].values[2].articles.should == [ article_with_multiple_tag_metatag ]
|
91
|
+
|
92
|
+
blog.metatags[1].label.should == 'title'
|
93
|
+
blog.metatags[1].should have(1).values
|
94
|
+
blog.metatags[1].values[0].content.should == 'This is a super post!'
|
95
|
+
blog.metatags[1].values[0].articles.should == [ article_with_title_metatag ]
|
96
|
+
|
97
|
+
blog.metatags[2].label.should == 'published'
|
98
|
+
blog.metatags[2].should have(1).values
|
99
|
+
blog.metatags[2].values[0].content.should == false
|
100
|
+
blog.metatags[2].values[0].articles.should == [ article_with_published_metatag ]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
69
104
|
context 'listing articles' do
|
70
105
|
let (:first_article) { TestArticle.new(id: '2013_05_01_My_first_post', title: 'My first post', date: Date.new(2013, 5, 1)) }
|
71
106
|
let (:second_article) { TestArticle.new(id: '2013_05_02_My_second_post', title: 'This is a super post!', date: Date.new(2013, 5, 2)) }
|
@@ -80,50 +115,44 @@ describe 'how rollin works' do
|
|
80
115
|
blog.articles[2].should == third_article
|
81
116
|
blog.articles[3].should == fourth_article
|
82
117
|
end
|
118
|
+
end
|
83
119
|
|
120
|
+
context 'archive' do
|
84
121
|
it 'provides monthly archive' do
|
85
122
|
blog.monthly_archive.should have(3).articles
|
86
123
|
|
87
124
|
blog.monthly_archive[0].year.should == 2013
|
88
125
|
blog.monthly_archive[0].month.should == 5
|
89
|
-
blog.monthly_archive[0].should
|
90
|
-
blog.monthly_archive[0].articles.should include(first_article, second_article)
|
126
|
+
blog.monthly_archive[0].articles.should == [ first_article, second_article ]
|
91
127
|
|
92
128
|
blog.monthly_archive[1].year.should == 2013
|
93
129
|
blog.monthly_archive[1].month.should == 6
|
94
|
-
blog.monthly_archive[1].should
|
95
|
-
blog.monthly_archive[1].articles.should include(third_article)
|
130
|
+
blog.monthly_archive[1].articles.should == [ third_article ]
|
96
131
|
|
97
132
|
blog.monthly_archive[2].year.should == 2014
|
98
133
|
blog.monthly_archive[2].month.should == 1
|
99
|
-
blog.monthly_archive[2].should
|
100
|
-
blog.monthly_archive[2].articles.should include(fourth_article)
|
134
|
+
blog.monthly_archive[2].articles.should == [ fourth_article ]
|
101
135
|
end
|
102
136
|
|
103
137
|
it 'provides annual archive' do
|
104
138
|
blog.should have(2).annual_archive
|
105
139
|
|
106
140
|
blog.annual_archive[0].year.should == 2013
|
141
|
+
blog.annual_archive[0].articles.should == [ first_article, second_article, third_article ]
|
107
142
|
blog.annual_archive[0].should have(2).monthly_archive
|
108
143
|
blog.annual_archive[0].monthly_archive[0].year.should == 2013
|
109
144
|
blog.annual_archive[0].monthly_archive[0].month.should == 5
|
110
|
-
blog.annual_archive[0].monthly_archive[0].should
|
111
|
-
blog.annual_archive[0].monthly_archive[0].articles.should include(first_article, second_article)
|
145
|
+
blog.annual_archive[0].monthly_archive[0].articles.should == [ first_article, second_article ]
|
112
146
|
blog.annual_archive[0].monthly_archive[1].year.should == 2013
|
113
147
|
blog.annual_archive[0].monthly_archive[1].month.should == 6
|
114
|
-
blog.annual_archive[0].monthly_archive[1].should
|
115
|
-
blog.annual_archive[0].monthly_archive[1].articles.should include(third_article)
|
116
|
-
blog.annual_archive[0].should have(3).articles
|
117
|
-
blog.annual_archive[0].articles.should include(first_article, second_article, third_article)
|
148
|
+
blog.annual_archive[0].monthly_archive[1].articles.should == [ third_article ]
|
118
149
|
|
119
150
|
blog.annual_archive[1].year.should == 2014
|
151
|
+
blog.annual_archive[1].articles.should == [ fourth_article ]
|
120
152
|
blog.annual_archive[1].should have(1).monthly_archive
|
121
153
|
blog.annual_archive[1].monthly_archive[0].year.should == 2014
|
122
154
|
blog.annual_archive[1].monthly_archive[0].month.should == 1
|
123
|
-
blog.annual_archive[1].monthly_archive[0].should
|
124
|
-
blog.annual_archive[1].monthly_archive[0].articles.should include(fourth_article)
|
125
|
-
blog.annual_archive[1].should have(1).articles
|
126
|
-
blog.annual_archive[1].articles.should include(fourth_article)
|
155
|
+
blog.annual_archive[1].monthly_archive[0].articles.should == [ fourth_article ]
|
127
156
|
end
|
128
157
|
end
|
129
158
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rollin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- marano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -126,6 +126,8 @@ files:
|
|
126
126
|
- lib/rollin.rb
|
127
127
|
- lib/rollin/article.rb
|
128
128
|
- lib/rollin/blog.rb
|
129
|
+
- lib/rollin/metatag_key.rb
|
130
|
+
- lib/rollin/metatag_value.rb
|
129
131
|
- lib/rollin/month_archive.rb
|
130
132
|
- lib/rollin/version.rb
|
131
133
|
- lib/rollin/year_archive.rb
|