comfortable_mexican_sofa 1.8.3 → 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. data/.gitignore +1 -1
  2. data/Gemfile +2 -2
  3. data/README.md +3 -3
  4. data/app/assets/stylesheets/comfortable_mexican_sofa/base.css.sass +11 -11
  5. data/app/assets/stylesheets/comfortable_mexican_sofa/bootstrap_overrides.css.sass +2 -2
  6. data/app/controllers/cms_admin/base_controller.rb +1 -1
  7. data/app/controllers/cms_content_controller.rb +1 -1
  8. data/app/models/cms/block.rb +1 -1
  9. data/app/models/cms/file.rb +4 -1
  10. data/config/database.yml +1 -1
  11. data/db/cms_fixtures/sample-site/categories/files.yml +1 -0
  12. data/db/cms_fixtures/sample-site/categories/pages.yml +1 -0
  13. data/db/cms_fixtures/sample-site/categories/snippets.yml +1 -0
  14. data/db/cms_fixtures/sample-site/files/_sample.jpg.yml +5 -0
  15. data/db/cms_fixtures/sample-site/files/sample.jpg +0 -0
  16. data/db/cms_fixtures/sample-site/layouts/default/{_default.yml → attributes.yml} +0 -0
  17. data/db/cms_fixtures/sample-site/layouts/default/{js.js → javascript.js} +0 -0
  18. data/db/cms_fixtures/sample-site/layouts/default/nested/{_nested.yml → attributes.yml} +0 -0
  19. data/db/cms_fixtures/sample-site/layouts/default/nested/{js.js → javascript.js} +0 -0
  20. data/db/cms_fixtures/sample-site/layouts/default/nested/{css.css → stylesheet.css} +0 -0
  21. data/db/cms_fixtures/sample-site/layouts/default/{css.css → stylesheet.css} +0 -0
  22. data/db/cms_fixtures/sample-site/pages/index/attributes.yml +6 -0
  23. data/db/cms_fixtures/sample-site/pages/index/child/{_child.yml → attributes.yml} +0 -0
  24. data/db/cms_fixtures/sample-site/snippets/default/attributes.yml +4 -0
  25. data/lib/comfortable_mexican_sofa.rb +25 -23
  26. data/lib/comfortable_mexican_sofa/fixture.rb +77 -0
  27. data/lib/comfortable_mexican_sofa/fixture/category.rb +35 -0
  28. data/lib/comfortable_mexican_sofa/fixture/file.rb +70 -0
  29. data/lib/comfortable_mexican_sofa/fixture/layout.rb +90 -0
  30. data/lib/comfortable_mexican_sofa/fixture/page.rb +122 -0
  31. data/lib/comfortable_mexican_sofa/fixture/snippet.rb +71 -0
  32. data/lib/comfortable_mexican_sofa/version.rb +1 -1
  33. data/lib/tasks/comfortable_mexican_sofa.rake +17 -20
  34. data/test/fixtures/cms/files.yml +2 -2
  35. data/test/functional/cms_admin/base_controller_test.rb +1 -1
  36. data/test/functional/cms_admin/categories_controller_test.rb +1 -1
  37. data/test/functional/cms_admin/files_controller_test.rb +1 -1
  38. data/test/functional/cms_admin/layouts_controller_test.rb +1 -1
  39. data/test/functional/cms_admin/pages_controller_test.rb +1 -1
  40. data/test/functional/cms_admin/revisions_controller_test.rb +1 -1
  41. data/test/functional/cms_admin/sites_controller_test.rb +1 -1
  42. data/test/functional/cms_admin/snippets_controller_test.rb +1 -1
  43. data/test/functional/cms_content_controller_test.rb +1 -1
  44. data/test/gemfiles/Gemfile.rails.3.1 +2 -1
  45. data/test/gemfiles/Gemfile.rails.3.2 +2 -1
  46. data/test/integration/authentication_test.rb +1 -1
  47. data/test/integration/fixtures_test.rb +5 -3
  48. data/test/integration/mirrors_test.rb +1 -1
  49. data/test/integration/render_cms_test.rb +1 -1
  50. data/test/integration/sites_test.rb +1 -1
  51. data/test/integration/view_hooks_test.rb +1 -1
  52. data/test/test_helper.rb +1 -0
  53. data/test/unit/configuration_test.rb +1 -1
  54. data/test/unit/fixtures/_sample.jpg.yml +0 -0
  55. data/test/unit/fixtures/categories_test.rb +35 -0
  56. data/test/unit/fixtures/files_test.rb +100 -0
  57. data/test/unit/fixtures/layouts_test.rb +135 -0
  58. data/test/unit/fixtures/pages_test.rb +152 -0
  59. data/test/unit/fixtures/snippets_test.rb +101 -0
  60. data/test/unit/fixtures_test.rb +11 -325
  61. data/test/unit/mirrors_test.rb +1 -1
  62. data/test/unit/models/block_test.rb +1 -1
  63. data/test/unit/models/categorization_test.rb +1 -1
  64. data/test/unit/models/category_test.rb +1 -1
  65. data/test/unit/models/file_test.rb +11 -6
  66. data/test/unit/models/layout_test.rb +1 -1
  67. data/test/unit/models/page_test.rb +2 -1
  68. data/test/unit/models/site_test.rb +1 -1
  69. data/test/unit/models/snippet_test.rb +1 -1
  70. data/test/unit/revisions_test.rb +1 -1
  71. data/test/unit/sitemap_test.rb +1 -1
  72. data/test/unit/tag_test.rb +1 -1
  73. data/test/unit/tags/asset_test.rb +1 -1
  74. data/test/unit/tags/collection_test.rb +1 -1
  75. data/test/unit/tags/field_datetime_test.rb +1 -1
  76. data/test/unit/tags/field_integer_test.rb +1 -1
  77. data/test/unit/tags/field_rich_text_test.rb +1 -1
  78. data/test/unit/tags/field_string_test.rb +1 -1
  79. data/test/unit/tags/field_text_test.rb +1 -1
  80. data/test/unit/tags/file_test.rb +1 -1
  81. data/test/unit/tags/helper_test.rb +1 -1
  82. data/test/unit/tags/page_datetime_test.rb +1 -1
  83. data/test/unit/tags/page_file_test.rb +1 -1
  84. data/test/unit/tags/page_files_test.rb +1 -1
  85. data/test/unit/tags/page_integer_test.rb +1 -1
  86. data/test/unit/tags/page_markdown_test.rb +1 -1
  87. data/test/unit/tags/page_rich_text_test.rb +1 -1
  88. data/test/unit/tags/page_string_test.rb +1 -1
  89. data/test/unit/tags/page_text_test.rb +1 -1
  90. data/test/unit/tags/partial_test.rb +1 -1
  91. data/test/unit/tags/snippet_test.rb +1 -1
  92. data/test/unit/view_methods_test.rb +1 -1
  93. metadata +28 -12
  94. data/db/cms_fixtures/sample-site/pages/index/_index.yml +0 -2
  95. data/db/cms_fixtures/sample-site/snippets/default/_default.yml +0 -1
  96. data/lib/comfortable_mexican_sofa/fixtures.rb +0 -289
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class MirrorsTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class CmsBlockTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class CmsCategorizationTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class CmsCategoryTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class CmsFileTest < ActiveSupport::TestCase
4
4
 
@@ -9,11 +9,16 @@ class CmsFileTest < ActiveSupport::TestCase
9
9
  end
10
10
 
11
11
  def test_validations
12
- assert_no_difference 'Cms::File.count' do
13
- file = Cms::File.create
14
- assert file.errors.present?
15
- assert_has_errors_on file, :site_id, :file
16
- end
12
+ file = Cms::File.new
13
+ assert file.invalid?
14
+ assert_has_errors_on file, :site_id, :file
15
+
16
+ cms_files(:default).update_column(:file_file_name, 'image.jpg')
17
+ file = cms_sites(:default).files.new(
18
+ :file => fixture_file_upload('files/image.jpg', 'image/jpeg')
19
+ )
20
+ assert file.invalid?
21
+ assert_has_errors_on file, :file_file_name
17
22
  end
18
23
 
19
24
  def test_create
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class CmsLayoutTest < ActiveSupport::TestCase
4
4
 
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
+
3
+ require_relative '../../test_helper'
3
4
 
4
5
  class CmsPageTest < ActiveSupport::TestCase
5
6
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class CmsSiteTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class CmsSnippetTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class RevisionsTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class SitemapTest < ActiveSupport::TestCase
4
4
  class DummySitemapExtension
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class TagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class AssetTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class CollectionTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class FieldDateTimeTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class FieldIntegerTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class FieldRichTextTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class FieldStringTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class FieldTextTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class FileTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class HelperTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class PageDateTimeTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class PageFileTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class PageFilesTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class PageIntegerTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class PageMarkdownTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class PageRichTextTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class PageStringTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class PageTextTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class PartialTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class SnippetTagTest < ActiveSupport::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class ViewMethodsTest < ActionView::TestCase
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.8.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-26 00:00:00.000000000 Z
13
+ date: 2013-07-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -305,20 +305,25 @@ files:
305
305
  - config/locales/sv.yml
306
306
  - config/locales/zh-CN.yml
307
307
  - config/routes.rb
308
- - db/cms_fixtures/sample-site/layouts/default/_default.yml
308
+ - db/cms_fixtures/sample-site/categories/files.yml
309
+ - db/cms_fixtures/sample-site/categories/pages.yml
310
+ - db/cms_fixtures/sample-site/categories/snippets.yml
311
+ - db/cms_fixtures/sample-site/files/_sample.jpg.yml
312
+ - db/cms_fixtures/sample-site/files/sample.jpg
313
+ - db/cms_fixtures/sample-site/layouts/default/attributes.yml
309
314
  - db/cms_fixtures/sample-site/layouts/default/content.html
310
- - db/cms_fixtures/sample-site/layouts/default/css.css
311
- - db/cms_fixtures/sample-site/layouts/default/js.js
312
- - db/cms_fixtures/sample-site/layouts/default/nested/_nested.yml
315
+ - db/cms_fixtures/sample-site/layouts/default/javascript.js
316
+ - db/cms_fixtures/sample-site/layouts/default/nested/attributes.yml
313
317
  - db/cms_fixtures/sample-site/layouts/default/nested/content.html
314
- - db/cms_fixtures/sample-site/layouts/default/nested/css.css
315
- - db/cms_fixtures/sample-site/layouts/default/nested/js.js
316
- - db/cms_fixtures/sample-site/pages/index/_index.yml
317
- - db/cms_fixtures/sample-site/pages/index/child/_child.yml
318
+ - db/cms_fixtures/sample-site/layouts/default/nested/javascript.js
319
+ - db/cms_fixtures/sample-site/layouts/default/nested/stylesheet.css
320
+ - db/cms_fixtures/sample-site/layouts/default/stylesheet.css
321
+ - db/cms_fixtures/sample-site/pages/index/attributes.yml
322
+ - db/cms_fixtures/sample-site/pages/index/child/attributes.yml
318
323
  - db/cms_fixtures/sample-site/pages/index/child/left.html
319
324
  - db/cms_fixtures/sample-site/pages/index/child/right.html
320
325
  - db/cms_fixtures/sample-site/pages/index/content.html
321
- - db/cms_fixtures/sample-site/snippets/default/_default.yml
326
+ - db/cms_fixtures/sample-site/snippets/default/attributes.yml
322
327
  - db/cms_fixtures/sample-site/snippets/default/content.html
323
328
  - db/migrate/01_create_cms.rb
324
329
  - db/seeds.rb
@@ -341,7 +346,12 @@ files:
341
346
  - lib/comfortable_mexican_sofa/extensions/is_categorized.rb
342
347
  - lib/comfortable_mexican_sofa/extensions/is_mirrored.rb
343
348
  - lib/comfortable_mexican_sofa/extensions/rails.rb
344
- - lib/comfortable_mexican_sofa/fixtures.rb
349
+ - lib/comfortable_mexican_sofa/fixture.rb
350
+ - lib/comfortable_mexican_sofa/fixture/category.rb
351
+ - lib/comfortable_mexican_sofa/fixture/file.rb
352
+ - lib/comfortable_mexican_sofa/fixture/layout.rb
353
+ - lib/comfortable_mexican_sofa/fixture/page.rb
354
+ - lib/comfortable_mexican_sofa/fixture/snippet.rb
345
355
  - lib/comfortable_mexican_sofa/form_builder.rb
346
356
  - lib/comfortable_mexican_sofa/render_methods.rb
347
357
  - lib/comfortable_mexican_sofa/routing.rb
@@ -410,6 +420,12 @@ files:
410
420
  - test/integration/view_hooks_test.rb
411
421
  - test/test_helper.rb
412
422
  - test/unit/configuration_test.rb
423
+ - test/unit/fixtures/_sample.jpg.yml
424
+ - test/unit/fixtures/categories_test.rb
425
+ - test/unit/fixtures/files_test.rb
426
+ - test/unit/fixtures/layouts_test.rb
427
+ - test/unit/fixtures/pages_test.rb
428
+ - test/unit/fixtures/snippets_test.rb
413
429
  - test/unit/fixtures_test.rb
414
430
  - test/unit/mirrors_test.rb
415
431
  - test/unit/models/block_test.rb
@@ -1,2 +0,0 @@
1
- label: Home Fixture Page
2
- layout: default
@@ -1 +0,0 @@
1
- label: Default Fixture Snippet
@@ -1,289 +0,0 @@
1
- module ComfortableMexicanSofa::Fixtures
2
-
3
- def self.import_all(to_site, from_folder = nil, force_import = false)
4
- import_layouts to_site, from_folder, nil, true, nil, [], force_import
5
- import_pages to_site, from_folder, nil, true, nil, [], force_import
6
- import_snippets to_site, from_folder, force_import
7
- end
8
-
9
- def self.export_all(from_site, to_folder = nil)
10
- export_layouts from_site, to_folder
11
- export_pages from_site, to_folder
12
- export_snippets from_site, to_folder
13
- end
14
-
15
- def self.import_layouts(to_site, from_folder = nil, path = nil, root = true, parent = nil, layout_ids = [], force_import = false)
16
- site = Cms::Site.find_or_create_by_identifier(to_site)
17
- unless path ||= find_fixtures_path((from_folder || to_site), 'layouts')
18
- ComfortableMexicanSofa.logger.warn('Cannot find Layout fixtures')
19
- return []
20
- end
21
-
22
- Dir.glob("#{path}/*").select{|f| File.directory?(f)}.each do |path|
23
- identifier = path.split('/').last
24
- layout = site.layouts.find_by_identifier(identifier) || site.layouts.new(:identifier => identifier)
25
-
26
- # updating attributes
27
- if File.exists?(file_path = File.join(path, "_#{identifier}.yml"))
28
- if layout.new_record? || File.mtime(file_path) > layout.updated_at || force_import
29
- attributes = YAML.load_file(file_path).try(:symbolize_keys!) || { }
30
- layout.label = attributes[:label] || identifier.titleize
31
- layout.app_layout = attributes[:app_layout] || parent.try(:app_layout)
32
- layout.position = attributes[:position] if attributes[:position]
33
- end
34
- elsif layout.new_record?
35
- layout.label = identifier.titleize
36
- layout.app_layout = parent.try(:app_layout)
37
- end
38
-
39
- # updating content
40
- if File.exists?(file_path = File.join(path, 'content.html'))
41
- if layout.new_record? || File.mtime(file_path) > layout.updated_at || force_import
42
- layout.content = File.open(file_path).read
43
- end
44
- end
45
- if File.exists?(file_path = File.join(path, 'css.css'))
46
- if layout.new_record? || File.mtime(file_path) > layout.updated_at || force_import
47
- layout.css = File.open(file_path).read
48
- end
49
- end
50
- if File.exists?(file_path = File.join(path, 'js.js'))
51
- if layout.new_record? || File.mtime(file_path) > layout.updated_at || force_import
52
- layout.js = File.open(file_path).read
53
- end
54
- end
55
-
56
- # saving
57
- layout.parent = parent
58
- if layout.changed?
59
- if layout.save
60
- ComfortableMexicanSofa.logger.warn("[Fixtures] Saved Layout {#{layout.identifier}}")
61
- else
62
- ComfortableMexicanSofa.logger.error("[Fixtures] Failed to save Layout {#{layout.errors.inspect}}")
63
- next
64
- end
65
- end
66
- layout_ids << layout.id
67
-
68
- # checking for nested fixtures
69
- layout_ids += import_layouts(to_site, from_folder, path, false, layout, layout_ids)
70
- end
71
-
72
- # removing all db entries that are not in fixtures
73
- if root
74
- site.layouts.where('id NOT IN (?)', layout_ids.uniq).each{ |l| l.destroy }
75
- ComfortableMexicanSofa.logger.warn('Imported Layouts!')
76
- end
77
-
78
- # returning ids of layouts in fixtures
79
- layout_ids.uniq
80
- end
81
-
82
- def self.import_pages(to_site, from_folder = nil, path = nil, root = true, parent = nil, page_ids = [], force_import = false)
83
- site = Cms::Site.find_or_create_by_identifier(to_site)
84
- unless path ||= find_fixtures_path((from_folder || to_site), 'pages')
85
- ComfortableMexicanSofa.logger.warn('Cannot find Page fixtures')
86
- return []
87
- end
88
-
89
- Dir.glob("#{path}/*").select{|f| File.directory?(f)}.each do |path|
90
- slug = path.split('/').last
91
- page = if parent
92
- parent.children.find_by_slug(slug) || site.pages.new(:parent => parent, :slug => slug)
93
- else
94
- site.pages.root || site.pages.new(:slug => slug)
95
- end
96
-
97
- # updating attributes
98
- if File.exists?(file_path = File.join(path, "_#{slug}.yml"))
99
- if page.new_record? || File.mtime(file_path) > page.updated_at || force_import
100
- attributes = YAML.load_file(file_path).try(:symbolize_keys!) || { }
101
- page.label = attributes[:label] || slug.titleize
102
- page.layout = site.layouts.find_by_identifier(attributes[:layout]) || parent.try(:layout)
103
- page.target_page = site.pages.find_by_full_path(attributes[:target_page])
104
- page.is_published = attributes[:is_published].nil?? true : attributes[:is_published]
105
- page.position = attributes[:position] if attributes[:position]
106
- end
107
- elsif page.new_record?
108
- page.label = slug.titleize
109
- page.layout = parent.try(:layout)
110
- end
111
-
112
- # updating content
113
- blocks_to_clear = page.blocks.collect(&:identifier)
114
- blocks_attributes = [ ]
115
- Dir.glob("#{path}/*.html").each do |file_path|
116
- identifier = file_path.split('/').last.gsub(/\.html$/, '')
117
- blocks_to_clear.delete(identifier)
118
- if page.new_record? || File.mtime(file_path) > page.updated_at || force_import
119
- blocks_attributes << {
120
- :identifier => identifier,
121
- :content => File.open(file_path).read
122
- }
123
- end
124
- end
125
-
126
- # clearing removed blocks
127
- blocks_to_clear.each do |identifier|
128
- blocks_attributes << {
129
- :identifier => identifier,
130
- :content => nil
131
- }
132
- end
133
-
134
- # saving
135
- page.blocks_attributes = blocks_attributes if blocks_attributes.present?
136
- if page.changed? || blocks_attributes.present?
137
- if page.save
138
- ComfortableMexicanSofa.logger.warn("[Fixtures] Saved Page {#{page.full_path}}")
139
- else
140
- ComfortableMexicanSofa.logger.warn("[Fixtures] Failed to save Page {#{page.errors.inspect}}")
141
- next
142
- end
143
- end
144
- page_ids << page.id
145
-
146
- # checking for nested fixtures
147
- page_ids += import_pages(to_site, from_folder, path, false, page, page_ids)
148
- end
149
-
150
- # removing all db entries that are not in fixtures
151
- if root
152
- site.pages.where('id NOT IN (?)', page_ids.uniq).each{ |p| p.destroy }
153
- ComfortableMexicanSofa.logger.warn('Imported Pages!')
154
- end
155
-
156
- # returning ids of layouts in fixtures
157
- page_ids.uniq
158
- end
159
-
160
- def self.import_snippets(to_site, from_folder = nil, force_import = false)
161
- site = Cms::Site.find_or_create_by_identifier(to_site)
162
- unless path = find_fixtures_path((from_folder || to_site), 'snippets')
163
- ComfortableMexicanSofa.logger.warn('Cannot find Snippet fixtures')
164
- return []
165
- end
166
-
167
- snippet_ids = []
168
- Dir.glob("#{path}/*").select{|f| File.directory?(f)}.each do |path|
169
- identifier = path.split('/').last
170
- snippet = site.snippets.find_by_identifier(identifier) || site.snippets.new(:identifier => identifier)
171
-
172
- # updating attributes
173
- if File.exists?(file_path = File.join(path, "_#{identifier}.yml"))
174
- if snippet.new_record? || File.mtime(file_path) > snippet.updated_at || force_import
175
- attributes = YAML.load_file(file_path).try(:symbolize_keys!) || { }
176
- snippet.label = attributes[:label] || identifier.titleize
177
- end
178
- elsif snippet.new_record?
179
- snippet.label = identifier.titleize
180
- end
181
-
182
- # updating content
183
- if File.exists?(file_path = File.join(path, 'content.html'))
184
- if snippet.new_record? || File.mtime(file_path) > snippet.updated_at || force_import
185
- snippet.content = File.open(file_path).read
186
- end
187
- end
188
-
189
- # saving
190
- if snippet.changed?
191
- if snippet.save
192
- ComfortableMexicanSofa.logger.warn("[Fixtures] Saved Snippet {#{snippet.identifier}}")
193
- else
194
- ComfortableMexicanSofa.logger.warn("[Fixtures] Failed to save Snippet {#{snippet.errors.inspect}}")
195
- next
196
- end
197
- end
198
- snippet_ids << snippet.id
199
- end
200
-
201
- # removing all db entries that are not in fixtures
202
- site.snippets.where('id NOT IN (?)', snippet_ids).each{ |s| s.destroy }
203
- ComfortableMexicanSofa.logger.warn('Imported Snippets!')
204
- end
205
-
206
- def self.export_layouts(from_site, to_folder = nil)
207
- return unless site = Cms::Site.find_by_identifier(from_site)
208
- path = File.join(ComfortableMexicanSofa.config.fixtures_path, (to_folder || site.identifier), 'layouts')
209
- FileUtils.rm_rf(path)
210
- FileUtils.mkdir_p(path)
211
-
212
- site.layouts.each do |layout|
213
- layout_path = File.join(path, layout.ancestors.reverse.collect{|l| l.identifier}, layout.identifier)
214
- FileUtils.mkdir_p(layout_path)
215
-
216
- open(File.join(layout_path, "_#{layout.identifier}.yml"), 'w') do |f|
217
- f.write({
218
- 'label' => layout.label,
219
- 'app_layout' => layout.app_layout,
220
- 'parent' => layout.parent.try(:identifier),
221
- 'position' => layout.position
222
- }.to_yaml)
223
- end
224
- open(File.join(layout_path, 'content.html'), 'w') do |f|
225
- f.write(layout.content)
226
- end
227
- open(File.join(layout_path, 'css.css'), 'w') do |f|
228
- f.write(layout.css)
229
- end
230
- open(File.join(layout_path, 'js.js'), 'w') do |f|
231
- f.write(layout.js)
232
- end
233
- end
234
- end
235
-
236
- def self.export_pages(from_site, to_folder = nil)
237
- return unless site = Cms::Site.find_by_identifier(from_site)
238
- path = File.join(ComfortableMexicanSofa.config.fixtures_path, (to_folder || site.identifier), 'pages')
239
- FileUtils.rm_rf(path)
240
- FileUtils.mkdir_p(path)
241
-
242
- site.pages.each do |page|
243
- page.slug = 'index' if page.slug.blank?
244
- page_path = File.join(path, page.ancestors.reverse.collect{|p| p.slug.blank?? 'index' : p.slug}, page.slug)
245
- FileUtils.mkdir_p(page_path)
246
-
247
- open(File.join(page_path, "_#{page.slug}.yml"), 'w') do |f|
248
- f.write({
249
- 'label' => page.label,
250
- 'layout' => page.layout.try(:identifier),
251
- 'parent' => page.parent && (page.parent.slug.present?? page.parent.slug : 'index'),
252
- 'target_page' => page.target_page.try(:slug),
253
- 'is_published' => page.is_published,
254
- 'position' => page.position
255
- }.to_yaml)
256
- end
257
- page.blocks_attributes.each do |block|
258
- open(File.join(page_path, "#{block[:identifier]}.html"), 'w') do |f|
259
- f.write(block[:content])
260
- end
261
- end
262
- end
263
- end
264
-
265
- def self.export_snippets(from_site, to_folder = nil)
266
- return unless site = Cms::Site.find_by_identifier(from_site)
267
- path = File.join(ComfortableMexicanSofa.config.fixtures_path, (to_folder || site.identifier), 'snippets')
268
- FileUtils.rm_rf(path)
269
- FileUtils.mkdir_p(path)
270
-
271
- site.snippets.each do |snippet|
272
- FileUtils.mkdir_p(snippet_path = File.join(path, snippet.identifier))
273
- open(File.join(snippet_path, "_#{snippet.identifier}.yml"), 'w') do |f|
274
- f.write({'label' => snippet.label}.to_yaml)
275
- end
276
- open(File.join(snippet_path, 'content.html'), 'w') do |f|
277
- f.write(snippet.content)
278
- end
279
- end
280
- end
281
-
282
- protected
283
-
284
- def self.find_fixtures_path(identifier, dir)
285
- path = File.join(ComfortableMexicanSofa.config.fixtures_path, identifier, dir)
286
- File.exists?(path) ? path : nil
287
- end
288
-
289
- end