rollin 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/VERSION +1 -1
- data/lib/rollin/article.rb +18 -11
- data/lib/rollin/blog.rb +10 -10
- data/spec/fixtures/{2014_01_01_My_fourth_post.mk → 2013_07_01_My_fourth_post.mk} +0 -0
- data/spec/fixtures/2014_01_01_My_fifth_post.mk +3 -0
- data/spec/rollin_spec.rb +67 -64
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aed1e3b07b9118c3ef734f8e27bbefc779344735
|
4
|
+
data.tar.gz: 2cf1e9f7bb365927af183e2ca8bd027549a900ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c50295fe5f6d471fc089d35df1c52c16c7ba1673711b27466406d28a142707b61a68489aa3fcbdfc5389c54780498967897b4a25978b1f19483e3b84dd221c76
|
7
|
+
data.tar.gz: 1f5e8c574977eefd769dd9ebe00d1980cd5aa9e5f8449f5b752875c94ac632b4ce2a4fafd5dccaa5e457a01defa23db65f3996db0e66c7d4527ad98c09804302
|
data/README.md
CHANGED
@@ -55,9 +55,10 @@ This is how you access the tag information.
|
|
55
55
|
|
56
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
57
|
|
58
|
-
| Metatag
|
59
|
-
|
60
|
-
| title
|
58
|
+
| Metatag | Description |
|
59
|
+
|:----------- |:----------- |
|
60
|
+
| title | The article title. It overrides the extracted title from the file name. |
|
61
|
+
| published | If the article is published. Defaults to "yes". Set it to "no" or "false" to hide an article. |
|
61
62
|
|
62
63
|
### Inquiring metatags
|
63
64
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/rollin/article.rb
CHANGED
@@ -11,28 +11,31 @@ class Rollin::Article
|
|
11
11
|
@day = filename[8, 2].to_i
|
12
12
|
end
|
13
13
|
|
14
|
+
def published?
|
15
|
+
!metatags.has_key?('published') || metatags['published'] == 'true'
|
16
|
+
end
|
17
|
+
|
14
18
|
def title
|
15
19
|
metatags['title'] || @title_from_filename
|
16
20
|
end
|
17
21
|
|
18
22
|
def matches?(search)
|
19
|
-
return
|
20
|
-
|
23
|
+
return @id == search if search.is_a? String
|
24
|
+
|
25
|
+
search = search.inject({}) { |hash, (k,v)| hash[k.to_s] = v; hash }
|
21
26
|
|
22
|
-
|
27
|
+
return false unless published? || show_unpublished?(search)
|
23
28
|
|
24
|
-
if search.has_key?(
|
25
|
-
return false if search.delete(
|
26
|
-
if search.has_key?(
|
27
|
-
return false if search.delete(
|
28
|
-
if search.has_key?(
|
29
|
-
return false if search.delete(
|
29
|
+
if search.has_key?('year')
|
30
|
+
return false if search.delete('year') != @year
|
31
|
+
if search.has_key?('month')
|
32
|
+
return false if search.delete('month') != @month
|
33
|
+
if search.has_key?('day')
|
34
|
+
return false if search.delete('day') != @day
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
34
|
-
search = search.inject({}) { |memo, (k,v)| memo[k.to_s] = v; memo }
|
35
|
-
|
36
39
|
if search.keys.empty?
|
37
40
|
return true
|
38
41
|
else
|
@@ -86,6 +89,10 @@ class Rollin::Article
|
|
86
89
|
FileContent.new(nil, raw)
|
87
90
|
end
|
88
91
|
end
|
92
|
+
|
93
|
+
def show_unpublished?(search)
|
94
|
+
search.has_key?('published') && search['published'].to_s != 'true' && search['published'] != 'yes'
|
95
|
+
end
|
89
96
|
end
|
90
97
|
|
91
98
|
class FileContent
|
data/lib/rollin/blog.rb
CHANGED
@@ -3,25 +3,25 @@ class Rollin::Blog
|
|
3
3
|
@articles_folder = options[:articles_folder] || 'articles'
|
4
4
|
end
|
5
5
|
|
6
|
-
def article(search)
|
7
|
-
|
6
|
+
def article(search = {})
|
7
|
+
unfiltered_articles.find { |article| article.matches?(search) }
|
8
8
|
end
|
9
9
|
|
10
|
-
def articles(search=
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
def articles(search = {})
|
11
|
+
unfiltered_articles.select { |article| article.matches?(search) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def unfiltered_articles
|
15
|
+
read_articles.reverse
|
16
16
|
end
|
17
17
|
|
18
18
|
def metatags
|
19
|
-
metatag_labels =
|
19
|
+
metatag_labels = unfiltered_articles.map do |article|
|
20
20
|
article.metatags.keys
|
21
21
|
end.flatten.uniq
|
22
22
|
|
23
23
|
metatag_labels.map do |metatag_label|
|
24
|
-
values =
|
24
|
+
values = unfiltered_articles.select { |article| article.metatags.has_key?(metatag_label) }.map do |article|
|
25
25
|
article.metatags[metatag_label]
|
26
26
|
end.flatten.uniq.map do |metatag_content|
|
27
27
|
Rollin::MetatagValue.new(metatag_content, articles(metatag_label => metatag_content))
|
File without changes
|
data/spec/rollin_spec.rb
CHANGED
@@ -6,23 +6,24 @@ require 'spec_helper'
|
|
6
6
|
# 2013_05_02_My_second_post.mk
|
7
7
|
# 2013_06_01_My_third_post.mk
|
8
8
|
# 2014_01_01_My_fourth_post.mk
|
9
|
+
# 2014_01_01_My_fifth_article.mk
|
9
10
|
|
10
11
|
describe 'how rollin works' do
|
11
12
|
|
12
13
|
subject (:blog) { Rollin::Blog.new(articles_folder: 'spec/fixtures') }
|
13
14
|
|
14
|
-
let (:first_article) { blog.articles
|
15
|
-
let (:second_article) { blog.articles[
|
16
|
-
let (:third_article) { blog.articles[
|
17
|
-
let (:
|
15
|
+
let (:first_article) { blog.articles[3] }
|
16
|
+
let (:second_article) { blog.articles[2] }
|
17
|
+
let (:third_article) { blog.articles[1] }
|
18
|
+
let (:fifth_article) { blog.articles[0] }
|
18
19
|
|
19
|
-
let (:article_with_single_tag_metatag) { blog.articles[
|
20
|
-
let (:article_with_title_metatag) { blog.articles[
|
21
|
-
let (:article_with_multiple_tag_metatag) { blog.articles[
|
22
|
-
let (:
|
20
|
+
let (:article_with_single_tag_metatag) { blog.articles[3] }
|
21
|
+
let (:article_with_title_metatag) { blog.articles[2] }
|
22
|
+
let (:article_with_multiple_tag_metatag) { blog.articles[1] }
|
23
|
+
let (:unpublished_article) { blog.article(:published => false) }
|
23
24
|
|
24
25
|
context 'article content' do
|
25
|
-
let (:article) { blog.articles.
|
26
|
+
let (:article) { blog.articles.last }
|
26
27
|
|
27
28
|
it 'exposes article information and content' do
|
28
29
|
article.id.should == '2013_05_01_My_first_post'
|
@@ -31,6 +32,7 @@ describe 'how rollin works' do
|
|
31
32
|
article.month.should == 5
|
32
33
|
article.day.should == 1
|
33
34
|
article.date.should == Date.new(2013, 5, 1)
|
35
|
+
article.published?.should be_true
|
34
36
|
article.body.should == "<h2>This is my first post</h2>\n\n<p>And here we go!</p>\n"
|
35
37
|
article.metatags.should == { 'tags' => [ 'manero' ] }
|
36
38
|
end
|
@@ -41,7 +43,7 @@ describe 'how rollin works' do
|
|
41
43
|
|
42
44
|
it 'exposes the list of defined metatags' do
|
43
45
|
article_with_multiple_tag_metatag.metatags.should == { 'tags' => ['manero', 'massa', 'bacana'] }
|
44
|
-
|
46
|
+
unpublished_article.metatags.should == { 'published' => false }
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
@@ -52,22 +54,22 @@ describe 'how rollin works' do
|
|
52
54
|
end
|
53
55
|
|
54
56
|
it 'searches by metatags' do
|
55
|
-
blog.article(:tags => 'manero').should ==
|
56
|
-
blog.article('tags' => 'manero').should ==
|
57
|
+
blog.article(:tags => 'manero').should == article_with_multiple_tag_metatag
|
58
|
+
blog.article('tags' => 'manero').should == article_with_multiple_tag_metatag
|
57
59
|
|
58
|
-
blog.articles(:tags => 'manero').should == [
|
59
|
-
blog.articles('tags' => 'manero').should == [
|
60
|
+
blog.articles(:tags => 'manero').should == [ article_with_multiple_tag_metatag, article_with_single_tag_metatag ]
|
61
|
+
blog.articles('tags' => 'manero').should == [ article_with_multiple_tag_metatag, article_with_single_tag_metatag ]
|
60
62
|
|
61
|
-
blog.article(:published => false).should ==
|
62
|
-
blog.article('published' => false).should ==
|
63
|
+
blog.article(:published => false).should == unpublished_article
|
64
|
+
blog.article('published' => false).should == unpublished_article
|
63
65
|
|
64
|
-
blog.articles(:published => false).should == [
|
65
|
-
blog.articles('published' => false).should == [
|
66
|
+
blog.articles(:published => false).should == [ unpublished_article ]
|
67
|
+
blog.articles('published' => false).should == [ unpublished_article ]
|
66
68
|
end
|
67
69
|
|
68
70
|
it 'searches by date' do
|
69
|
-
blog.articles(year: 2013).should == [
|
70
|
-
blog.articles(year: 2013, month: 5).should == [
|
71
|
+
blog.articles(year: 2013).should == [ third_article, second_article, first_article ]
|
72
|
+
blog.articles(year: 2013, month: 5).should == [second_article, first_article ]
|
71
73
|
blog.articles(year: 2013, month: 5, day: 1).should == [ first_article ]
|
72
74
|
end
|
73
75
|
|
@@ -81,24 +83,24 @@ describe 'how rollin works' do
|
|
81
83
|
it 'shows a list of existent metatags' do
|
82
84
|
blog.should have(3).metatags
|
83
85
|
|
84
|
-
blog.metatags[0].label.should == '
|
85
|
-
blog.metatags[0].should have(
|
86
|
-
blog.metatags[0].values[0].content.should ==
|
87
|
-
blog.metatags[0].values[0].articles.should == [
|
88
|
-
|
89
|
-
blog.metatags[
|
90
|
-
blog.metatags[
|
91
|
-
blog.metatags[
|
92
|
-
|
93
|
-
blog.metatags[1].
|
94
|
-
blog.metatags[1].should
|
95
|
-
blog.metatags[1].values[0].content.should == '
|
96
|
-
blog.metatags[1].values[0].articles.should == [
|
97
|
-
|
98
|
-
blog.metatags[2].label.should == '
|
86
|
+
blog.metatags[0].label.should == 'published'
|
87
|
+
blog.metatags[0].should have(1).values
|
88
|
+
blog.metatags[0].values[0].content.should == false
|
89
|
+
blog.metatags[0].values[0].articles.should == [ unpublished_article ]
|
90
|
+
|
91
|
+
blog.metatags[1].label.should == 'tags'
|
92
|
+
blog.metatags[1].should have(3).values
|
93
|
+
blog.metatags[1].values[2].content.should == 'bacana'
|
94
|
+
blog.metatags[1].values[2].articles.should == [ article_with_multiple_tag_metatag ]
|
95
|
+
blog.metatags[1].values[1].content.should == 'massa'
|
96
|
+
blog.metatags[1].values[1].articles.should == [ article_with_multiple_tag_metatag ]
|
97
|
+
blog.metatags[1].values[0].content.should == 'manero'
|
98
|
+
blog.metatags[1].values[0].articles.should == [ article_with_multiple_tag_metatag, article_with_single_tag_metatag ]
|
99
|
+
|
100
|
+
blog.metatags[2].label.should == 'title'
|
99
101
|
blog.metatags[2].should have(1).values
|
100
|
-
blog.metatags[2].values[0].content.should ==
|
101
|
-
blog.metatags[2].values[0].articles.should == [
|
102
|
+
blog.metatags[2].values[0].content.should == 'This is a super post!'
|
103
|
+
blog.metatags[2].values[0].articles.should == [ article_with_title_metatag ]
|
102
104
|
end
|
103
105
|
end
|
104
106
|
|
@@ -106,15 +108,15 @@ describe 'how rollin works' do
|
|
106
108
|
let (:first_article) { TestArticle.new(id: '2013_05_01_My_first_post', title: 'My first post', date: Date.new(2013, 5, 1)) }
|
107
109
|
let (:second_article) { TestArticle.new(id: '2013_05_02_My_second_post', title: 'This is a super post!', date: Date.new(2013, 5, 2)) }
|
108
110
|
let (:third_article) { TestArticle.new(id: '2013_06_01_My_third_post', title: 'My third post', date: Date.new(2013, 6, 1)) }
|
109
|
-
let (:
|
111
|
+
let (:fifth_article) { TestArticle.new(id: '2014_01_01_My_fifth_post', title: 'My fifth post', date: Date.new(2014, 1, 1)) }
|
110
112
|
|
111
113
|
it 'lists all articles' do
|
112
114
|
blog.should have(4).articles
|
113
115
|
|
114
|
-
blog.articles[0].should ==
|
115
|
-
blog.articles[1].should ==
|
116
|
-
blog.articles[2].should ==
|
117
|
-
blog.articles[3].should ==
|
116
|
+
blog.articles[0].should == fifth_article
|
117
|
+
blog.articles[1].should == third_article
|
118
|
+
blog.articles[2].should == second_article
|
119
|
+
blog.articles[3].should == first_article
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
@@ -122,38 +124,39 @@ describe 'how rollin works' do
|
|
122
124
|
it 'provides monthly archive' do
|
123
125
|
blog.monthly_archive.should have(3).articles
|
124
126
|
|
125
|
-
blog.monthly_archive[0].year.should ==
|
126
|
-
blog.monthly_archive[0].month.should ==
|
127
|
-
blog.monthly_archive[0].articles.should == [
|
127
|
+
blog.monthly_archive[0].year.should == 2014
|
128
|
+
blog.monthly_archive[0].month.should == 1
|
129
|
+
blog.monthly_archive[0].articles.should == [ fifth_article ]
|
128
130
|
|
129
131
|
blog.monthly_archive[1].year.should == 2013
|
130
132
|
blog.monthly_archive[1].month.should == 6
|
131
133
|
blog.monthly_archive[1].articles.should == [ third_article ]
|
132
134
|
|
133
|
-
blog.monthly_archive[2].year.should ==
|
134
|
-
blog.monthly_archive[2].month.should ==
|
135
|
-
blog.monthly_archive[2].articles.should == [
|
135
|
+
blog.monthly_archive[2].year.should == 2013
|
136
|
+
blog.monthly_archive[2].month.should == 5
|
137
|
+
blog.monthly_archive[2].articles.should == [ second_article, first_article ]
|
136
138
|
end
|
137
139
|
|
138
140
|
it 'provides annual archive' do
|
139
141
|
blog.should have(2).annual_archive
|
140
142
|
|
141
|
-
blog.annual_archive[0].year.should ==
|
142
|
-
blog.annual_archive[0].articles.should == [
|
143
|
-
blog.annual_archive[0].should have(
|
144
|
-
blog.annual_archive[0].monthly_archive[0].year.should ==
|
145
|
-
blog.annual_archive[0].monthly_archive[0].month.should ==
|
146
|
-
blog.annual_archive[0].monthly_archive[0].articles.should == [
|
147
|
-
|
148
|
-
blog.annual_archive[
|
149
|
-
blog.annual_archive[
|
150
|
-
|
151
|
-
blog.annual_archive[1].year.should ==
|
152
|
-
blog.annual_archive[1].
|
153
|
-
blog.annual_archive[1].should
|
154
|
-
|
155
|
-
blog.annual_archive[1].monthly_archive[
|
156
|
-
blog.annual_archive[1].monthly_archive[
|
143
|
+
blog.annual_archive[0].year.should == 2014
|
144
|
+
blog.annual_archive[0].articles.should == [ fifth_article ]
|
145
|
+
blog.annual_archive[0].should have(1).monthly_archive
|
146
|
+
blog.annual_archive[0].monthly_archive[0].year.should == 2014
|
147
|
+
blog.annual_archive[0].monthly_archive[0].month.should == 1
|
148
|
+
blog.annual_archive[0].monthly_archive[0].articles.should == [ fifth_article ]
|
149
|
+
|
150
|
+
blog.annual_archive[1].year.should == 2013
|
151
|
+
blog.annual_archive[1].articles.should == [ third_article, second_article, first_article ]
|
152
|
+
blog.annual_archive[1].should have(2).monthly_archive
|
153
|
+
blog.annual_archive[1].monthly_archive[0].year.should == 2013
|
154
|
+
blog.annual_archive[1].monthly_archive[0].month.should == 6
|
155
|
+
blog.annual_archive[1].monthly_archive[0].articles.should == [ third_article ]
|
156
|
+
|
157
|
+
blog.annual_archive[1].monthly_archive[1].year.should == 2013
|
158
|
+
blog.annual_archive[1].monthly_archive[1].month.should == 5
|
159
|
+
blog.annual_archive[1].monthly_archive[1].articles.should == [ second_article, first_article ]
|
157
160
|
end
|
158
161
|
end
|
159
162
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- marano
|
@@ -135,7 +135,8 @@ files:
|
|
135
135
|
- spec/fixtures/2013_05_01_My_first_post.mk
|
136
136
|
- spec/fixtures/2013_05_02_My_second_post.mk
|
137
137
|
- spec/fixtures/2013_06_01_My_third_post.mk
|
138
|
-
- spec/fixtures/
|
138
|
+
- spec/fixtures/2013_07_01_My_fourth_post.mk
|
139
|
+
- spec/fixtures/2014_01_01_My_fifth_post.mk
|
139
140
|
- spec/rollin_spec.rb
|
140
141
|
- spec/spec_helper.rb
|
141
142
|
homepage: http://github.com/marano/rollin
|
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
version: '0'
|
159
160
|
requirements: []
|
160
161
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.0.
|
162
|
+
rubygems_version: 2.0.0
|
162
163
|
signing_key:
|
163
164
|
specification_version: 4
|
164
165
|
summary: A Ruby minimalistic blog engine ... WATTT!!?!??
|
@@ -166,6 +167,7 @@ test_files:
|
|
166
167
|
- spec/fixtures/2013_05_01_My_first_post.mk
|
167
168
|
- spec/fixtures/2013_05_02_My_second_post.mk
|
168
169
|
- spec/fixtures/2013_06_01_My_third_post.mk
|
169
|
-
- spec/fixtures/
|
170
|
+
- spec/fixtures/2013_07_01_My_fourth_post.mk
|
171
|
+
- spec/fixtures/2014_01_01_My_fifth_post.mk
|
170
172
|
- spec/rollin_spec.rb
|
171
173
|
- spec/spec_helper.rb
|