Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
2 lib/rollin.rb
@@ -7,6 +7,8 @@
require "rollin/article"
require "rollin/month_archive"
require "rollin/year_archive"
+require "rollin/metatag_key"
+require "rollin/metatag_value"
module Rollin
end
View
11 lib/rollin/article.rb
@@ -12,13 +12,14 @@ def initialize(source_file)
end
def title
- metatags[:title] || @title_from_filename
+ metatags['title'] || @title_from_filename
end
def matches?(search)
- search = search.clone
-
return true if @id == search
+ return false if @searh.is_a? String
+
+ search = search.clone
if search.has_key?(:year)
return false if search.delete(:year) != @year
@@ -30,6 +31,8 @@ def matches?(search)
end
end
+ search = search.inject({}) { |memo, (k,v)| memo[k.to_s] = v; memo }
+
if search.keys.empty?
return true
else
@@ -47,7 +50,7 @@ def metatags
if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
content = $POSTMATCH
- return YAML.safe_load($1).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
+ return YAML.safe_load($1)
end
rescue SyntaxError => e
puts "YAML Exception reading #{File.join(@source_file)}: #{e.message}"
View
15 lib/rollin/blog.rb
@@ -15,6 +15,21 @@ def articles(search=nil)
end
end
+ def metatags
+ metatag_labels = articles.map do |article|
+ article.metatags.keys
+ end.flatten.uniq
+
+ metatag_labels.map do |metatag_label|
+ values = articles.select { |article| article.metatags.has_key?(metatag_label) }.map do |article|
+ article.metatags[metatag_label]
+ end.flatten.uniq.map do |metatag_content|
+ Rollin::MetatagValue.new(metatag_content, articles(metatag_label => metatag_content))
+ end
+ Rollin::MetatagKey.new(metatag_label, values)
+ end
+ end
+
def annual_archive
monthly_archive.map { |month_archive| month_archive.year }.uniq.map do |year|
Rollin::YearArchive.new(year, monthly_archive.select { |aMonth| aMonth.year == year })
View
7 lib/rollin/metatag_key.rb
@@ -0,0 +1,7 @@
+class Rollin::MetatagKey
+ attr_reader :label, :values
+
+ def initialize(label, values)
+ @label, @values = label, values
+ end
+end
View
7 lib/rollin/metatag_value.rb
@@ -0,0 +1,7 @@
+class Rollin::MetatagValue
+ attr_reader :content, :articles
+
+ def initialize(content, articles)
+ @content, @articles = content, articles
+ end
+end
View
1 spec/fixtures/2013_06_01_My_third_post.mk
@@ -3,7 +3,6 @@ tags:
- manero
- massa
- bacana
-published: false
---
## This is my second post
View
8 spec/fixtures/2014_01_01_My_fourth_post.mk
@@ -1 +1,7 @@
-
+---
+published: false
+---
+
+## This is my fourth post
+
+Really awesome!!
View
60 spec/rollin_spec.rb
@@ -11,10 +11,17 @@
subject (:blog) { Rollin::Blog.new(articles_folder: 'spec/fixtures') }
+ let (:first_article) { blog.articles.first }
+ let (:second_article) { blog.articles[1] }
+ let (:third_article) { blog.articles[2] }
+ let (:fourth_article) { blog.articles[3] }
+
+ let (:article_with_title_metatag) { blog.articles[1] }
+ let (:article_with_tag_metatag) { blog.articles[2] }
+ let (:article_with_published_metatag) { blog.articles[3] }
+
context 'article content' do
let (:article) { blog.articles.first }
- let (:article_with_title_metatag) { blog.articles[1] }
- let (:article_with_custom_metatags) { blog.articles[2] }
it 'exposes article information and content' do
article.id.should == '2013_05_01_My_first_post'
@@ -32,26 +39,28 @@
end
it 'exposes the list of defined metatags' do
- article_with_custom_metatags.metatags.should == { tags: ['manero', 'massa', 'bacana'], published: false }
+ article_with_tag_metatag.metatags.should == { 'tags' => ['manero', 'massa', 'bacana'] }
+ article_with_published_metatag.metatags.should == { 'published' => false }
end
end
context 'searching for articles' do
- let (:first_article) { blog.articles.first }
- let (:second_article) { blog.articles[1] }
- let (:third_article) { blog.articles[2] }
- let (:article_with_custom_metatags) { blog.articles[2] }
-
it 'searches by article id' do
blog.article('2013_05_01_My_first_post').should == first_article
end
it 'searches by metatags' do
- blog.article(tags: 'manero').should == article_with_custom_metatags
- blog.articles(tags: 'manero').should == [ article_with_custom_metatags ]
+ blog.article(:tags => 'manero').should == article_with_tag_metatag
+ blog.article('tags' => 'manero').should == article_with_tag_metatag
+
+ blog.articles(:tags => 'manero').should == [ article_with_tag_metatag ]
+ blog.articles('tags' => 'manero').should == [ article_with_tag_metatag ]
+
+ blog.article(:published => false).should == article_with_published_metatag
+ blog.article('published' => false).should == article_with_published_metatag
- blog.article(published: false).should == article_with_custom_metatags
- blog.articles(published: false).should == [ article_with_custom_metatags ]
+ blog.articles(:published => false).should == [ article_with_published_metatag ]
+ blog.articles('published' => false).should == [ article_with_published_metatag ]
end
it 'searches by date' do
@@ -66,6 +75,31 @@
end
end
+ context 'inquiring metatags' do
+ it 'shows a list of existent metatags' do
+ blog.should have(3).metatags
+
+ blog.metatags[0].label.should == 'title'
+ blog.metatags[0].should have(1).values
+ blog.metatags[0].values[0].content.should == 'This is a super post!'
+ blog.metatags[0].values[0].articles.should == [ article_with_title_metatag ]
+
+ blog.metatags[1].label.should == 'tags'
+ blog.metatags[1].should have(3).values
+ blog.metatags[1].values[0].content.should == 'manero'
+ blog.metatags[1].values[0].articles.should == [ article_with_tag_metatag ]
+ blog.metatags[1].values[1].content.should == 'massa'
+ blog.metatags[1].values[1].articles.should == [ article_with_tag_metatag ]
+ blog.metatags[1].values[2].content.should == 'bacana'
+ blog.metatags[1].values[2].articles.should == [ article_with_tag_metatag ]
+
+ blog.metatags[2].label.should == 'published'
+ blog.metatags[2].should have(1).values
+ blog.metatags[2].values[0].content.should == false
+ blog.metatags[2].values[0].articles.should == [ article_with_published_metatag ]
+ end
+ end
+
context 'listing articles' do
let (:first_article) { TestArticle.new(id: '2013_05_01_My_first_post', title: 'My first post', date: Date.new(2013, 5, 1)) }
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,7 +114,9 @@
blog.articles[2].should == third_article
blog.articles[3].should == fourth_article
end
+ end
+ context 'archive' do
it 'provides monthly archive' do
blog.monthly_archive.should have(3).articles

No commit comments for this range

Something went wrong with that request. Please try again.