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
@@ -0,0 +1,90 @@
1
+ module ComfortableMexicanSofa::Fixture::Layout
2
+ class Importer < ComfortableMexicanSofa::Fixture::Importer
3
+
4
+ def import!(path = self.path, parent = nil)
5
+ Dir["#{path}*/"].each do |path|
6
+ identifier = path.split('/').last
7
+
8
+ layout = self.site.layouts.find_or_initialize_by_identifier(identifier)
9
+ layout.parent = parent
10
+
11
+ # setting attributes
12
+ if File.exists?(attrs_path = File.join(path, 'attributes.yml'))
13
+ if fresh_fixture?(layout, attrs_path)
14
+ attrs = get_attributes(attrs_path)
15
+ layout.label = attrs['label']
16
+ layout.app_layout = attrs['app_layout'] || parent.try(:app_layout)
17
+ layout.position = attrs['position'] if attrs['position']
18
+ end
19
+ end
20
+
21
+ # setting content
22
+ if File.exists?(content_path = File.join(path, 'content.html'))
23
+ if fresh_fixture?(layout, content_path)
24
+ layout.content = File.open(content_path).read
25
+ end
26
+ end
27
+ if File.exists?(content_path = File.join(path, 'stylesheet.css'))
28
+ if fresh_fixture?(layout, content_path)
29
+ layout.css = File.open(content_path).read
30
+ end
31
+ end
32
+ if File.exists?(content_path = File.join(path, 'javascript.js'))
33
+ if fresh_fixture?(layout, content_path)
34
+ layout.js = File.open(content_path).read
35
+ end
36
+ end
37
+
38
+ # saving
39
+ if layout.changed? || self.force_import
40
+ if layout.save
41
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Imported Layout \t #{layout.identifier}")
42
+ else
43
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Failed to import Layout \n#{layout.errors.inspect}")
44
+ end
45
+ end
46
+
47
+ self.fixture_ids << layout.id
48
+
49
+ # importing child layouts
50
+ import!(path, layout)
51
+ end
52
+
53
+ # cleaning up
54
+ unless parent
55
+ self.site.layouts.where('id NOT IN (?)', self.fixture_ids).each{ |s| s.destroy }
56
+ end
57
+ end
58
+ end
59
+
60
+ class Exporter < ComfortableMexicanSofa::Fixture::Exporter
61
+ def export!
62
+ prepare_folder!(self.path)
63
+
64
+ self.site.layouts.each do |layout|
65
+ layout_path = File.join(path, layout.ancestors.reverse.collect{|l| l.identifier}, layout.identifier)
66
+ FileUtils.mkdir_p(layout_path)
67
+
68
+ # writing attributes
69
+ open(File.join(layout_path, 'attributes.yml'), 'w') do |f|
70
+ f.write({
71
+ 'label' => layout.label,
72
+ 'app_layout' => layout.app_layout,
73
+ 'position' => layout.position
74
+ }.to_yaml)
75
+ end
76
+ open(File.join(layout_path, 'content.html'), 'w') do |f|
77
+ f.write(layout.content)
78
+ end
79
+ open(File.join(layout_path, 'stylesheet.css'), 'w') do |f|
80
+ f.write(layout.css)
81
+ end
82
+ open(File.join(layout_path, 'javascript.js'), 'w') do |f|
83
+ f.write(layout.js)
84
+ end
85
+
86
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Exported Layout \t #{layout.identifier}")
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,122 @@
1
+ module ComfortableMexicanSofa::Fixture::Page
2
+ class Importer < ComfortableMexicanSofa::Fixture::Importer
3
+
4
+ attr_accessor :target_pages
5
+
6
+ def import!(path = self.path, parent = nil)
7
+ Dir["#{path}*/"].each do |path|
8
+ slug = path.split('/').last
9
+
10
+ page = if parent
11
+ parent.children.where(:slug => slug).first || site.pages.new(:parent => parent, :slug => slug)
12
+ else
13
+ site.pages.root || site.pages.new(:slug => slug)
14
+ end
15
+
16
+ # setting attributes
17
+ categories = []
18
+ if File.exists?(attrs_path = File.join(path, 'attributes.yml'))
19
+ if fresh_fixture?(page, attrs_path)
20
+ attrs = get_attributes(attrs_path)
21
+
22
+ page.label = attrs['label']
23
+ page.layout = site.layouts.where(:identifier => attrs['layout']).first || parent.try(:layout)
24
+ page.is_published = attrs['is_published'].nil?? true : attrs['is_published']
25
+ page.position = attrs['position'] if attrs['position']
26
+
27
+ categories = attrs['categories']
28
+
29
+ if attrs['target_page']
30
+ self.target_pages ||= {}
31
+ self.target_pages[page] = attrs['target_page']
32
+ end
33
+ end
34
+ end
35
+
36
+ # setting content
37
+ blocks_to_clear = page.blocks.collect(&:identifier)
38
+ blocks_attributes = [ ]
39
+ Dir.glob("#{path}/*.html").each do |block_path|
40
+ identifier = block_path.split('/').last.gsub(/\.html$/, '')
41
+ blocks_to_clear.delete(identifier)
42
+ if fresh_fixture?(page, block_path)
43
+ blocks_attributes << {
44
+ :identifier => identifier,
45
+ :content => File.open(block_path).read
46
+ }
47
+ end
48
+ end
49
+
50
+ blocks_to_clear.each do |identifier|
51
+ blocks_attributes << {
52
+ :identifier => identifier,
53
+ :content => nil
54
+ }
55
+ end
56
+
57
+ page.blocks_attributes = blocks_attributes if blocks_attributes.present?
58
+
59
+ # saving
60
+ if page.changed? || self.force_import
61
+ if page.save
62
+ save_categorizations!(page, categories)
63
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Imported Page \t #{page.full_path}")
64
+ else
65
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Failed to import Page \n#{page.errors.inspect}")
66
+ end
67
+ end
68
+
69
+ self.fixture_ids << page.id
70
+
71
+ # importing child pages
72
+ import!(path, page)
73
+ end
74
+
75
+ # linking up target pages
76
+ if self.target_pages.present?
77
+ self.target_pages.each do |page, target|
78
+ if target_page = self.site.pages.where(:full_path => target).first
79
+ page.target_page = target_page
80
+ page.save
81
+ end
82
+ end
83
+ end
84
+
85
+ # cleaning up
86
+ unless parent
87
+ self.site.pages.where('id NOT IN (?)', self.fixture_ids).each{ |s| s.destroy }
88
+ end
89
+ end
90
+ end
91
+
92
+ class Exporter < ComfortableMexicanSofa::Fixture::Exporter
93
+ def export!
94
+ prepare_folder!(self.path)
95
+
96
+ self.site.pages.each do |page|
97
+ page.slug = 'index' if page.slug.blank?
98
+ page_path = File.join(path, page.ancestors.reverse.collect{|p| p.slug.blank?? 'index' : p.slug}, page.slug)
99
+ FileUtils.mkdir_p(page_path)
100
+
101
+ open(File.join(page_path, 'attributes.yml'), 'w') do |f|
102
+ f.write({
103
+ 'label' => page.label,
104
+ 'layout' => page.layout.try(:identifier),
105
+ 'parent' => page.parent && (page.parent.slug.present?? page.parent.slug : 'index'),
106
+ 'target_page' => page.target_page.try(:full_path),
107
+ 'categories' => page.categories.map{|c| c.label},
108
+ 'is_published' => page.is_published,
109
+ 'position' => page.position
110
+ }.to_yaml)
111
+ end
112
+ page.blocks_attributes.each do |block|
113
+ open(File.join(page_path, "#{block[:identifier]}.html"), 'w') do |f|
114
+ f.write(block[:content])
115
+ end
116
+ end
117
+
118
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Exported Page \t #{page.full_path}")
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,71 @@
1
+ module ComfortableMexicanSofa::Fixture::Snippet
2
+ class Importer < ComfortableMexicanSofa::Fixture::Importer
3
+
4
+ def import!
5
+ Dir["#{self.path}*/"].each do |path|
6
+ identifier = path.split('/').last
7
+ snippet = self.site.snippets.find_or_initialize_by_identifier(identifier)
8
+
9
+ # setting attributes
10
+ categories = []
11
+ if File.exists?(attrs_path = File.join(path, 'attributes.yml'))
12
+ if fresh_fixture?(snippet, attrs_path)
13
+ attrs = get_attributes(attrs_path)
14
+
15
+ snippet.label = attrs['label']
16
+ categories = attrs['categories']
17
+ end
18
+ end
19
+
20
+ # setting content
21
+ if File.exists?(content_path = File.join(path, 'content.html'))
22
+ if fresh_fixture?(snippet, content_path)
23
+ snippet.content = File.open(content_path).read
24
+ end
25
+ end
26
+
27
+ # saving
28
+ if snippet.changed? || self.force_import
29
+ if snippet.save
30
+ save_categorizations!(snippet, categories)
31
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Imported Snippet \t #{snippet.identifier}")
32
+ else
33
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Failed to import Snippet \n#{snippet.errors.inspect}")
34
+ end
35
+ end
36
+
37
+ self.fixture_ids << snippet.id
38
+ end
39
+
40
+ # cleaning up
41
+ self.site.snippets.where('id NOT IN (?)', fixture_ids).each{ |s| s.destroy }
42
+ end
43
+ end
44
+
45
+ class Exporter < ComfortableMexicanSofa::Fixture::Exporter
46
+
47
+ def export!
48
+ prepare_folder!(self.path)
49
+
50
+ self.site.snippets.each do |snippet|
51
+ snippet_path = File.join(self.path, snippet.identifier)
52
+ FileUtils.mkdir_p(snippet_path)
53
+
54
+ # writing attributes
55
+ open(File.join(snippet_path, 'attributes.yml'), 'w') do |f|
56
+ f.write({
57
+ 'label' => snippet.label,
58
+ 'categories' => snippet.categories.map{|c| c.label}
59
+ }.to_yaml)
60
+ end
61
+
62
+ # writing content
63
+ open(File.join(snippet_path, 'content.html'), 'w') do |f|
64
+ f.write(snippet.content)
65
+ end
66
+
67
+ ComfortableMexicanSofa.logger.warn("[FIXTURES] Exported Snippet \t #{snippet.identifier}")
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,3 +1,3 @@
1
1
  module ComfortableMexicanSofa
2
- VERSION = "1.8.3"
2
+ VERSION = "1.8.4"
3
3
  end
@@ -7,39 +7,36 @@ namespace :comfortable_mexican_sofa do
7
7
  namespace :fixtures do
8
8
 
9
9
  desc 'Import Fixture data into database (options: FROM=folder_name TO=site_identifier)'
10
-
10
+
11
11
  task :import => :environment do
12
- to = ENV['TO'] || ENV['FROM']
13
- from = ENV['FROM']
14
- force_reload = ENV['FORCE'].try(:downcase) != 'false'
15
-
12
+ from = ENV['FROM']
13
+ to = ENV['TO'] || ENV['FROM']
14
+
16
15
  puts "Importing CMS Fixtures from Folder [#{from}] to Site [#{to}] ..."
17
-
16
+
18
17
  # changing so that logger is going straight to screen
19
- logger_org = ComfortableMexicanSofa.logger
18
+ logger = ComfortableMexicanSofa.logger
20
19
  ComfortableMexicanSofa.logger = Logger.new(STDOUT)
21
-
22
- ComfortableMexicanSofa::Fixtures.import_all(to, from, force_reload)
23
-
24
- ComfortableMexicanSofa.logger = logger_org
20
+
21
+ ComfortableMexicanSofa::Fixture::Importer.new(from, to, :force).import!
22
+
23
+ ComfortableMexicanSofa.logger = logger
25
24
  end
26
25
 
27
- desc 'Export database data into Fixtures (options: FROM=site_identifier.com TO=folder_name)'
26
+ desc 'Export database data into Fixtures (options: FROM=site_identifier TO=folder_name)'
28
27
  task :export => :environment do
29
- to = ENV['TO'] || ENV['FROM']
30
28
  from = ENV['FROM']
29
+ to = ENV['TO'] || ENV['FROM']
31
30
 
32
31
  puts "Exporting CMS data from Site [#{from}] to Folder [#{to}] ..."
33
-
32
+
34
33
  # changing so that logger is going straight to screen
35
- logger_org = ComfortableMexicanSofa.logger
34
+ logger = ComfortableMexicanSofa.logger
36
35
  ComfortableMexicanSofa.logger = Logger.new(STDOUT)
37
-
38
- ComfortableMexicanSofa::Fixtures.export_all(from, to)
39
-
40
- ComfortableMexicanSofa.logger = logger_org
41
36
 
42
- puts 'Done!'
37
+ ComfortableMexicanSofa::Fixture::Exporter.new(from, to).export!
38
+
39
+ ComfortableMexicanSofa.logger = logger
43
40
  end
44
41
  end
45
42
  end
@@ -1,9 +1,9 @@
1
1
  default:
2
2
  site: default
3
3
  block:
4
- label: Sample
4
+ label: Default File
5
5
  file_file_name: sample.jpg
6
6
  file_content_type: image/jpeg
7
7
  file_file_size: 20099
8
- description: Description
8
+ description: Default Description
9
9
  position: 0
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
1
+ require_relative '../../test_helper'
2
2
 
3
3
  class CmsAdmin::BaseControllerTest < ActionController::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 CmsAdmin::CategoriesControllerTest < ActionController::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 CmsAdmin::FilesControllerTest < ActionController::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 CmsAdmin::LayoutsControllerTest < ActionController::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 CmsAdmin::PagesControllerTest < ActionController::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 CmsAdmin::RevisionsControllerTest < ActionController::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 CmsAdmin::SitesControllerTest < ActionController::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 CmsAdmin::SnippetsControllerTest < ActionController::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 CmsContentControllerTest < ActionController::TestCase
4
4
 
@@ -14,5 +14,6 @@ group :test do
14
14
  gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
15
15
  gem 'jdbc-sqlite3', :platform => :jruby
16
16
  gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
17
- gem 'coveralls', :require => false
17
+ gem 'mocha', :require => false
18
+ gem 'coveralls', :require => false
18
19
  end
@@ -14,5 +14,6 @@ group :test do
14
14
  gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
15
15
  gem 'jdbc-sqlite3', :platform => :jruby
16
16
  gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
17
- gem 'coveralls', :require => false
17
+ gem 'coveralls', :require => false
18
+ gem 'mocha', :require => false
18
19
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../test_helper', File.dirname(__FILE__))
1
+ require_relative '../test_helper'
2
2
 
3
3
  class AuthenticationTest < ActionDispatch::IntegrationTest
4
4