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

fix seeds exporter #911

Merged
merged 1 commit into from
Apr 4, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/comfortable_mexican_sofa/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ def export!(classes = nil)
def write_file_content(path, data)
::File.open(::File.join(path), "wb") do |f|
data.each do |item|
f.write("[#{item[:header]}]\n")
f.write("#{item[:content]}\n")
f.write("[#{item[:header]}]\n#{item[:content]}")
# adds a newline between items if not already there
# makes sure last item does not have a newline
if data.last != item && !item[:content].to_s.end_with?("\n")
f.write("\n")
end
end
end
end
Expand Down
10 changes: 4 additions & 6 deletions test/lib/seeds/layouts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,28 @@ def test_export
assert File.exist?(layout_2_content_path)
assert File.exist?(layout_3_content_path)

out = <<~TEXT
out = <<~TEXT.chomp
[attributes]
---
label: Default Layout
app_layout:\s
position: 0

[content]
{{cms:textarea content}}
[js]
default_js
[css]
default_css
TEXT

assert_equal out, IO.read(layout_1_content_path)

out = <<~TEXT
out = <<~TEXT.chomp
[attributes]
---
label: Nested Layout
app_layout:\s
position: 0

[content]
{{cms:text header}}
{{cms:textarea content}}
Expand All @@ -135,13 +134,12 @@ def test_export
TEXT
assert_equal out, IO.read(layout_2_content_path)

out = <<~TEXT
out = <<~TEXT.chomp
[attributes]
---
label: Child Layout
app_layout:\s
position: 0

[content]
{{cms:textarea left_column}}
{{cms:textarea right_column}}
Expand Down
8 changes: 3 additions & 5 deletions test/lib/seeds/pages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_export

ComfortableMexicanSofa::Seeds::Page::Exporter.new("default-site", "test-site").export!

out = <<~TEXT
out = <<~TEXT.chomp
[attributes]
---
label: Default Page
Expand All @@ -186,7 +186,6 @@ def test_export
- Default
is_published: true
position: 0

[checkbox boolean]
true
[file file]
Expand All @@ -200,7 +199,7 @@ def test_export

assert File.exist?(page_1_attachment_path)

out = <<~TEXT
out = <<~TEXT.chomp
[attributes]
---
label: Child Page
Expand All @@ -213,13 +212,12 @@ def test_export
TEXT
assert_equal out, IO.read(page_2_content_path)

out = <<~TEXT
out = <<~TEXT.chomp
[attributes]
---
label: Default Translation
layout: default
is_published: true

[markdown content]
translation content
TEXT
Expand Down
3 changes: 1 addition & 2 deletions test/lib/seeds/snippets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ def test_export
ComfortableMexicanSofa::Seeds::Snippet::Exporter.new("default-site", "test-site").export!

assert File.exist?(content_path)
out = <<~TEXT
out = <<~TEXT.chomp
[attributes]
---
label: Default Snippet
categories:
- Default
position: 0

[content]
snippet content
TEXT
Expand Down