mr_poole 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30428d35eafd9d58388483a2a69f299e7014f89a
4
- data.tar.gz: b1f25c5ba6677ddc1568f3d62310a751f0a6b68a
3
+ metadata.gz: bb4818933c757b8aa91900c8c95dac0d225afd49
4
+ data.tar.gz: 88de70683c306da09dd89bfe901ce5c08f10e9b8
5
5
  SHA512:
6
- metadata.gz: 83cbc63e84de3ac30014a48b4ba1d376ea12add90644c3c320d9456737d26931a03050f09b38cbd1b1f642b20da5f654740e2b286d0e0cf24e423c8e4c0b30b1
7
- data.tar.gz: 0bc63bef197d7b5d5d5e4f9a8840e9faaf42aab26f0fbdd2b2ff334380d50ac1b6b5b51dd0debdf0c161fcc330606165e2d62d6a7a88634f3a757581ba6a36a0
6
+ metadata.gz: daa89c474db50ae3deb18407cc2c2fb9ad9709e60456e79bffce23f55e11b607c07a20b7eea9cb62e2c1ad50373a55c5437ed79278cf63d6873af3d3ccce8b1d
7
+ data.tar.gz: 2fdb742701f6e8a8f947d440e27157889e16927e97580736a283be1697b0cf23bc517eb10b07d74089ae70155416a828f9b82cf7df4def7501d65b312d3d00d6
data/CHANGES.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ### v0.2.0 (2013-09-21)
4
+
5
+ - Hooked into Jekyll's `_config.yml` for customizations
6
+ - Added support for custom layouts
7
+ - Added support for custom file extensions
8
+ - Improvements to tests
9
+
10
+ ### v0.1.0 (2013-09-21)
11
+
12
+ - Initial release
data/README.md CHANGED
@@ -20,13 +20,23 @@ publish, and unpublish.
20
20
  poole post [OPTIONS] TITLE
21
21
 
22
22
  Generates a timestamped post in your `_posts` directory, with the format
23
- `YYYY-MM-DD-slug.md` (other formats to be suppored in the future). With no
24
- options, will generate a slug based on your title by replacing spaces with
25
- underscores, downcasing, and removing any special character. With option
26
- `--slug` (or `-s`), you can provide a custom slug.
23
+ `YYYY-MM-DD-slug.md`. With no options, will generate a slug based on your title
24
+ by replacing spaces with underscores, downcasing, and removing any special
25
+ character.
27
26
 
28
- Poole generates a simple file (in the future, this will be customizable) that
29
- looks like this:
27
+ Options:
28
+
29
+ ```
30
+ --slug (-s) Define a custom slug for post, used for generated file name
31
+
32
+ --title (-t) Define a title for post. This option may be omitted provided
33
+ that TITLE is given as the last argument to poole
34
+
35
+ --layout (-l) Path to a custom layout file to use
36
+ ```
37
+
38
+ By default, poole generates a simple file that looks like this (but see section
39
+ on configuration for more options).
30
40
 
31
41
  ```yaml
32
42
  ---
@@ -41,8 +51,8 @@ date: (current date automatically inserted here)
41
51
  poole draft [OPTIONS] TITLE
42
52
 
43
53
  Just like `poole post`, except that it creates an untimestamped post in your
44
- `_drafts` directory (creating it if it doesn't exist yet). Also takes
45
- `--slug`/`-s` as an option. In the generated file, no date is inserted.
54
+ `_drafts` directory (creating it if it doesn't exist yet). Uses same options
55
+ as `post`. In the generated file, no date is inserted.
46
56
 
47
57
  ### Publish
48
58
 
@@ -65,7 +75,7 @@ The life, universe, and everything.
65
75
 
66
76
  A call to `poole publish` will generate a file named
67
77
  `_posts/yyyy-mm-dd-test_draft.md` and delete the draft. (TODO: add flags for
68
- no-delete drafts, and no-update timstamp.) Also updates the date filed in the
78
+ no-delete drafts, and no-update timestamp.) Also updates the date filed in the
69
79
  header with a date, and HH:MM, producing this file:
70
80
 
71
81
  ```
@@ -95,13 +105,31 @@ The actual work is done in `MrPoole::Commands`: calls into that class return
95
105
  the path name for newly created files, so you can do something useful with
96
106
  them if you want to. This should get better in the future.
97
107
 
108
+ ## Configuration
109
+
110
+ You may also include directives for `poole` in Jekyll's `_config.yml` file. You
111
+ should provide a `poole` key, which may take the following subkeys:
112
+
113
+ - `default_layout` - path to a default layout to use
114
+ - `default_extension` - file extension to use
115
+
116
+ Any options you provide in `_config.yml` will override poole's built-in
117
+ defaults. Mr. Poole defaults to using Markdown (with extension "md"), and the
118
+ default layout is given above in the "Post" section. The default layout is
119
+ actually just YAML front matter for Jekyll, so it can be used with any
120
+ extension.
121
+
122
+ Note that command-line options override anything set in your config file. For
123
+ example, if you have your default extension set to `textile`, but then pass the
124
+ `--layout` flag to post/draft with a Markdown template, the generated post will
125
+ use the Markdown extension.
126
+
98
127
 
99
128
  ## To do
100
129
 
101
- - Configuration: custom templates, hooking into jekyll's `_config.yml`
102
- - Support for multiple output formats (right now, only markdown is supported)
103
- - Better option handling (allow custom templates, more flexible date
104
- substitution)
130
+ - Configuration: hooking into jekyll's `_config.yml` (mostly done)
131
+ - Support for multiple output formats (done, but needs better tests)
132
+ - Better option handling (more flexible date substitution)
105
133
  - Better documentation (this is an open source project, after all)
106
134
 
107
135
  ## Installation
@@ -118,7 +146,7 @@ Or install it yourself as:
118
146
 
119
147
  $ gem install mr_poole
120
148
 
121
- ## Contact
149
+ A## Contact
122
150
 
123
151
  Contact me on Github, at michael@mcclimon.org, or on twitter, @mmcclimon.
124
152
 
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
3
 
4
+ desc "Run rspec tests with short output"
4
5
  RSpec::Core::RakeTask.new(:spec) do |t|
5
- t.rspec_opts = "--color --format doc"
6
+ t.rspec_opts = "--color"
7
+ end
8
+
9
+ desc "Run rspec tests with long output"
10
+ RSpec::Core::RakeTask.new(:dspec) do |t|
11
+ t.rspec_opts = "--color --format documentation"
6
12
  end
data/lib/mr_poole/cli.rb CHANGED
@@ -9,7 +9,10 @@ module MrPoole
9
9
  @helper.ensure_jekyll_dir
10
10
 
11
11
  @params = args
12
- @commands = Commands.new
12
+ @config = Config.new
13
+
14
+ ext = @config.default_extension || 'md'
15
+ @commands = Commands.new(ext)
13
16
  end
14
17
 
15
18
  def execute(action)
@@ -27,7 +30,7 @@ module MrPoole
27
30
  options.title ||= @params.first
28
31
 
29
32
  @helper.post_usage unless options.title
30
- @commands.post(options.title, options.slug)
33
+ @commands.post(options)
31
34
  end
32
35
 
33
36
  def handle_draft
@@ -35,7 +38,7 @@ module MrPoole
35
38
  options.title ||= @params.first
36
39
 
37
40
  @helper.draft_usage unless options.title
38
- @commands.draft(options.title, options.slug)
41
+ @commands.draft(options)
39
42
  end
40
43
 
41
44
  def handle_publish
@@ -66,6 +69,7 @@ module MrPoole
66
69
  options = OpenStruct.new
67
70
  options.slug = nil
68
71
  options.title = nil
72
+ options.layout = nil
69
73
 
70
74
  opt_parser = OptionParser.new do |opts|
71
75
  opts.on('-s', '--slug [SLUG]', "Use custom slug") do |s|
@@ -75,8 +79,14 @@ module MrPoole
75
79
  opts.on('-t', '--title [TITLE]', "Specifiy title") do |t|
76
80
  options.title = t
77
81
  end
82
+
83
+ opts.on('-l', '--layout PATH', "Specify a custom layout file") do |l|
84
+ options.layout = l
85
+ end
78
86
  end
79
87
 
88
+ options.layout ||= @config.default_layout
89
+
80
90
  opt_parser.parse! @params
81
91
  options
82
92
  end
@@ -1,5 +1,4 @@
1
1
  require 'fileutils'
2
- require 'shellwords'
3
2
 
4
3
  module MrPoole
5
4
  class Commands
@@ -7,25 +6,30 @@ module MrPoole
7
6
  POSTS_FOLDER = '_posts'
8
7
  DRAFTS_FOLDER = '_drafts'
9
8
 
10
- def initialize
9
+ def initialize(extension='md')
11
10
  @helper = Helper.new
12
- @default_layout = @helper.get_default_layout
11
+ @ext = extension
13
12
  end
14
13
 
15
14
  # Generate a timestamped post
16
- def post(title, slug='')
15
+ def post(opts)
17
16
  date = @helper.get_date_stamp
18
17
 
19
18
  # still want to escape any garbage in the slug
20
- slug = title if slug.nil? || slug.empty?
19
+ slug = if opts[:slug].nil? || opts[:slug].empty?
20
+ opts[:title]
21
+ else
22
+ opts[:slug]
23
+ end
21
24
  slug = @helper.get_slug_for(slug)
22
25
 
23
26
  # put the metadata into the layout header
24
- head = @default_layout
25
- head.sub!(/^title:\s*$/, "title: #{title}")
27
+ head, ext = @helper.get_layout(opts[:layout])
28
+ head.sub!(/^title:\s*$/, "title: #{opts[:title]}")
26
29
  head.sub!(/^date:\s*$/, "date: #{date}")
30
+ ext ||= @ext
27
31
 
28
- path = File.join(POSTS_FOLDER, "#{date}-#{slug}.md")
32
+ path = File.join(POSTS_FOLDER, "#{date}-#{slug}.#{ext}")
29
33
  f = File.open(path, "w")
30
34
  f.write(head)
31
35
  f.close
@@ -34,17 +38,23 @@ module MrPoole
34
38
  end
35
39
 
36
40
  # Generate a non-timestamped draft
37
- def draft(title, slug='')
41
+ def draft(opts)
38
42
  # the drafts folder might not exist yet...create it just in case
39
43
  FileUtils.mkdir_p(DRAFTS_FOLDER)
40
44
 
41
- slug = title if slug.nil? || slug.empty?
45
+ slug = if opts[:slug].nil? || opts[:slug].empty?
46
+ opts[:title]
47
+ else
48
+ opts[:slug]
49
+ end
42
50
  slug = @helper.get_slug_for(slug)
43
51
 
44
- head = @default_layout
45
- head.sub!(/^title:\s*$/, "title: #{title}")
52
+ # put the metadata into the layout header
53
+ head, ext = @helper.get_layout(opts[:layout])
54
+ head.sub!(/^title:\s*$/, "title: #{opts[:title]}")
55
+ ext ||= @ext
46
56
 
47
- path = File.join(DRAFTS_FOLDER, "#{slug}.md")
57
+ path = File.join(DRAFTS_FOLDER, "#{slug}.#{ext}")
48
58
  f = File.open(path, "w")
49
59
  f.write(head)
50
60
  f.close
@@ -54,7 +64,7 @@ module MrPoole
54
64
 
55
65
  # Todo make this take a path instead?
56
66
  def publish(draftpath)
57
- slug = File.basename(draftpath, '.md')
67
+ tail = File.basename(draftpath)
58
68
 
59
69
  begin
60
70
  infile = File.open(draftpath, "r")
@@ -65,7 +75,7 @@ module MrPoole
65
75
  date = @helper.get_date_stamp
66
76
  time = @helper.get_time_stamp
67
77
 
68
- outpath = File.join(POSTS_FOLDER, "#{date}-#{slug}.md")
78
+ outpath = File.join(POSTS_FOLDER, "#{date}-#{tail}")
69
79
  outfile = File.open(outpath, "w")
70
80
 
71
81
  infile.each_line do |line|
@@ -0,0 +1,29 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+
4
+ module MrPoole
5
+ class Config
6
+
7
+ def initialize
8
+ if File.exists?('_config.yml')
9
+ yaml = YAML.load(File.read('_config.yml'))
10
+ @config = OpenStruct.new(yaml["poole"])
11
+ else
12
+ @config = OpenStruct.new
13
+ end
14
+ end
15
+
16
+ def empty?
17
+ @config.to_h.empty?
18
+ end
19
+
20
+ def inspect
21
+ @config.inspect
22
+ end
23
+
24
+ def method_missing(sym, *args)
25
+ @config.send(sym)
26
+ end
27
+
28
+ end
29
+ end
@@ -15,22 +15,28 @@ module MrPoole
15
15
  end
16
16
  end
17
17
 
18
- # Configure the default layout.
19
- #
20
- # If a user has $HOME/.poole_default_layout, will use the contents of
21
- # that file, otherwise will use a simple template
22
- def get_default_layout
23
- config_path = File.join(Dir.home, '.poole_default_layout')
18
+ # Get a layout as a string. If layout_path is non-nil, will open that
19
+ # file and read it, otherwise will return a default one, and a file
20
+ # extension to use
21
+ def get_layout(layout_path)
24
22
 
25
- if File.exists?(config_path)
26
- return File.open(config_path, 'r').read
23
+ if layout_path.nil?
24
+ contents = "---\n"
25
+ contents << "title:\n"
26
+ contents << "layout: post\n"
27
+ contents << "date:\n"
28
+ contents << "---\n"
29
+ ext = nil
27
30
  else
28
- s = "---\n"
29
- s << "title:\n"
30
- s << "layout: post\n"
31
- s << "date:\n"
32
- s << "---\n"
31
+ begin
32
+ contents = File.open(layout_path, "r").read()
33
+ ext = layout_path.match(/\.(.*?)$/)[1]
34
+ rescue Errno::ENOENT
35
+ bad_path(layout_path)
36
+ end
33
37
  end
38
+
39
+ return contents, ext
34
40
  end
35
41
 
36
42
  # Given a post title (mixed case, spaces, etc.), generates a slug for
@@ -75,6 +81,7 @@ module MrPoole
75
81
  puts ' --title Define a title for post (also available with -t)'
76
82
  puts ' This option may be omitted provided that TITLE is given as'
77
83
  puts ' the last argument to poole'
84
+ puts ' --layout Path to a custom layout file to use (also availabe with -l)'
78
85
  exit
79
86
  end
80
87
 
@@ -88,6 +95,7 @@ module MrPoole
88
95
  puts ' --title Define a title for post (also available with -t)'
89
96
  puts ' This option may be omitted provided that TITLE is given as'
90
97
  puts ' the last argument to poole'
98
+ puts ' --layout Path to a custom layout file to use (also availabe with -l)'
91
99
  exit
92
100
  end
93
101
 
@@ -1,3 +1,3 @@
1
1
  module MrPoole
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/mr_poole.rb CHANGED
@@ -3,6 +3,7 @@ require 'fileutils'
3
3
  require 'mr_poole/commands'
4
4
  require 'mr_poole/helper'
5
5
  require 'mr_poole/cli'
6
+ require 'mr_poole/config'
6
7
 
7
8
  module MrPoole
8
9
  end