middleman-blog-authors 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ # Ignore bundler lock file
2
+ /Gemfile.lock
3
+
4
+ # Ignore pkg folder
5
+ /pkg
6
+
7
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ # If you have OpenSSL installed, we recommend updating
2
+ # the following line to use "https"
3
+ source 'http://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in middleman-blog-authors.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem "rake"
10
+ gem "rdoc"
11
+ gem "yard"
12
+ end
13
+
14
+ group :test do
15
+ gem "cucumber"
16
+ gem "fivemat"
17
+ gem "aruba"
18
+ gem "rspec"
19
+ end
@@ -0,0 +1,46 @@
1
+ # Middleman-Blog-Authors
2
+
3
+ ## Installation
4
+
5
+ In your Gemfile:
6
+
7
+ ```
8
+ gem "middleman-blog-authors", :git => "git@github.com:bellycard/middleman-blog-authors.git"
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ In your config.rb:
14
+
15
+ ```
16
+ activate :authors
17
+ ```
18
+
19
+ In your blog posts, add authors to the metadata:
20
+
21
+ ```
22
+ ---
23
+ title: Building Middleman Addons
24
+ date: 2013-07-17
25
+ authors: Darby Frey
26
+ ---
27
+ ```
28
+
29
+ Create a template for the author page:
30
+
31
+ `author.html.haml`
32
+
33
+ ```
34
+ ---
35
+ title: #{author.name}
36
+ pageable: true
37
+ per_page: 10
38
+ ---
39
+
40
+ %h1= author.name
41
+
42
+ %ul
43
+ - page_articles.each do |article|
44
+ %li= link_to article.title, article
45
+
46
+ ```
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task :test => ["cucumber"]
13
+
14
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require "middleman-core"
3
+ require "middleman-core/step_definitions"
4
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-blog-authors')
@@ -0,0 +1,22 @@
1
+ module Middleman
2
+ class BlogAuthors
3
+ class Author
4
+ attr_accessor :attributes, :articles
5
+ def initialize(name, local_data = nil)
6
+ @articles = []
7
+ @attributes = {
8
+ "name" => name,
9
+ "permalink" => BlogAuthors::AuthorPages.permalink(name)
10
+ }
11
+
12
+ if local_data.try(:authors)
13
+ @attributes.merge!(local_data.authors[@attributes["permalink"]]) if local_data.authors[@attributes["permalink"]]
14
+ end
15
+
16
+ @attributes.each do |attribute|
17
+ eval "def #{attribute[0]}; @attributes['#{attribute[0]}']; end"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,63 @@
1
+ module Middleman
2
+ class BlogAuthors
3
+
4
+ # A sitemap plugin that adds author pages to the sitemap
5
+ # based on the authors of blog articles.
6
+ class AuthorPages
7
+ class << self
8
+ def permalink(author_name)
9
+ author_name.parameterize
10
+ end
11
+
12
+ def link(blog_authors_options, author)
13
+ ::Middleman::Util.normalize_path(blog_authors_options.author_path.sub(':author', AuthorPages.permalink(author.name)))
14
+ end
15
+ end
16
+
17
+ def initialize(app, controller=nil)
18
+ @app = app
19
+ @blog_controller = controller
20
+ end
21
+
22
+ def blog_data
23
+ @app.blog
24
+ end
25
+
26
+ def blog_authors_options
27
+ @app.blog_authors_options
28
+ end
29
+
30
+ def manipulate_resource_list(resources)
31
+ # collect authors
32
+ @app.set :blog_authors_data, {}
33
+ @app.blog.articles.each do |article|
34
+ article.author_names.each do |author|
35
+ permalink = Middleman::BlogAuthors::AuthorPages.permalink(author)
36
+ if @app.blog_authors_data[permalink].nil?
37
+ @app.blog_authors_data[permalink] = ::Middleman::BlogAuthors::Author.new(author, @app.data)
38
+ end
39
+ @app.blog_authors_data[permalink].articles << article
40
+ end
41
+ end
42
+
43
+ resources + self.blog_data.authors.map do |author|
44
+ path = AuthorPages.link(self.blog_authors_options, author)
45
+
46
+ p = ::Middleman::Sitemap::Resource.new(
47
+ @app.sitemap,
48
+ path
49
+ )
50
+ p.proxy_to(self.blog_authors_options.author_template)
51
+
52
+ p.add_metadata :locals => {
53
+ 'page_type' => 'author',
54
+ 'author' => author,
55
+ 'articles' => author.articles,
56
+ }
57
+
58
+ p
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,17 @@
1
+ module Middleman
2
+ module Blog
3
+ module BlogArticle
4
+ def authors
5
+ author_permalinks.map{|permalink| @app.blog_authors_data[permalink]}
6
+ end
7
+
8
+ def author_permalinks
9
+ data.authors ? data.authors.split(',').map{|author| Middleman::BlogAuthors::AuthorPages.permalink(author)} : []
10
+ end
11
+
12
+ def author_names
13
+ data.authors ? data.authors.split(',').map{|author| author.strip} : []
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Middleman
2
+ module Blog
3
+ class BlogData
4
+
5
+ def authors
6
+ permalinks = @_articles.map{|article| article.author_permalinks}.flatten.uniq
7
+ permalinks.map{|permalink| @app.blog_authors_data[permalink]}
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ # Require core library
2
+ require "middleman-core"
3
+
4
+ class BlogAuthors < ::Middleman::Extension
5
+ option :author_path, "authors/:author.html", 'Path to the individual author pages'
6
+ option :author_template, "author.html", 'Template for the individual author pages'
7
+
8
+ def initialize(app, options_hash={}, &block)
9
+ super
10
+ require 'blog_article'
11
+ require 'blog_data'
12
+ require 'author_pages'
13
+ require 'author'
14
+
15
+ app.set :blog_authors_options, options
16
+ app.set :blog_authors_data, {}
17
+ end
18
+
19
+ def after_configuration
20
+ @app.sitemap.register_resource_list_manipulator(
21
+ :author_pages,
22
+ ::Middleman::BlogAuthors::AuthorPages.new(@app, self),
23
+ false
24
+ )
25
+ end
26
+
27
+ helpers do
28
+ def link_to_author(author)
29
+ author_path = ::Middleman::BlogAuthors::AuthorPages.link(self.blog_authors_options, author)
30
+ link_to author.name, "/#{author_path}"
31
+ end
32
+ end
33
+ end
34
+
35
+ ::Middleman::Extensions.register(:authors, BlogAuthors)
@@ -0,0 +1 @@
1
+ require "middleman-blog-authors"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "middleman-blog-authors"
6
+ s.version = "0.0.1"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Darby Frey"]
9
+ s.email = ["darby@bellycard.com"]
10
+ # s.homepage = "http://example.com"
11
+ s.summary = %q{A Middleman extension to add author profile pages to a blog}
12
+ s.description = %q{A Middleman extension to add author profile pages to a blog}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # The version of middleman-core your extension depends on
20
+ s.add_runtime_dependency("middleman-core", [">= 3.1.3"])
21
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-blog-authors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Darby Frey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: middleman-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.3
30
+ description: A Middleman extension to add author profile pages to a blog
31
+ email:
32
+ - darby@bellycard.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - README.md
40
+ - Rakefile
41
+ - features/support/env.rb
42
+ - lib/author.rb
43
+ - lib/author_pages.rb
44
+ - lib/blog_article.rb
45
+ - lib/blog_data.rb
46
+ - lib/middleman-blog-authors.rb
47
+ - lib/middleman_extension.rb
48
+ - middleman-blog-authors.gemspec
49
+ homepage:
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ segments:
62
+ - 0
63
+ hash: -3201365490752007184
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ segments:
71
+ - 0
72
+ hash: -3201365490752007184
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.25
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: A Middleman extension to add author profile pages to a blog
79
+ test_files:
80
+ - features/support/env.rb
81
+ has_rdoc: