bunto-compose 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/bunto-compose.rb +18 -0
- data/lib/bunto-compose/arg_parser.rb +27 -0
- data/lib/bunto-compose/file_creator.rb +36 -0
- data/lib/bunto-compose/file_info.rb +20 -0
- data/lib/bunto-compose/file_mover.rb +34 -0
- data/lib/bunto-compose/movement_arg_parser.rb +19 -0
- data/lib/bunto-compose/version.rb +5 -0
- data/lib/bunto/commands/draft.rb +44 -0
- data/lib/bunto/commands/page.rb +48 -0
- data/lib/bunto/commands/post.rb +59 -0
- data/lib/bunto/commands/publish.rb +65 -0
- data/lib/bunto/commands/unpublish.rb +58 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a4719b3f94e4602b6613f7defe5376caa3e85b0
|
4
|
+
data.tar.gz: a1c4dfe36598a5a526300a52ea1f8459dabcfdd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06800c16c6c6eed4693bed4117ab02ea01b2b114991085b3cf6b8ece88598c263330818dadcd3adf4a676e1188da09fdee1aa6cb8881d55e363ecb759aa6c004
|
7
|
+
data.tar.gz: 27e2ec49303058a96f27c7f44e59fdd003aeae4cf42c8efc9e74a810f2a969a8b256ccc1325d6a1ab20d5cd1839095ccd24c5792c37555f9258feef7aefb9242
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bunto-compose/version"
|
2
|
+
require "bunto-compose/arg_parser"
|
3
|
+
require "bunto-compose/movement_arg_parser"
|
4
|
+
require "bunto-compose/file_creator"
|
5
|
+
require "bunto-compose/file_mover"
|
6
|
+
require "bunto-compose/file_info"
|
7
|
+
|
8
|
+
module Bunto
|
9
|
+
module Compose
|
10
|
+
DEFAULT_TYPE = "md"
|
11
|
+
DEFAULT_LAYOUT = "post"
|
12
|
+
DEFAULT_LAYOUT_PAGE = "page"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
%w{draft post publish unpublish page}.each do |file|
|
17
|
+
require File.expand_path("bunto/commands/#{file}.rb", File.dirname(__FILE__))
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Bunto::Compose::ArgParser
|
2
|
+
attr_reader :args, :options
|
3
|
+
def initialize(args, options)
|
4
|
+
@args = args
|
5
|
+
@options = options
|
6
|
+
end
|
7
|
+
|
8
|
+
def validate!
|
9
|
+
raise ArgumentError.new('You must specify a name.') if args.empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
type = options["extension"] || Bunto::Compose::DEFAULT_TYPE
|
14
|
+
end
|
15
|
+
|
16
|
+
def layout
|
17
|
+
layout = options["layout"] || Bunto::Compose::DEFAULT_LAYOUT
|
18
|
+
end
|
19
|
+
|
20
|
+
def title
|
21
|
+
args.join ' '
|
22
|
+
end
|
23
|
+
|
24
|
+
def force?
|
25
|
+
!!options["force"]
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Bunto
|
2
|
+
module Compose
|
3
|
+
class FileCreator
|
4
|
+
attr_reader :file, :force
|
5
|
+
def initialize(fileInfo, force = false)
|
6
|
+
@file = fileInfo
|
7
|
+
@force = force
|
8
|
+
end
|
9
|
+
|
10
|
+
def create!
|
11
|
+
validate_should_write!
|
12
|
+
ensure_directory_exists
|
13
|
+
write_file
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def validate_should_write!
|
19
|
+
raise ArgumentError.new("A #{file.resource_type} already exists at #{file.path}") if File.exist?(file.path) and !force
|
20
|
+
end
|
21
|
+
|
22
|
+
def ensure_directory_exists
|
23
|
+
dir = File.dirname file.path
|
24
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
25
|
+
end
|
26
|
+
|
27
|
+
def write_file
|
28
|
+
File.open(file.path, "w") do |f|
|
29
|
+
f.puts(file.content)
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "New #{file.resource_type} created at #{file.path}."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Bunto::Compose::FileInfo
|
2
|
+
attr_reader :params
|
3
|
+
def initialize(params)
|
4
|
+
@params = params
|
5
|
+
end
|
6
|
+
|
7
|
+
def file_name
|
8
|
+
name = Bunto::Utils.slugify params.title
|
9
|
+
"#{name}.#{params.type}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def content
|
13
|
+
front_matter = YAML.dump({
|
14
|
+
'layout' => params.layout,
|
15
|
+
'title' => params.title,
|
16
|
+
})
|
17
|
+
|
18
|
+
front_matter + "---\n"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Bunto
|
2
|
+
module Compose
|
3
|
+
class FileMover
|
4
|
+
attr_reader :movement
|
5
|
+
def initialize(movement)
|
6
|
+
@movement = movement
|
7
|
+
end
|
8
|
+
|
9
|
+
def resource_type
|
10
|
+
'file'
|
11
|
+
end
|
12
|
+
|
13
|
+
def move
|
14
|
+
validate_source
|
15
|
+
ensure_directory_exists
|
16
|
+
move_file
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate_source
|
20
|
+
raise ArgumentError.new("There was no #{resource_type} found at '#{movement.from}'.") unless File.exist? movement.from
|
21
|
+
end
|
22
|
+
|
23
|
+
def ensure_directory_exists
|
24
|
+
dir = File.dirname movement.to
|
25
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
26
|
+
end
|
27
|
+
|
28
|
+
def move_file
|
29
|
+
FileUtils.mv(movement.from, movement.to)
|
30
|
+
puts "#{resource_type.capitalize} #{movement.from} was moved to #{movement.to}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Bunto
|
2
|
+
module Compose
|
3
|
+
class MovementArgParser
|
4
|
+
attr_reader :args, :options
|
5
|
+
def initialize(args, options)
|
6
|
+
@args = args
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate!
|
11
|
+
raise ArgumentError.new("You must specify a #{resource_type} path.") if args.empty?
|
12
|
+
end
|
13
|
+
|
14
|
+
def path
|
15
|
+
args.join ' '
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Bunto
|
2
|
+
module Commands
|
3
|
+
class Draft < Command
|
4
|
+
def self.init_with_program(prog)
|
5
|
+
prog.command(:draft) do |c|
|
6
|
+
c.syntax 'draft NAME'
|
7
|
+
c.description 'Creates a new draft post with the given NAME'
|
8
|
+
|
9
|
+
options.each {|opt| c.option *opt }
|
10
|
+
|
11
|
+
c.action { |args, options| process args, options }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.options
|
16
|
+
[
|
17
|
+
['extension', '-x EXTENSION', '--extension EXTENSION', 'Specify the file extension'],
|
18
|
+
['layout', '-l LAYOUT', '--layout LAYOUT', "Specify the draft layout"],
|
19
|
+
['force', '-f', '--force', 'Overwrite a draft if it already exists']
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def self.process(args = [], options = {})
|
25
|
+
params = Compose::ArgParser.new args, options
|
26
|
+
params.validate!
|
27
|
+
|
28
|
+
draft = DraftFileInfo.new params
|
29
|
+
|
30
|
+
Compose::FileCreator.new(draft, params.force?).create!
|
31
|
+
end
|
32
|
+
|
33
|
+
class DraftFileInfo < Compose::FileInfo
|
34
|
+
def resource_type
|
35
|
+
'draft'
|
36
|
+
end
|
37
|
+
|
38
|
+
def path
|
39
|
+
"_drafts/#{file_name}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Bunto
|
2
|
+
module Commands
|
3
|
+
class Page < Command
|
4
|
+
def self.init_with_program(prog)
|
5
|
+
prog.command(:page) do |c|
|
6
|
+
c.syntax 'page NAME'
|
7
|
+
c.description 'Creates a new page with the given NAME'
|
8
|
+
|
9
|
+
options.each {|opt| c.option *opt }
|
10
|
+
|
11
|
+
c.action { |args, options| process args, options }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.options
|
16
|
+
[
|
17
|
+
['extension', '-x EXTENSION', '--extension EXTENSION', 'Specify the file extension'],
|
18
|
+
['layout', '-l LAYOUT', '--layout LAYOUT', "Specify the page layout"],
|
19
|
+
['force', '-f', '--force', 'Overwrite a page if it already exists']
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.process(args = [], options = {})
|
24
|
+
params = PageArgParser.new args, options
|
25
|
+
params.validate!
|
26
|
+
|
27
|
+
page = PageFileInfo.new params
|
28
|
+
|
29
|
+
Compose::FileCreator.new(page, params.force?).create!
|
30
|
+
end
|
31
|
+
|
32
|
+
class PageArgParser < Compose::ArgParser
|
33
|
+
def layout
|
34
|
+
layout = options["layout"] || Bunto::Compose::DEFAULT_LAYOUT_PAGE
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class PageFileInfo < Compose::FileInfo
|
39
|
+
def resource_type
|
40
|
+
'page'
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :path, :file_name
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Bunto
|
2
|
+
module Commands
|
3
|
+
class Post < Command
|
4
|
+
def self.init_with_program(prog)
|
5
|
+
prog.command(:post) do |c|
|
6
|
+
c.syntax 'post NAME'
|
7
|
+
c.description 'Creates a new post with the given NAME'
|
8
|
+
|
9
|
+
options.each {|opt| c.option *opt }
|
10
|
+
|
11
|
+
c.action { |args, options| process args, options }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.options
|
16
|
+
[
|
17
|
+
['extension', '-x EXTENSION', '--extension EXTENSION', 'Specify the file extension'],
|
18
|
+
['layout', '-l LAYOUT', '--layout LAYOUT', "Specify the post layout"],
|
19
|
+
['force', '-f', '--force', 'Overwrite a post if it already exists'],
|
20
|
+
['date', '-d DATE', '--date DATE', 'Specify the post date']
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.process(args = [], options = {})
|
25
|
+
params = PostArgParser.new args, options
|
26
|
+
params.validate!
|
27
|
+
|
28
|
+
post = PostFileInfo.new params
|
29
|
+
|
30
|
+
Compose::FileCreator.new(post, params.force?).create!
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
class PostArgParser < Compose::ArgParser
|
35
|
+
def date
|
36
|
+
options["date"].nil? ? Time.now : DateTime.parse(options["date"])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class PostFileInfo < Compose::FileInfo
|
41
|
+
def resource_type
|
42
|
+
'post'
|
43
|
+
end
|
44
|
+
|
45
|
+
def path
|
46
|
+
"_posts/#{file_name}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def file_name
|
50
|
+
"#{_date_stamp}-#{super}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def _date_stamp
|
54
|
+
@params.date.strftime '%Y-%m-%d'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Bunto
|
2
|
+
module Commands
|
3
|
+
class Publish < Command
|
4
|
+
def self.init_with_program(prog)
|
5
|
+
prog.command(:publish) do |c|
|
6
|
+
c.syntax 'publish DRAFT_PATH'
|
7
|
+
c.description 'Moves a draft into the _posts directory and sets the date'
|
8
|
+
|
9
|
+
c.option 'date', '-d DATE', '--date DATE', 'Specify the post date'
|
10
|
+
|
11
|
+
c.action do |args, options|
|
12
|
+
Bunto::Commands::Publish.process(args, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.process(args = [], options = {})
|
18
|
+
params = PublishArgParser.new args, options
|
19
|
+
params.validate!
|
20
|
+
|
21
|
+
movement = DraftMovementInfo.new params
|
22
|
+
|
23
|
+
mover = DraftMover.new movement
|
24
|
+
mover.move
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class PublishArgParser < Compose::MovementArgParser
|
30
|
+
def resource_type
|
31
|
+
"draft"
|
32
|
+
end
|
33
|
+
|
34
|
+
def date
|
35
|
+
options["date"].nil? ? Date.today : Date.parse(options["date"])
|
36
|
+
end
|
37
|
+
|
38
|
+
def name
|
39
|
+
File.basename path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class DraftMovementInfo
|
44
|
+
attr_reader :params
|
45
|
+
def initialize(params)
|
46
|
+
@params = params
|
47
|
+
end
|
48
|
+
|
49
|
+
def from
|
50
|
+
params.path
|
51
|
+
end
|
52
|
+
|
53
|
+
def to
|
54
|
+
date_stamp = params.date.strftime '%Y-%m-%d'
|
55
|
+
"_posts/#{date_stamp}-#{params.name}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class DraftMover < Compose::FileMover
|
60
|
+
def resource_type
|
61
|
+
'draft'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Bunto
|
2
|
+
module Commands
|
3
|
+
class Unpublish < Command
|
4
|
+
def self.init_with_program(prog)
|
5
|
+
prog.command(:unpublish) do |c|
|
6
|
+
c.syntax 'unpublish POST_PATH'
|
7
|
+
c.description 'Moves a post back into the _drafts directory'
|
8
|
+
|
9
|
+
c.action do |args, options|
|
10
|
+
process(args, options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.process(args = [], options = {})
|
16
|
+
params = UnpublishArgParser.new args, options
|
17
|
+
params.validate!
|
18
|
+
|
19
|
+
movement = PostMovementInfo.new params
|
20
|
+
|
21
|
+
mover = PostMover.new movement
|
22
|
+
mover.move
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class UnpublishArgParser < Compose::MovementArgParser
|
28
|
+
def resource_type
|
29
|
+
'post'
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
File.basename(path).sub /\d{4}-\d{2}-\d{2}-/, ''
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class PostMovementInfo
|
38
|
+
attr_reader :params
|
39
|
+
def initialize(params)
|
40
|
+
@params = params
|
41
|
+
end
|
42
|
+
|
43
|
+
def from
|
44
|
+
params.path
|
45
|
+
end
|
46
|
+
|
47
|
+
def to
|
48
|
+
"_drafts/#{params.name}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class PostMover < Compose::FileMover
|
53
|
+
def resource_type
|
54
|
+
'post'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bunto-compose
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Parker Moore
|
8
|
+
- Suriyaa Kudo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-03-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
name: bunto
|
21
|
+
prerelease: false
|
22
|
+
type: :runtime
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.0.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
name: bundler
|
35
|
+
prerelease: false
|
36
|
+
type: :development
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.5'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
name: rake
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
name: rspec
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
70
|
+
description: Streamline your writing in Bunto with these commands.
|
71
|
+
email:
|
72
|
+
- parkrmoore@gmail.com
|
73
|
+
- SuriyaaKudoIsc@users.noreply.github.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- lib/bunto-compose.rb
|
79
|
+
- lib/bunto-compose/arg_parser.rb
|
80
|
+
- lib/bunto-compose/file_creator.rb
|
81
|
+
- lib/bunto-compose/file_info.rb
|
82
|
+
- lib/bunto-compose/file_mover.rb
|
83
|
+
- lib/bunto-compose/movement_arg_parser.rb
|
84
|
+
- lib/bunto-compose/version.rb
|
85
|
+
- lib/bunto/commands/draft.rb
|
86
|
+
- lib/bunto/commands/page.rb
|
87
|
+
- lib/bunto/commands/post.rb
|
88
|
+
- lib/bunto/commands/publish.rb
|
89
|
+
- lib/bunto/commands/unpublish.rb
|
90
|
+
homepage: https://github.com/bunto/bunto-compose
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.8
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Streamline your writing in Bunto with these commands.
|
114
|
+
test_files: []
|