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.
- data/.gitignore +1 -1
- data/Gemfile +2 -2
- data/README.md +3 -3
- data/app/assets/stylesheets/comfortable_mexican_sofa/base.css.sass +11 -11
- data/app/assets/stylesheets/comfortable_mexican_sofa/bootstrap_overrides.css.sass +2 -2
- data/app/controllers/cms_admin/base_controller.rb +1 -1
- data/app/controllers/cms_content_controller.rb +1 -1
- data/app/models/cms/block.rb +1 -1
- data/app/models/cms/file.rb +4 -1
- data/config/database.yml +1 -1
- data/db/cms_fixtures/sample-site/categories/files.yml +1 -0
- data/db/cms_fixtures/sample-site/categories/pages.yml +1 -0
- data/db/cms_fixtures/sample-site/categories/snippets.yml +1 -0
- data/db/cms_fixtures/sample-site/files/_sample.jpg.yml +5 -0
- data/db/cms_fixtures/sample-site/files/sample.jpg +0 -0
- data/db/cms_fixtures/sample-site/layouts/default/{_default.yml → attributes.yml} +0 -0
- data/db/cms_fixtures/sample-site/layouts/default/{js.js → javascript.js} +0 -0
- data/db/cms_fixtures/sample-site/layouts/default/nested/{_nested.yml → attributes.yml} +0 -0
- data/db/cms_fixtures/sample-site/layouts/default/nested/{js.js → javascript.js} +0 -0
- data/db/cms_fixtures/sample-site/layouts/default/nested/{css.css → stylesheet.css} +0 -0
- data/db/cms_fixtures/sample-site/layouts/default/{css.css → stylesheet.css} +0 -0
- data/db/cms_fixtures/sample-site/pages/index/attributes.yml +6 -0
- data/db/cms_fixtures/sample-site/pages/index/child/{_child.yml → attributes.yml} +0 -0
- data/db/cms_fixtures/sample-site/snippets/default/attributes.yml +4 -0
- data/lib/comfortable_mexican_sofa.rb +25 -23
- data/lib/comfortable_mexican_sofa/fixture.rb +77 -0
- data/lib/comfortable_mexican_sofa/fixture/category.rb +35 -0
- data/lib/comfortable_mexican_sofa/fixture/file.rb +70 -0
- data/lib/comfortable_mexican_sofa/fixture/layout.rb +90 -0
- data/lib/comfortable_mexican_sofa/fixture/page.rb +122 -0
- data/lib/comfortable_mexican_sofa/fixture/snippet.rb +71 -0
- data/lib/comfortable_mexican_sofa/version.rb +1 -1
- data/lib/tasks/comfortable_mexican_sofa.rake +17 -20
- data/test/fixtures/cms/files.yml +2 -2
- data/test/functional/cms_admin/base_controller_test.rb +1 -1
- data/test/functional/cms_admin/categories_controller_test.rb +1 -1
- data/test/functional/cms_admin/files_controller_test.rb +1 -1
- data/test/functional/cms_admin/layouts_controller_test.rb +1 -1
- data/test/functional/cms_admin/pages_controller_test.rb +1 -1
- data/test/functional/cms_admin/revisions_controller_test.rb +1 -1
- data/test/functional/cms_admin/sites_controller_test.rb +1 -1
- data/test/functional/cms_admin/snippets_controller_test.rb +1 -1
- data/test/functional/cms_content_controller_test.rb +1 -1
- data/test/gemfiles/Gemfile.rails.3.1 +2 -1
- data/test/gemfiles/Gemfile.rails.3.2 +2 -1
- data/test/integration/authentication_test.rb +1 -1
- data/test/integration/fixtures_test.rb +5 -3
- data/test/integration/mirrors_test.rb +1 -1
- data/test/integration/render_cms_test.rb +1 -1
- data/test/integration/sites_test.rb +1 -1
- data/test/integration/view_hooks_test.rb +1 -1
- data/test/test_helper.rb +1 -0
- data/test/unit/configuration_test.rb +1 -1
- data/test/unit/fixtures/_sample.jpg.yml +0 -0
- data/test/unit/fixtures/categories_test.rb +35 -0
- data/test/unit/fixtures/files_test.rb +100 -0
- data/test/unit/fixtures/layouts_test.rb +135 -0
- data/test/unit/fixtures/pages_test.rb +152 -0
- data/test/unit/fixtures/snippets_test.rb +101 -0
- data/test/unit/fixtures_test.rb +11 -325
- data/test/unit/mirrors_test.rb +1 -1
- data/test/unit/models/block_test.rb +1 -1
- data/test/unit/models/categorization_test.rb +1 -1
- data/test/unit/models/category_test.rb +1 -1
- data/test/unit/models/file_test.rb +11 -6
- data/test/unit/models/layout_test.rb +1 -1
- data/test/unit/models/page_test.rb +2 -1
- data/test/unit/models/site_test.rb +1 -1
- data/test/unit/models/snippet_test.rb +1 -1
- data/test/unit/revisions_test.rb +1 -1
- data/test/unit/sitemap_test.rb +1 -1
- data/test/unit/tag_test.rb +1 -1
- data/test/unit/tags/asset_test.rb +1 -1
- data/test/unit/tags/collection_test.rb +1 -1
- data/test/unit/tags/field_datetime_test.rb +1 -1
- data/test/unit/tags/field_integer_test.rb +1 -1
- data/test/unit/tags/field_rich_text_test.rb +1 -1
- data/test/unit/tags/field_string_test.rb +1 -1
- data/test/unit/tags/field_text_test.rb +1 -1
- data/test/unit/tags/file_test.rb +1 -1
- data/test/unit/tags/helper_test.rb +1 -1
- data/test/unit/tags/page_datetime_test.rb +1 -1
- data/test/unit/tags/page_file_test.rb +1 -1
- data/test/unit/tags/page_files_test.rb +1 -1
- data/test/unit/tags/page_integer_test.rb +1 -1
- data/test/unit/tags/page_markdown_test.rb +1 -1
- data/test/unit/tags/page_rich_text_test.rb +1 -1
- data/test/unit/tags/page_string_test.rb +1 -1
- data/test/unit/tags/page_text_test.rb +1 -1
- data/test/unit/tags/partial_test.rb +1 -1
- data/test/unit/tags/snippet_test.rb +1 -1
- data/test/unit/view_methods_test.rb +1 -1
- metadata +28 -12
- data/db/cms_fixtures/sample-site/pages/index/_index.yml +0 -2
- data/db/cms_fixtures/sample-site/snippets/default/_default.yml +0 -1
- 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
|
@@ -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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
18
|
+
logger = ComfortableMexicanSofa.logger
|
20
19
|
ComfortableMexicanSofa.logger = Logger.new(STDOUT)
|
21
|
-
|
22
|
-
ComfortableMexicanSofa::
|
23
|
-
|
24
|
-
ComfortableMexicanSofa.logger =
|
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
|
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
|
-
|
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
|
-
|
37
|
+
ComfortableMexicanSofa::Fixture::Exporter.new(from, to).export!
|
38
|
+
|
39
|
+
ComfortableMexicanSofa.logger = logger
|
43
40
|
end
|
44
41
|
end
|
45
42
|
end
|
data/test/fixtures/cms/files.yml
CHANGED
@@ -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 '
|
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',
|
17
|
+
gem 'coveralls', :require => false
|
18
|
+
gem 'mocha', :require => false
|
18
19
|
end
|