refactor file+matter creation in cucumber steps
This commit is contained in:
parent
12a55b86ac
commit
5b2480c8ba
|
@ -1,3 +1,25 @@
|
||||||
|
def file_content_from_hash(input_hash)
|
||||||
|
matter_hash = {}
|
||||||
|
%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
|
||||||
|
|
||||||
|
content = if input_hash['input'] && input_hash['filter']
|
||||||
|
"{{ #{input_hash['input']} | #{input_hash['filter']} }}"
|
||||||
|
else
|
||||||
|
input_hash['content']
|
||||||
|
end
|
||||||
|
|
||||||
|
<<EOF
|
||||||
|
---
|
||||||
|
#{matter}
|
||||||
|
---
|
||||||
|
#{content}
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
Before do
|
Before do
|
||||||
FileUtils.mkdir(TEST_DIR)
|
FileUtils.mkdir(TEST_DIR)
|
||||||
Dir.chdir(TEST_DIR)
|
Dir.chdir(TEST_DIR)
|
||||||
|
@ -78,26 +100,8 @@ Given /^I have the following (draft|post)s?(?: (in|under) "([^"]+)")?:$/ do |sta
|
||||||
end
|
end
|
||||||
|
|
||||||
path = File.join(before, folder_post, after, filename)
|
path = File.join(before, folder_post, after, filename)
|
||||||
|
|
||||||
matter_hash = {}
|
|
||||||
%w(title layout tag tags category categories published author path date permalink).each do |key|
|
|
||||||
matter_hash[key] = post[key] if post[key]
|
|
||||||
end
|
|
||||||
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp
|
|
||||||
|
|
||||||
content = if post['input'] && post['filter']
|
|
||||||
"{{ #{post['input']} | #{post['filter']} }}"
|
|
||||||
else
|
|
||||||
post['content']
|
|
||||||
end
|
|
||||||
|
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
f.write <<EOF
|
f.write file_content_from_hash(post)
|
||||||
---
|
|
||||||
#{matter}
|
|
||||||
---
|
|
||||||
#{content}
|
|
||||||
EOF
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue