plate 0.7.0.pre → 0.7.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +1 -0
- data/README.md +6 -1
- data/lib/plate.rb +1 -0
- data/lib/plate/builder.rb +8 -0
- data/lib/plate/cli.rb +19 -3
- data/lib/plate/draft.rb +33 -0
- data/lib/plate/site.rb +62 -5
- data/lib/plate/version.rb +1 -1
- data/lib/templates/config.yml +25 -1
- metadata +15 -14
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -71,6 +71,7 @@ Plate observes the following folder structure in your site:
|
|
71
71
|
|
72
72
|
* config/ - Put your global configuration settings here.
|
73
73
|
* content/ - All custom content for the site, besides blog posts. Everything in this folder will be copied over to the published site.
|
74
|
+
* drafts/ - All drafted blog posts. Posts in this directory are rendered into the `/_drafts` destination.
|
74
75
|
* helpers/ - Helpers are loaded into views automatically and can be used within dynamically rendered pages using a template language. (Such as Erb or Haml)
|
75
76
|
* layouts/ - Global layouts available for use on all content pages and posts.
|
76
77
|
* lib/ - Extend the basic functionality of Plate with plugins in this directory. All `.rb` files run against the Plate DSL.
|
@@ -115,9 +116,13 @@ Then, in your `.erb` view you can call `sample_helper_method`.
|
|
115
116
|
|
116
117
|
All files in the `helpers/` directory are assumed to be helper modules and will be loaded automatically at runtime.
|
117
118
|
|
119
|
+
### Draft Posts
|
120
|
+
|
121
|
+
**In development -docs coming soon.**
|
122
|
+
|
118
123
|
### Partials
|
119
124
|
|
120
|
-
**
|
125
|
+
**In development -docs coming soon.**
|
121
126
|
|
122
127
|
## Full Documentation
|
123
128
|
|
data/lib/plate.rb
CHANGED
data/lib/plate/builder.rb
CHANGED
@@ -215,6 +215,13 @@ module Plate
|
|
215
215
|
end
|
216
216
|
|
217
217
|
page.reload!
|
218
|
+
|
219
|
+
# If this page was a draft, and now is published. Reload the entire site
|
220
|
+
# and publish it.
|
221
|
+
if Draft === page and page.publish?
|
222
|
+
rebuild! and return
|
223
|
+
end
|
224
|
+
|
218
225
|
page.write!
|
219
226
|
|
220
227
|
# File should exist again, even though we just removed it since we re-wrote it.
|
@@ -439,6 +446,7 @@ module Plate
|
|
439
446
|
paths += site.assets.collect(&:write!)
|
440
447
|
paths += site.pages.collect(&:write!)
|
441
448
|
paths += site.posts.collect(&:write!)
|
449
|
+
paths += site.drafts.collect(&:write!)
|
442
450
|
|
443
451
|
@build_paths = paths
|
444
452
|
|
data/lib/plate/cli.rb
CHANGED
@@ -41,6 +41,10 @@ module Plate
|
|
41
41
|
@destination = File.expand_path(d)
|
42
42
|
end
|
43
43
|
|
44
|
+
opts.on("--[no-]draft", "Create a new post as a draft.") do |v|
|
45
|
+
options[:draft] = v
|
46
|
+
end
|
47
|
+
|
44
48
|
opts.on('--layout [LAYOUT]', '-l', 'Pass in a layout for creating a new post.') do |l|
|
45
49
|
options[:layout] = l
|
46
50
|
end
|
@@ -163,6 +167,7 @@ module Plate
|
|
163
167
|
/
|
164
168
|
config
|
165
169
|
content
|
170
|
+
drafts
|
166
171
|
content/css
|
167
172
|
layouts
|
168
173
|
lib
|
@@ -209,14 +214,25 @@ module Plate
|
|
209
214
|
|
210
215
|
category = options[:category] ? "\ncategory: #{options[:category]}" : ""
|
211
216
|
layout = options[:layout] ? "\nlayout: #{options[:layout]}" : ""
|
217
|
+
publish = "\npublish: false"
|
218
|
+
label = "draft"
|
219
|
+
|
220
|
+
filename = File.join(self.source, 'drafts', "#{date.strftime('%Y-%m-%d')}-#{slug}.md")
|
221
|
+
|
222
|
+
# If drafts are disabled, just build the post and put it in its
|
223
|
+
# normal destination file.
|
224
|
+
if options[:draft] == false
|
225
|
+
filename = File.join(self.source, 'posts', date.strftime('%Y/%m'), "#{date.strftime('%Y-%m-%d')}-#{slug}.md")
|
226
|
+
publish = ""
|
227
|
+
label = "post"
|
228
|
+
end
|
212
229
|
|
213
|
-
|
214
|
-
content = %Q(---\ntitle: "#{title}"\ndate: #{date.strftime('%Y-%m-%d %H:%M:%S')}#{category}#{layout}\ntags: []\n\n# #{title}\n\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.)
|
230
|
+
content = %Q(---\ntitle: "#{title}"\ndate: #{date.strftime('%Y-%m-%d %H:%M:%S')}#{category}#{layout}\ntags: []#{publish}\n\n# #{title}\n\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.)
|
215
231
|
|
216
232
|
FileUtils.mkdir_p(File.dirname(filename))
|
217
233
|
File.open(filename, 'w') { |f| f.write(content) }
|
218
234
|
|
219
|
-
puts "New
|
235
|
+
puts "New #{label} file added [#{filename}]"
|
220
236
|
end
|
221
237
|
|
222
238
|
def create_template(path, template, root, root_path)
|
data/lib/plate/draft.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Plate
|
2
|
+
# Draft posts are located in the drafts/ folder and are not yet published.
|
3
|
+
#
|
4
|
+
# Add a publish: true meta flag to any draft post to publish it automatically
|
5
|
+
# on the next build.
|
6
|
+
class Draft < Post
|
7
|
+
# Draft posts are placed in the /_drafts/ directory
|
8
|
+
def file_path
|
9
|
+
"/_drafts#{permalink}/index.html"
|
10
|
+
end
|
11
|
+
|
12
|
+
# Is this post ready to be published? (assumes meta data value of publish: true)
|
13
|
+
def publish?
|
14
|
+
!!self.meta[:publish]
|
15
|
+
end
|
16
|
+
|
17
|
+
# If this post is ready to be published, move it to its proper place in posts/
|
18
|
+
def publish!
|
19
|
+
return unless publish?
|
20
|
+
|
21
|
+
new_file = File.join(self.site.source, 'posts', self.date.strftime('%Y/%m'), self.basename)
|
22
|
+
|
23
|
+
self.site.log("Publishing draft #{self.name}")
|
24
|
+
|
25
|
+
if File.exists?(self.file) and !File.exists?(new_file)
|
26
|
+
FileUtils.mkdir_p(File.dirname(new_file))
|
27
|
+
FileUtils.mv(self.file, new_file)
|
28
|
+
end
|
29
|
+
|
30
|
+
new_file
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/plate/site.rb
CHANGED
@@ -6,12 +6,45 @@ module Plate
|
|
6
6
|
class Site
|
7
7
|
include Callbacks
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
# [Array] An array of all dynamic assets for this site
|
10
|
+
attr_accessor :assets
|
11
11
|
|
12
|
-
#
|
12
|
+
# [String] The directory where the built site will be created for this site.
|
13
|
+
attr_accessor :build_destination
|
14
|
+
|
15
|
+
# [String] The file path of the cache directory for this site.
|
16
|
+
attr_accessor :cache_location
|
17
|
+
|
18
|
+
# [String] The destination directory file path for this site
|
19
|
+
attr_accessor :destination
|
20
|
+
|
21
|
+
# [Array] Any posts marked as drafts for this site
|
22
|
+
attr_accessor :drafts
|
23
|
+
|
24
|
+
# [Array] An array of all layout classes used for this site
|
25
|
+
attr_accessor :layouts
|
26
|
+
|
27
|
+
# [Object] The logger instance for this site.
|
28
|
+
attr_accessor :logger
|
29
|
+
|
30
|
+
# [Hash] A hash of all default meta data options for this site.
|
31
|
+
attr_accessor :metadata
|
32
|
+
|
33
|
+
# [Hash] A hash of configuration options for this site
|
34
|
+
attr_accessor :options
|
35
|
+
|
36
|
+
# [Array] An array of all non-blog post pages for this site
|
37
|
+
attr_accessor :pages
|
38
|
+
|
39
|
+
# [Array] An array of all view partials available in this site.
|
13
40
|
attr_accessor :partials
|
14
41
|
|
42
|
+
# [PostCollection] All blog posts for this site
|
43
|
+
attr_accessor :posts
|
44
|
+
|
45
|
+
# [String] The source directory file path for building this site
|
46
|
+
attr_accessor :source
|
47
|
+
|
15
48
|
def initialize(source, destination, options = {})
|
16
49
|
# Setup source and destination for the site files
|
17
50
|
self.source = source
|
@@ -28,12 +61,12 @@ module Plate
|
|
28
61
|
clear
|
29
62
|
end
|
30
63
|
|
31
|
-
%w( assets layouts pages posts ).each do |group|
|
64
|
+
%w( assets drafts layouts pages posts ).each do |group|
|
32
65
|
class_eval "def #{group}; load!; @#{group}; end"
|
33
66
|
end
|
34
67
|
|
35
68
|
def all_files
|
36
|
-
@all_files ||= self.assets + self.layouts + self.pages + self.posts.to_a
|
69
|
+
@all_files ||= self.assets + self.layouts + self.pages + self.posts.to_a + self.drafts
|
37
70
|
end
|
38
71
|
|
39
72
|
# All extensions that are registered, as strings.
|
@@ -57,6 +90,7 @@ module Plate
|
|
57
90
|
self.pages = []
|
58
91
|
self.posts = PostCollection.new
|
59
92
|
self.partials = []
|
93
|
+
self.drafts = []
|
60
94
|
|
61
95
|
@metadata = {}
|
62
96
|
end
|
@@ -279,8 +313,10 @@ module Plate
|
|
279
313
|
|
280
314
|
# Load blog posts from posts/
|
281
315
|
def load_posts!(verbose = true)
|
316
|
+
@drafts = []
|
282
317
|
@posts = PostCollection.new
|
283
318
|
|
319
|
+
# Load up all published posts from posts/ directory
|
284
320
|
Dir.glob(File.join(source, "posts/**/*")).each do |file|
|
285
321
|
# If this 'file' is a directory, just skip it. We only care about files.
|
286
322
|
unless File.directory?(file)
|
@@ -294,6 +330,27 @@ module Plate
|
|
294
330
|
end
|
295
331
|
end
|
296
332
|
|
333
|
+
# Load up any drafts, and publish as needed
|
334
|
+
Dir.glob(File.join(source, "drafts/**/*")).each do |file|
|
335
|
+
# If this 'file' is a directory, just skip it. We only care about files.
|
336
|
+
unless File.directory?(file)
|
337
|
+
# Check for YAML meta header. If it starts with ---, then process it as a page
|
338
|
+
intro = File.open(file) { |f| f.read(3) }
|
339
|
+
|
340
|
+
# If file contents start with ---, then it is something we should process as a page.
|
341
|
+
if intro == "---"
|
342
|
+
draft = Draft.new(self, file)
|
343
|
+
|
344
|
+
if draft.publish?
|
345
|
+
new_file = draft.publish!
|
346
|
+
@posts.add(Post.new(self, new_file))
|
347
|
+
else
|
348
|
+
@drafts << draft
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
297
354
|
@posts.sort!
|
298
355
|
|
299
356
|
log("#{@posts.size} posts loaded") if verbose
|
data/lib/plate/version.rb
CHANGED
data/lib/templates/config.yml
CHANGED
@@ -1,7 +1,31 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
2
|
+
#
|
3
|
+
# Plate Configuration File
|
4
|
+
# ========================
|
5
|
+
#
|
6
|
+
# The root domain and protocol for this website
|
3
7
|
base_url: "http://example.com"
|
8
|
+
|
9
|
+
# The default format for URL structure of blog posts.
|
10
|
+
# Variables starting with a colon will be replaced with the value for that
|
11
|
+
# post on build.
|
12
|
+
#
|
13
|
+
# Variable options are:
|
14
|
+
# * `date` - The date of this post, formatted as YYYY-MM-DD
|
15
|
+
# * `title` - The title of this post, formatted for URL
|
16
|
+
# * `slug` - The blog post URL slug (the name of the post)
|
17
|
+
# * `year` - The 4-digit year of this post
|
18
|
+
# * `month` - The 2-digit month for this post
|
19
|
+
# * `day` - The 2-digit day of month for this post
|
20
|
+
# * `category` - The category for this post
|
4
21
|
permalink: "/posts/:year/:month/:slug"
|
22
|
+
|
23
|
+
# New posts generated with the `plate post 'Title'` command can be put into a draft
|
24
|
+
# state by setting this to true. Once your post is ready, add `publish: true` to the
|
25
|
+
# meta information for that post and it will be published on the next build.
|
26
|
+
draft: false
|
27
|
+
|
28
|
+
# The default meta data for your site
|
5
29
|
meta:
|
6
30
|
title: "My New Site"
|
7
31
|
description: "A really great site, generated with Plate!"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.pre2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07
|
12
|
+
date: 2012-08-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70317428454140 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70317428454140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: directory_watcher
|
27
|
-
requirement: &
|
27
|
+
requirement: &70317428453760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70317428453760
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: i18n
|
38
|
-
requirement: &
|
38
|
+
requirement: &70317428453220 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0.6'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70317428453220
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70317428452800 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70317428452800
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: redcarpet
|
60
|
-
requirement: &
|
60
|
+
requirement: &70317428452260 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '2'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70317428452260
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: tilt
|
71
|
-
requirement: &
|
71
|
+
requirement: &70317428451720 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '1.3'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70317428451720
|
80
80
|
description: Plate is a simple, static site generator and blog engine.
|
81
81
|
email:
|
82
82
|
- john@johntornow.com
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/plate/builder.rb
|
93
93
|
- lib/plate/callbacks.rb
|
94
94
|
- lib/plate/cli.rb
|
95
|
+
- lib/plate/draft.rb
|
95
96
|
- lib/plate/dsl.rb
|
96
97
|
- lib/plate/dynamic_page.rb
|
97
98
|
- lib/plate/engine.rb
|