middleman-blog_page 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +32 -0
- data/LICENSE.md +20 -0
- data/README.md +60 -0
- data/Rakefile +38 -0
- data/lib/middleman-blog_page.rb +13 -0
- data/lib/middleman-blog_page/blog_page_article.rb +103 -0
- data/lib/middleman-blog_page/blog_page_data.rb +141 -0
- data/lib/middleman-blog_page/extension_3_0.rb +100 -0
- data/lib/middleman-blog_page/extension_3_1.rb +113 -0
- data/lib/middleman-blog_page/version.rb +5 -0
- data/lib/middleman_extension.rb +1 -0
- data/middleman-blog_page.gemspec +20 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5efa1eba15007d13993ea3d6220bec1f663a5dba
|
4
|
+
data.tar.gz: 4c8d620e17b223ea5abcf9f005ba3b4d5507a39e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 172d0ce78c56e53b2f01d59a780b65e2adbfa3fd59b7f15b0e72a89296d0050020de4b0596153d2fa19dce3f1af5df20e4870952dfc5c8b9c1453fe50aafaab9
|
7
|
+
data.tar.gz: e84c51e7dcc9b5652cda47855fff1fbcd1a178b6c6d1b5603afa4de601b7fe7681a91e2f9e82d28442ed8afe0c9f973dbb528c2476499e6aab2518be55267840
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem "middleman-core", :github => "middleman/middleman"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in middleman-blog.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 10.0.3", :require => false
|
9
|
+
gem "yard", "~> 0.8.0", :require => false
|
10
|
+
|
11
|
+
# Test tools
|
12
|
+
gem "cucumber", "~> 1.3.1"
|
13
|
+
gem "fivemat"
|
14
|
+
gem "aruba", "~> 0.5.1"
|
15
|
+
gem "rspec", "~> 2.12"
|
16
|
+
gem "simplecov"
|
17
|
+
|
18
|
+
gem "timecop", "~> 0.4.0"
|
19
|
+
gem "nokogiri", "~> 1.5.0" # 1.6.0 requires Ruby 1.9+ but we still test on 1.8
|
20
|
+
gem "kramdown"
|
21
|
+
|
22
|
+
# Code Quality
|
23
|
+
gem "cane", :platforms => [:mri_19, :mri_20], :require => false
|
24
|
+
|
25
|
+
platforms :ruby do
|
26
|
+
gem "redcarpet", "~> 3.0"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Cross-templating language block fix for Ruby 1.8
|
30
|
+
platforms :mri_18 do
|
31
|
+
gem "ruby18_source_location"
|
32
|
+
end
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010-2013 Jasl
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Middleman-BlogPage
|
2
|
+
|
3
|
+
`middleman-blog_page` is an extension for the [Middleman] static site generator that help to manage static pages ```e.g: about me, resume, contact, etc.```. This includes handling pages, helpers for listing pages.
|
4
|
+
|
5
|
+
**This gem is copy and simplify from [Middleman-blog] .**
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
If you're just getting started, install the `middleman` gem and generate a new project:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install middleman
|
13
|
+
middleman init MY_PROJECT
|
14
|
+
```
|
15
|
+
|
16
|
+
If you already have a Middleman project: Add `gem "middleman-blog_page"` to your `Gemfile` and run `bundle install`
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
```
|
21
|
+
activate :blog_page
|
22
|
+
```
|
23
|
+
|
24
|
+
for advance:
|
25
|
+
|
26
|
+
```
|
27
|
+
activate :blog_page do |page|
|
28
|
+
# page.prefix = "page"
|
29
|
+
# page.permalink = ":title.html"
|
30
|
+
# page.sources = "pages/:title.html"
|
31
|
+
# page.layout = "layout"
|
32
|
+
# page.default_extension = ".markdown"
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
## Bug Reports
|
37
|
+
|
38
|
+
Github Issues are used for managing bug reports and feature requests. If you run into issues, please search the issues and submit new problems: https://github.com/middleman/middleman-blog/issues
|
39
|
+
|
40
|
+
The best way to get quick responses to your issues and swift fixes to your bugs is to submit detailed bug reports, include test cases and respond to developer questions in a timely manner. Even better, if you know Ruby, you can submit [Pull Requests](https://help.github.com/articles/using-pull-requests) containing Cucumber Features which describe how your feature should work or exploit the bug you are submitting.
|
41
|
+
|
42
|
+
## How to Run Cucumber Tests
|
43
|
+
|
44
|
+
1. Checkout Repository: `git clone https://github.com/jasl/middleman-blog_page.git`
|
45
|
+
2. Install Bundler: `gem install bundler`
|
46
|
+
3. Run `bundle install` inside the project root to install the gem dependencies.
|
47
|
+
4. Run test cases: `bundle exec rake test`
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
Copyright (c) 2010-2013 Jasl. MIT Licensed, see [LICENSE] for details.
|
52
|
+
|
53
|
+
[middleman]: http://middlemanapp.com
|
54
|
+
[middleman-blog]: https://github.com/middleman/middleman-blog
|
55
|
+
[gem]: https://rubygems.org/gems/middleman-blog
|
56
|
+
[travis]: http://travis-ci.org/middleman/middleman-blog
|
57
|
+
[gemnasium]: https://gemnasium.com/middleman/middleman-blog
|
58
|
+
[codeclimate]: https://codeclimate.com/github/middleman/middleman-blog
|
59
|
+
[rubydoc]: http://rubydoc.info/github/middleman/middleman-blog
|
60
|
+
[LICENSE]: https://github.com/jasl/middleman-blog_page/blob/master/LICENSE.md
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
require 'middleman-core'
|
7
|
+
|
8
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
9
|
+
ENV["TEST"] = "true"
|
10
|
+
|
11
|
+
exempt_tags = ""
|
12
|
+
exempt_tags << "--tags ~@nojava " if RUBY_PLATFORM == "java"
|
13
|
+
exempt_tags << "--tags ~@three_one " unless ::Middleman::VERSION.match(/^3\.1\./)
|
14
|
+
|
15
|
+
t.cucumber_opts = "--color --tags ~@wip #{exempt_tags} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rake/clean'
|
19
|
+
|
20
|
+
task :test => ["cucumber"]
|
21
|
+
|
22
|
+
begin
|
23
|
+
require 'cane/rake_task'
|
24
|
+
|
25
|
+
desc "Run cane to check quality metrics"
|
26
|
+
Cane::RakeTask.new(:quality) do |cane|
|
27
|
+
cane.no_style = true
|
28
|
+
cane.no_doc = true
|
29
|
+
cane.abc_glob = "lib/middleman-blog_page/**/*.rb"
|
30
|
+
end
|
31
|
+
rescue LoadError
|
32
|
+
# warn "cane not available, quality task not provided."
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Build HTML documentation"
|
36
|
+
task :doc do
|
37
|
+
sh 'bundle exec yard'
|
38
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "middleman-core"
|
2
|
+
|
3
|
+
require "middleman-blog_page/version"
|
4
|
+
|
5
|
+
::Middleman::Extensions.register(:blog_page) do
|
6
|
+
if defined?(::Middleman::Extension)
|
7
|
+
require "middleman-blog_page/extension_3_1"
|
8
|
+
::Middleman::BlogPageExtension
|
9
|
+
else
|
10
|
+
require "middleman-blog_page/extension_3_0"
|
11
|
+
::Middleman::BlogPage
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'active_support/time_with_zone'
|
2
|
+
require 'active_support/core_ext/time/calculations'
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module BlogPage
|
6
|
+
# A module that adds blog_page-article methods to Resources.
|
7
|
+
module BlogPageArticle
|
8
|
+
def self.extended(base)
|
9
|
+
base.class.send(:attr_accessor, :blog_page_controller)
|
10
|
+
end
|
11
|
+
|
12
|
+
def blog_page_data
|
13
|
+
if self.blog_page_controller
|
14
|
+
self.blog_page_controller.data
|
15
|
+
else
|
16
|
+
app.blog_page
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def blog_options
|
21
|
+
if self.blog_page_controller
|
22
|
+
self.blog_page_controller.options
|
23
|
+
else
|
24
|
+
app.blog_page.options
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Render this resource
|
29
|
+
# @return [String]
|
30
|
+
def render(opts={}, locs={}, &block)
|
31
|
+
if opts[:layout].nil?
|
32
|
+
if metadata[:options] && !metadata[:options][:layout].nil?
|
33
|
+
opts[:layout] = metadata[:options][:layout]
|
34
|
+
end
|
35
|
+
opts[:layout] = blog_options.layout if opts[:layout].nil?
|
36
|
+
opts[:layout] = opts[:layout].to_s if opts[:layout].is_a? Symbol
|
37
|
+
end
|
38
|
+
|
39
|
+
super(opts, locs, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
# The title of the article, set from frontmatter
|
43
|
+
# @return [String]
|
44
|
+
def title
|
45
|
+
data["title"]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Whether or not this article has been published
|
49
|
+
#
|
50
|
+
# An article is considered published in the following scenarios:
|
51
|
+
#
|
52
|
+
# 1. frontmatter does not set published to false and either
|
53
|
+
# 2. published_future_dated is true or
|
54
|
+
# 3. article date is after the current time
|
55
|
+
# @return [Boolean]
|
56
|
+
def published?
|
57
|
+
(data["published"] != false) and
|
58
|
+
(blog_options.publish_future_dated || date <= Time.current)
|
59
|
+
end
|
60
|
+
|
61
|
+
# The body of this article, in HTML. This is for
|
62
|
+
# things like RSS feeds or lists of articles - individual
|
63
|
+
# articles will automatically be rendered from their
|
64
|
+
# template.
|
65
|
+
# @return [String]
|
66
|
+
def body
|
67
|
+
render(:layout => false)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Retrieve a section of the source path
|
71
|
+
# @param [String] The part of the path, e.g. "year", "month", "day", "title"
|
72
|
+
# @return [String]
|
73
|
+
def path_part(part)
|
74
|
+
@_path_parts ||= blog_page_data.path_matcher.match(path).captures
|
75
|
+
@_path_parts[blog_page_data.matcher_indexes[part]]
|
76
|
+
end
|
77
|
+
|
78
|
+
# The "slug" of the article that shows up in its URL.
|
79
|
+
# @return [String]
|
80
|
+
def slug
|
81
|
+
@_slug ||= data["slug"]
|
82
|
+
|
83
|
+
@_slug ||= if blog_options.sources.include?(":title")
|
84
|
+
path_part("title")
|
85
|
+
elsif title
|
86
|
+
title.parameterize
|
87
|
+
else
|
88
|
+
raise "Can't generate a slug for #{path} because it has no :title in its path pattern or title/slug in its frontmatter."
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# The "priority" of the article make how order articles
|
93
|
+
# @return [Integer]
|
94
|
+
def priority
|
95
|
+
@_priority ||= data["priority"].to_i
|
96
|
+
end
|
97
|
+
|
98
|
+
def inspect
|
99
|
+
"#<Middleman::BlogPage::BlogPageArticle: #{data.inspect}>"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
module Middleman
|
2
|
+
module BlogPage
|
3
|
+
# A store of all the blog articles in the site, with accessors
|
4
|
+
# for the articles by various dimensions. Accessed via "blog" in
|
5
|
+
# templates.
|
6
|
+
class BlogPageData
|
7
|
+
# A regex for matching blog article source paths
|
8
|
+
# @return [Regex]
|
9
|
+
attr_reader :path_matcher
|
10
|
+
|
11
|
+
# A hash of indexes into the path_matcher captures
|
12
|
+
# @return [Hash]
|
13
|
+
attr_reader :matcher_indexes
|
14
|
+
|
15
|
+
# The configured options for this blog
|
16
|
+
# @return [Thor::CoreExt::HashWithIndifferentAccess]
|
17
|
+
attr_reader :options
|
18
|
+
|
19
|
+
attr_reader :controller
|
20
|
+
|
21
|
+
# @private
|
22
|
+
def initialize(app, options={}, controller=nil)
|
23
|
+
@app = app
|
24
|
+
@options = options
|
25
|
+
@controller = controller
|
26
|
+
|
27
|
+
# A list of resources corresponding to blog page articles
|
28
|
+
@_articles = []
|
29
|
+
|
30
|
+
matcher = Regexp.escape(options.sources).
|
31
|
+
sub(/^\//, "").
|
32
|
+
sub(":title", "([^/]+)")
|
33
|
+
|
34
|
+
subdir_matcher = matcher.sub(/\\\.[^.]+$/, "(/.*)$")
|
35
|
+
|
36
|
+
@path_matcher = /^#{matcher}/
|
37
|
+
@subdir_matcher = /^#{subdir_matcher}/
|
38
|
+
|
39
|
+
# Build a hash of part name to capture index, e.g. {"year" => 0}
|
40
|
+
@matcher_indexes = {}
|
41
|
+
options.sources.scan(/:title/).
|
42
|
+
each_with_index do |key, i|
|
43
|
+
@matcher_indexes[key[1..-1]] = i
|
44
|
+
end
|
45
|
+
# The path always appears at the end.
|
46
|
+
@matcher_indexes["path"] = @matcher_indexes.size
|
47
|
+
end
|
48
|
+
|
49
|
+
# A list of all blog articles, sorted by descending priority
|
50
|
+
# @return [Array<Middleman::Sitemap::Resource>]
|
51
|
+
def pages
|
52
|
+
@_articles.sort_by(&:priority).reverse
|
53
|
+
end
|
54
|
+
|
55
|
+
# The BlogArticle for the given path, or nil if one doesn't exist.
|
56
|
+
# @return [Middleman::Sitemap::Resource]
|
57
|
+
def page(path)
|
58
|
+
article = @app.sitemap.find_resource_by_path(path.to_s)
|
59
|
+
if article && article.is_a?(BlogPageArticle)
|
60
|
+
article
|
61
|
+
else
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Updates' blog articles destination paths to be the
|
67
|
+
# permalink.
|
68
|
+
# @return [void]
|
69
|
+
def manipulate_resource_list(resources)
|
70
|
+
@_articles = []
|
71
|
+
used_resources = []
|
72
|
+
|
73
|
+
resources.each do |resource|
|
74
|
+
if resource.path =~ path_matcher
|
75
|
+
resource.extend BlogPageArticle
|
76
|
+
|
77
|
+
if @controller
|
78
|
+
resource.blog_page_controller = controller
|
79
|
+
end
|
80
|
+
|
81
|
+
# Skip articles that are not published (in non-development environments)
|
82
|
+
next unless @app.environment == :development || resource.published?
|
83
|
+
|
84
|
+
# compute output path:
|
85
|
+
# substitute date parts to path pattern
|
86
|
+
resource.destination_path = Middleman::Util.normalize_path parse_permalink_options(resource)
|
87
|
+
|
88
|
+
@_articles << resource
|
89
|
+
|
90
|
+
elsif resource.path =~ @subdir_matcher
|
91
|
+
match = $~.captures
|
92
|
+
|
93
|
+
article_path = options.sources
|
94
|
+
article_path = article_path.sub(":title", match[@matcher_indexes["title"]]) if @matcher_indexes["title"]
|
95
|
+
puts article_path
|
96
|
+
|
97
|
+
article = @app.sitemap.find_resource_by_path(article_path)
|
98
|
+
raise "Article for #{resource.path} not found" if article.nil?
|
99
|
+
article.extend BlogPageArticle
|
100
|
+
|
101
|
+
# Skip files that belong to articles that are not published (in non-development environments)
|
102
|
+
next unless @app.environment == :development || article.published?
|
103
|
+
|
104
|
+
# The subdir path is the article path with the index file name
|
105
|
+
# or file extension stripped off.
|
106
|
+
resource.destination_path = parse_permalink_options(article).
|
107
|
+
sub(/(\/#{@app.index_file}$)|(\.[^.]+$)|(\/$)/, match[@matcher_indexes["path"]])
|
108
|
+
|
109
|
+
resource.destination_path = Middleman::Util.normalize_path(resource.destination_path)
|
110
|
+
end
|
111
|
+
|
112
|
+
used_resources << resource
|
113
|
+
end
|
114
|
+
|
115
|
+
used_resources
|
116
|
+
end
|
117
|
+
|
118
|
+
def parse_permalink_options(resource)
|
119
|
+
permalink = options.permalink.sub(':title', resource.slug)
|
120
|
+
|
121
|
+
custom_permalink_components.each do |component|
|
122
|
+
permalink = permalink.sub(":#{component}", resource.data[component].parameterize)
|
123
|
+
end
|
124
|
+
|
125
|
+
permalink
|
126
|
+
end
|
127
|
+
|
128
|
+
def custom_permalink_components
|
129
|
+
permalink_url_components.reject { |component| component.to_sym == :title }
|
130
|
+
end
|
131
|
+
|
132
|
+
def permalink_url_components
|
133
|
+
options.permalink.scan(/:([A-Za-z0-9]+)/).flatten
|
134
|
+
end
|
135
|
+
|
136
|
+
def inspect
|
137
|
+
"#<Middleman::BlogPage::BlogPageData: #{articles.inspect}>"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Middleman
|
2
|
+
module BlogPage
|
3
|
+
class Options
|
4
|
+
KEYS = [
|
5
|
+
:prefix,
|
6
|
+
:permalink,
|
7
|
+
:sources,
|
8
|
+
:layout,
|
9
|
+
:default_extension
|
10
|
+
]
|
11
|
+
|
12
|
+
KEYS.each do |name|
|
13
|
+
attr_accessor name
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(options={})
|
17
|
+
options.each do |k,v|
|
18
|
+
self.send(:"#{k}=", v)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def registered(app, options_hash={}, &block)
|
25
|
+
require 'middleman-blog/blog_page_data'
|
26
|
+
require 'middleman-blog/blog_page_article'
|
27
|
+
require 'active_support/core_ext/time/zones'
|
28
|
+
|
29
|
+
app.send :include, Helpers
|
30
|
+
|
31
|
+
options = Options.new(options_hash)
|
32
|
+
yield options if block_given?
|
33
|
+
|
34
|
+
options.permalink ||= ":title.html"
|
35
|
+
options.sources ||= "pages/:title.html"
|
36
|
+
options.layout ||= "layout"
|
37
|
+
options.default_extension ||= ".markdown"
|
38
|
+
|
39
|
+
# If "prefix" option is specified, all other paths are relative to it.
|
40
|
+
if options.prefix
|
41
|
+
options.prefix = "/#{options.prefix}" unless options.prefix.start_with? '/'
|
42
|
+
options.permalink = File.join(options.prefix, options.permalink)
|
43
|
+
options.sources = File.join(options.prefix, options.sources)
|
44
|
+
end
|
45
|
+
|
46
|
+
app.after_configuration do
|
47
|
+
# Make sure ActiveSupport's TimeZone stuff has something to work with,
|
48
|
+
# allowing people to set their desired time zone via Time.zone or
|
49
|
+
# set :time_zone
|
50
|
+
Time.zone = self.time_zone if self.respond_to?(:time_zone)
|
51
|
+
time_zone = Time.zone if Time.zone
|
52
|
+
zone_default = Time.find_zone!(time_zone || 'UTC')
|
53
|
+
unless zone_default
|
54
|
+
raise 'Value assigned to time_zone not recognized.'
|
55
|
+
end
|
56
|
+
Time.zone_default = zone_default
|
57
|
+
|
58
|
+
# Initialize blog with options
|
59
|
+
blog_page(options)
|
60
|
+
|
61
|
+
sitemap.register_resource_list_manipulator(
|
62
|
+
:blog_pages,
|
63
|
+
blog_page,
|
64
|
+
false
|
65
|
+
)
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
alias :included :registered
|
70
|
+
end
|
71
|
+
|
72
|
+
# Helpers for use within templates and layouts.
|
73
|
+
module Helpers
|
74
|
+
# Get the {BlogPageData} for this site.
|
75
|
+
# @return [BlogPageData]
|
76
|
+
def blog_page(options=nil)
|
77
|
+
@_blog_page ||= BlogPageData.new(self, options)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Determine whether the currently rendering template is a blog article.
|
81
|
+
# This can be useful in layouts.
|
82
|
+
# @return [Boolean]
|
83
|
+
def is_blog_page?
|
84
|
+
!current_blog_page.nil?
|
85
|
+
end
|
86
|
+
|
87
|
+
# Get a {Resource} with mixed in {BlogArticle} methods representing the current article.
|
88
|
+
# @return [Middleman::Sitemap::Resource]
|
89
|
+
def current_blog_page
|
90
|
+
blog_page.page(current_resource.path)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns the list of articles to display on this page.
|
94
|
+
# @return [Array<Middleman::Sitemap::Resource>]
|
95
|
+
def blog_pages
|
96
|
+
blog_page.pages
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Middleman
|
2
|
+
class BlogPageExtension < Extension
|
3
|
+
self.supports_multiple_instances = true
|
4
|
+
|
5
|
+
option :name, nil, 'Unique ID for telling multiple blog pages apart'
|
6
|
+
option :prefix, nil, 'Prefix to mount the blog page at'
|
7
|
+
option :permalink, ":title.html", 'HTTP path to host pages at'
|
8
|
+
option :sources, "pages/:title.html", 'How to extract metadata from on-disk files'
|
9
|
+
option :layout, "layout", 'Article-specific layout'
|
10
|
+
option :default_extension, ".markdown", 'Default article extension'
|
11
|
+
|
12
|
+
attr_accessor :data, :uid
|
13
|
+
|
14
|
+
def initialize(app, options_hash={}, &block)
|
15
|
+
super
|
16
|
+
|
17
|
+
@uid = options.name
|
18
|
+
|
19
|
+
require 'middleman-blog_page/blog_page_data'
|
20
|
+
require 'middleman-blog_page/blog_page_article'
|
21
|
+
require 'active_support/core_ext/time/zones'
|
22
|
+
|
23
|
+
# app.set :time_zone, 'UTC'
|
24
|
+
|
25
|
+
# If "prefix" option is specified, all other paths are relative to it.
|
26
|
+
if options.prefix
|
27
|
+
options.prefix = "/#{options.prefix}" unless options.prefix.start_with? '/'
|
28
|
+
options.permalink = File.join(options.prefix, options.permalink)
|
29
|
+
options.sources = File.join(options.prefix, options.sources)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def after_configuration
|
34
|
+
@uid ||= "blog_page#{@app.blog_instances.keys.length}"
|
35
|
+
|
36
|
+
@app.blog_page_instances[@uid.to_sym] = self
|
37
|
+
|
38
|
+
# Make sure ActiveSupport's TimeZone stuff has something to work with,
|
39
|
+
# allowing people to set their desired time zone via Time.zone or
|
40
|
+
# set :time_zone
|
41
|
+
Time.zone = app.config[:time_zone] if app.config[:time_zone]
|
42
|
+
time_zone = Time.zone if Time.zone
|
43
|
+
zone_default = Time.find_zone!(time_zone || 'UTC')
|
44
|
+
unless zone_default
|
45
|
+
raise 'Value assigned to time_zone not recognized.'
|
46
|
+
end
|
47
|
+
Time.zone_default = zone_default
|
48
|
+
|
49
|
+
# Initialize blog with options
|
50
|
+
|
51
|
+
@data = ::Middleman::BlogPage::BlogPageData.new(@app, options, self)
|
52
|
+
|
53
|
+
@app.sitemap.register_resource_list_manipulator(
|
54
|
+
:"blog_#{uid}_pages",
|
55
|
+
@data,
|
56
|
+
false
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Helpers for use within templates and layouts.
|
61
|
+
helpers do
|
62
|
+
def blog_page_instances
|
63
|
+
@blog_page_instances ||= {}
|
64
|
+
end
|
65
|
+
|
66
|
+
def blog_page_controller(key=nil)
|
67
|
+
if !key && current_resource
|
68
|
+
key = current_resource.metadata[:page]["blog_page"]
|
69
|
+
|
70
|
+
if !key && current_resource.respond_to?(:blog_page_controller) && current_resource.blog_page_controller
|
71
|
+
return current_resource.blog_page_controller
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# In multiblog situations, force people to specify the blog
|
76
|
+
if !key && blog_page_instances.size > 1
|
77
|
+
raise "You must either specify the blog page name in calling this method or in your page frontmatter (using the 'blog' key)"
|
78
|
+
end
|
79
|
+
|
80
|
+
key ||= blog_page_instances.keys.first
|
81
|
+
blog_page_instances[key.to_sym]
|
82
|
+
end
|
83
|
+
|
84
|
+
def blog_page(key=nil)
|
85
|
+
blog_page_controller(key).data
|
86
|
+
end
|
87
|
+
|
88
|
+
# Determine whether the currently rendering template is a blog article.
|
89
|
+
# This can be useful in layouts.
|
90
|
+
# @return [Boolean]
|
91
|
+
def is_blog_page?
|
92
|
+
!current_blog_page.nil?
|
93
|
+
end
|
94
|
+
|
95
|
+
# Get a {Resource} with mixed in {BlogArticle} methods representing the current article.
|
96
|
+
# @return [Middleman::Sitemap::Resource]
|
97
|
+
def current_blog_page
|
98
|
+
blog_page_instances.each do |key, blog|
|
99
|
+
found = blog.data.page(current_resource.path)
|
100
|
+
return found if found
|
101
|
+
end
|
102
|
+
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns the list of articles to display on this page.
|
107
|
+
# @return [Array<Middleman::Sitemap::Resource>]
|
108
|
+
def blog_pages(key=nil)
|
109
|
+
blog_page(key).pages
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "middleman-blog_page"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "middleman-blog_page/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "middleman-blog_page"
|
7
|
+
s.version = Middleman::BlogPage::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["jasl"]
|
10
|
+
s.email = ["jasl9187@hotmail.com"]
|
11
|
+
s.homepage = "https://github.com/jasl/middleman-blog_page"
|
12
|
+
s.summary = %q{Blog page engine for Middleman}
|
13
|
+
s.description = %q{Blog page engine for Middleman}
|
14
|
+
s.license = "MIT"
|
15
|
+
s.files = `git ls-files -z`.split("\0")
|
16
|
+
s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.add_dependency("middleman-core", ["~> 3.2"])
|
19
|
+
s.add_dependency("tzinfo", ["~> 0.3.0"])
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-blog_page
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jasl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tzinfo
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.0
|
41
|
+
description: Blog page engine for Middleman
|
42
|
+
email:
|
43
|
+
- jasl9187@hotmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.md
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/middleman-blog_page.rb
|
54
|
+
- lib/middleman-blog_page/blog_page_article.rb
|
55
|
+
- lib/middleman-blog_page/blog_page_data.rb
|
56
|
+
- lib/middleman-blog_page/extension_3_0.rb
|
57
|
+
- lib/middleman-blog_page/extension_3_1.rb
|
58
|
+
- lib/middleman-blog_page/version.rb
|
59
|
+
- lib/middleman_extension.rb
|
60
|
+
- middleman-blog_page.gemspec
|
61
|
+
homepage: https://github.com/jasl/middleman-blog_page
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.3
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Blog page engine for Middleman
|
85
|
+
test_files: []
|
86
|
+
has_rdoc:
|