refactor step to support page creation
This commit is contained in:
parent
5b2480c8ba
commit
396aa16f99
|
@ -1,8 +1,5 @@
|
||||||
def file_content_from_hash(input_hash)
|
def file_content_from_hash(input_hash)
|
||||||
matter_hash = {}
|
matter_hash = input_hash.reject { |k, v| k == "content" }
|
||||||
%w(title layout tag tags category categories published author path date permalink).each do |key|
|
|
||||||
matter_hash[key] = input_hash[key] if input_hash[key]
|
|
||||||
end
|
|
||||||
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp
|
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp
|
||||||
|
|
||||||
content = if input_hash['input'] && input_hash['filter']
|
content = if input_hash['input'] && input_hash['filter']
|
||||||
|
@ -84,24 +81,28 @@ Given /^I have an? (.*) directory$/ do |dir|
|
||||||
FileUtils.mkdir_p(dir)
|
FileUtils.mkdir_p(dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^I have the following (draft|post)s?(?: (in|under) "([^"]+)")?:$/ do |status, direction, folder, table|
|
Given /^I have the following (draft|page|post)s?(?: (in|under) "([^"]+)")?:$/ do |status, direction, folder, table|
|
||||||
table.hashes.each do |post|
|
table.hashes.each do |input_hash|
|
||||||
title = slug(post['title'])
|
title = slug(input_hash['title'])
|
||||||
ext = post['type'] || 'textile'
|
ext = input_hash['type'] || 'textile'
|
||||||
before, after = location(folder, direction)
|
before, after = location(folder, direction)
|
||||||
|
|
||||||
if "draft" == status
|
case status
|
||||||
folder_post = '_drafts'
|
when "draft"
|
||||||
|
dest_folder = '_drafts'
|
||||||
filename = "#{title}.#{ext}"
|
filename = "#{title}.#{ext}"
|
||||||
elsif "post" == status
|
when "page"
|
||||||
parsed_date = Time.xmlschema(post['date']) rescue Time.parse(post['date'])
|
dest_folder = ''
|
||||||
folder_post = '_posts'
|
filename = "#{title}.#{ext}"
|
||||||
|
when "post"
|
||||||
|
parsed_date = Time.xmlschema(input_hash['date']) rescue Time.parse(input_hash['date'])
|
||||||
|
dest_folder = '_posts'
|
||||||
filename = "#{parsed_date.strftime('%Y-%m-%d')}-#{title}.#{ext}"
|
filename = "#{parsed_date.strftime('%Y-%m-%d')}-#{title}.#{ext}"
|
||||||
end
|
end
|
||||||
|
|
||||||
path = File.join(before, folder_post, after, filename)
|
path = File.join(before, dest_folder, after, filename)
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
f.write file_content_from_hash(post)
|
f.write file_content_from_hash(input_hash)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue