Skip to content

Commit

Permalink
moving forward with 3.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Dec 4, 2011
1 parent c8e7182 commit 134bda3
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 57 deletions.
Empty file added .gemtest
Empty file.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
script: "bundle exec rake test"
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ source "http://rubygems.org"

# Specify your gem's dependencies in middleman-blog.gemspec
gemspec
gem "middleman", :path => "../middleman"
15 changes: 15 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
require 'bundler'
Bundler::GemHelper.install_tasks

require 'cucumber/rake/task'

Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
end

require 'rake/clean'

task :test => ["cucumber"]

desc "Build HTML documentation"
task :doc do
sh 'bundle exec yard'
end
Empty file added features/encoding.feature
Empty file.
28 changes: 28 additions & 0 deletions features/preview.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: Preview Changes
In order to run quickly, we should update internal caches on file changes

Scenario: A template changes contents during preview
Given the Server is running at "preview-app"
And the file "source/2011/01/01/new-article.html.markdown" has the contents
"""
---
title: "New Article"
date: 01/01/2011
---
New Article Content
"""
When I go to "/2011/01/01/new-article.html"
Then I should see "New Article Content"
And I should see "New Article</title>"
And the file "source/2011/01/01/new-article.html.markdown" has the contents
"""
---
title: "Newer Article"
date: 01/01/2011
---
Newer Article Content
"""
Then I should see "Newer Article Content"
And I should see "Newer Article</title>"
4 changes: 4 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
require "middleman"
require "middleman/step_definitions"
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-blog')
1 change: 1 addition & 0 deletions fixtures/preview-app/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
activate :blog
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "Newer Article"
date: 01/01/2011
---

Newer Article Content
10 changes: 10 additions & 0 deletions fixtures/preview-app/source/_article_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<article class="hentry">
<h1 class="entry-title">
<%= current_article_title %>
<time class="updated" pubdate><%= current_article_date.strftime('%b %e %Y') %></time>
</h1>

<div class="entry-content">
<%= yield_content :blog_article %>
</div>
</article>
9 changes: 9 additions & 0 deletions fixtures/preview-app/source/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% data.blog.articles[0...5].each_with_index do |article, i| %>
<article class="<%= (i == 0) ? 'first' : '' %>">
<h1><a href="<%= article.url %>"><%= article.title %></a> <span><%= article.date.strftime('%b %e %Y') %></span></h1>

<%= article.summary %>

<div class="more"><a href="<%= article.url %>">read on &raquo;</a></div>
</article>
<% end %>
22 changes: 22 additions & 0 deletions fixtures/preview-app/source/layout.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv='X-UA-Compatible' content='IE=edge;chrome=1' />

<% if is_blog_article? %>
<title><%= current_article_title %></title>
<% end %>
</head>
<body>

<div id="main" role="main">
<% if is_blog_article? %>
<% content_for :blog_article, yield %>
<%= partial settings.blog_article_template %>
<% else %>
<%= yield %>
<% end %>
</div>
</body>
</html>
2 changes: 0 additions & 2 deletions fixtures/utf8ouch/config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Encoding.default_external = 'utf-8'

activate :blog
# set :blog_permalink, ":year/:month/:day/:title.html"
# set :blog_summary_separator, /READMORE/
Expand Down
6 changes: 4 additions & 2 deletions lib/middleman-blog.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Middleman::Extensions.register(:blog, ">= 3.0.0.alpha") do
require "middleman"

::Middleman::Extensions.register(:blog, ">= 3.0.0.alpha") do
require "middleman-blog/extension"
require "middleman-blog/template"

Middleman::Extensions::Blog
::Middleman::Extensions::Blog
end
111 changes: 59 additions & 52 deletions lib/middleman-blog/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def registered(app)
matcher.sub!(":title", "(.*)")
BlogData.matcher = %r{#{source}/#{matcher}}

file_changed BlogData.matcher do |file|
frontmatter_changed BlogData.matcher do |file|
blog.touch_file(file)
end

Expand Down Expand Up @@ -83,13 +83,21 @@ def initialize(app)
end

def sorted_articles
@sorted_articles ||= begin
@_sorted_articles ||= begin
@articles.values.sort do |a, b|
b.date <=> a.date
end
end
end

def article(path)
if @articles.has_key?(path.to_s)
@articles[path.to_s]
else
nil
end
end

def tags
@tags ||= begin
tags = {}
Expand All @@ -115,34 +123,34 @@ def tags

def touch_file(file)
output_path = @app.sitemap.file_to_path(file)

$stderr.puts "touching"
if @app.sitemap.exists?(output_path)
if @articles.has_key?(file)
@articles[file].update!
if @articles.has_key?(output_path)
$stderr.puts "update"
@articles[output_path].update!
else
@articles[file] = BlogArticle.new(@app, @app.sitemap.page(output_path))
$stderr.puts "new"
@articles[output_path] = BlogArticle.new(@app, @app.sitemap.page(output_path))
end
$stderr.puts output_path
end

self.update_data
end

def remove_file(file)
if @articles.has_key?(file)
@articles.delete(file)
output_path = @app.sitemap.file_to_path(file)

if @articles.has_key?(output_path)
@articles.delete(output_path)
self.update_data
end
end

protected
def update_data
@sorted_articles = false
@tags = false

@app.data_content("blog", {
:articles => self.sorted_articles.map(&:to_h),
:tags => self.tags
})
@_sorted_articles = nil
@tags = nil
end
end

Expand All @@ -153,13 +161,16 @@ def initialize(app, page)
@app = app
@page = page

@page.custom_renderer do
"Hi mom"
end
# @page.custom_renderer do
# "Hi mom"
# end

template_content = @app.cache.get([:raw_template, page.source_file])

data, content = app.frontmatter.data(page.source_file.sub(@app.source_dir, ""))
self.update!
end

def update!
path = @page.source_file.sub(@app.source_dir, "")
data, content = @app.frontmatter.data(path)

if data && data["date"] && data["date"].is_a?(String)
if data["date"].match(/\d{4}\/\d{2}\/\d{2}/)
Expand All @@ -172,12 +183,8 @@ def initialize(app, page)
self.frontmatter = data
self.title = data["title"]
self.raw = content
self.url = page.path
self.url = @page.path

self.update!
end

def update!
@_body = nil
@_summary = nil
end
Expand All @@ -202,16 +209,16 @@ def summary
end
end

def to_h
{
:date => self.date,
:raw => self.raw,
:url => self.url,
:body => self.body,
:title => self.title,
:summary => self.summary
}
end
# def to_h
# {
# :date => self.date,
# :raw => self.raw,
# :url => self.url,
# :body => self.body,
# :title => self.title,
# :summary => self.summary
# }
# end
end

module InstanceMethods
Expand All @@ -220,51 +227,51 @@ def blog
end

def is_blog_article?
!current_article_title.blank?
!current_article.nil?
end

def blog_title
end
# def blog_title
# end

def current_article_date
DateTime.parse("#{current_article_metadata.date}")
current_article.date
end

def current_article_title
current_article_metadata.title
current_article.title
end

def current_article_metadata
data.page
def current_article
blog.article(current_path.sub(/^\//, ""))
end

def current_article_tags
article_tags_hash = {}
if is_blog_article? && current_article_metadata.tags
article_tags = current_article_metadata.tags.split(',').map{|t| t.strip}
if is_blog_article? && current_article.tags
article_tags = current_article.tags.split(',').map{|t| t.strip}
article_tags.each do |tag_title|
article_tags_hash[tag_title] = self.class.blog_taglink.gsub(/(:\w+)/, tag_title.parameterize)
article_tags_hash[tag_title] = self.blog_taglink.gsub(/(:\w+)/, tag_title.parameterize)
end
end
article_tags_hash
end

def blog_tags
data.blog.tags
blog.tags
end

def current_tag_data
data.blog.tags[request.path]
def current_tag
blog.tags[request.path]
end

def current_tag_articles
data.blog.articles.map do |article|
article if current_tag_data.pages.has_value?(article.url)
blog.articles.map do |article|
article if current_tag.pages.has_value?(article.url)
end.compact
end

def current_tag_title
current_tag_data[:title]
current_tag_data.title
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion middleman-blog.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_runtime_dependency("middleman", [">= 3.0.0.alpha"])
s.add_development_dependency("rake")
s.add_development_dependency("cucumber", ["~> 1.1.0"])
s.add_development_dependency("rake", ["~> 0.9.2"])
s.add_development_dependency("rspec", ["~> 2.7.0"])
s.add_development_dependency("rdiscount")
end

0 comments on commit 134bda3

Please sign in to comment.