middleman-blog-drafts 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +14 -12
- data/Gemfile.lock +59 -48
- data/LICENSE.txt +2 -2
- data/README.md +18 -2
- data/Rakefile +28 -2
- data/features/publish_cli.feature +14 -14
- data/fixtures/drafts-app/config.rb +2 -2
- data/fixtures/drafts-app/source/layout.erb +1 -1
- data/lib/middleman-blog-drafts.rb +1 -1
- data/lib/middleman-blog-drafts/blog_data_extensions.rb +49 -33
- data/lib/middleman-blog-drafts/commands/draft.rb +12 -9
- data/lib/middleman-blog-drafts/commands/publish.rb +29 -21
- data/lib/middleman-blog-drafts/draft_article.rb +8 -5
- data/lib/middleman-blog-drafts/extension.rb +18 -50
- data/lib/middleman-blog-drafts/helpers.rb +21 -0
- data/lib/middleman-blog-drafts/version.rb +1 -1
- data/middleman-blog-drafts.gemspec +12 -8
- metadata +38 -19
- checksums.yaml +0 -7
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
gem "middleman-core", :github => "middleman/middleman", :branch => 'v3-stable'
|
4
|
+
|
3
5
|
# Specify your gem's dependencies in middleman-blog-drafts.gemspec
|
4
6
|
gemspec
|
5
7
|
|
8
|
+
gem "sass"
|
9
|
+
gem "compass"
|
10
|
+
gem "kramdown"
|
11
|
+
|
12
|
+
gem "rake", "~> 10.1.0"
|
13
|
+
gem "cucumber", "~> 1.3.1"
|
14
|
+
gem "fivemat"
|
15
|
+
gem "aruba", "~> 0.5.1"
|
16
|
+
gem "cane", :platforms => [:mri_19, :mri_20], :require => false
|
17
|
+
|
6
18
|
group :development do
|
7
|
-
gem "rdoc",
|
8
|
-
gem "yard",
|
19
|
+
gem "rdoc", "~> 3.9"
|
20
|
+
gem "yard", "~> 0.8.0"
|
9
21
|
gem "guard-cucumber"
|
10
22
|
end
|
11
|
-
|
12
|
-
group :development, :test do
|
13
|
-
gem "sass"
|
14
|
-
gem "compass"
|
15
|
-
gem "rake", "~> 0.9.2"
|
16
|
-
gem "cucumber", "~> 1.2.0"
|
17
|
-
gem "fivemat"
|
18
|
-
gem "aruba", "~> 0.4.11"
|
19
|
-
gem "rspec", "~> 2.7"
|
20
|
-
end
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,61 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/middleman/middleman.git
|
3
|
+
revision: 049866ee2e74972292687a7d1dff0e69f942f83a
|
4
|
+
branch: v3-stable
|
5
|
+
specs:
|
6
|
+
middleman-core (3.2.2)
|
7
|
+
activesupport (~> 3.2.6)
|
8
|
+
bundler (~> 1.1)
|
9
|
+
hooks (~> 0.3)
|
10
|
+
i18n (~> 0.6.9)
|
11
|
+
listen (~> 1.1)
|
12
|
+
rack (>= 1.4.5)
|
13
|
+
rack-test (~> 0.6.1)
|
14
|
+
thor (>= 0.15.2, < 2.0)
|
15
|
+
tilt (~> 1.4.1)
|
16
|
+
|
1
17
|
PATH
|
2
18
|
remote: .
|
3
19
|
specs:
|
4
|
-
middleman-blog-drafts (0.
|
5
|
-
middleman-blog
|
6
|
-
middleman-core (
|
20
|
+
middleman-blog-drafts (0.2.0)
|
21
|
+
middleman-blog (~> 3.5.1)
|
22
|
+
middleman-core (~> 3.2.2)
|
7
23
|
|
8
24
|
GEM
|
9
25
|
remote: https://rubygems.org/
|
10
26
|
specs:
|
11
|
-
activesupport (3.2.
|
27
|
+
activesupport (3.2.16)
|
12
28
|
i18n (~> 0.6, >= 0.6.4)
|
13
29
|
multi_json (~> 1.0)
|
14
|
-
|
15
|
-
|
30
|
+
addressable (2.3.5)
|
31
|
+
aruba (0.5.4)
|
32
|
+
childprocess (>= 0.3.6)
|
16
33
|
cucumber (>= 1.1.1)
|
17
|
-
|
18
|
-
|
34
|
+
rspec-expectations (>= 2.7.0)
|
35
|
+
atomic (1.1.14)
|
19
36
|
builder (3.2.2)
|
20
|
-
|
37
|
+
cane (2.6.1)
|
38
|
+
parallel
|
39
|
+
childprocess (0.4.0)
|
21
40
|
ffi (~> 1.0, >= 1.0.11)
|
22
|
-
chunky_png (1.
|
41
|
+
chunky_png (1.3.0)
|
23
42
|
coderay (1.0.9)
|
24
43
|
compass (0.12.2)
|
25
44
|
chunky_png (~> 1.2)
|
26
45
|
fssm (>= 0.2.7)
|
27
46
|
sass (~> 3.1)
|
28
|
-
cucumber (1.
|
47
|
+
cucumber (1.3.10)
|
29
48
|
builder (>= 2.1.2)
|
30
49
|
diff-lcs (>= 1.1.3)
|
31
|
-
gherkin (~> 2.
|
32
|
-
multi_json (
|
33
|
-
|
50
|
+
gherkin (~> 2.12)
|
51
|
+
multi_json (>= 1.7.5, < 2.0)
|
52
|
+
multi_test (>= 0.0.2)
|
53
|
+
diff-lcs (1.2.5)
|
34
54
|
ffi (1.9.0)
|
35
55
|
fivemat (1.2.1)
|
36
56
|
formatador (0.2.4)
|
37
57
|
fssm (0.2.10)
|
38
|
-
gherkin (2.
|
58
|
+
gherkin (2.12.2)
|
39
59
|
multi_json (~> 1.3)
|
40
60
|
guard (1.8.2)
|
41
61
|
formatador (>= 0.2.4)
|
@@ -46,30 +66,23 @@ GEM
|
|
46
66
|
guard-cucumber (1.4.0)
|
47
67
|
cucumber (>= 1.2.0)
|
48
68
|
guard (>= 1.1.0)
|
49
|
-
|
69
|
+
hooks (0.3.3)
|
70
|
+
i18n (0.6.9)
|
50
71
|
json (1.8.0)
|
72
|
+
kramdown (1.3.1)
|
51
73
|
listen (1.2.3)
|
52
74
|
rb-fsevent (>= 0.9.3)
|
53
75
|
rb-inotify (>= 0.9)
|
54
76
|
rb-kqueue (>= 0.2)
|
55
77
|
lumberjack (1.0.4)
|
56
|
-
maruku (0.6.1)
|
57
|
-
syntax (>= 1.0.0)
|
58
78
|
method_source (0.8.2)
|
59
|
-
middleman-blog (3.
|
60
|
-
|
61
|
-
middleman-core (~> 3.
|
62
|
-
tzinfo (
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
i18n (~> 0.6.1)
|
67
|
-
listen (~> 1.2.2)
|
68
|
-
rack (>= 1.4.5)
|
69
|
-
rack-test (~> 0.6.1)
|
70
|
-
thor (>= 0.15.2, < 2.0)
|
71
|
-
tilt (~> 1.3.6)
|
72
|
-
multi_json (1.7.9)
|
79
|
+
middleman-blog (3.5.1)
|
80
|
+
addressable (~> 2.3.5)
|
81
|
+
middleman-core (~> 3.2)
|
82
|
+
tzinfo (>= 0.3.0)
|
83
|
+
multi_json (1.8.4)
|
84
|
+
multi_test (0.0.3)
|
85
|
+
parallel (0.9.2)
|
73
86
|
pry (0.9.12.2)
|
74
87
|
coderay (~> 1.0.5)
|
75
88
|
method_source (~> 0.8)
|
@@ -77,7 +90,7 @@ GEM
|
|
77
90
|
rack (1.5.2)
|
78
91
|
rack-test (0.6.2)
|
79
92
|
rack (>= 1.0)
|
80
|
-
rake (
|
93
|
+
rake (10.1.1)
|
81
94
|
rb-fsevent (0.9.3)
|
82
95
|
rb-inotify (0.9.1)
|
83
96
|
ffi (>= 0.5.0)
|
@@ -85,34 +98,32 @@ GEM
|
|
85
98
|
ffi (>= 0.5.0)
|
86
99
|
rdoc (3.12.2)
|
87
100
|
json (~> 1.4)
|
88
|
-
rspec (2.14.
|
89
|
-
rspec-core (~> 2.14.0)
|
90
|
-
rspec-expectations (~> 2.14.0)
|
91
|
-
rspec-mocks (~> 2.14.0)
|
92
|
-
rspec-core (2.14.5)
|
93
|
-
rspec-expectations (2.14.2)
|
101
|
+
rspec-expectations (2.14.5)
|
94
102
|
diff-lcs (>= 1.1.3, < 2.0)
|
95
|
-
|
96
|
-
sass (3.2.9)
|
103
|
+
sass (3.2.14)
|
97
104
|
slop (3.4.6)
|
98
|
-
syntax (1.0.0)
|
99
105
|
thor (0.18.1)
|
100
|
-
|
101
|
-
|
106
|
+
thread_safe (0.1.3)
|
107
|
+
atomic
|
108
|
+
tilt (1.4.1)
|
109
|
+
tzinfo (1.1.0)
|
110
|
+
thread_safe (~> 0.1)
|
102
111
|
yard (0.8.7)
|
103
112
|
|
104
113
|
PLATFORMS
|
105
114
|
ruby
|
106
115
|
|
107
116
|
DEPENDENCIES
|
108
|
-
aruba (~> 0.
|
117
|
+
aruba (~> 0.5.1)
|
118
|
+
cane
|
109
119
|
compass
|
110
|
-
cucumber (~> 1.
|
120
|
+
cucumber (~> 1.3.1)
|
111
121
|
fivemat
|
112
122
|
guard-cucumber
|
123
|
+
kramdown
|
113
124
|
middleman-blog-drafts!
|
114
|
-
|
125
|
+
middleman-core!
|
126
|
+
rake (~> 10.1.0)
|
115
127
|
rdoc (~> 3.9)
|
116
|
-
rspec (~> 2.7)
|
117
128
|
sass
|
118
129
|
yard (~> 0.8.0)
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2013 Fabio Rehm
|
1
|
+
Copyright (c) 2013-2014 Fabio Rehm, Serge Gebhardt
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ middleman publish source/drafts/my-awesome-new-blog-post.markdown
|
|
35
35
|
## Listing drafts on a page
|
36
36
|
|
37
37
|
```erb
|
38
|
-
<% if
|
38
|
+
<% if drafts.any? %>
|
39
39
|
<ul>
|
40
40
|
<% drafts.each do |draft| %>
|
41
41
|
<li><%= link_to draft.title, draft.path %></li>
|
@@ -44,9 +44,25 @@ middleman publish source/drafts/my-awesome-new-blog-post.markdown
|
|
44
44
|
<% end %>
|
45
45
|
```
|
46
46
|
|
47
|
+
As drafts won't be be available in the generated page by default, checking whether there are any is enough to decide whether to render the listing or not.
|
48
|
+
|
49
|
+
## Configuration options
|
50
|
+
|
51
|
+
`build`: when `true`, the drafts will be available unconditionally. If not given, the drafts will be available in middlemans development mode and unavailable in `middleman build`.
|
52
|
+
|
53
|
+
This allows you to control the behaviour, for example if you have a preview instance of your blog. One way to do so would be to set it based on an environment variable:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
activate :drafts do |drafts|
|
57
|
+
drafts.build = true if ENV["SHOW_DRAFTS"]
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
This activates drafts in any environment where `SHOW_DRAFTS` is given and uses the default otherwise.
|
62
|
+
|
47
63
|
## Learn More
|
48
64
|
|
49
|
-
See the [blog extension guide](http://middlemanapp.com/blogging/) for detailed
|
65
|
+
See the [blog extension guide](http://middlemanapp.com/basics/blogging/) for detailed
|
50
66
|
information on configuring and using the blog extension.
|
51
67
|
|
52
68
|
## Credits
|
data/Rakefile
CHANGED
@@ -7,8 +7,34 @@ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
|
7
7
|
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
8
8
|
end
|
9
9
|
|
10
|
+
Cucumber::Rake::Task.new(:cucumber_wip, 'Run only WIP features') do |t|
|
11
|
+
t.cucumber_opts = "--color --tags @wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
12
|
+
end
|
13
|
+
|
14
|
+
task :test => :cucumber
|
15
|
+
task :wip => :cucumber_wip
|
16
|
+
task :default => [:test]
|
17
|
+
|
10
18
|
require 'rake/clean'
|
11
19
|
|
12
|
-
|
20
|
+
begin
|
21
|
+
require 'cane/rake_task'
|
22
|
+
|
23
|
+
desc "Run cane to check quality metrics"
|
24
|
+
Cane::RakeTask.new(:quality) do |cane|
|
25
|
+
cane.no_style = true
|
26
|
+
cane.no_doc = true
|
27
|
+
cane.abc_glob = "lib/middleman-blog-drafts/**/*.rb"
|
28
|
+
cane.style_glob = "lib/middleman-blog-drafts/**/*.rb"
|
29
|
+
end
|
30
|
+
|
31
|
+
task :default => [:quality]
|
32
|
+
rescue LoadError
|
33
|
+
warn "cane not available, quality task not provided."
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Build HTML documentation"
|
37
|
+
task :doc do
|
38
|
+
sh 'bundle exec yard'
|
39
|
+
end
|
13
40
|
|
14
|
-
task :default => :test
|
@@ -1,17 +1,17 @@
|
|
1
1
|
Feature: Publish draft CLI command
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
Scenario: Publish a new blog draft article with the CLI
|
3
|
+
Given a fixture app "drafts-app"
|
4
|
+
And I run `middleman draft "My New Article"`
|
5
|
+
And I run `middleman publish source/drafts/my-new-article.html.markdown --date 2012-03-07`
|
6
|
+
Then the exit status should be 0
|
7
|
+
And the following files should exist:
|
8
|
+
| source/blog/2012-03-07-my-new-article.html.markdown |
|
9
|
+
And the following files should not exist:
|
10
|
+
| source/drafts/my-new-article.html.markdown |
|
11
11
|
|
12
12
|
Scenario: Viewing a published article
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
Given a fixture app "drafts-app"
|
14
|
+
And I run `middleman publish source/drafts/new-draft.html.erb --date 2012-03-07`
|
15
|
+
When the Server is running at "drafts-app"
|
16
|
+
And I go to "/blog/2012/03/07/new-draft.html"
|
17
|
+
Then I should see '2012-03-07'
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'middleman-blog/uri_templates'
|
2
|
+
require 'middleman-blog-drafts/draft_article'
|
3
|
+
|
1
4
|
module Middleman
|
2
5
|
module Blog
|
3
6
|
module Drafts
|
@@ -20,55 +23,52 @@ module Middleman
|
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
|
-
# A store of all the draft articles in the site. Accessed via
|
24
|
-
# templates.
|
26
|
+
# A store of all the draft articles in the site. Accessed via
|
27
|
+
# {blog.drafts} in templates.
|
25
28
|
class Data
|
26
|
-
|
29
|
+
include UriTemplates
|
30
|
+
|
31
|
+
# A URITemplate for the source file path relative to blog's :source_dir
|
32
|
+
# @return [URITemplate]
|
33
|
+
attr_reader :source_template
|
34
|
+
|
35
|
+
# The configured options for this blog
|
36
|
+
# @return [Thor::CoreExt::HashWithIndifferentAccess]
|
37
|
+
attr_reader :options
|
27
38
|
|
28
39
|
# @private
|
29
40
|
def initialize(blog_data, app, options)
|
30
41
|
@blog_data = blog_data
|
31
|
-
@options = options
|
32
42
|
@app = app
|
43
|
+
@options = options
|
33
44
|
|
34
45
|
# A list of resources corresponding to draft articles
|
35
46
|
@_drafts = []
|
36
47
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@path_matcher = /^#{matcher}/
|
48
|
+
@source_template = uri_template options.sources
|
49
|
+
@permalink_template = uri_template options.permalink
|
50
|
+
end
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
@matcher_indexes[key[1..-1]] = i
|
48
|
-
end
|
49
|
-
# The path always appears at the end.
|
50
|
-
@matcher_indexes["path"] = @matcher_indexes.size
|
52
|
+
# A list of all draft articles.
|
53
|
+
# @return [Array<Middleman::Sitemap::Resource>]
|
54
|
+
def articles
|
55
|
+
@_drafts.sort_by(&:title)
|
51
56
|
end
|
52
57
|
|
53
|
-
#
|
54
|
-
# permalink.
|
58
|
+
# Update blog draft articles destination paths to be the permalink.
|
55
59
|
# @return [void]
|
56
60
|
def manipulate_resource_list(resources)
|
57
61
|
@_drafts = []
|
58
62
|
used_resources = []
|
59
63
|
|
60
64
|
resources.each do |resource|
|
61
|
-
if resource.path
|
62
|
-
resource
|
63
|
-
|
65
|
+
if (params = extract_params(@source_template, resource.path))
|
66
|
+
draft = convert_to_draft(resource)
|
67
|
+
next unless build?(draft)
|
64
68
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
resource.destination_path = options.permalink.
|
69
|
-
sub(':title', resource.slug)
|
70
|
-
|
71
|
-
resource.destination_path = Middleman::Util.normalize_path(resource.destination_path)
|
69
|
+
# compute output path
|
70
|
+
draft.destination_path =
|
71
|
+
apply_uri_template @permalink_template, title: draft.slug
|
72
72
|
|
73
73
|
@_drafts << resource
|
74
74
|
end
|
@@ -79,10 +79,26 @@ module Middleman
|
|
79
79
|
used_resources
|
80
80
|
end
|
81
81
|
|
82
|
-
#
|
83
|
-
# @
|
84
|
-
|
85
|
-
|
82
|
+
# Whether or not a given draft should be included in the sitemap.
|
83
|
+
# @param [DraftArticle] draft A draft article
|
84
|
+
# @return [Boolean] Whether it should be built
|
85
|
+
def build?(draft)
|
86
|
+
@app.environment == :development || @options.build
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
# Convert the resource into a DraftArticle.
|
92
|
+
# @param [Sitemap::Resource] resource The resource to convert
|
93
|
+
# @return [Sitemap::Resource] The converted resource
|
94
|
+
def convert_to_draft(resource)
|
95
|
+
return resource if resource.is_a? DraftArticle
|
96
|
+
|
97
|
+
resource.extend BlogArticle
|
98
|
+
resource.extend DraftArticle
|
99
|
+
resource.blog_controller = @blog_data.controller
|
100
|
+
|
101
|
+
resource
|
86
102
|
end
|
87
103
|
end
|
88
104
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'middleman-core/cli'
|
2
|
+
require 'middleman-blog/uri_templates'
|
2
3
|
|
3
4
|
module Middleman
|
4
5
|
module Cli
|
5
6
|
# This class provides a "draft" command for the middleman CLI.
|
6
7
|
class Draft < Thor
|
7
8
|
include Thor::Actions
|
9
|
+
include Blog::UriTemplates
|
8
10
|
|
9
11
|
check_unknown_options!
|
10
12
|
|
@@ -26,17 +28,18 @@ module Middleman
|
|
26
28
|
shared_instance = ::Middleman::Application.server.inst
|
27
29
|
|
28
30
|
# This only exists when the config.rb sets it!
|
29
|
-
|
30
|
-
@title = title
|
31
|
-
@slug = title.parameterize
|
32
|
-
|
33
|
-
draft_path = shared_instance.blog.drafts.options.sources.
|
34
|
-
sub(':title', @slug)
|
35
|
-
|
36
|
-
template "draft.tt", File.join(shared_instance.source_dir, draft_path + shared_instance.blog.options.default_extension)
|
37
|
-
else
|
31
|
+
unless shared_instance.blog.respond_to? :drafts
|
38
32
|
raise Thor::Error.new "You need to activate the drafts extension in config.rb before you can create an article"
|
39
33
|
end
|
34
|
+
|
35
|
+
@title = title
|
36
|
+
@slug = safe_parameterize title
|
37
|
+
|
38
|
+
path_template = shared_instance.blog.drafts.source_template
|
39
|
+
draft_path = apply_uri_template path_template, title: @slug
|
40
|
+
draft_path << shared_instance.blog.options.default_extension
|
41
|
+
|
42
|
+
template "draft.tt", File.join(shared_instance.source_dir, draft_path)
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'middleman-core/cli'
|
2
|
+
require 'date'
|
3
|
+
require 'middleman-blog/uri_templates'
|
2
4
|
|
3
5
|
module Middleman
|
4
6
|
module Cli
|
5
7
|
# This class provides a "publish" command for the middleman CLI.
|
6
8
|
class Publish < Thor
|
7
9
|
include Thor::Actions
|
10
|
+
include Blog::UriTemplates
|
8
11
|
|
9
12
|
check_unknown_options!
|
10
13
|
|
@@ -26,31 +29,36 @@ module Middleman
|
|
26
29
|
:aliases => "-d",
|
27
30
|
:desc => "The date to create the post with (defaults to now)"
|
28
31
|
def publish(draft_path)
|
29
|
-
shared_instance = ::Middleman::Application.server.inst
|
32
|
+
@shared_instance = ::Middleman::Application.server.inst
|
30
33
|
|
31
34
|
# This only exists when the config.rb sets it!
|
32
|
-
|
33
|
-
@slug = draft_path.split('/').last.split('.').first.parameterize
|
34
|
-
@date = options[:date] ? DateTime.parse(options[:date]) : DateTime.now
|
35
|
-
|
36
|
-
draft_path = File.expand_path draft_path
|
37
|
-
extension = File.extname draft_path
|
38
|
-
|
39
|
-
article_path = shared_instance.blog.options.sources.
|
40
|
-
sub(':year', @date.year.to_s).
|
41
|
-
sub(':month', @date.month.to_s.rjust(2,'0')).
|
42
|
-
sub(':day', @date.day.to_s.rjust(2,'0')).
|
43
|
-
sub(':title', @slug)
|
44
|
-
article_path = File.join(shared_instance.source_dir, article_path + extension)
|
45
|
-
|
46
|
-
data, content = shared_instance.extensions[:frontmatter].data(draft_path)
|
47
|
-
data = data.dup.tap { |d| d[:date] = Date.parse @date.strftime('%F') }
|
48
|
-
|
49
|
-
create_file article_path, "#{YAML::dump(data).sub(/^--- !ruby.*$/, '---')}---\n#{content}"
|
50
|
-
remove_file draft_path
|
51
|
-
else
|
35
|
+
unless @shared_instance.blog.respond_to? :drafts
|
52
36
|
raise Thor::Error.new "You need to activate the drafts extension in config.rb before you can publish an article"
|
53
37
|
end
|
38
|
+
|
39
|
+
@slug = safe_parameterize draft_path.split('/').last.split('.').first
|
40
|
+
@date = options[:date] ? Time.zone.parse(options[:date]) : Time.zone.now
|
41
|
+
@draft_path = File.expand_path draft_path
|
42
|
+
|
43
|
+
create_file article_path, article_content
|
44
|
+
remove_file draft_path
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def article_path
|
50
|
+
extension = File.extname @draft_path
|
51
|
+
path_template = @shared_instance.blog.source_template
|
52
|
+
params = date_to_params(@date).merge(title: @slug)
|
53
|
+
article_path = apply_uri_template path_template, params
|
54
|
+
article_path = File.join(@shared_instance.source_dir, article_path + extension)
|
55
|
+
end
|
56
|
+
|
57
|
+
def article_content
|
58
|
+
data, content = @shared_instance.extensions[:frontmatter].data(@draft_path)
|
59
|
+
data = data.dup.tap { |d| d[:date] = Date.parse @date.strftime('%F') }
|
60
|
+
|
61
|
+
"#{YAML::dump(data).sub(/^--- !ruby.*$/, '---')}---\n#{content}"
|
54
62
|
end
|
55
63
|
end
|
56
64
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Middleman
|
2
2
|
module Blog
|
3
3
|
module Drafts
|
4
|
+
# A module that adds draft-article-specific methods to Resources.
|
5
|
+
# A {DraftArticle} can be retrieved via {Blog::Drafts::Helpers#current_article} or
|
6
|
+
# methods on {Blog::Drafts::Data} (accessible through BlogData#drafts).
|
7
|
+
# @see http://rdoc.info/github/middleman/middleman/Middleman/Sitemap/Resource Middleman::Sitemap::Resource
|
4
8
|
module DraftArticle
|
5
9
|
# The "slug" of the draft article that shows up in its URL.
|
6
10
|
# @return [String]
|
@@ -12,13 +16,12 @@ module Middleman
|
|
12
16
|
# @param [String] The part of the path, e.g. "title"
|
13
17
|
# @return [String]
|
14
18
|
def path_part(part)
|
15
|
-
@_path_parts ||=
|
16
|
-
|
17
|
-
@_path_parts[app.blog.drafts.matcher_indexes[part]]
|
19
|
+
@_path_parts ||= blog_data.drafts.source_template.extract(path)
|
20
|
+
@_path_parts[part.to_s]
|
18
21
|
end
|
19
22
|
|
20
|
-
# Returns current date as we can't guess when the article will be
|
21
|
-
#
|
23
|
+
# Returns current date as we can't guess when the article will be
|
24
|
+
# published
|
22
25
|
# We need this in place or the layout used for blog posts might blow up
|
23
26
|
#
|
24
27
|
# @return [TimeWithZone]
|
@@ -1,61 +1,29 @@
|
|
1
|
+
require 'middleman-blog-drafts/helpers'
|
2
|
+
|
1
3
|
module Middleman
|
2
4
|
module Blog
|
3
|
-
|
4
|
-
|
5
|
-
attr_accessor :sources, :layout, :permalink, :build
|
6
|
-
|
7
|
-
def initialize(options={})
|
8
|
-
options.each do |k,v|
|
9
|
-
self.send(:"#{k}=", v)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class << self
|
15
|
-
# Called when user `activate`s your extension
|
16
|
-
def registered(app, options_hash={}, &block)
|
17
|
-
require 'middleman-blog/extension'
|
18
|
-
require 'middleman-blog/blog_data'
|
19
|
-
require 'middleman-blog-drafts/draft_article'
|
20
|
-
require 'middleman-blog-drafts/blog_data_extensions'
|
5
|
+
class DraftsExtension < ::Middleman::Extension
|
6
|
+
self.supports_multiple_instances = false
|
21
7
|
|
22
|
-
|
23
|
-
|
8
|
+
option :sources, 'drafts/{title}.html', 'Pattern for matching draft articles (no template extensions)'
|
9
|
+
option :permalink, '/drafts/{title}.html', 'Path draft are served from'
|
10
|
+
option :build, false, 'Whether to include drafts when building the site'
|
24
11
|
|
25
|
-
|
26
|
-
options.permalink ||= "/drafts/:title.html"
|
12
|
+
self.defined_helpers = [ ::Middleman::Blog::Drafts::Helpers ]
|
27
13
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
app.after_configuration do
|
32
|
-
options.layout = blog.options.layout
|
33
|
-
blog.drafts(self, options)
|
34
|
-
|
35
|
-
sitemap.register_resource_list_manipulator(
|
36
|
-
:blog_drafts,
|
37
|
-
blog.drafts,
|
38
|
-
false
|
39
|
-
)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
alias :included :registered
|
14
|
+
def initialize(app, options_hash={}, &block)
|
15
|
+
super
|
43
16
|
end
|
44
17
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def current_article
|
49
|
-
super || blog.draft(current_resource.path)
|
50
|
-
end
|
51
|
-
|
18
|
+
def after_configuration
|
19
|
+
require 'middleman-blog/blog_data'
|
20
|
+
require 'middleman-blog-drafts/blog_data_extensions'
|
52
21
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
blog.drafts
|
57
|
-
end
|
22
|
+
::Middleman::Blog::BlogData.send :include, Drafts::BlogDataExtensions
|
23
|
+
app.blog.drafts(app, options)
|
24
|
+
app.sitemap.register_resource_list_manipulator(:blog_drafts,
|
25
|
+
app.blog.drafts, false)
|
58
26
|
end
|
59
27
|
end
|
60
28
|
end
|
61
|
-
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Blog
|
3
|
+
module Drafts
|
4
|
+
# Drafts-related helpers that are available to the Middleman application in +config.rb+ and in templates.
|
5
|
+
module Helpers
|
6
|
+
# Get a {Resource} with mixed in {BlogArticle} methods representing the
|
7
|
+
# current article.
|
8
|
+
# @return [Middleman::Sitemap::Resource]
|
9
|
+
def current_article
|
10
|
+
blog.draft(current_resource.path)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the list of drafts on the site.
|
14
|
+
# @return [Array<Middleman::Sitemap::Resource>]
|
15
|
+
def drafts
|
16
|
+
blog.drafts.articles
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -5,17 +5,21 @@ require "middleman-blog-drafts/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "middleman-blog-drafts"
|
7
7
|
s.version = Middleman::Blog::Drafts::VERSION
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.summary = s.description
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Fabio Rehm", "Serge Gebhardt"]
|
10
|
+
s.email = ["fgrehm@gmail.com", "serge.gebhardt@gmail.com"]
|
12
11
|
s.homepage = "https://github.com/fgrehm/middleman-draft-articles"
|
12
|
+
s.summary = %q{middleman-blog extension adding draft articles}
|
13
|
+
s.description = s.summary
|
14
|
+
s.license = "MIT"
|
13
15
|
|
14
|
-
s.files = `git ls-files`.split(
|
16
|
+
s.files = `git ls-files -z`.split("\0")
|
15
17
|
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features|fixtures)/})
|
17
19
|
s.require_paths = ["lib"]
|
18
20
|
|
19
|
-
s.
|
20
|
-
|
21
|
+
s.required_ruby_version = '>= 1.9.3'
|
22
|
+
|
23
|
+
s.add_runtime_dependency("middleman-core", ["~> 3.2.2"])
|
24
|
+
s.add_runtime_dependency("middleman-blog", ["~> 3.5.1"])
|
21
25
|
end
|
metadata
CHANGED
@@ -1,52 +1,60 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-blog-drafts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Fabio Rehm
|
9
|
+
- Serge Gebhardt
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: middleman-core
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
16
19
|
requirements:
|
17
|
-
- -
|
20
|
+
- - ~>
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
22
|
+
version: 3.2.2
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
23
27
|
requirements:
|
24
|
-
- -
|
28
|
+
- - ~>
|
25
29
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
30
|
+
version: 3.2.2
|
27
31
|
- !ruby/object:Gem::Dependency
|
28
32
|
name: middleman-blog
|
29
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
30
35
|
requirements:
|
31
|
-
- -
|
36
|
+
- - ~>
|
32
37
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
38
|
+
version: 3.5.1
|
34
39
|
type: :runtime
|
35
40
|
prerelease: false
|
36
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
37
43
|
requirements:
|
38
|
-
- -
|
44
|
+
- - ~>
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
description: middleman-blog extension
|
46
|
+
version: 3.5.1
|
47
|
+
description: middleman-blog extension adding draft articles
|
42
48
|
email:
|
43
49
|
- fgrehm@gmail.com
|
50
|
+
- serge.gebhardt@gmail.com
|
44
51
|
executables: []
|
45
52
|
extensions: []
|
46
53
|
extra_rdoc_files: []
|
47
54
|
files:
|
48
55
|
- .gitignore
|
49
56
|
- .travis.yml
|
57
|
+
- CHANGELOG.md
|
50
58
|
- Gemfile
|
51
59
|
- Gemfile.lock
|
52
60
|
- Guardfile
|
@@ -72,32 +80,38 @@ files:
|
|
72
80
|
- lib/middleman-blog-drafts/commands/publish.rb
|
73
81
|
- lib/middleman-blog-drafts/draft_article.rb
|
74
82
|
- lib/middleman-blog-drafts/extension.rb
|
83
|
+
- lib/middleman-blog-drafts/helpers.rb
|
75
84
|
- lib/middleman-blog-drafts/version.rb
|
76
85
|
- lib/middleman_extension.rb
|
77
86
|
- middleman-blog-drafts.gemspec
|
78
87
|
homepage: https://github.com/fgrehm/middleman-draft-articles
|
79
|
-
licenses:
|
80
|
-
|
88
|
+
licenses:
|
89
|
+
- MIT
|
81
90
|
post_install_message:
|
82
91
|
rdoc_options: []
|
83
92
|
require_paths:
|
84
93
|
- lib
|
85
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
86
96
|
requirements:
|
87
|
-
- - '>='
|
97
|
+
- - ! '>='
|
88
98
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
99
|
+
version: 1.9.3
|
90
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
91
102
|
requirements:
|
92
|
-
- - '>='
|
103
|
+
- - ! '>='
|
93
104
|
- !ruby/object:Gem::Version
|
94
105
|
version: '0'
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
hash: -4520017841201487203
|
95
109
|
requirements: []
|
96
110
|
rubyforge_project:
|
97
|
-
rubygems_version:
|
111
|
+
rubygems_version: 1.8.25
|
98
112
|
signing_key:
|
99
|
-
specification_version:
|
100
|
-
summary: middleman-blog extension
|
113
|
+
specification_version: 3
|
114
|
+
summary: middleman-blog extension adding draft articles
|
101
115
|
test_files:
|
102
116
|
- features/build.feature
|
103
117
|
- features/draft_cli.feature
|
@@ -106,4 +120,9 @@ test_files:
|
|
106
120
|
- features/publish_cli.feature
|
107
121
|
- features/step_definitions/drafts_steps.rb
|
108
122
|
- features/support/env.rb
|
123
|
+
- fixtures/drafts-app/config.rb
|
124
|
+
- fixtures/drafts-app/source/drafts/listing_drafts.html.erb
|
125
|
+
- fixtures/drafts-app/source/drafts/new-draft.html.erb
|
126
|
+
- fixtures/drafts-app/source/drafts/other-draft.html.erb
|
127
|
+
- fixtures/drafts-app/source/layout.erb
|
109
128
|
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 5411e1cced547a8c93ce28423232d05a205fe8dc
|
4
|
-
data.tar.gz: 896813a71b38c3ebc709555aea36ff34598c09a3
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 0d85dd8d6e96b5d55216c2be0400bf441edc4c8c033bccefdea145bac4eda233159629e54fd22759efbe9fa12ef97205800f59c45812059d4cf016c3b76427c8
|
7
|
-
data.tar.gz: 90bdcdcafcf524652955ec0f9ae9e8b027271e6edc0350b17f746fda1033a2130e87c912e052add0130e41c4b10c10bb6a77cb739abc3d21b4e7ecc3277bd966
|