mr_poole 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/README.md +13 -1
- data/lib/mr_poole/cli.rb +1 -1
- data/lib/mr_poole/config.rb +17 -5
- data/lib/mr_poole/helper.rb +6 -9
- data/lib/mr_poole/version.rb +1 -1
- data/spec/command_spec.rb +27 -0
- data/spec/config_spec.rb +20 -0
- data/spec/spec_helper.rb +9 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db31487041b5c6ed8e580f7d8a8b003bb65c775a
|
4
|
+
data.tar.gz: 9999f65961a392b2b3121ccb0edff2c87d69d06a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5f0071a2daf4825b72f3eecc81cf54afcc1d032fcaf6ba07f4a29bacbad69ea4d2c4ec1aebc62fd72ceb817b94a3d593ee9349463d789401a77e2cbbb850cdb
|
7
|
+
data.tar.gz: 83515d8083a1734d9a50c5c7a097acc12a7ab5e1f0b2e0a681eee3b809cfea58fd73467479139f7805578758f09a0a4fdee669f0d6c383aef968d0e6bffd7b1c
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### v0.5.0 (2014-01-31)
|
4
|
+
|
5
|
+
- Add word_separator configuration option (to use hyphens). Thanks to [Harry
|
6
|
+
Schwartz](http://github.com/hrs) for the inspiration!
|
7
|
+
|
3
8
|
### v0.4.3 (2014-01-28)
|
4
9
|
|
5
10
|
- Make echoed paths reflect custom source directory. Now you can `poole post
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ immediately.
|
|
30
30
|
Generates a timestamped post in your `_posts` directory, with the format
|
31
31
|
`YYYY-MM-DD-slug.md`. With no options, will generate a slug based on your title
|
32
32
|
by replacing spaces with underscores, downcasing, and removing any special
|
33
|
-
character.
|
33
|
+
character (see configuration section if you don't like the underscores).
|
34
34
|
|
35
35
|
Options:
|
36
36
|
|
@@ -127,6 +127,7 @@ should provide a `poole` key, which may take the following subkeys:
|
|
127
127
|
|
128
128
|
- `default_layout` - path to a default layout to use
|
129
129
|
- `default_extension` - file extension to use
|
130
|
+
- `word_separator` - character to use for slug generation
|
130
131
|
|
131
132
|
Any options you provide in `_config.yml` will override poole's built-in
|
132
133
|
defaults. Mr. Poole defaults to using Markdown (with extension "md"), and the
|
@@ -139,6 +140,17 @@ example, if you have your default extension set to `textile`, but then pass the
|
|
139
140
|
`--layout` flag to post/draft with a Markdown template, the generated post will
|
140
141
|
use the Markdown extension.
|
141
142
|
|
143
|
+
*Important!* If you want to use hyphens for the `word_separator` option, you'll
|
144
|
+
need to escape it (because a single dash is the beginning a YAML bulleted
|
145
|
+
list). If you don't, the YAML parser will choke (I don't have any control over
|
146
|
+
this).
|
147
|
+
|
148
|
+
```
|
149
|
+
poole:
|
150
|
+
word_separator: "-" # correct
|
151
|
+
word_separator: - # WRONG...don't do this!
|
152
|
+
```
|
153
|
+
|
142
154
|
|
143
155
|
## To do
|
144
156
|
|
data/lib/mr_poole/cli.rb
CHANGED
data/lib/mr_poole/config.rb
CHANGED
@@ -5,11 +5,17 @@ module MrPoole
|
|
5
5
|
class Config
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
begin
|
9
|
+
if File.exists?('_config.yml')
|
10
|
+
yaml = YAML.load(File.read('_config.yml'))
|
11
|
+
@config = OpenStruct.new(yaml["poole"])
|
12
|
+
@config.srcdir = yaml['source'] if yaml['source']
|
13
|
+
else
|
14
|
+
@config = OpenStruct.new
|
15
|
+
end
|
16
|
+
rescue Psych::SyntaxError
|
17
|
+
bad_yaml_message
|
18
|
+
exit
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
@@ -25,5 +31,11 @@ module MrPoole
|
|
25
31
|
@config.send(sym)
|
26
32
|
end
|
27
33
|
|
34
|
+
private
|
35
|
+
|
36
|
+
def bad_yaml_message
|
37
|
+
puts 'Error reading YAML file _config.yml!'
|
38
|
+
puts ' (Did you forget to escape a hyphen?)'
|
39
|
+
end
|
28
40
|
end
|
29
41
|
end
|
data/lib/mr_poole/helper.rb
CHANGED
@@ -4,8 +4,10 @@ require 'pathname'
|
|
4
4
|
module MrPoole
|
5
5
|
class Helper
|
6
6
|
|
7
|
+
attr_accessor :config
|
8
|
+
|
7
9
|
def initialize
|
8
|
-
|
10
|
+
@config = Config.new
|
9
11
|
end
|
10
12
|
|
11
13
|
# Check for a _posts directory in current directory. If there's not one,
|
@@ -70,7 +72,8 @@ module MrPoole
|
|
70
72
|
# Given a post title (mixed case, spaces, etc.), generates a slug for
|
71
73
|
# This clobbers any non-ASCII text (TODO don't do that)
|
72
74
|
def get_slug_for(title)
|
73
|
-
|
75
|
+
word_sep = @config.word_separator || '_'
|
76
|
+
title.downcase.gsub(/[^a-z0-9_\s-]/, '').gsub(/\s+/, word_sep)
|
74
77
|
end
|
75
78
|
|
76
79
|
def get_date_stamp
|
@@ -159,13 +162,7 @@ module MrPoole
|
|
159
162
|
# If a user has a custom 'source' defined in their _config.yml, change
|
160
163
|
# to that directory for everything else
|
161
164
|
def check_custom_src_dir!
|
162
|
-
srcdir =
|
163
|
-
|
164
|
-
if File.exists?('_config.yml')
|
165
|
-
yaml = YAML.load(File.read('_config.yml'))
|
166
|
-
srcdir = yaml['source']
|
167
|
-
end
|
168
|
-
|
165
|
+
srcdir = @config.srcdir
|
169
166
|
Dir.chdir(srcdir) if srcdir
|
170
167
|
end
|
171
168
|
|
data/lib/mr_poole/version.rb
CHANGED
data/spec/command_spec.rb
CHANGED
@@ -190,6 +190,33 @@ module MrPoole
|
|
190
190
|
expect(content).to match(/tags: testing/)
|
191
191
|
end
|
192
192
|
end # context custom layout
|
193
|
+
|
194
|
+
# I'm not sure why I originally decided to test all the slug generation
|
195
|
+
# code in the draft section, but here we go anyway.
|
196
|
+
context 'with custom word_separator in config file' do
|
197
|
+
before(:each) { write_config_file_custom_word_sep }
|
198
|
+
|
199
|
+
it "should downcase and underscore title for slug" do
|
200
|
+
fn = c.draft({:title => "Test Post with Spaces"})
|
201
|
+
expect(fn).to match(/test-post-with-spaces[.]md/)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should remove non-word characters for slug" do
|
205
|
+
fn = c.draft({:title => "On (function() {}()) in JavaScript"})
|
206
|
+
expect(fn).to match(/on-function-in-javascript[.]md/)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "explicit slug overrides custom word_separator" do
|
210
|
+
fn = c.draft({:title => "Test Draft", :slug => 'unique_slug'})
|
211
|
+
expect(fn).to match(/unique_slug[.]md$/)
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should sub any weird characters in slug" do
|
215
|
+
fn = c.draft({:title => "Test Post with Spaces", :slug => "(stupid] {slüg/"})
|
216
|
+
expect(fn).to match(/stupid-slg[.]md/)
|
217
|
+
end
|
218
|
+
|
219
|
+
end # end context custom word_separator
|
193
220
|
end # end describe draft
|
194
221
|
|
195
222
|
describe "#publish" do
|
data/spec/config_spec.rb
CHANGED
@@ -17,6 +17,13 @@ def write_config_file_no_poole
|
|
17
17
|
f.close
|
18
18
|
end
|
19
19
|
|
20
|
+
def write_config_file_bad_yaml
|
21
|
+
c = File.open('_config.yml', 'w')
|
22
|
+
c.puts 'poole:'
|
23
|
+
c.puts ' word_separator: -'
|
24
|
+
c.close
|
25
|
+
end
|
26
|
+
|
20
27
|
module MrPoole
|
21
28
|
describe Config do
|
22
29
|
before(:each) { @olddir, @tmpdir = make_jekyll_dir }
|
@@ -39,6 +46,19 @@ module MrPoole
|
|
39
46
|
config = Config.new
|
40
47
|
expect(config).not_to be_empty
|
41
48
|
end
|
49
|
+
|
50
|
+
it "exits with on bad YAML" do
|
51
|
+
write_config_file_bad_yaml
|
52
|
+
expect {
|
53
|
+
capture_stdout { cli = CLI.new([]) }
|
54
|
+
}.to raise_error(SystemExit)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "prints a reasonable error message on bad YAML" do
|
58
|
+
write_config_file_bad_yaml
|
59
|
+
msg = aborted_poole_output(['post', 'title']).call
|
60
|
+
expect(msg).to match(/error.*yaml/i)
|
61
|
+
end
|
42
62
|
end
|
43
63
|
|
44
64
|
describe '#inspect' do
|
data/spec/spec_helper.rb
CHANGED
@@ -150,6 +150,12 @@ def write_config_file_custom_layout
|
|
150
150
|
filename
|
151
151
|
end
|
152
152
|
|
153
|
+
def write_config_file_custom_src_dir
|
154
|
+
c = File.open('_config.yml', 'w')
|
155
|
+
c.puts 'source: src'
|
156
|
+
c.close
|
157
|
+
end
|
158
|
+
|
153
159
|
def write_config_file_custom_extension
|
154
160
|
c = File.open('_config.yml', 'w')
|
155
161
|
c.puts 'poole:'
|
@@ -157,8 +163,9 @@ def write_config_file_custom_extension
|
|
157
163
|
c.close
|
158
164
|
end
|
159
165
|
|
160
|
-
def
|
166
|
+
def write_config_file_custom_word_sep
|
161
167
|
c = File.open('_config.yml', 'w')
|
162
|
-
c.puts '
|
168
|
+
c.puts 'poole:'
|
169
|
+
c.puts ' word_separator: "-"'
|
163
170
|
c.close
|
164
171
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mr_poole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael McClimon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01
|
11
|
+
date: 2014-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|