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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1f08424b6aa0754fe3ac1911e0e14325fb656c0
4
- data.tar.gz: ec44591799d4d3d1754d33d3e88a783374312a42
3
+ metadata.gz: aed1e3b07b9118c3ef734f8e27bbefc779344735
4
+ data.tar.gz: 2cf1e9f7bb365927af183e2ca8bd027549a900ae
5
5
  SHA512:
6
- metadata.gz: 35098a90e5468154cf7abcf2b33de1404485e0235a78c5baeb948c5450b5adc52f41ab7c4e6f8c97547e6b94b2fec0da8c24f4f26e463ecd01234b6d3cb5664b
7
- data.tar.gz: 51f989a668f92fd7f0165b0dd06241641f524493ae3af83dd929d36da0fa01ccf5d38171661cf5d799fe9be84922914fdf577845a4be6c7ea79fdb5e2105bad7
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 | Description |
59
- |:------- |:----------- |
60
- | title | The article title. It overrides the on extracted from the file name. |
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.3
1
+ 0.1.4
@@ -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 true if @id == search
20
- return false if search.is_a? String
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
- search = search.clone
27
+ return false unless published? || show_unpublished?(search)
23
28
 
24
- if search.has_key?(:year)
25
- return false if search.delete(:year) != @year
26
- if search.has_key?(:month)
27
- return false if search.delete(:month) != @month
28
- if search.has_key?(:day)
29
- return false if search.delete(:day) != @day
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
- read_articles.find { |article| article.matches?(search) }
6
+ def article(search = {})
7
+ unfiltered_articles.find { |article| article.matches?(search) }
8
8
  end
9
9
 
10
- def articles(search=nil)
11
- if search.nil?
12
- read_articles
13
- else
14
- read_articles.select { |article| article.matches?(search) }
15
- end
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 = articles.map do |article|
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 = articles.select { |article| article.metatags.has_key?(metatag_label) }.map do |article|
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))
@@ -0,0 +1,3 @@
1
+ ## This is my fourth post
2
+
3
+ Really awesome!!
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.first }
15
- let (:second_article) { blog.articles[1] }
16
- let (:third_article) { blog.articles[2] }
17
- let (:fourth_article) { blog.articles[3] }
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[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] }
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.first }
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
- article_with_published_metatag.metatags.should == { 'published' => false }
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 == article_with_single_tag_metatag
56
- blog.article('tags' => 'manero').should == article_with_single_tag_metatag
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 == [ article_with_single_tag_metatag, article_with_multiple_tag_metatag ]
59
- blog.articles('tags' => 'manero').should == [ article_with_single_tag_metatag, article_with_multiple_tag_metatag ]
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 == article_with_published_metatag
62
- blog.article('published' => false).should == article_with_published_metatag
63
+ blog.article(:published => false).should == unpublished_article
64
+ blog.article('published' => false).should == unpublished_article
63
65
 
64
- blog.articles(:published => false).should == [ article_with_published_metatag ]
65
- blog.articles('published' => false).should == [ article_with_published_metatag ]
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 == [ first_article, second_article, third_article ]
70
- blog.articles(year: 2013, month: 5).should == [first_article, second_article ]
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 == 'tags'
85
- blog.metatags[0].should have(3).values
86
- blog.metatags[0].values[0].content.should == 'manero'
87
- blog.metatags[0].values[0].articles.should == [ article_with_single_tag_metatag, article_with_multiple_tag_metatag ]
88
- blog.metatags[0].values[1].content.should == 'massa'
89
- blog.metatags[0].values[1].articles.should == [ article_with_multiple_tag_metatag ]
90
- blog.metatags[0].values[2].content.should == 'bacana'
91
- blog.metatags[0].values[2].articles.should == [ article_with_multiple_tag_metatag ]
92
-
93
- blog.metatags[1].label.should == 'title'
94
- blog.metatags[1].should have(1).values
95
- blog.metatags[1].values[0].content.should == 'This is a super post!'
96
- blog.metatags[1].values[0].articles.should == [ article_with_title_metatag ]
97
-
98
- blog.metatags[2].label.should == 'published'
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 == false
101
- blog.metatags[2].values[0].articles.should == [ article_with_published_metatag ]
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 (:fourth_article) { TestArticle.new(id: '2014_01_01_My_fourth_post', title: 'My fourth post', date: Date.new(2014, 1, 1)) }
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 == first_article
115
- blog.articles[1].should == second_article
116
- blog.articles[2].should == third_article
117
- blog.articles[3].should == fourth_article
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 == 2013
126
- blog.monthly_archive[0].month.should == 5
127
- blog.monthly_archive[0].articles.should == [ first_article, second_article ]
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 == 2014
134
- blog.monthly_archive[2].month.should == 1
135
- blog.monthly_archive[2].articles.should == [ fourth_article ]
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 == 2013
142
- blog.annual_archive[0].articles.should == [ first_article, second_article, third_article ]
143
- blog.annual_archive[0].should have(2).monthly_archive
144
- blog.annual_archive[0].monthly_archive[0].year.should == 2013
145
- blog.annual_archive[0].monthly_archive[0].month.should == 5
146
- blog.annual_archive[0].monthly_archive[0].articles.should == [ first_article, second_article ]
147
- blog.annual_archive[0].monthly_archive[1].year.should == 2013
148
- blog.annual_archive[0].monthly_archive[1].month.should == 6
149
- blog.annual_archive[0].monthly_archive[1].articles.should == [ third_article ]
150
-
151
- blog.annual_archive[1].year.should == 2014
152
- blog.annual_archive[1].articles.should == [ fourth_article ]
153
- blog.annual_archive[1].should have(1).monthly_archive
154
- blog.annual_archive[1].monthly_archive[0].year.should == 2014
155
- blog.annual_archive[1].monthly_archive[0].month.should == 1
156
- blog.annual_archive[1].monthly_archive[0].articles.should == [ fourth_article ]
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.3
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/2014_01_01_My_fourth_post.mk
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.3
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/2014_01_01_My_fourth_post.mk
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