rollin 0.0.16 → 0.1.0

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: 5ade074bbfd7d18abfa9bca1ef589d5f3b56a099
4
- data.tar.gz: c336bc00ea0c729578e6a448a2074b3843f88a57
3
+ metadata.gz: eec28f29a0e5d44ec5f898ec1cc57a5e2ceb7309
4
+ data.tar.gz: 747351059a59ee276bb140861d2b742fc4c976b2
5
5
  SHA512:
6
- metadata.gz: ddd4e082b2aa1628ae152ca37e0f31eca19f0dd3aef2dceac5e7e7918e180097bd4e2e47732b9958484a8c1576e05438a90999e1f69dcc183d99f89d33adb400
7
- data.tar.gz: 68b8e9837ae7cb3fbd36d32cd4498c8529019069ca2a4bb2fd274be552114d8688c4250cc75f4f0002787c2e4034f0b505a1eab804374e610676a1f66506adc2
6
+ metadata.gz: cb937284f72d047aba71e4cda7a0e1ba18ef88b66a842c784ff7a97c916f3233da72ae190169752981e5fdf9a1ffdb63aee7ee6a9f3080a328e02bea71c4ad9d
7
+ data.tar.gz: 1cc3d83c410c5febc1df9cc58257c614db44748d97e71e1bf4942ff65c0b8cb15dd03e24b656c2c0d43dc577c9b9edac463f6461bd8f92828af8128b7a4b7a5c
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Rollin
1
+ # rollin
2
2
 
3
3
  A Ruby minimalistic filesystem based blog engine made for developers.
4
4
 
5
- Different from other blog engines Rollin only does what matters, and leave the rest to you.
5
+ Different from other blog engines, rollin only does what matters, and leave the rest to you.
6
6
 
7
- Rollin currently only supports Markdown format and uses the Github's awesome redcarpet.
7
+ It currently supports Markdown format and uses the Github's awesome redcarpet.
8
8
 
9
9
  ## Installation
10
10
 
@@ -18,41 +18,39 @@ Add the dependency to your Gemfile:
18
18
 
19
19
  First you will need to have the following structure in your filesystem.
20
20
 
21
- ├── my_posts
21
+ ├── posts
22
22
  └── 2013_05_01_My_first_post.mk
23
23
 
24
24
  ### Articles
25
-
26
- In your code.
27
25
 
28
- blog = Rollin::Blog.new({article_folder: "my_posts"}) # Defaults to "articles"
26
+ blog = Rollin::Blog.new({articles_folder: "posts"}) # Defaults to "articles"
29
27
 
30
- anArticle = blog.articles.first
28
+ first_post = blog.articles.first
31
29
 
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>"
30
+ first_post.id # => "2013_05_01_My_first_post"
31
+ first_post.title # => "My first post"
32
+ first_post.body # => "<h3>My first post!</h3>\n<p>blah blah blah</p>"
35
33
 
36
- anArticle.date # => #<Date: 2013-05-01 ((2456414j,0s,0n),+0s,2299161j)>
37
- anArticle.year # => 2013
38
- anArticle.month # => 05
39
- anArticle.day # => 01
34
+ first_post.date # => #<Date: 2013-05-01 ((2456414j,0s,0n),+0s,2299161j)>
35
+ first_post.year # => 2013
36
+ first_post.month # => 05
37
+ first_post.day # => 01
40
38
 
41
39
  ### Monthly archive
42
40
 
43
- a_monthly_archive = blog.monthly_archive.first
41
+ may_archive = blog.monthly_archive.first
44
42
 
45
- a_monthly_archive.year # => 2013
46
- a_monthly_archive.month # => 5
47
- a_monthly_archive.articles # => [ Rollin::Article(:title => "My first post" ...) ]
43
+ may_archive.year # => 2013
44
+ may_archive.month # => 5
45
+ may_archive.articles # => [ Rollin::Article(:title => "My first post" ...) ]
48
46
 
49
47
  ### Annual archive
50
48
 
51
- an_annual_archive = blog.annual_archive.first
49
+ twenty_thirteen_archive = blog.annual_archive.first
52
50
 
53
- an_annual_archive.year # => 2013
54
- an_annual_archive.articles # => [ Rollin::Article(:title => "My first post" ...) ]
55
- an_annual_archive.monthly_archive # => [ Rollin::MonthArchive(:year => 2013, :month => 5 ...) ]
51
+ twenty_thirteen_archive.year # => 2013
52
+ twenty_thirteen_archive.articles # => [ Rollin::Article(:title => "My first post" ...) ]
53
+ twenty_thirteen_archive.monthly_archive # => [ Rollin::MonthArchive(:year => 2013, :month => 5 ...) ]
56
54
 
57
55
  ### Finding an article
58
56
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.16
1
+ 0.1.0
@@ -1,16 +1,63 @@
1
1
  class Rollin::Article
2
- attr_reader :id, :title, :year, :month, :day
2
+ attr_reader :id, :year, :month, :day
3
3
 
4
4
  def initialize(source_file)
5
5
  @source_file = source_file
6
6
  filename = File.basename(@source_file)
7
7
  @id = filename[0, filename.length - 3]
8
- @title = filename[11, filename.length - 11 - 3].gsub('_', ' ')
8
+ @title_from_filename = filename[11, filename.length - 11 - 3].gsub('_', ' ')
9
9
  @year = filename[0, 4].to_i
10
10
  @month = filename[5, 2].to_i
11
11
  @day = filename[8, 2].to_i
12
12
  end
13
13
 
14
+ def title
15
+ metatags[:title] || @title_from_filename
16
+ end
17
+
18
+ def matches?(search)
19
+ search = search.clone
20
+
21
+ return true if @id == search
22
+
23
+ if search.has_key?(:year)
24
+ return false if search.delete(:year) != @year
25
+ if search.has_key?(:month)
26
+ return false if search.delete(:month) != @month
27
+ if search.has_key?(:day)
28
+ return false if search.delete(:day) != @day
29
+ end
30
+ end
31
+ end
32
+
33
+ if search.keys.empty?
34
+ return true
35
+ else
36
+ search.each do |key, value|
37
+ return true if metatags[key] != nil && (metatags[key] == value || metatags[key].include?(value))
38
+ end
39
+ return false
40
+ end
41
+ end
42
+
43
+ def metatags
44
+ # Stolen from Jekyll
45
+ begin
46
+ content = File.read(@source_file)
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
52
+ rescue SyntaxError => e
53
+ puts "YAML Exception reading #{File.join(@source_file)}: #{e.message}"
54
+ rescue Exception => e
55
+ puts "Error reading file #{File.join(@source_file)}: #{e.message}"
56
+ end
57
+
58
+ return {}
59
+ end
60
+
14
61
  def date
15
62
  Date.new(@year, @month, @day)
16
63
  end
data/lib/rollin/blog.rb CHANGED
@@ -3,13 +3,15 @@ class Rollin::Blog
3
3
  @articles_folder = options[:articles_folder] || 'articles'
4
4
  end
5
5
 
6
- def find_article_by_id(article_id)
7
- articles.find { |article| article.id == article_id }
6
+ def article(search)
7
+ read_articles.find { |article| article.matches?(search) }
8
8
  end
9
9
 
10
- def articles
11
- Dir["#{@articles_folder}/**/*.mk"].sort.map do |article_source|
12
- Rollin::Article.new(article_source)
10
+ def articles(search=nil)
11
+ if search.nil?
12
+ read_articles
13
+ else
14
+ read_articles.select { |article| article.matches?(search) }
13
15
  end
14
16
  end
15
17
 
@@ -27,4 +29,12 @@ class Rollin::Blog
27
29
  Rollin::MonthArchive.new(year, month, articles_for_month)
28
30
  end
29
31
  end
32
+
33
+ private
34
+
35
+ def read_articles
36
+ Dir["#{@articles_folder}/**/*.mk"].sort.map do |article_source|
37
+ Rollin::Article.new(article_source)
38
+ end
39
+ end
30
40
  end
data/lib/rollin.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "redcarpet"
2
2
  require "date"
3
+ require "safe_yaml"
3
4
 
4
5
  require "rollin/version"
5
6
  require "rollin/blog"
data/rollin.gemspec CHANGED
@@ -21,7 +21,9 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
24
25
  spec.add_development_dependency "version"
25
26
 
26
27
  spec.add_dependency "redcarpet"
28
+ spec.add_dependency "safe_yaml"
27
29
  end
@@ -1,3 +1,7 @@
1
+ ---
2
+ title: This is a super post!
3
+ ---
4
+
1
5
  ## This is my second post
2
6
 
3
7
  Really awesome!!
@@ -0,0 +1,11 @@
1
+ ---
2
+ tags:
3
+ - manero
4
+ - massa
5
+ - bacana
6
+ published: false
7
+ ---
8
+
9
+ ## This is my second post
10
+
11
+ Really awesome!!
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ # Fixtures
4
+ #
5
+ # 2013_05_01_My_first_post.mk
6
+ # 2013_05_02_My_second_post.mk
7
+ # 2013_06_01_My_third_post.mk
8
+ # 2014_01_01_My_fourth_post.mk
9
+
10
+ describe 'how rollin works' do
11
+
12
+ subject (:blog) { Rollin::Blog.new(articles_folder: 'spec/fixtures') }
13
+
14
+ context 'article content' do
15
+ let (:article) { blog.articles.first }
16
+ let (:article_with_title_metatag) { blog.articles[1] }
17
+ let (:article_with_custom_metatags) { blog.articles[2] }
18
+
19
+ it 'exposes article information and content' do
20
+ article.id.should == '2013_05_01_My_first_post'
21
+ article.title.should == 'My first post'
22
+ article.year.should == 2013
23
+ article.month.should == 5
24
+ article.day.should == 1
25
+ article.date.should == Date.new(2013, 5, 1)
26
+ article.body.should == "<h2>This is my first post</h2>\n\n<p>And here we go!</p>\n"
27
+ article.metatags.should be_empty
28
+ end
29
+
30
+ it 'allows article title definition with metatag' do
31
+ article_with_title_metatag.title.should == 'This is a super post!'
32
+ end
33
+
34
+ it 'exposes the list of defined metatags' do
35
+ article_with_custom_metatags.metatags.should == { tags: ['manero', 'massa', 'bacana'], published: false }
36
+ end
37
+ end
38
+
39
+ 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
+ it 'searches by article id' do
46
+ blog.article('2013_05_01_My_first_post').should == first_article
47
+ end
48
+
49
+ it 'searches by metatags' do
50
+ blog.article(tags: 'manero').should == article_with_custom_metatags
51
+ blog.articles(tags: 'manero').should == [ article_with_custom_metatags ]
52
+
53
+ blog.article(published: false).should == article_with_custom_metatags
54
+ blog.articles(published: false).should == [ article_with_custom_metatags ]
55
+ end
56
+
57
+ it 'searches by date' do
58
+ blog.articles(year: 2013).should include(first_article, second_article, third_article)
59
+ blog.articles(year: 2013, month: 5).should include(first_article, second_article)
60
+ blog.articles(year: 2013, month: 5, day: 1).should include(first_article)
61
+ end
62
+
63
+ it 'narrows search by date when searching for metatags' do
64
+ blog.articles(year: 2013, :tags => 'manero').should { article_with_custom_metatags }
65
+ blog.articles(year: 2014, :tags => 'manero').should be_empty
66
+ end
67
+ end
68
+
69
+ context 'listing articles' do
70
+ let (:first_article) { TestArticle.new(id: '2013_05_01_My_first_post', title: 'My first post', date: Date.new(2013, 5, 1)) }
71
+ let (:second_article) { TestArticle.new(id: '2013_05_02_My_second_post', title: 'This is a super post!', date: Date.new(2013, 5, 2)) }
72
+ let (:third_article) { TestArticle.new(id: '2013_06_01_My_third_post', title: 'My third post', date: Date.new(2013, 6, 1)) }
73
+ let (:fourth_article) { TestArticle.new(id: '2014_01_01_My_fourth_post', title: 'My fourth post', date: Date.new(2014, 1, 1)) }
74
+
75
+ it 'lists all articles' do
76
+ blog.should have(4).articles
77
+
78
+ blog.articles[0].should == first_article
79
+ blog.articles[1].should == second_article
80
+ blog.articles[2].should == third_article
81
+ blog.articles[3].should == fourth_article
82
+ end
83
+
84
+ it 'provides monthly archive' do
85
+ blog.monthly_archive.should have(3).articles
86
+
87
+ blog.monthly_archive[0].year.should == 2013
88
+ blog.monthly_archive[0].month.should == 5
89
+ blog.monthly_archive[0].should have(2).articles
90
+ blog.monthly_archive[0].articles.should include(first_article, second_article)
91
+
92
+ blog.monthly_archive[1].year.should == 2013
93
+ blog.monthly_archive[1].month.should == 6
94
+ blog.monthly_archive[1].should have(1).articles
95
+ blog.monthly_archive[1].articles.should include(third_article)
96
+
97
+ blog.monthly_archive[2].year.should == 2014
98
+ blog.monthly_archive[2].month.should == 1
99
+ blog.monthly_archive[2].should have(1).articles
100
+ blog.monthly_archive[2].articles.should include(fourth_article)
101
+ end
102
+
103
+ it 'provides annual archive' do
104
+ blog.should have(2).annual_archive
105
+
106
+ blog.annual_archive[0].year.should == 2013
107
+ blog.annual_archive[0].should have(2).monthly_archive
108
+ blog.annual_archive[0].monthly_archive[0].year.should == 2013
109
+ blog.annual_archive[0].monthly_archive[0].month.should == 5
110
+ blog.annual_archive[0].monthly_archive[0].should have(2).articles
111
+ blog.annual_archive[0].monthly_archive[0].articles.should include(first_article, second_article)
112
+ blog.annual_archive[0].monthly_archive[1].year.should == 2013
113
+ blog.annual_archive[0].monthly_archive[1].month.should == 6
114
+ blog.annual_archive[0].monthly_archive[1].should have(1).articles
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)
118
+
119
+ blog.annual_archive[1].year.should == 2014
120
+ blog.annual_archive[1].should have(1).monthly_archive
121
+ blog.annual_archive[1].monthly_archive[0].year.should == 2014
122
+ blog.annual_archive[1].monthly_archive[0].month.should == 1
123
+ blog.annual_archive[1].monthly_archive[0].should have(1).articles
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)
127
+ end
128
+ end
129
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,3 +3,19 @@ require 'bundler/setup'
3
3
  Bundler.require :development
4
4
 
5
5
  require './lib/rollin'
6
+
7
+ class Rollin::Article
8
+ def ==(other)
9
+ id == other.id && title == other.title && date == other.date
10
+ end
11
+ end
12
+
13
+ class TestArticle
14
+ attr_reader :id, :title, :date
15
+
16
+ def initialize(properties)
17
+ @id = properties[:id]
18
+ @title = properties[:title]
19
+ @date = properties[:date]
20
+ end
21
+ 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.0.16
4
+ version: 0.1.0
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-01 00:00:00.000000000 Z
11
+ date: 2013-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: version
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - '>='
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: safe_yaml
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: ''
84
112
  email:
85
113
  - thiagomarano@gmail.com
@@ -102,14 +130,11 @@ files:
102
130
  - lib/rollin/version.rb
103
131
  - lib/rollin/year_archive.rb
104
132
  - rollin.gemspec
105
- - spec/annual_archive_spec.rb
106
- - spec/article_spec.rb
107
- - spec/blog_spec.rb
108
- - spec/fixtures/articles/2013_05_01_My_first_post.mk
109
- - spec/fixtures/articles/2013_05_02_My_second_post.mk
110
- - spec/fixtures/articles/2013_06_01_My_third_post.mk
111
- - spec/fixtures/articles/2014_01_01_My_fourth_post.mk
112
- - spec/month_archive_spec.rb
133
+ - spec/fixtures/2013_05_01_My_first_post.mk
134
+ - spec/fixtures/2013_05_02_My_second_post.mk
135
+ - spec/fixtures/2013_06_01_My_third_post.mk
136
+ - spec/fixtures/2014_01_01_My_fourth_post.mk
137
+ - spec/rollin_spec.rb
113
138
  - spec/spec_helper.rb
114
139
  homepage: http://github.com/marano/rollin
115
140
  licenses:
@@ -136,12 +161,9 @@ signing_key:
136
161
  specification_version: 4
137
162
  summary: A Ruby minimalistic blog engine ... WATTT!!?!??
138
163
  test_files:
139
- - spec/annual_archive_spec.rb
140
- - spec/article_spec.rb
141
- - spec/blog_spec.rb
142
- - spec/fixtures/articles/2013_05_01_My_first_post.mk
143
- - spec/fixtures/articles/2013_05_02_My_second_post.mk
144
- - spec/fixtures/articles/2013_06_01_My_third_post.mk
145
- - spec/fixtures/articles/2014_01_01_My_fourth_post.mk
146
- - spec/month_archive_spec.rb
164
+ - spec/fixtures/2013_05_01_My_first_post.mk
165
+ - spec/fixtures/2013_05_02_My_second_post.mk
166
+ - spec/fixtures/2013_06_01_My_third_post.mk
167
+ - spec/fixtures/2014_01_01_My_fourth_post.mk
168
+ - spec/rollin_spec.rb
147
169
  - spec/spec_helper.rb
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rollin::YearArchive do
4
- let (:article) { Rollin::Article.new('spec/fixtures/2013_05_01_My_first_post.mk') }
5
- subject (:month_archive) { Rollin::MonthArchive.new(2013, 05, [ article ]) }
6
- subject (:year_archive) { Rollin::YearArchive.new(2013, [ month_archive ]) }
7
-
8
- it 'tells the year' do
9
- year_archive.year.should == 2013
10
- end
11
-
12
- it 'has monthly archives' do
13
- year_archive.monthly_archive.size.should == 1
14
- year_archive.monthly_archive.first.should == month_archive
15
- end
16
-
17
- it 'has a list of articles' do
18
- year_archive.articles.first.should == article
19
- end
20
- end
data/spec/article_spec.rb DELETED
@@ -1,33 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- describe Rollin::Article do
4
- subject (:article) { Rollin::Article.new('spec/fixtures/articles/2013_05_01_My_first_post.mk') }
5
-
6
- it 'tells article id' do
7
- article.id.should == '2013_05_01_My_first_post'
8
- end
9
-
10
- it 'tells article title' do
11
- article.title.should == 'My first post'
12
- end
13
-
14
- it 'compiles article body to html' do
15
- article.body.should == "<h2>This is my first post</h2>\n\n<p>And here we go!</p>\n"
16
- end
17
-
18
- it 'tells article year' do
19
- article.year.should == 2013
20
- end
21
-
22
- it 'tells article month' do
23
- article.month.should == 5
24
- end
25
-
26
- it 'tells article day' do
27
- article.day.should == 1
28
- end
29
-
30
- it 'tells article date' do
31
- article.date.should == Date.new(2013, 5, 1)
32
- end
33
- end
data/spec/blog_spec.rb DELETED
@@ -1,29 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- describe Rollin::Blog do
4
- context 'reading articles from articles folder' do
5
- subject (:blog) { Rollin::Blog.new(articles_folder: 'spec/fixtures/articles') }
6
-
7
- it 'has the right amount of articles' do
8
- blog.articles.size.should == 4
9
- end
10
-
11
- it 'has monthly archives' do
12
- blog.monthly_archive.size.should == 3
13
- blog.monthly_archive.first.class.should == Rollin::MonthArchive
14
- end
15
-
16
- it 'has annual archives' do
17
- blog.annual_archive.size.should == 2
18
- blog.annual_archive.first.class.should == Rollin::YearArchive
19
- blog.annual_archive.first.monthly_archive.size.should == 2
20
- blog.annual_archive.first.monthly_archive.first.class.should == Rollin::MonthArchive
21
- blog.annual_archive.first.monthly_archive.first.articles.size.should == 2
22
- blog.annual_archive.first.monthly_archive.first.articles.first.class.should == Rollin::Article
23
- end
24
-
25
- it 'finds article by its id' do
26
- blog.find_article_by_id('2013_05_01_My_first_post').title.should == 'My first post'
27
- end
28
- end
29
- end
@@ -1,3 +0,0 @@
1
- ## This is my second post
2
-
3
- Really awesome!!
@@ -1,16 +0,0 @@
1
- describe Rollin::MonthArchive 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
-
5
- it 'tells the year' do
6
- month_archive.year.should == 2013
7
- end
8
-
9
- it 'tells the month' do
10
- month_archive.month.should == 5
11
- end
12
-
13
- it 'has a list of articles' do
14
- month_archive.articles.first.should == article
15
- end
16
- end