Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for collections_dir configuration #74

Merged
merged 3 commits into from Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/jekyll-compose/arg_parser.rb
Expand Up @@ -33,7 +33,8 @@ def force?
end

def source
config["source"].gsub(%r!^#{Regexp.quote(Dir.pwd)}!, "")
File.join(config["source"], config["collections_dir"])
.gsub(%r!^#{Regexp.quote(Dir.pwd)}/*!, "")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-compose/file_creator.rb
Expand Up @@ -30,7 +30,7 @@ def validate_should_write!

def ensure_directory_exists
dir = File.dirname file_path
Dir.mkdir(dir) unless Dir.exist?(dir)
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
end

def write_file
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-compose/movement_arg_parser.rb
Expand Up @@ -8,7 +8,7 @@ def validate!
end

def path
args.join " "
File.join(source, args.join(" ")).sub(%r!\A/!, "")
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions spec/draft_spec.rb
Expand Up @@ -139,6 +139,29 @@
end
end
end

context "and collections_dir is set" do
let(:collections_dir) { "my_collections" }
let(:drafts_dir) { Pathname.new source_dir("site", collections_dir, "_drafts") }
let(:config_data) do
%(
source: site
collections_dir: #{collections_dir}
)
end

it "should create drafts at the correct location" do
expect(path).not_to exist
capture_stdout { described_class.process(args) }
expect(path).to exist
end

it "should write a helpful message when successful" do
output = capture_stdout { described_class.process(args) }
generated_path = File.join("site", collections_dir, "_drafts", "a-test-post.md").cyan
expect(output).to include("New draft created at #{generated_path}")
end
end
end

context "when source option is set" do
Expand Down
23 changes: 23 additions & 0 deletions spec/post_spec.rb
Expand Up @@ -150,6 +150,29 @@
end
end
end

context "and collections_dir is set" do
let(:collections_dir) { "my_collections" }
let(:posts_dir) { Pathname.new source_dir("site", collections_dir, "_posts") }
let(:config_data) do
%(
source: site
collections_dir: #{collections_dir}
)
end

it "should create posts at the correct location" do
expect(path).not_to exist
capture_stdout { described_class.process(args) }
expect(path).to exist
end

it "should write a helpful message when successful" do
output = capture_stdout { described_class.process(args) }
generated_path = File.join("site", collections_dir, "_posts", filename).cyan
expect(output).to include("New post created at #{generated_path}")
end
end
end

context "when source option is set" do
Expand Down
13 changes: 6 additions & 7 deletions spec/publish_spec.rb
Expand Up @@ -102,14 +102,15 @@
let(:config) { source_dir("_config.yml") }
let(:drafts_dir) { Pathname.new source_dir("site", "_drafts") }
let(:posts_dir) { Pathname.new source_dir("site", "_posts") }

let(:args) { ["site/_drafts/#{draft_to_publish}"] }
let(:config_data) do
%(
source: site
)
end

before(:each) do
File.open(config, "w") do |f|
f.write(%(
source: site
))
f.write(config_data)
end
end

Expand All @@ -129,8 +130,6 @@
let(:drafts_dir) { Pathname.new source_dir("site", "_drafts") }
let(:posts_dir) { Pathname.new source_dir("site", "_posts") }

let(:args) { ["site/_drafts/#{draft_to_publish}"] }

it "should use source directory set by command line option" do
expect(post_path).not_to exist
expect(draft_path).to exist
Expand Down
39 changes: 32 additions & 7 deletions spec/unpublish_spec.rb
Expand Up @@ -87,14 +87,15 @@
let(:config) { source_dir("_config.yml") }
let(:drafts_dir) { Pathname.new(source_dir("site", "_drafts")) }
let(:posts_dir) { Pathname.new(source_dir("site", "_posts")) }

let(:args) { ["site/_posts/#{post_filename}"] }
let(:config_data) do
%(
source: site
)
end

before(:each) do
File.open(config, "w") do |f|
f.write(%(
source: site
))
f.write(config_data)
end
end

Expand All @@ -109,14 +110,38 @@
expect(post_path).not_to exist
expect(draft_path).to exist
end

context "and collections_dir is set" do
let(:collections_dir) { "my_collections" }
let(:drafts_dir) { Pathname.new(source_dir("site", collections_dir, "_drafts")) }
let(:posts_dir) { Pathname.new(source_dir("site", collections_dir, "_posts")) }
let(:config_data) do
%(
source: site
collections_dir: #{collections_dir}
)
end

it "should move posts to the correct location" do
expect(post_path).to exist
expect(draft_path).not_to exist
capture_stdout { described_class.process(args) }
expect(draft_path).to exist
end

it "should write a helpful message when successful" do
output = capture_stdout { described_class.process(args) }
post_filepath = File.join("site", collections_dir, "_posts", post_filename)
draft_filepath = File.join("site", collections_dir, "_drafts", post_name)
expect(output).to include("Post #{post_filepath} was moved to #{draft_filepath}")
end
end
end

context "when source option is set" do
let(:drafts_dir) { Pathname.new(source_dir("site", "_drafts")) }
let(:posts_dir) { Pathname.new(source_dir("site", "_posts")) }

let(:args) { ["site/_posts/#{post_filename}"] }

it "should use source directory set by command line option" do
expect(post_path).to exist
expect(draft_path).not_to exist
Expand Down