rollin 0.0.12 → 0.0.13
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 +9 -3
- data/VERSION +1 -1
- data/lib/rollin/blog.rb +11 -20
- data/lib/rollin/year_archive.rb +11 -0
- data/lib/rollin.rb +1 -0
- data/spec/blog_spec.rb +6 -2
- data/spec/fixtures/articles/2014_01_01_My_fourth_post.mk +1 -0
- data/spec/year_archive_spec.rb +17 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 049730c65afc7a862413afa2d4cb68e79ce28adb
|
4
|
+
data.tar.gz: 3dd7bd4326661904a43a8ad20c544fa4c738ffb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7d53f585e4e0493a00f526def30670eb2b95fff27d5c21479e5986965510009dd52341eb4c1d5f4ff249cbf648d433a25bb4ba0ddc5b042a26dbcf1fe567bce
|
7
|
+
data.tar.gz: 88612276e7ffe27f8e84f546bd99aa7e6e3eed8cc8b5dd90fc53fd9f5ce3a7411bb6886aa21c0a4e9e8c361de201cad0e1243656408106e73d80360ebde7a18f
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ First you will need to have the following structure in your filesystem.
|
|
21
21
|
├── my_posts
|
22
22
|
└── 2013_05_01_My_first_post.mk
|
23
23
|
|
24
|
-
### Getting articles
|
24
|
+
### Getting the articles
|
25
25
|
|
26
26
|
In your code.
|
27
27
|
|
@@ -29,12 +29,14 @@ In your code.
|
|
29
29
|
|
30
30
|
anArticle = blog.articles.first
|
31
31
|
|
32
|
+
anArticle.id # => "2013_05_01_My_first_post"
|
33
|
+
anArticle.title # => "My first post"
|
34
|
+
anArticle.body # => "<h3>My first post!</h3>\n<p>blah blah blah</p>"
|
35
|
+
|
32
36
|
anArticle.date # => #<Date: 2013-05-01 ((2456414j,0s,0n),+0s,2299161j)>
|
33
37
|
anArticle.year # => 2013
|
34
38
|
anArticle.month # => 05
|
35
39
|
anArticle.day # => 01
|
36
|
-
anArticle.title # => "My first post"
|
37
|
-
anArticle.body # => "<h3>My first post!</h3>\n<p>blah blah blah</p>"
|
38
40
|
|
39
41
|
### Getting the archive
|
40
42
|
|
@@ -44,6 +46,10 @@ In your code.
|
|
44
46
|
a_monthly_archive.month # => 5
|
45
47
|
a_monthly_archive.articles # => [ Rollin::Article(:title => "My first post" ...) ]
|
46
48
|
|
49
|
+
### Finding an article
|
50
|
+
|
51
|
+
blog.find_article_by_id('2013_05_01_My_first_post') # => #Rollin::Article(:title => "My first post" ...)
|
52
|
+
|
47
53
|
## Build status
|
48
54
|
|
49
55
|
[](https://travis-ci.org/marano/rollin)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
data/lib/rollin/blog.rb
CHANGED
@@ -13,27 +13,18 @@ class Rollin::Blog
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
if years.has_key?(article.year)
|
20
|
-
year = years[article.year]
|
21
|
-
if year.has_key?(article.month)
|
22
|
-
year[article.month] << article
|
23
|
-
else
|
24
|
-
year[article.month] = [ article ]
|
25
|
-
end
|
26
|
-
else
|
27
|
-
years[article.year] = { article.month => [ article ] }
|
28
|
-
end
|
16
|
+
def annually_archive
|
17
|
+
monthly_archive.map { |month_archive| month_archive.year }.uniq.map do |year|
|
18
|
+
Rollin::YearArchive.new(year, monthly_archive.map { |aMonth| aMonth.year == year })
|
29
19
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
20
|
+
end
|
21
|
+
|
22
|
+
def monthly_archive
|
23
|
+
articles.map { |article| [article.year, article.month] }.uniq.map do |year_and_month|
|
24
|
+
year = year_and_month[0]
|
25
|
+
month = year_and_month[1]
|
26
|
+
articles_for_month = articles.map { |anArticle| anArticle.year == year && anArticle.month }
|
27
|
+
Rollin::MonthArchive.new(year, month, articles_for_month)
|
36
28
|
end
|
37
|
-
return archives_list
|
38
29
|
end
|
39
30
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Rollin::YearArchive
|
2
|
+
attr_reader :year, :monthly_archive
|
3
|
+
|
4
|
+
def initialize(year, monthly_archive)
|
5
|
+
@year, @monthly_archive = year, monthly_archive
|
6
|
+
end
|
7
|
+
|
8
|
+
def articles
|
9
|
+
monthly_archive.map { |month_archive| month_archive.articles }.flatten
|
10
|
+
end
|
11
|
+
end
|
data/lib/rollin.rb
CHANGED
data/spec/blog_spec.rb
CHANGED
@@ -5,11 +5,15 @@ describe Rollin::Blog do
|
|
5
5
|
subject (:blog) { Rollin::Blog.new(articles_folder: 'spec/fixtures/articles') }
|
6
6
|
|
7
7
|
it 'has the right amount of articles' do
|
8
|
-
blog.articles.size.should ==
|
8
|
+
blog.articles.size.should == 4
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'has the right amount of monthly archives' do
|
12
|
-
blog.monthly_archive.size.should ==
|
12
|
+
blog.monthly_archive.size.should == 3
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'has the right amount of yearly archives' do
|
16
|
+
blog.annually_archive.size.should == 2
|
13
17
|
end
|
14
18
|
|
15
19
|
it 'finds article by its id' do
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe Rollin::YearArchive do
|
2
|
+
let (:article) { Rollin::Article.new('spec/fixtures/2013_05_01_My_first_post.mk') }
|
3
|
+
subject (:month_archive) { Rollin::MonthArchive.new(2013, 05, [ article ]) }
|
4
|
+
subject (:year_archive) { Rollin::YearArchive.new(2013, [ month_archive ]) }
|
5
|
+
|
6
|
+
it 'tells the year' do
|
7
|
+
year_archive.year.should == 2013
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'has monthly archives' do
|
11
|
+
year_archive.monthly_archive.size.should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has a list of articles' do
|
15
|
+
year_archive.articles.first.should == article
|
16
|
+
end
|
17
|
+
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.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- marano
|
@@ -100,14 +100,17 @@ files:
|
|
100
100
|
- lib/rollin/blog.rb
|
101
101
|
- lib/rollin/month_archive.rb
|
102
102
|
- lib/rollin/version.rb
|
103
|
+
- lib/rollin/year_archive.rb
|
103
104
|
- rollin.gemspec
|
104
105
|
- spec/article_spec.rb
|
105
106
|
- spec/blog_spec.rb
|
106
107
|
- spec/fixtures/articles/2013_05_01_My_first_post.mk
|
107
108
|
- spec/fixtures/articles/2013_05_02_My_second_post.mk
|
108
109
|
- spec/fixtures/articles/2013_06_01_My_third_post.mk
|
110
|
+
- spec/fixtures/articles/2014_01_01_My_fourth_post.mk
|
109
111
|
- spec/month_archive_spec.rb
|
110
112
|
- spec/spec_helper.rb
|
113
|
+
- spec/year_archive_spec.rb
|
111
114
|
homepage: http://github.com/marano/rollin
|
112
115
|
licenses:
|
113
116
|
- MIT
|
@@ -138,5 +141,7 @@ test_files:
|
|
138
141
|
- spec/fixtures/articles/2013_05_01_My_first_post.mk
|
139
142
|
- spec/fixtures/articles/2013_05_02_My_second_post.mk
|
140
143
|
- spec/fixtures/articles/2013_06_01_My_third_post.mk
|
144
|
+
- spec/fixtures/articles/2014_01_01_My_fourth_post.mk
|
141
145
|
- spec/month_archive_spec.rb
|
142
146
|
- spec/spec_helper.rb
|
147
|
+
- spec/year_archive_spec.rb
|