comfortable_mexican_sofa 1.0.51 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/README.md +8 -18
  2. data/Rakefile +1 -4
  3. data/VERSION +1 -1
  4. data/app/controllers/cms_admin/base_controller.rb +8 -9
  5. data/app/controllers/cms_admin/layouts_controller.rb +5 -5
  6. data/app/controllers/cms_admin/pages_controller.rb +14 -14
  7. data/app/controllers/cms_admin/sites_controller.rb +4 -4
  8. data/app/controllers/cms_admin/snippets_controller.rb +4 -4
  9. data/app/controllers/cms_admin/uploads_controller.rb +2 -2
  10. data/app/controllers/cms_content_controller.rb +21 -8
  11. data/app/models/cms/block.rb +13 -0
  12. data/app/models/{cms_layout.rb → cms/layout.rb} +16 -44
  13. data/app/models/{cms_page.rb → cms/page.rb} +26 -57
  14. data/app/models/{cms_site.rb → cms/site.rb} +8 -6
  15. data/app/models/cms/snippet.rb +36 -0
  16. data/app/models/{cms_upload.rb → cms/upload.rb} +5 -3
  17. data/app/views/cms_admin/layouts/_form.html.erb +2 -2
  18. data/app/views/cms_admin/pages/_form.html.erb +5 -5
  19. data/app/views/cms_admin/pages/_form_blocks.html.erb +3 -3
  20. data/app/views/cms_admin/uploads/_index.html.erb +1 -1
  21. data/app/views/layouts/cms_admin.html.erb +2 -38
  22. data/app/views/layouts/cms_admin/_body.html.erb +17 -0
  23. data/app/views/layouts/cms_admin/_center.html.erb +6 -0
  24. data/app/views/layouts/cms_admin/_head.html.erb +11 -0
  25. data/app/views/layouts/cms_admin/_left.html.erb +7 -0
  26. data/app/views/layouts/cms_admin/_right.html.erb +1 -0
  27. data/comfortable_mexican_sofa.gemspec +94 -96
  28. data/config/environments/development.rb +1 -1
  29. data/config/environments/production.rb +1 -1
  30. data/config/environments/test.rb +1 -1
  31. data/config/initializers/comfortable_mexican_sofa.rb +10 -12
  32. data/db/cms_fixtures/example.com/layouts/default/_default.yml +1 -0
  33. data/db/cms_fixtures/example.com/layouts/default/content.html +5 -0
  34. data/db/cms_fixtures/example.com/layouts/default/css.css +1 -0
  35. data/db/cms_fixtures/example.com/layouts/default/js.js +1 -0
  36. data/db/cms_fixtures/example.com/layouts/default/nested/_nested.yml +1 -0
  37. data/db/cms_fixtures/example.com/layouts/default/nested/content.html +2 -0
  38. data/db/cms_fixtures/example.com/layouts/default/nested/css.css +1 -0
  39. data/db/cms_fixtures/example.com/layouts/default/nested/js.js +1 -0
  40. data/db/cms_fixtures/example.com/pages/index/_index.yml +2 -0
  41. data/db/cms_fixtures/example.com/pages/index/child/_child.yml +2 -0
  42. data/db/cms_fixtures/example.com/pages/index/child/left.html +1 -0
  43. data/db/cms_fixtures/example.com/pages/index/child/right.html +1 -0
  44. data/db/cms_fixtures/example.com/pages/index/content.html +2 -0
  45. data/db/cms_fixtures/example.com/snippets/default/_default.yml +1 -0
  46. data/db/cms_fixtures/example.com/snippets/default/content.html +1 -0
  47. data/db/migrate/01_create_cms.rb +11 -11
  48. data/db/migrate/upgrades/02_upgrade_to_1_1_0.rb +19 -0
  49. data/lib/comfortable_mexican_sofa.rb +6 -13
  50. data/lib/comfortable_mexican_sofa/configuration.rb +21 -20
  51. data/lib/comfortable_mexican_sofa/controller_methods.rb +3 -4
  52. data/lib/comfortable_mexican_sofa/engine.rb +1 -1
  53. data/lib/comfortable_mexican_sofa/fixtures.rb +155 -0
  54. data/lib/comfortable_mexican_sofa/form_builder.rb +7 -15
  55. data/lib/comfortable_mexican_sofa/{cms_tag.rb → tag.rb} +42 -23
  56. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_datetime.rb +4 -5
  57. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_integer.rb +4 -5
  58. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_string.rb +4 -5
  59. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_text.rb +4 -5
  60. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/helper.rb +2 -5
  61. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_datetime.rb +4 -5
  62. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_integer.rb +4 -5
  63. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_rich_text.rb +4 -5
  64. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_string.rb +4 -5
  65. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_text.rb +4 -5
  66. data/lib/comfortable_mexican_sofa/{cms_tag → tags}/partial.rb +2 -5
  67. data/lib/comfortable_mexican_sofa/tags/snippet.rb +13 -0
  68. data/lib/comfortable_mexican_sofa/view_methods.rb +4 -3
  69. data/lib/generators/cms_generator.rb +1 -1
  70. data/lib/tasks/comfortable_mexican_sofa.rake +12 -272
  71. data/public/javascripts/comfortable_mexican_sofa/cms.js +1 -1
  72. data/test/fixtures/{cms_blocks.yml → cms/blocks.yml} +2 -2
  73. data/test/fixtures/{cms_layouts.yml → cms/layouts.yml} +3 -3
  74. data/test/fixtures/{cms_pages.yml → cms/pages.yml} +4 -4
  75. data/test/fixtures/{cms_sites.yml → cms/sites.yml} +0 -0
  76. data/test/fixtures/{cms_snippets.yml → cms/snippets.yml} +1 -1
  77. data/test/fixtures/{cms_uploads.yml → cms/uploads.yml} +1 -1
  78. data/test/functional/cms_admin/layouts_controller_test.rb +6 -6
  79. data/test/functional/cms_admin/pages_controller_test.rb +64 -64
  80. data/test/functional/cms_admin/sites_controller_test.rb +5 -5
  81. data/test/functional/cms_admin/snippets_controller_test.rb +6 -6
  82. data/test/functional/cms_admin/uploads_controller_test.rb +4 -4
  83. data/test/functional/cms_content_controller_test.rb +27 -11
  84. data/test/integration/fixtures_test.rb +43 -0
  85. data/test/integration/sites_test.rb +23 -13
  86. data/test/test_helper.rb +9 -8
  87. data/test/unit/{cms_configuration_test.rb → configuration_test.rb} +5 -3
  88. data/test/unit/fixtures_test.rb +198 -0
  89. data/test/unit/models/block_test.rb +33 -0
  90. data/test/unit/models/layout_test.rb +129 -0
  91. data/test/unit/models/page_test.rb +199 -0
  92. data/test/unit/models/site_test.rb +41 -0
  93. data/test/unit/models/snippet_test.rb +32 -0
  94. data/test/unit/models/upload_test.rb +32 -0
  95. data/test/unit/{cms_tag_test.rb → tag_test.rb} +61 -44
  96. data/test/unit/tags/field_datetime_test.rb +44 -0
  97. data/test/unit/tags/field_integer_test.rb +43 -0
  98. data/test/unit/tags/field_string_test.rb +46 -0
  99. data/test/unit/tags/field_text_test.rb +42 -0
  100. data/test/unit/{cms_tags → tags}/helper_test.rb +18 -6
  101. data/test/unit/tags/page_datetime_test.rb +44 -0
  102. data/test/unit/tags/page_integer_test.rb +43 -0
  103. data/test/unit/tags/page_rich_text.rb +43 -0
  104. data/test/unit/{cms_tags → tags}/page_string_test.rb +15 -5
  105. data/test/unit/tags/page_text_test.rb +46 -0
  106. data/test/unit/{cms_tags → tags}/partial_test.rb +24 -8
  107. data/test/unit/tags/snippet_test.rb +45 -0
  108. data/test/unit/view_methods_test.rb +2 -2
  109. metadata +95 -121
  110. data/app/models/cms_block.rb +0 -28
  111. data/app/models/cms_snippet.rb +0 -69
  112. data/db/cms_seeds/example.local/layouts/default.yml +0 -8
  113. data/db/cms_seeds/example.local/layouts/nested.yml +0 -6
  114. data/db/cms_seeds/example.local/pages/child.yml +0 -10
  115. data/db/cms_seeds/example.local/pages/child/subchild.yml +0 -14
  116. data/db/cms_seeds/example.local/pages/index.yml +0 -11
  117. data/db/cms_seeds/example.local/snippets/example.yml +0 -4
  118. data/lib/comfortable_mexican_sofa/cms_tag/snippet.rb +0 -18
  119. data/test/cms_seeds/test.host/layouts/broken.yml +0 -1
  120. data/test/cms_seeds/test.host/layouts/default.yml +0 -3
  121. data/test/cms_seeds/test.host/layouts/nested.yml +0 -4
  122. data/test/cms_seeds/test.host/pages/broken.yml +0 -1
  123. data/test/cms_seeds/test.host/pages/child.yml +0 -10
  124. data/test/cms_seeds/test.host/pages/child/subchild.yml +0 -10
  125. data/test/cms_seeds/test.host/pages/index.yml +0 -10
  126. data/test/cms_seeds/test.host/snippets/broken.yml +0 -1
  127. data/test/cms_seeds/test.host/snippets/default.yml +0 -3
  128. data/test/integration/rake_tasks_test.rb +0 -65
  129. data/test/integration/render_cms_seed_test.rb +0 -34
  130. data/test/unit/cms_block_test.rb +0 -43
  131. data/test/unit/cms_layout_test.rb +0 -179
  132. data/test/unit/cms_page_test.rb +0 -257
  133. data/test/unit/cms_site_test.rb +0 -41
  134. data/test/unit/cms_snippet_test.rb +0 -77
  135. data/test/unit/cms_tags/field_datetime_test.rb +0 -34
  136. data/test/unit/cms_tags/field_integer_test.rb +0 -33
  137. data/test/unit/cms_tags/field_string_test.rb +0 -34
  138. data/test/unit/cms_tags/field_text_test.rb +0 -32
  139. data/test/unit/cms_tags/page_datetime_test.rb +0 -34
  140. data/test/unit/cms_tags/page_integer_test.rb +0 -33
  141. data/test/unit/cms_tags/page_rich_text.rb +0 -33
  142. data/test/unit/cms_tags/page_text_test.rb +0 -34
  143. data/test/unit/cms_tags/snippet_test.rb +0 -33
  144. data/test/unit/cms_upload_test.rb +0 -26
@@ -1,4 +1,4 @@
1
- ComfortableMexicanSofa::Application.configure do
1
+ defined?(ComfortableMexicanSofa::Application) && ComfortableMexicanSofa::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/environment.rb
3
3
 
4
4
  # In the development environment your application's code is reloaded on
@@ -1,4 +1,4 @@
1
- ComfortableMexicanSofa::Application.configure do
1
+ defined?(ComfortableMexicanSofa::Application) && ComfortableMexicanSofa::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/environment.rb
3
3
 
4
4
  # The production environment is meant for finished, "live" apps.
@@ -1,4 +1,4 @@
1
- ComfortableMexicanSofa::Application.configure do
1
+ defined?(ComfortableMexicanSofa::Application) && ComfortableMexicanSofa::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/environment.rb
3
3
 
4
4
  # The test environment is used exclusively to run your application's
@@ -14,13 +14,9 @@ ComfortableMexicanSofa.configure do |config|
14
14
  # You don't need to change it when changing admin_route_prefix
15
15
  # config.admin_route_redirect = '/cms-admin/pages'
16
16
 
17
- # Location of YAML files that can be used to render pages instead of pulling
18
- # data from the database. Not active if not specified. Containing folder name
19
- # should be the hostname of the site. Example: my-app.local
20
- # config.seed_data_path = File.expand_path('db/cms_seeds', Rails.root)
21
-
22
- # Let CMS handle site creation and management. Enabled by default.
23
- # config.auto_manage_sites = true
17
+ # If you enable this setting you'll be able to serve completely different set
18
+ # of sites with their own layouts and pages.
19
+ # config.enable_multiple_sites = false
24
20
 
25
21
  # By default you cannot have irb code inside your layouts/pages/snippets.
26
22
  # Generally this is to prevent putting something like this:
@@ -38,11 +34,13 @@ ComfortableMexicanSofa.configure do |config|
38
34
  # filesystem see: http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/S3
39
35
  # config.upload_file_options = {:storage => :filesystem}
40
36
 
41
- # Override the host used to look up the active CmsSite. If you are not
42
- # planning on using the site features, I recommend you set this override to
43
- # limit unexpected "Site not found" errors when you try to hit app01.example.com
44
- # instead of www.example.com.
45
- # config.override_host = "www.example.com"
37
+ # Sofa allows you to setup entire site from files. Database is updated with each
38
+ # request (if nessesary). Please note that database entries are destroyed if there's
39
+ # no corresponding file. Fixtures are disabled by default.
40
+ # config.enable_fixtures = false
41
+
42
+ # Path where fixtures can be located.
43
+ # config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
46
44
 
47
45
  end
48
46
 
@@ -0,0 +1 @@
1
+ label: Default Fixture Layout
@@ -0,0 +1,5 @@
1
+ <html>
2
+ <body>
3
+ {{ cms:page:content }}
4
+ </body>
5
+ </html>
@@ -0,0 +1 @@
1
+ body{color: red}
@@ -0,0 +1 @@
1
+ // default js
@@ -0,0 +1 @@
1
+ label: Default Fixture Nested Layout
@@ -0,0 +1,2 @@
1
+ <div class='left'> {{ cms:page:left }} </div>
2
+ <div class='right'> {{ cms:page:right }} </div>
@@ -0,0 +1 @@
1
+ div{float:left}
@@ -0,0 +1 @@
1
+ // nested js
@@ -0,0 +1,2 @@
1
+ label: Home Fixture Page
2
+ layout: default
@@ -0,0 +1,2 @@
1
+ label: Child Fixture Page
2
+ layout: nested
@@ -0,0 +1 @@
1
+ Child Page Left Fixture Content
@@ -0,0 +1 @@
1
+ Child Page Right Fixture Content
@@ -0,0 +1,2 @@
1
+ Home Page Fixture Content
2
+ {{ cms:snippet:default }}
@@ -0,0 +1 @@
1
+ label: Default Fixture Snippet
@@ -0,0 +1 @@
1
+ Fixture Content for Default Snippet
@@ -10,7 +10,7 @@ class CreateCms < ActiveRecord::Migration
10
10
 
11
11
  # -- Layouts ------------------------------------------------------------
12
12
  create_table :cms_layouts do |t|
13
- t.integer :cms_site_id
13
+ t.integer :site_id
14
14
  t.integer :parent_id
15
15
  t.string :app_layout
16
16
  t.string :label
@@ -22,12 +22,12 @@ class CreateCms < ActiveRecord::Migration
22
22
  t.timestamps
23
23
  end
24
24
  add_index :cms_layouts, [:parent_id, :position]
25
- add_index :cms_layouts, [:cms_site_id, :slug], :unique => true
25
+ add_index :cms_layouts, [:site_id, :slug], :unique => true
26
26
 
27
27
  # -- Pages --------------------------------------------------------------
28
28
  create_table :cms_pages do |t|
29
- t.integer :cms_site_id
30
- t.integer :cms_layout_id
29
+ t.integer :site_id
30
+ t.integer :layout_id
31
31
  t.integer :parent_id
32
32
  t.integer :target_page_id
33
33
  t.string :label
@@ -39,37 +39,37 @@ class CreateCms < ActiveRecord::Migration
39
39
  t.boolean :is_published, :null => false, :default => true
40
40
  t.timestamps
41
41
  end
42
- add_index :cms_pages, [:cms_site_id, :full_path]
42
+ add_index :cms_pages, [:site_id, :full_path]
43
43
  add_index :cms_pages, [:parent_id, :position]
44
44
 
45
45
  # -- Page Blocks --------------------------------------------------------
46
46
  create_table :cms_blocks do |t|
47
- t.integer :cms_page_id
47
+ t.integer :page_id
48
48
  t.string :label
49
49
  t.text :content
50
50
  t.timestamps
51
51
  end
52
- add_index :cms_blocks, [:cms_page_id, :label]
52
+ add_index :cms_blocks, [:page_id, :label]
53
53
 
54
54
  # -- Snippets -----------------------------------------------------------
55
55
  create_table :cms_snippets do |t|
56
- t.integer :cms_site_id
56
+ t.integer :site_id
57
57
  t.string :label
58
58
  t.string :slug
59
59
  t.text :content
60
60
  t.timestamps
61
61
  end
62
- add_index :cms_snippets, [:cms_site_id, :slug], :unique => true
62
+ add_index :cms_snippets, [:site_id, :slug], :unique => true
63
63
 
64
64
  # -- Assets -------------------------------------------------------------
65
65
  create_table :cms_uploads do |t|
66
- t.integer :cms_site_id
66
+ t.integer :site_id
67
67
  t.string :file_file_name
68
68
  t.string :file_content_type
69
69
  t.integer :file_file_size
70
70
  t.timestamps
71
71
  end
72
- add_index :cms_uploads, [:cms_site_id, :file_file_name]
72
+ add_index :cms_uploads, [:site_id, :file_file_name]
73
73
  end
74
74
 
75
75
  def self.down
@@ -0,0 +1,19 @@
1
+ class UpgradeTo110 < ActiveRecord::Migration
2
+ def self.up
3
+ rename_column :cms_layouts, :cms_site_id, :site_id
4
+ rename_column :cms_pages, :cms_site_id, :site_id
5
+ rename_column :cms_pages, :cms_layout_id, :layout_id
6
+ rename_column :cms_blocks, :cms_page_id, :page_id
7
+ rename_column :cms_snippets, :cms_site_id, :site_id
8
+ rename_column :cms_uploads, :cms_site_id, :site_id
9
+ end
10
+
11
+ def self.down
12
+ rename_column :cms_uploads, :site_id, :cms_site_id
13
+ rename_column :cms_snippets, :site_id, :cms_site_id
14
+ rename_column :cms_blocks, :page_id, :cms_page_id
15
+ rename_column :cms_layouts, :site_id, :cms_site_id
16
+ rename_column :cms_pages, :layout_id, :cms_layout_id
17
+ rename_column :cms_pages, :site_id, :cms_site_id
18
+ end
19
+ end
@@ -1,9 +1,5 @@
1
- # Loading engine only if this is not a standalone installation
2
- unless defined? ComfortableMexicanSofa::Application
3
- require File.expand_path('comfortable_mexican_sofa/engine', File.dirname(__FILE__))
4
- end
5
-
6
- [ 'comfortable_mexican_sofa/configuration',
1
+ [ 'comfortable_mexican_sofa/engine',
2
+ 'comfortable_mexican_sofa/configuration',
7
3
  'comfortable_mexican_sofa/http_auth',
8
4
  'comfortable_mexican_sofa/rails_extensions',
9
5
  'comfortable_mexican_sofa/controller_methods',
@@ -11,19 +7,17 @@ end
11
7
  'comfortable_mexican_sofa/view_methods',
12
8
  'comfortable_mexican_sofa/form_builder',
13
9
  'comfortable_mexican_sofa/acts_as_tree',
14
- '../app/models/cms_block',
15
- '../app/models/cms_snippet',
16
- 'comfortable_mexican_sofa/cms_tag'
10
+ 'comfortable_mexican_sofa/tag',
11
+ 'comfortable_mexican_sofa/fixtures'
17
12
  ].each do |path|
18
13
  require File.expand_path(path, File.dirname(__FILE__))
19
14
  end
20
15
 
21
- Dir.glob(File.expand_path('comfortable_mexican_sofa/cms_tag/*.rb', File.dirname(__FILE__))).each do |tag_path|
22
- require tag_path
16
+ Dir.glob(File.expand_path('comfortable_mexican_sofa/tags/*.rb', File.dirname(__FILE__))).each do |path|
17
+ require path
23
18
  end
24
19
 
25
20
  module ComfortableMexicanSofa
26
-
27
21
  class << self
28
22
 
29
23
  # Modify CMS configuration
@@ -42,5 +36,4 @@ module ComfortableMexicanSofa
42
36
  alias :config :configuration
43
37
 
44
38
  end
45
-
46
39
  end
@@ -6,10 +6,6 @@ class ComfortableMexicanSofa::Configuration
6
6
  # Module that will handle authentication to access cms-admin area
7
7
  attr_accessor :authentication
8
8
 
9
- # Location of YAML files that can be used to render pages instead of pulling
10
- # data from the database. Not active if not specified.
11
- attr_accessor :seed_data_path
12
-
13
9
  # Default url to access admin area is http://yourhost/cms-admin/
14
10
  # You can change 'cms-admin' to 'admin', for example.
15
11
  attr_accessor :admin_route_prefix
@@ -18,11 +14,11 @@ class ComfortableMexicanSofa::Configuration
18
14
  # to something else
19
15
  attr_accessor :admin_route_redirect
20
16
 
21
- # Let CMS handle site creation and management. Enabled by default.
22
- attr_accessor :auto_manage_sites
17
+ # Are you running multiple sites from single install? Default assumption is 'No'
18
+ attr_accessor :enable_multiple_sites
23
19
 
24
- # Not allowing irb code to be run inside page content. True by default.
25
- attr_accessor :disable_irb
20
+ # Not allowing irb code to be run inside page content. False by default.
21
+ attr_accessor :allow_irb
26
22
 
27
23
  # Caching for css/js. For admin layout and ones for cms content. Enabled by default.
28
24
  attr_accessor :enable_caching
@@ -30,21 +26,26 @@ class ComfortableMexicanSofa::Configuration
30
26
  # Upload settings
31
27
  attr_accessor :upload_file_options
32
28
 
33
- # Override the hostname when looking up which site to use
34
- attr_accessor :override_host
29
+ # With each page load, files will be synched with the database. Database entries are
30
+ # destroyed if there's no corresponding file. Fixtures are disabled by default.
31
+ attr_accessor :enable_fixtures
32
+
33
+ # Path where fixtures can be located.
34
+ attr_accessor :fixtures_path
35
35
 
36
36
  # Configuration defaults
37
37
  def initialize
38
- @cms_title = 'ComfortableMexicanSofa MicroCMS'
39
- @authentication = 'ComfortableMexicanSofa::HttpAuth'
40
- @seed_data_path = nil
41
- @admin_route_prefix = 'cms-admin'
42
- @admin_route_redirect = "/#{@admin_route_prefix}/pages"
43
- @auto_manage_sites = true
44
- @disable_irb = true
45
- @enable_caching = true
46
- @upload_file_options = {}
47
- @override_host = nil
38
+ @cms_title = 'ComfortableMexicanSofa MicroCMS'
39
+ @authentication = 'ComfortableMexicanSofa::HttpAuth'
40
+ @seed_data_path = nil
41
+ @admin_route_prefix = 'cms-admin'
42
+ @admin_route_redirect = "/#{@admin_route_prefix}/pages"
43
+ @enable_multiple_sites = false
44
+ @allow_irb = false
45
+ @enable_caching = true
46
+ @upload_file_options = {}
47
+ @enable_fixtures = false
48
+ @fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
48
49
  end
49
50
 
50
51
  end
@@ -20,11 +20,10 @@ module ComfortableMexicanSofa::ControllerMethods
20
20
  # by the cms page and/or layout)
21
21
  def render(options = {}, locals = {}, &block)
22
22
  if options.is_a?(Hash) && path = options.delete(:cms_page)
23
- site = CmsSite.find_by_hostname(request.host.downcase)
24
- page = CmsPage.load_from_file(site, path) if site && ComfortableMexicanSofa.configuration.seed_data_path
25
- page ||= site && site.cms_pages.find_by_full_path(path)
23
+ site = Cms::Site.find_by_hostname(request.host.downcase)
24
+ page = site && site.pages.find_by_full_path(path)
26
25
  if page
27
- cms_app_layout = page.cms_layout.try(:app_layout)
26
+ cms_app_layout = page.layout.try(:app_layout)
28
27
  options[:layout] ||= cms_app_layout.blank?? nil : cms_app_layout
29
28
  options[:inline] = page.content
30
29
  @cms_page = page
@@ -6,7 +6,7 @@ require 'mime/types'
6
6
 
7
7
  module ComfortableMexicanSofa
8
8
  class Engine < ::Rails::Engine
9
-
9
+ # ...
10
10
  end
11
11
  end
12
12
 
@@ -0,0 +1,155 @@
1
+ module ComfortableMexicanSofa::Fixtures
2
+
3
+ def self.sync(site)
4
+ sync_layouts(site)
5
+ sync_pages(site)
6
+ sync_snippets(site)
7
+ end
8
+
9
+ def self.sync_layouts(site, path = nil, root = true, parent = nil, layout_ids = [])
10
+ return unless path ||= find_path(site, 'layouts')
11
+
12
+ Dir.glob("#{path}/*").select{|f| File.directory?(f)}.each do |path|
13
+ slug = path.split('/').last
14
+ layout = site.layouts.find_by_slug(slug) || site.layouts.new(:slug => slug)
15
+
16
+ # updating attributes
17
+ if File.exists?(file_path = File.join(path, "_#{slug}.yml"))
18
+ if layout.new_record? || File.mtime(file_path) > layout.updated_at
19
+ attributes = YAML.load_file(file_path).symbolize_keys!
20
+ layout.label = attributes[:label] || slug.titleize
21
+ end
22
+ elsif layout.new_record?
23
+ layout.label = slug.titleize
24
+ end
25
+
26
+ # updating content
27
+ if File.exists?(file_path = File.join(path, 'content.html'))
28
+ if layout.new_record? || File.mtime(file_path) > layout.updated_at
29
+ layout.content = File.open(file_path, 'rb').read
30
+ end
31
+ end
32
+ if File.exists?(file_path = File.join(path, 'css.css'))
33
+ if layout.new_record? || File.mtime(file_path) > layout.updated_at
34
+ layout.css = File.open(file_path, 'rb').read
35
+ end
36
+ end
37
+ if File.exists?(file_path = File.join(path, 'js.js'))
38
+ if layout.new_record? || File.mtime(file_path) > layout.updated_at
39
+ layout.js = File.open(file_path, 'rb').read
40
+ end
41
+ end
42
+
43
+ # saving
44
+ layout.parent = parent
45
+ layout.save! if layout.changed?
46
+ layout_ids << layout.id
47
+
48
+ # checking for nested fixtures
49
+ layout_ids += sync_layouts(site, path, false, layout, layout_ids)
50
+ end
51
+
52
+ # removing all db entries that are not in fixtures
53
+ site.layouts.where('id NOT IN (?)', layout_ids.uniq).each{ |l| l.destroy } if root
54
+
55
+ # returning ids of layouts in fixtures
56
+ layout_ids
57
+ end
58
+
59
+ def self.sync_pages(site, path = nil, root = true, parent = nil, page_ids = [])
60
+ return unless path ||= find_path(site, 'pages')
61
+
62
+ Dir.glob("#{path}/*").select{|f| File.directory?(f)}.each do |path|
63
+ slug = path.split('/').last
64
+ page = if parent
65
+ parent.children.find_by_slug(slug) || parent.children.new(:slug => slug, :site => site)
66
+ else
67
+ site.pages.root || site.pages.new(:slug => slug)
68
+ end
69
+
70
+ # updating attributes
71
+ if File.exists?(file_path = File.join(path, "_#{slug}.yml"))
72
+ if page.new_record? || File.mtime(file_path) > page.updated_at
73
+ attributes = YAML.load_file(file_path).symbolize_keys!
74
+ page.label = attributes[:label] || slug.titleize
75
+ page.layout = site.layouts.find_by_slug(attributes[:layout]) || parent.try(:layout)
76
+ page.target_page = site.pages.find_by_full_path(attributes[:target_page])
77
+ page.is_published = attributes[:is_published].present?? attributes[:is_published] : true
78
+ end
79
+ elsif page.new_record?
80
+ page.label = slug.titleize
81
+ page.layout = site.layouts.find_by_slug(attributes[:layout]) || parent.try(:layout)
82
+
83
+ end
84
+
85
+ # updating content
86
+ blocks_attributes = [ ]
87
+ Dir.glob("#{path}/*.html").each do |file_path|
88
+ if page.new_record? || File.mtime(file_path) > page.updated_at
89
+ label = file_path.split('/').last.split('.').first
90
+ blocks_attributes << {
91
+ :label => label,
92
+ :content => File.open(file_path, 'rb').read
93
+ }
94
+ end
95
+ end
96
+
97
+ # saving
98
+ page.blocks_attributes = blocks_attributes if blocks_attributes.present?
99
+ page.save! if page.changed?
100
+ page_ids << page.id
101
+
102
+ # checking for nested fixtures
103
+ page_ids += sync_pages(site, path, false, page, page_ids)
104
+ end
105
+
106
+ # removing all db entries that are not in fixtures
107
+ site.pages.where('id NOT IN (?)', page_ids.uniq).each{ |p| p.destroy } if root
108
+
109
+ # returning ids of layouts in fixtures
110
+ page_ids
111
+ end
112
+
113
+ def self.sync_snippets(site)
114
+ return unless path = find_path(site, 'snippets')
115
+
116
+ snippet_ids = []
117
+ Dir.glob("#{path}/*").select{|f| File.directory?(f)}.each do |path|
118
+ slug = path.split('/').last
119
+ snippet = site.snippets.find_by_slug(slug) || site.snippets.new(:slug => slug)
120
+
121
+ # updating attributes
122
+ if File.exists?(file_path = File.join(path, "_#{slug}.yml"))
123
+ if snippet.new_record? || File.mtime(file_path) > snippet.updated_at
124
+ attributes = YAML.load_file(file_path).symbolize_keys!
125
+ snippet.label = attributes[:label] || slug.titleize
126
+ end
127
+ elsif snippet.new_record?
128
+ snippet.label = slug.titleize
129
+ end
130
+
131
+ # updating content
132
+ if File.exists?(file_path = File.join(path, 'content.html'))
133
+ if snippet.new_record? || File.mtime(file_path) > snippet.updated_at
134
+ snippet.content = File.open(file_path, 'rb').read
135
+ end
136
+ end
137
+
138
+ # saving
139
+ snippet.save! if snippet.changed?
140
+ snippet_ids << snippet.id
141
+ end
142
+
143
+ # removing all db entries that are not in fixtures
144
+ site.snippets.where('id NOT IN (?)', snippet_ids).each{ |s| s.destroy }
145
+ end
146
+
147
+ def self.find_path(site, dir)
148
+ path = nil
149
+ File.exists?(path = File.join(ComfortableMexicanSofa.config.fixtures_path, site.hostname, dir)) ||
150
+ !ComfortableMexicanSofa.config.enable_multiple_sites &&
151
+ File.exists?(path = File.join(ComfortableMexicanSofa.config.fixtures_path, dir))
152
+ return path
153
+ end
154
+
155
+ end