comfortable_mexican_sofa 1.8.3 → 1.8.4

Sign up to get free protection for your applications and to get access to all the features.
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
data/.gitignore CHANGED
@@ -13,4 +13,4 @@ Gemfile.lock
13
13
  .rvmrc
14
14
  .ruby-version
15
15
  /.sass-cache
16
- /coverage
16
+ coverage/
data/Gemfile CHANGED
@@ -6,6 +6,6 @@ group :test do
6
6
  gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
7
7
  gem 'jdbc-sqlite3', :platform => :jruby
8
8
  gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
9
-
10
- gem 'coveralls', :require => false
9
+ gem 'mocha', :require => false
10
+ gem 'coveralls', :require => false
11
11
  end
data/README.md CHANGED
@@ -16,13 +16,13 @@ Features
16
16
 
17
17
  Installation for Rails 4
18
18
  ------------------------
19
- For Rails 4 apps feel free to use [2.0.0.beta1](https://github.com/comfy/comfortable-mexican-sofa/tree/2.0) release.
19
+ For Rails 4 apps feel free to use [2.0.0.beta1](https://github.com/comfy/comfortable-mexican-sofa/tree/1.9) release.
20
20
 
21
21
  gem 'comfortable_mexican_sofa', '~> 2.0.0.beta1'
22
22
 
23
- Or even better work with the latest 2.0 branch:
23
+ Or even better work with the latest 1.9 branch:
24
24
 
25
- gem 'comfortable_mexican_sofa', :github => 'comfy/comfortable-mexican-sofa', :branch => '2.0'
25
+ gem 'comfortable_mexican_sofa', :github => 'comfy/comfortable-mexican-sofa', :branch => '1.9'
26
26
 
27
27
  Installation
28
28
  ------------
@@ -54,7 +54,7 @@ body#comfy
54
54
  display: block
55
55
  height: 16px
56
56
  width: 8px
57
- background: transparent url("/assets/comfortable_mexican_sofa/nav_arrow.png")
57
+ background: transparent url(image-path("comfortable_mexican_sofa/nav_arrow.png"))
58
58
 
59
59
  // -- Right Side Boxes ----------------------------------------------------
60
60
  .right-column-content
@@ -118,7 +118,7 @@ body#comfy
118
118
  height: 60px
119
119
  width: 80px
120
120
  float: left
121
- background: url("/assets/comfortable_mexican_sofa/checkerboard.gif")
121
+ background: url(image-path("comfortable_mexican_sofa/checkerboard.gif"))
122
122
  .details
123
123
  margin-left: 85px
124
124
  font-size: 11px
@@ -136,11 +136,11 @@ body#comfy
136
136
  .icon
137
137
  width: 28px
138
138
  height: 28px
139
- background: url("/assets/comfortable_mexican_sofa/icon_page.gif")
139
+ background: url(image-path("comfortable_mexican_sofa/icon_page.gif"))
140
140
  .dragger
141
141
  width: 28px
142
142
  height: 28px
143
- background: url("/assets/comfortable_mexican_sofa/icon_move.gif")
143
+ background: url(image-path("comfortable_mexican_sofa/icon_move.gif"))
144
144
  cursor: move
145
145
  display: none
146
146
  span
@@ -244,18 +244,18 @@ body#comfy
244
244
  height: 28px
245
245
  width: 28px
246
246
  &.open a
247
- background-image: url("/assets/comfortable_mexican_sofa/arrow_bottom.gif")
247
+ background-image: url(image-path("comfortable_mexican_sofa/arrow_bottom.gif"))
248
248
  a
249
249
  display: block
250
250
  height: 28px
251
251
  width: 28px
252
- background: url("/assets/comfortable_mexican_sofa/arrow_right.gif") center center no-repeat
252
+ background: url(image-path("comfortable_mexican_sofa/arrow_right.gif")) center center no-repeat
253
253
  span
254
254
  display: none
255
255
  .icon
256
256
  float: left
257
257
  &.draft
258
- background: url("/assets/comfortable_mexican_sofa/icon_draft.gif")
258
+ background: url(image-path("comfortable_mexican_sofa/icon_draft.gif"))
259
259
  .item-content
260
260
  margin-left: 60px
261
261
  a.item-label
@@ -269,14 +269,14 @@ body#comfy
269
269
  // -- Sites ---------------------------------------------------------------
270
270
  &.c-cms-admin-sites
271
271
  table .icon
272
- background: url("/assets/comfortable_mexican_sofa/icon_site.gif")
272
+ background: url(image-path("comfortable_mexican_sofa/icon_site.gif"))
273
273
 
274
274
  // -- Layouts -------------------------------------------------------------
275
275
  &.c-cms-admin-layouts
276
276
  ul.list
277
277
  .item
278
278
  .icon
279
- background: url("/assets/comfortable_mexican_sofa/icon_layout.gif")
279
+ background: url(image-path("comfortable_mexican_sofa/icon_layout.gif"))
280
280
  .item-content
281
281
  margin-left: 35px
282
282
 
@@ -304,12 +304,12 @@ body#comfy
304
304
  // -- Snippets ------------------------------------------------------------
305
305
  &.c-cms-admin-snippets
306
306
  table .icon
307
- background: url("/assets/comfortable_mexican_sofa/icon_snippet.gif")
307
+ background: url(image-path("comfortable_mexican_sofa/icon_snippet.gif"))
308
308
 
309
309
  // -- Files ---------------------------------------------------------------
310
310
  &.c-cms-admin-files
311
311
  table .icon
312
- background: url("/assets/comfortable_mexican_sofa/icon_file.gif")
312
+ background: url(image-path("comfortable_mexican_sofa/icon_file.gif"))
313
313
 
314
314
  // -- Revisions -----------------------------------------------------------
315
315
  &.c-cms-admin-revisions
@@ -15,9 +15,9 @@ body#comfy
15
15
  text-align: right
16
16
 
17
17
  [class^="icon-"], [class*=" icon-"]
18
- background-image: url("/assets/comfortable_mexican_sofa/bootstrap/glyphicons-halflings.png")
18
+ background-image: url(image-path("comfortable_mexican_sofa/bootstrap/glyphicons-halflings.png"))
19
19
  .icon-white
20
- background-image: url("/assets/comfortable_mexican_sofa/bootstrap/glyphicons-halflings-white.png")
20
+ background-image: url(image-path("comfortable_mexican_sofa/bootstrap/glyphicons-halflings-white.png"))
21
21
 
22
22
  // -- Setting up border-box sizing, letting fields size themselves --------
23
23
  *
@@ -44,7 +44,7 @@ protected
44
44
  def load_fixtures
45
45
  return unless ComfortableMexicanSofa.config.enable_fixtures
46
46
  if %w(cms_admin/layouts cms_admin/pages cms_admin/snippets).member?(params[:controller])
47
- ComfortableMexicanSofa::Fixtures.import_all(@site.identifier)
47
+ ComfortableMexicanSofa::Fixture::Importer.new(@site.identifier).import!
48
48
  flash.now[:error] = I18n.t('cms.base.fixtures_enabled')
49
49
  end
50
50
  end
@@ -36,7 +36,7 @@ protected
36
36
 
37
37
  def load_fixtures
38
38
  return unless ComfortableMexicanSofa.config.enable_fixtures
39
- ComfortableMexicanSofa::Fixtures.import_all(@cms_site.identifier)
39
+ ComfortableMexicanSofa::Fixture::Importer.new(@cms_site.identifier).import!
40
40
  end
41
41
 
42
42
  def load_cms_site
@@ -26,7 +26,7 @@ class Cms::Block < ActiveRecord::Base
26
26
  def tag
27
27
  @tag ||= page.tags(true).detect{|t| t.is_cms_block? && t.identifier == identifier}
28
28
  end
29
-
29
+
30
30
  protected
31
31
 
32
32
  def prepare_files
@@ -36,8 +36,11 @@ class Cms::File < ActiveRecord::Base
36
36
  belongs_to :block
37
37
 
38
38
  # -- Validations ----------------------------------------------------------
39
- validates :site_id, :presence => true
39
+ validates :site_id,
40
+ :presence => true
40
41
  validates_attachment_presence :file
42
+ validates :file_file_name,
43
+ :uniqueness => {:scope => :site_id}
41
44
 
42
45
  # -- Callbacks ------------------------------------------------------------
43
46
  before_save :assign_label
@@ -1,6 +1,6 @@
1
1
  development:
2
2
  adapter: sqlite3
3
- database: ":memory:"
3
+ database: db/cms_development.sqlite3
4
4
  pool: 5
5
5
  timeout: 10000
6
6
 
@@ -0,0 +1 @@
1
+ - File Category
@@ -0,0 +1 @@
1
+ - Page Category
@@ -0,0 +1 @@
1
+ - Snippet Category
@@ -0,0 +1,5 @@
1
+ label: Fixture File
2
+ description: Fixture Description
3
+ categories:
4
+ - category_a
5
+ - category_b
@@ -0,0 +1,6 @@
1
+ label: Home Fixture Page
2
+ layout: default
3
+ target_page: '/child'
4
+ categories:
5
+ - category_a
6
+ - category_b
@@ -0,0 +1,4 @@
1
+ label: Default Fixture Snippet
2
+ categories:
3
+ - category_a
4
+ - category_b
@@ -1,32 +1,34 @@
1
1
  # Loading engine only if this is not a standalone installation
2
2
  unless defined? ComfortableMexicanSofa::Application
3
- require File.expand_path('comfortable_mexican_sofa/engine', File.dirname(__FILE__))
3
+ require_relative 'comfortable_mexican_sofa/engine'
4
4
  end
5
5
 
6
- [ 'comfortable_mexican_sofa/version',
7
- 'comfortable_mexican_sofa/error',
8
- 'comfortable_mexican_sofa/configuration',
9
- 'comfortable_mexican_sofa/routing',
10
- 'comfortable_mexican_sofa/authentication/http_auth',
11
- 'comfortable_mexican_sofa/authentication/dummy_auth',
12
- 'comfortable_mexican_sofa/render_methods',
13
- 'comfortable_mexican_sofa/view_hooks',
14
- 'comfortable_mexican_sofa/view_methods',
15
- 'comfortable_mexican_sofa/form_builder',
16
- 'comfortable_mexican_sofa/tag',
17
- 'comfortable_mexican_sofa/sitemap',
18
- 'comfortable_mexican_sofa/fixtures',
19
- 'comfortable_mexican_sofa/extensions/rails',
20
- 'comfortable_mexican_sofa/extensions/acts_as_tree',
21
- 'comfortable_mexican_sofa/extensions/has_revisions',
22
- 'comfortable_mexican_sofa/extensions/is_mirrored',
23
- 'comfortable_mexican_sofa/extensions/is_categorized'
24
- ].each do |path|
25
- require File.expand_path(path, File.dirname(__FILE__))
26
- end
6
+ require_relative 'comfortable_mexican_sofa/version'
7
+ require_relative 'comfortable_mexican_sofa/error'
8
+ require_relative 'comfortable_mexican_sofa/configuration'
9
+ require_relative 'comfortable_mexican_sofa/routing'
10
+ require_relative 'comfortable_mexican_sofa/authentication/http_auth'
11
+ require_relative 'comfortable_mexican_sofa/authentication/dummy_auth'
12
+ require_relative 'comfortable_mexican_sofa/render_methods'
13
+ require_relative 'comfortable_mexican_sofa/view_hooks'
14
+ require_relative 'comfortable_mexican_sofa/view_methods'
15
+ require_relative 'comfortable_mexican_sofa/form_builder'
16
+ require_relative 'comfortable_mexican_sofa/tag'
17
+ require_relative 'comfortable_mexican_sofa/sitemap'
18
+ require_relative 'comfortable_mexican_sofa/fixture'
19
+ require_relative 'comfortable_mexican_sofa/fixture/category'
20
+ require_relative 'comfortable_mexican_sofa/fixture/layout'
21
+ require_relative 'comfortable_mexican_sofa/fixture/page'
22
+ require_relative 'comfortable_mexican_sofa/fixture/snippet'
23
+ require_relative 'comfortable_mexican_sofa/fixture/file'
24
+ require_relative 'comfortable_mexican_sofa/extensions/rails'
25
+ require_relative 'comfortable_mexican_sofa/extensions/acts_as_tree'
26
+ require_relative 'comfortable_mexican_sofa/extensions/has_revisions'
27
+ require_relative 'comfortable_mexican_sofa/extensions/is_mirrored'
28
+ require_relative 'comfortable_mexican_sofa/extensions/is_categorized'
27
29
 
28
30
  Dir.glob(File.expand_path('comfortable_mexican_sofa/tags/*.rb', File.dirname(__FILE__))).each do |path|
29
- require path
31
+ require_relative path
30
32
  end
31
33
 
32
34
  module ComfortableMexicanSofa
@@ -0,0 +1,77 @@
1
+ module ComfortableMexicanSofa::Fixture
2
+
3
+ class Importer
4
+ attr_accessor :site,
5
+ :path,
6
+ :from,
7
+ :to,
8
+ :fixture_ids,
9
+ :force_import
10
+
11
+ def initialize(from, to = from, force_import = false)
12
+ self.from = from
13
+ self.to = to
14
+ self.site = Cms::Site.where(:identifier => to).first!
15
+ self.fixture_ids = []
16
+ self.force_import = force_import
17
+
18
+ dir = self.class.name.split('::')[2].downcase.pluralize
19
+ self.path = ::File.join(ComfortableMexicanSofa.config.fixtures_path, from, dir, '/')
20
+ end
21
+
22
+ def fresh_fixture?(object, file_path)
23
+ object.new_record? || self.force_import || ::File.mtime(file_path) > object.updated_at
24
+ end
25
+
26
+ def get_attributes(file_path)
27
+ YAML.load_file(file_path)
28
+ end
29
+
30
+ def save_categorizations!(object, categories)
31
+ object.categorizations.delete_all
32
+ [categories].flatten.compact.each do |label|
33
+ category = self.site.categories.find_or_create_by_label_and_categorized_type(label, object.class.to_s)
34
+ category.categorizations.create!(
35
+ :categorized => object
36
+ )
37
+ end
38
+ end
39
+
40
+ def import!
41
+ ComfortableMexicanSofa::Fixture::Category::Importer.new(from, to, force_import).import!
42
+ ComfortableMexicanSofa::Fixture::File::Importer.new( from, to, force_import).import!
43
+ ComfortableMexicanSofa::Fixture::Layout::Importer.new( from, to, force_import).import!
44
+ ComfortableMexicanSofa::Fixture::Page::Importer.new( from, to, force_import).import!
45
+ ComfortableMexicanSofa::Fixture::Snippet::Importer.new( from, to, force_import).import!
46
+ end
47
+ end
48
+
49
+ class Exporter
50
+ attr_accessor :site,
51
+ :path,
52
+ :from,
53
+ :to
54
+
55
+ def initialize(from, to = from)
56
+ self.from = from
57
+ self.to = to
58
+ self.site = Cms::Site.where(:identifier => from).first!
59
+ dir = self.class.name.split('::')[2].downcase.pluralize
60
+ self.path = ::File.join(ComfortableMexicanSofa.config.fixtures_path, to, dir)
61
+ end
62
+
63
+ def prepare_folder!(path)
64
+ FileUtils.rm_rf(path)
65
+ FileUtils.mkdir_p(path)
66
+ end
67
+
68
+ def export!
69
+ ComfortableMexicanSofa::Fixture::File::Exporter.new( from, to).export!
70
+ ComfortableMexicanSofa::Fixture::Category::Exporter.new(from, to).export!
71
+ ComfortableMexicanSofa::Fixture::Layout::Exporter.new( from, to).export!
72
+ ComfortableMexicanSofa::Fixture::Page::Exporter.new( from, to).export!
73
+ ComfortableMexicanSofa::Fixture::Snippet::Exporter.new( from, to).export!
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,35 @@
1
+ module ComfortableMexicanSofa::Fixture::Category
2
+ class Importer < ComfortableMexicanSofa::Fixture::Importer
3
+ def import!
4
+ {
5
+ 'files' => 'Cms::File',
6
+ 'pages' => 'Cms::Page',
7
+ 'snippets' => 'Cms::Snippet'
8
+ }.each do |file, type|
9
+ if File.exists?(attrs_path = File.join(path, "#{file}.yml"))
10
+ categories = get_attributes(attrs_path)
11
+ [categories].flatten.each do |label|
12
+ self.site.categories.find_or_create_by_label_and_categorized_type(label, type)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ class Exporter < ComfortableMexicanSofa::Fixture::Exporter
20
+ def export!
21
+ prepare_folder!(self.path)
22
+ {
23
+ 'files' => 'Cms::File',
24
+ 'pages' => 'Cms::Page',
25
+ 'snippets' => 'Cms::Snippet'
26
+ }.each do |file, type|
27
+ if (categories = self.site.categories.of_type(type)).present?
28
+ open(File.join(self.path, "#{file}.yml"), 'w') do |f|
29
+ f.write(categories.map{|c| c.label}.to_yaml)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,70 @@
1
+ module ComfortableMexicanSofa::Fixture::File
2
+ class Importer < ComfortableMexicanSofa::Fixture::Importer
3
+ def import!
4
+ Dir["#{self.path}[^_]*"].each do |file_path|
5
+ filename = ::File.basename(file_path)
6
+ file = self.site.files.where(:file_file_name => filename).first || self.site.files.new
7
+
8
+ # setting attributes
9
+ categories = []
10
+ if File.exists?(attrs_path = File.join(self.path, "_#{filename}.yml"))
11
+ if fresh_fixture?(file, attrs_path)
12
+ attrs = get_attributes(attrs_path)
13
+ file.label = attrs['label']
14
+ file.description = attrs['description']
15
+ categories = attrs['categories']
16
+ end
17
+ end
18
+
19
+ # setting actual file
20
+ if fresh_fixture?(file, file_path)
21
+ file.file = open(file_path)
22
+ end
23
+
24
+ if file.changed? || self.force_import
25
+ if file.save
26
+ save_categorizations!(file, categories)
27
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Imported File \t #{file.file_file_name}")
28
+ else
29
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Failed to import File \n#{file.errors.inspect}")
30
+ end
31
+ end
32
+
33
+ self.fixture_ids << file.id
34
+ end
35
+
36
+ # cleaning up
37
+ self.site.files.where('id NOT IN (?)', fixture_ids).each{ |s| s.destroy }
38
+ end
39
+ end
40
+
41
+ class Exporter < ComfortableMexicanSofa::Fixture::Exporter
42
+ def export!
43
+ prepare_folder!(self.path)
44
+
45
+ self.site.files.each do |file|
46
+ file_path = File.join(self.path, file.file_file_name)
47
+
48
+ # writing attributes
49
+ open(::File.join(self.path, "_#{file.file_file_name}.yml"), 'w') do |f|
50
+ f.write({
51
+ 'label' => file.label,
52
+ 'description' => file.description,
53
+ 'categories' => file.categories.map{|c| c.label}
54
+ }.to_yaml)
55
+ end
56
+
57
+ # writing content
58
+ data_path = file.file.options[:storage] == :filesystem ?
59
+ file.file.path :
60
+ file.file.url
61
+
62
+ open(::File.join(self.path, ::File.basename(file_path)), 'w') do |f|
63
+ f.write(open(data_path))
64
+ end
65
+
66
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Exported File \t #{file.file_file_name}")
67
+ end
68
+ end
69
+ end
70
+ end