Skip to content

Commit

Permalink
position handling with layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
holli committed Feb 5, 2012
1 parent db386ea commit 8047922
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
@@ -1 +1,2 @@
label: Default Fixture Nested Layout
label: Default Fixture Nested Layout
position: 42
6 changes: 4 additions & 2 deletions lib/comfortable_mexican_sofa/fixtures.rb
Expand Up @@ -28,7 +28,8 @@ def self.import_layouts(to_hostname, from_hostname = nil, path = nil, root = tru
if layout.new_record? || File.mtime(file_path) > layout.updated_at
attributes = YAML.load_file(file_path).try(:symbolize_keys!) || { }
layout.label = attributes[:label] || identifier.titleize
layout.app_layout = attributes[:app_layout] || parent.try(:app_layout)
layout.app_layout = attributes[:app_layout] || parent.try(:app_layout)
layout.position = attributes[:position] if attributes[:position]
end
elsif layout.new_record?
layout.label = identifier.titleize
Expand Down Expand Up @@ -206,7 +207,8 @@ def self.export_layouts(from_hostname, to_hostname = nil)
f.write({
'label' => layout.label,
'app_layout' => layout.app_layout,
'parent' => layout.parent.try(:identifier)
'parent' => layout.parent.try(:identifier),
'position' => layout.position
}.to_yaml)
end
open(File.join(layout_path, 'content.html'), 'w') do |f|
Expand Down
8 changes: 6 additions & 2 deletions test/unit/fixtures_test.rb
Expand Up @@ -41,13 +41,15 @@ def test_import_layouts_updating_and_deleting
assert_equal "<html>\n <body>\n {{ cms:page:content }}\n </body>\n</html>", layout.content
assert_equal 'body{color: red}', layout.css
assert_equal '// default js', layout.js
assert_equal 0, layout.position

nested_layout.reload
assert_equal layout, nested_layout.parent
assert_equal 'Default Fixture Nested Layout', nested_layout.label
assert_equal "<div class='left'> {{ cms:page:left }} </div>\n<div class='right'> {{ cms:page:right }} </div>", nested_layout.content
assert_equal 'div{float:left}', nested_layout.css
assert_equal '// nested js', nested_layout.js
assert_equal 42, nested_layout.position

assert_nil Cms::Layout.find_by_identifier('child')
end
Expand Down Expand Up @@ -250,7 +252,8 @@ def test_export_layouts
assert_equal ({
'label' => 'Nested Layout',
'app_layout' => nil,
'parent' => nil
'parent' => nil,
'position' => 0
}), YAML.load_file(layout_1_attr_path)
assert_equal cms_layouts(:nested).content, IO.read(layout_1_content_path)
assert_equal cms_layouts(:nested).css, IO.read(layout_1_css_path)
Expand All @@ -259,7 +262,8 @@ def test_export_layouts
assert_equal ({
'label' => 'Child Layout',
'app_layout' => nil,
'parent' => 'nested'
'parent' => 'nested',
'position' => 0
}), YAML.load_file(layout_2_attr_path)
assert_equal cms_layouts(:child).content, IO.read(layout_2_content_path)
assert_equal cms_layouts(:child).css, IO.read(layout_2_css_path)
Expand Down

0 comments on commit 8047922

Please sign in to comment.