Skip to content

Commit

Permalink
fix seeds exporter (#911)
Browse files Browse the repository at this point in the history
Awesome. Thank you.
  • Loading branch information
lopesrb authored Apr 4, 2020
1 parent e1160ce commit 8f7e425
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
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

0 comments on commit 8f7e425

Please sign in to comment.