middleman-blog 0.1.5 → 3.0.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +5 -0
  3. data/.travis.yml +9 -0
  4. data/.yardopts +3 -0
  5. data/Gemfile +19 -0
  6. data/LICENSE +20 -0
  7. data/README.md +62 -0
  8. data/Rakefile +15 -0
  9. data/features/article_cli.feature +7 -0
  10. data/features/blog_sources.feature +9 -0
  11. data/features/calendar.feature +30 -0
  12. data/features/directory_indexes.feature +6 -0
  13. data/features/encoding.feature +0 -0
  14. data/features/filename_date.feature +9 -0
  15. data/features/next_previous.feature +8 -0
  16. data/features/preview.feature +29 -0
  17. data/features/support/env.rb +4 -0
  18. data/features/tags.feature +50 -0
  19. data/fixtures/blog-sources-app/config.rb +3 -0
  20. data/fixtures/blog-sources-app/source/_article_template.erb +1 -0
  21. data/fixtures/blog-sources-app/source/blog/2011-01-01-new-article.html.markdown +6 -0
  22. data/fixtures/blog-sources-app/source/index.html.erb +9 -0
  23. data/fixtures/blog-sources-app/source/layout.erb +13 -0
  24. data/fixtures/calendar-app/config.rb +5 -0
  25. data/fixtures/calendar-app/source/blog/2011-01-01-new-article.html.markdown +7 -0
  26. data/fixtures/calendar-app/source/blog/2011-01-02-another-article.html.markdown +8 -0
  27. data/fixtures/calendar-app/source/calendar.html.erb +13 -0
  28. data/fixtures/calendar-app/source/index.html.erb +3 -0
  29. data/fixtures/calendar-app/source/layout.erb +15 -0
  30. data/fixtures/filename-date-app/config.rb +1 -0
  31. data/fixtures/filename-date-app/source/2011-01-01-new-article.html.markdown +5 -0
  32. data/fixtures/filename-date-app/source/2011-01-03-filename-and-frontmatter.html.markdown +6 -0
  33. data/fixtures/filename-date-app/source/layout.erb +14 -0
  34. data/fixtures/indexes-app/config.rb +5 -0
  35. data/fixtures/indexes-app/source/2011/01/01/new-article.html.markdown +6 -0
  36. data/fixtures/indexes-app/source/_article_template.erb +1 -0
  37. data/fixtures/indexes-app/source/index.html.erb +9 -0
  38. data/fixtures/indexes-app/source/layout.erb +13 -0
  39. data/fixtures/preview-app/config.rb +3 -0
  40. data/fixtures/preview-app/source/2011/01/01/new-article.html.markdown +6 -0
  41. data/fixtures/preview-app/source/_article_template.erb +10 -0
  42. data/fixtures/preview-app/source/index.html.erb +9 -0
  43. data/fixtures/preview-app/source/layout.erb +22 -0
  44. data/fixtures/tags-app/config.rb +6 -0
  45. data/fixtures/tags-app/source/blog/2011-01-01-new-article.html.markdown +7 -0
  46. data/fixtures/tags-app/source/blog/2011-01-02-another-article.html.markdown +8 -0
  47. data/fixtures/tags-app/source/index.html.erb +3 -0
  48. data/fixtures/tags-app/source/layout.erb +13 -0
  49. data/fixtures/tags-app/source/tag.html.erb +7 -0
  50. data/fixtures/utf8ouch/config.rb +17 -0
  51. data/fixtures/utf8ouch/source/2010/11/13/telling-time.html.markdown +73 -0
  52. data/fixtures/utf8ouch/source/2011/01/01/new-article.html.markdown +6 -0
  53. data/{lib/middleman-blog/template → fixtures/utf8ouch}/source/_article_template.erb +0 -0
  54. data/{lib/middleman-blog/template → fixtures/utf8ouch}/source/archives/index.html.erb +0 -0
  55. data/fixtures/utf8ouch/source/feed.xml.builder +23 -0
  56. data/fixtures/utf8ouch/source/index.html.erb +9 -0
  57. data/fixtures/utf8ouch/source/layout.erb +30 -0
  58. data/lib/middleman-blog.rb +10 -2
  59. data/lib/middleman-blog/blog_article.rb +123 -0
  60. data/lib/middleman-blog/blog_data.rb +94 -0
  61. data/lib/middleman-blog/calendar_pages.rb +85 -0
  62. data/lib/middleman-blog/commands/article.rb +52 -0
  63. data/lib/middleman-blog/commands/article.tt +6 -0
  64. data/lib/middleman-blog/extension.rb +170 -0
  65. data/lib/middleman-blog/tag_pages.rb +33 -0
  66. data/lib/middleman-blog/template.rb +19 -8
  67. data/lib/middleman-blog/template/config.tt +101 -5
  68. data/lib/middleman-blog/template/shared/Gemfile.tt +4 -0
  69. data/lib/middleman-blog/template/source/2012-01-01-example-article.html.markdown +7 -0
  70. data/lib/middleman-blog/template/source/calendar.html.erb +15 -0
  71. data/lib/middleman-blog/template/source/feed.xml.builder +2 -2
  72. data/lib/middleman-blog/template/source/index.html.erb +8 -9
  73. data/lib/middleman-blog/template/source/layout.erb +18 -12
  74. data/lib/middleman-blog/template/source/tag.html.erb +7 -0
  75. data/lib/middleman-blog/version.rb +1 -1
  76. data/lib/{middleman_init.rb → middleman_extension.rb} +0 -0
  77. data/middleman-blog.gemspec +1 -2
  78. metadata +110 -63
  79. data/lib/middleman-blog/feature.rb +0 -162
  80. data/lib/middleman-blog/template/config.ru +0 -9
  81. data/lib/middleman-blog/template/source/2011/01/01/new-article.html.markdown +0 -6
@@ -0,0 +1,14 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <% if is_blog_article? %>
7
+ <%= yield %>
8
+ <%= current_article.url %>
9
+ <p>Date: <%= current_article.date %></p>
10
+ <% else %>
11
+ <%= yield %>
12
+ <% end %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,5 @@
1
+ activate :blog do |blog|
2
+ blog.sources = ":year/:month/:day/:title.html"
3
+ end
4
+
5
+ activate :directory_indexes
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Newer Article"
3
+ date: 2011-01-01
4
+ ---
5
+
6
+ Newer Article Content
@@ -0,0 +1 @@
1
+ <%= current_article.url %>
@@ -0,0 +1,9 @@
1
+ <% blog.articles[0...5].each_with_index do |article, i| %>
2
+ <article class="<%= (i == 0) ? 'first' : '' %>">
3
+ <h1><a href="<%= article.url %>"><%= article.title %></a> <span><%= article.date.strftime('%b %e %Y') %></span></h1>
4
+
5
+ <%= article.summary %>
6
+
7
+ <div class="more"><a href="<%= article.url %>">read on &raquo;</a></div>
8
+ </article>
9
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <% if is_blog_article? %>
7
+ <% content_for :blog_article, yield %>
8
+ <%= partial 'article_template' %>
9
+ <% else %>
10
+ <%= yield %>
11
+ <% end %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ activate :blog do |blog|
2
+ blog.sources = ":year/:month/:day/:title.html"
3
+ end
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Newer Article"
3
+ date: 2011-01-01
4
+ ---
5
+
6
+ Newer Article Content
@@ -0,0 +1,10 @@
1
+ <article class="hentry">
2
+ <h1 class="entry-title">
3
+ <%= current_article.title %>
4
+ <time class="updated"><%= current_article.date.strftime('%b %e %Y') %></time>
5
+ </h1>
6
+
7
+ <div class="entry-content">
8
+ <%= yield_content :blog_article %>
9
+ </div>
10
+ </article>
@@ -0,0 +1,9 @@
1
+ <% data.blog.articles[0...5].each_with_index do |article, i| %>
2
+ <article class="<%= (i == 0) ? 'first' : '' %>">
3
+ <h1><a href="<%= article.url %>"><%= article.title %></a> <span><%= article.date.strftime('%b %e %Y') %></span></h1>
4
+
5
+ <%= article.summary %>
6
+
7
+ <div class="more"><a href="<%= article.url %>">read on &raquo;</a></div>
8
+ </article>
9
+ <% end %>
@@ -0,0 +1,22 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta http-equiv='X-UA-Compatible' content='IE=edge;chrome=1' />
6
+
7
+ <% if is_blog_article? %>
8
+ <title><%= current_article.title %></title>
9
+ <% end %>
10
+ </head>
11
+ <body>
12
+
13
+ <div id="main" role="main">
14
+ <% if is_blog_article? %>
15
+ <% content_for :blog_article, yield %>
16
+ <%= partial 'article_template' %>
17
+ <% else %>
18
+ <%= yield %>
19
+ <% end %>
20
+ </div>
21
+ </body>
22
+ </html>
@@ -0,0 +1,6 @@
1
+ require "middleman-blog"
2
+ activate :blog do |blog|
3
+ blog.sources = "blog/:year-:month-:day-:title.html"
4
+ blog.permalink = "blog/:year-:month-:day-:title.html"
5
+ blog.tag_template = "/tag.html"
6
+ end
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: "Newer Article"
3
+ date: 2011-01-01
4
+ tags: foo, bar
5
+ ---
6
+
7
+ Newer Article Content
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: "Another Article"
3
+ date: 2011-01-02
4
+ tags:
5
+ - foo
6
+ ---
7
+
8
+ Another Article Content
@@ -0,0 +1,3 @@
1
+ <% blog.articles[0...12].each do |article| %>
2
+ <li><a href="<%= article.url %>"><%= article.title %></a> <time><%= article.date.strftime('%b %e') %></time></li>
3
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <% if is_blog_article? %>
7
+ <%= yield %>
8
+ <%= current_article.url %>
9
+ <% else %>
10
+ <%= yield %>
11
+ <% end %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,7 @@
1
+ Tag: <%= @tag %>
2
+
3
+ <% if @articles %>
4
+ <% @articles[0...12].each do |article| %>
5
+ <li><a href="<%= article.url %>"><%= article.title %></a> <time><%= article.date.strftime('%b %e') %></time></li>
6
+ <% end %>
7
+ <% end %>
@@ -0,0 +1,17 @@
1
+ activate :blog do |blog|
2
+ blog.sources = ":year/:month/:day/:title.html"
3
+ end
4
+
5
+ page "/feed.xml", :layout => false
6
+
7
+ # Build-specific configuration
8
+ configure :build do
9
+ # For example, change the Compass output style for deployment
10
+ # activate :minify_css
11
+
12
+ # Minify Javascript on build
13
+ # activate :minify_javascript
14
+
15
+ # Enable cache buster
16
+ # activate :cache_buster
17
+ end
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: Telling Time.
3
+ date: 2010/11/13
4
+ ---
5
+
6
+ Norse legend tells of the end of this cycle of Middle Earth,
7
+ before the death of gods and the total submergence of its peoples. A
8
+ great battle will take place before this time, called Ragnarok, in
9
+ which even Odin will meet his fate in the jaws of Fenrir. Yet, the
10
+ future might be bent; the All Father watches anxiously for signs of
11
+ Ragnarok's quickening.
12
+
13
+ READMORE
14
+
15
+ It was said that after hanging from Yggdrasil, Odin learned of eighteen runes; nine of which he would tell no one. From these had Odin learned Posix programming perhaps he might have constructed himself a warning device.
16
+
17
+ #include <stdio.h>
18
+ #include <stdlib.h>
19
+ #include <signal.h>
20
+ #include <stdbool.h>
21
+ #include <sys/time.h>
22
+
23
+ bool near = false ;
24
+
25
+ void handler(int cause, siginfo_t *HowCome, void *ucontext) {
26
+ near = !near;
27
+ }
28
+
29
+ int main() {
30
+ struct itimerval itimer;
31
+ struct sigaction sa;
32
+ int i = 0;
33
+
34
+ sigemptyset( &sa.sa_mask ); /* Block no signals. */
35
+ sa.sa_flags = SA_SIGINFO; /* Route signal handler to sa_sigaction */
36
+ sa.sa_sigaction = handler; /* Define fancy handler. */
37
+ if (sigaction (SIGALRM, &sa, 0)) {
38
+ perror("sigaction");
39
+ exit(EXIT_FAILURE);
40
+ }
41
+
42
+ itimer.it_value.tv_sec=0;
43
+ itimer.it_value.tv_usec=7000; /* 0.007 seconds to the next timer. */
44
+ itimer.it_interval.tv_sec=0;
45
+ itimer.it_interval.tv_usec=7000; /* 0.007 seconds for each timer after. */
46
+ setitimer(ITIMER_REAL, &itimer, NULL);
47
+
48
+ while (i != 1000000) {
49
+ switch (near) {
50
+ case false: {
51
+ ++i;
52
+ } break;
53
+ case true: {
54
+ --i; // BUG FIX: Damned small monitor. + is - with only one eye!
55
+ } break;
56
+ }
57
+ }
58
+
59
+ /*
60
+ Sneru þær af afli
61
+ örlögþáttu,
62
+ þá er borgir braut
63
+ í Bráluni;
64
+ þær of greiddu
65
+ gullin símu
66
+ ok und mánasal
67
+ miðjan festu.
68
+ */
69
+
70
+ printf("Ragnarök is nigh.\n");
71
+ exit(EXIT_SUCCESS);
72
+ }
73
+
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "New Article title"
3
+ date: 2011/01/01
4
+ ---
5
+
6
+ Content of my article
@@ -0,0 +1,23 @@
1
+ xml.instruct!
2
+ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3
+ xml.title "Blog Name"
4
+ xml.subtitle "Blog subtitle"
5
+ xml.id "http://blog.url.com/"
6
+ xml.link "href" => "http://blog.url.com/"
7
+ xml.link "href" => "http://blog.url.com/feed.xml", "rel" => "self"
8
+ xml.updated data.blog.articles.first.date.to_time.iso8601
9
+ xml.author { xml.name "Blog Author" }
10
+
11
+ data.blog.articles.each do |article|
12
+ xml.entry do
13
+ xml.title article.title
14
+ xml.link "rel" => "alternate", "href" => article.url
15
+ xml.id article.url
16
+ xml.published article.date.to_time.iso8601
17
+ xml.updated article.date.to_time.iso8601
18
+ xml.author { xml.name "Article Author" }
19
+ xml.summary article.summary, "type" => "html"
20
+ xml.content article.body, "type" => "html"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ <% data.blog.articles[0...5].each_with_index do |article, i| %>
2
+ <article class="<%= (i == 0) ? 'first' : '' %>">
3
+ <h1><a href="<%= article.url %>"><%= article.title %></a> <span><%= article.date.strftime('%b %e %Y') %></span></h1>
4
+
5
+ <%= article.summary %>
6
+
7
+ <div class="more"><a href="<%= article.url %>">read on &raquo;</a></div>
8
+ </article>
9
+ <% end %>
@@ -0,0 +1,30 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta http-equiv='X-UA-Compatible' content='IE=edge;chrome=1' />
6
+ </head>
7
+ <body>
8
+
9
+ <div id="main" role="main">
10
+ <% if is_blog_article? %>
11
+ <% content_for :blog_article, yield %>
12
+ <%= partial blog.article_template %>
13
+ <% else %>
14
+ <%= yield %>
15
+ <% end %>
16
+ </div>
17
+
18
+ <aside>
19
+ <h2>
20
+ Recent Articles
21
+ <a href="/archives">Archive</a>
22
+ </h2>
23
+ <ol>
24
+ <% data.blog.articles[0...10].each do |article| %>
25
+ <li><a href="<%= article.url %>"><%= article.title %></a> <span><%= article.date.strftime('%b %e') %></span></li>
26
+ <% end %>
27
+ </li>
28
+ </aside>
29
+ </body>
30
+ </html>
@@ -1,2 +1,10 @@
1
- require "middleman-blog/feature"
2
- require "middleman-blog/template"
1
+ require "middleman-core"
2
+
3
+ require "middleman-blog/version"
4
+ require "middleman-blog/template"
5
+ require "middleman-blog/commands/article"
6
+
7
+ ::Middleman::Extensions.register(:blog, ">= 3.0.0.beta.3") do
8
+ require "middleman-blog/extension"
9
+ ::Middleman::Blog
10
+ end
@@ -0,0 +1,123 @@
1
+ require 'date'
2
+
3
+ module Middleman
4
+ module Blog
5
+ # A module that adds blog-article methods to Resources.
6
+ module BlogArticle
7
+ # The "slug" of the article that shows up in its URL.
8
+ # @return [String]
9
+ attr_accessor :slug
10
+
11
+ # Render this resource
12
+ # @return [String]
13
+ def render(opts={}, locs={}, &block)
14
+ opts[:layout] = app.blog.options.layout if opts[:layout].nil?
15
+
16
+ content = super(opts, locs, &block)
17
+
18
+ unless opts[:keep_separator]
19
+ if content =~ app.blog.options.summary_separator
20
+ content.sub!($1, "")
21
+ end
22
+ end
23
+
24
+ content
25
+ end
26
+
27
+ # The title of the article, set from frontmatter
28
+ # @return [String]
29
+ def title
30
+ data["title"]
31
+ end
32
+
33
+ # The body of this article, in HTML. This is for
34
+ # things like RSS feeds or lists of articles - individual
35
+ # articles will automatically be rendered from their
36
+ # template.
37
+ # @return [String]
38
+ def body
39
+ render(:layout => false)
40
+ end
41
+
42
+ # The summary for this article, in HTML. The summary is either
43
+ # everything before the summary separator (set via :summary_separator
44
+ # and defaulting to "READMORE") or the first :summary_length
45
+ # characters of the post.
46
+ # @return [String]
47
+ def summary
48
+ @_summary ||= begin
49
+ all_content = render(:layout => false, :keep_separator => true)
50
+ if all_content =~ app.blog.options.summary_separator
51
+ all_content.split(app.blog.options.summary_separator).first
52
+ else
53
+ all_content.match(/(.{1,#{app.blog.options.summary_length}}.*?)(\n|\Z)/m).to_s
54
+ end
55
+ end
56
+ end
57
+
58
+ # A list of tags for this article, set from frontmatter.
59
+ # @return [Array<String>] (never nil)
60
+ def tags
61
+ article_tags = data["tags"]
62
+
63
+ if article_tags.is_a? String
64
+ article_tags.split(',').map(&:strip)
65
+ else
66
+ article_tags || []
67
+ end
68
+ end
69
+
70
+ # Attempt to figure out the date of the post. The date should be
71
+ # present in the source path, but users may also provide a date
72
+ # in the frontmatter in order to provide a time of day for sorting
73
+ # reasons.
74
+ #
75
+ # @return [DateTime]
76
+ def date
77
+ return @_date if @_date
78
+
79
+ frontmatter_date = data["date"]
80
+
81
+ # First get the date from frontmatter
82
+ if frontmatter_date.is_a?(String)
83
+ @_date = DateTime.parse(frontmatter_date)
84
+ else
85
+ @_date = frontmatter_date
86
+ end
87
+
88
+ # Next figure out the date from the filename
89
+ if app.blog.options.sources.include?(":year") &&
90
+ app.blog.options.sources.include?(":month") &&
91
+ app.blog.options.sources.include?(":day")
92
+
93
+ date_parts = @app.blog.path_matcher.match(path).captures
94
+
95
+ filename_date = Date.new(date_parts[0].to_i, date_parts[1].to_i, date_parts[2].to_i)
96
+ if @_date
97
+ raise "The date in #{path}'s filename doesn't match the date in its frontmatter" unless @_date.to_date == filename_date
98
+ else
99
+ @_date = filename_date.to_datetime
100
+ end
101
+ end
102
+
103
+ raise "Blog post #{path} needs a date in its filename or frontmatter" unless @_date
104
+
105
+ @_date
106
+ end
107
+
108
+ # The previous (chronologically earlier) article before this one
109
+ # or nil if this is the first article.
110
+ # @return [Middleman::Sitemap::Resource]
111
+ def previous_article
112
+ app.blog.articles.find {|a| a.date < self.date }
113
+ end
114
+
115
+ # The next (chronologically later) article after this one
116
+ # or nil if this is the most recent article.
117
+ # @return [Middleman::Sitemap::Resource]
118
+ def next_article
119
+ app.blog.articles.reverse.find {|a| a.date > self.date }
120
+ end
121
+ end
122
+ end
123
+ end