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.
- data/README.md +8 -18
- data/Rakefile +1 -4
- data/VERSION +1 -1
- data/app/controllers/cms_admin/base_controller.rb +8 -9
- data/app/controllers/cms_admin/layouts_controller.rb +5 -5
- data/app/controllers/cms_admin/pages_controller.rb +14 -14
- data/app/controllers/cms_admin/sites_controller.rb +4 -4
- data/app/controllers/cms_admin/snippets_controller.rb +4 -4
- data/app/controllers/cms_admin/uploads_controller.rb +2 -2
- data/app/controllers/cms_content_controller.rb +21 -8
- data/app/models/cms/block.rb +13 -0
- data/app/models/{cms_layout.rb → cms/layout.rb} +16 -44
- data/app/models/{cms_page.rb → cms/page.rb} +26 -57
- data/app/models/{cms_site.rb → cms/site.rb} +8 -6
- data/app/models/cms/snippet.rb +36 -0
- data/app/models/{cms_upload.rb → cms/upload.rb} +5 -3
- data/app/views/cms_admin/layouts/_form.html.erb +2 -2
- data/app/views/cms_admin/pages/_form.html.erb +5 -5
- data/app/views/cms_admin/pages/_form_blocks.html.erb +3 -3
- data/app/views/cms_admin/uploads/_index.html.erb +1 -1
- data/app/views/layouts/cms_admin.html.erb +2 -38
- data/app/views/layouts/cms_admin/_body.html.erb +17 -0
- data/app/views/layouts/cms_admin/_center.html.erb +6 -0
- data/app/views/layouts/cms_admin/_head.html.erb +11 -0
- data/app/views/layouts/cms_admin/_left.html.erb +7 -0
- data/app/views/layouts/cms_admin/_right.html.erb +1 -0
- data/comfortable_mexican_sofa.gemspec +94 -96
- data/config/environments/development.rb +1 -1
- data/config/environments/production.rb +1 -1
- data/config/environments/test.rb +1 -1
- data/config/initializers/comfortable_mexican_sofa.rb +10 -12
- data/db/cms_fixtures/example.com/layouts/default/_default.yml +1 -0
- data/db/cms_fixtures/example.com/layouts/default/content.html +5 -0
- data/db/cms_fixtures/example.com/layouts/default/css.css +1 -0
- data/db/cms_fixtures/example.com/layouts/default/js.js +1 -0
- data/db/cms_fixtures/example.com/layouts/default/nested/_nested.yml +1 -0
- data/db/cms_fixtures/example.com/layouts/default/nested/content.html +2 -0
- data/db/cms_fixtures/example.com/layouts/default/nested/css.css +1 -0
- data/db/cms_fixtures/example.com/layouts/default/nested/js.js +1 -0
- data/db/cms_fixtures/example.com/pages/index/_index.yml +2 -0
- data/db/cms_fixtures/example.com/pages/index/child/_child.yml +2 -0
- data/db/cms_fixtures/example.com/pages/index/child/left.html +1 -0
- data/db/cms_fixtures/example.com/pages/index/child/right.html +1 -0
- data/db/cms_fixtures/example.com/pages/index/content.html +2 -0
- data/db/cms_fixtures/example.com/snippets/default/_default.yml +1 -0
- data/db/cms_fixtures/example.com/snippets/default/content.html +1 -0
- data/db/migrate/01_create_cms.rb +11 -11
- data/db/migrate/upgrades/02_upgrade_to_1_1_0.rb +19 -0
- data/lib/comfortable_mexican_sofa.rb +6 -13
- data/lib/comfortable_mexican_sofa/configuration.rb +21 -20
- data/lib/comfortable_mexican_sofa/controller_methods.rb +3 -4
- data/lib/comfortable_mexican_sofa/engine.rb +1 -1
- data/lib/comfortable_mexican_sofa/fixtures.rb +155 -0
- data/lib/comfortable_mexican_sofa/form_builder.rb +7 -15
- data/lib/comfortable_mexican_sofa/{cms_tag.rb → tag.rb} +42 -23
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_datetime.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_integer.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_string.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/field_text.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/helper.rb +2 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_datetime.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_integer.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_rich_text.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_string.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/page_text.rb +4 -5
- data/lib/comfortable_mexican_sofa/{cms_tag → tags}/partial.rb +2 -5
- data/lib/comfortable_mexican_sofa/tags/snippet.rb +13 -0
- data/lib/comfortable_mexican_sofa/view_methods.rb +4 -3
- data/lib/generators/cms_generator.rb +1 -1
- data/lib/tasks/comfortable_mexican_sofa.rake +12 -272
- data/public/javascripts/comfortable_mexican_sofa/cms.js +1 -1
- data/test/fixtures/{cms_blocks.yml → cms/blocks.yml} +2 -2
- data/test/fixtures/{cms_layouts.yml → cms/layouts.yml} +3 -3
- data/test/fixtures/{cms_pages.yml → cms/pages.yml} +4 -4
- data/test/fixtures/{cms_sites.yml → cms/sites.yml} +0 -0
- data/test/fixtures/{cms_snippets.yml → cms/snippets.yml} +1 -1
- data/test/fixtures/{cms_uploads.yml → cms/uploads.yml} +1 -1
- data/test/functional/cms_admin/layouts_controller_test.rb +6 -6
- data/test/functional/cms_admin/pages_controller_test.rb +64 -64
- data/test/functional/cms_admin/sites_controller_test.rb +5 -5
- data/test/functional/cms_admin/snippets_controller_test.rb +6 -6
- data/test/functional/cms_admin/uploads_controller_test.rb +4 -4
- data/test/functional/cms_content_controller_test.rb +27 -11
- data/test/integration/fixtures_test.rb +43 -0
- data/test/integration/sites_test.rb +23 -13
- data/test/test_helper.rb +9 -8
- data/test/unit/{cms_configuration_test.rb → configuration_test.rb} +5 -3
- data/test/unit/fixtures_test.rb +198 -0
- data/test/unit/models/block_test.rb +33 -0
- data/test/unit/models/layout_test.rb +129 -0
- data/test/unit/models/page_test.rb +199 -0
- data/test/unit/models/site_test.rb +41 -0
- data/test/unit/models/snippet_test.rb +32 -0
- data/test/unit/models/upload_test.rb +32 -0
- data/test/unit/{cms_tag_test.rb → tag_test.rb} +61 -44
- data/test/unit/tags/field_datetime_test.rb +44 -0
- data/test/unit/tags/field_integer_test.rb +43 -0
- data/test/unit/tags/field_string_test.rb +46 -0
- data/test/unit/tags/field_text_test.rb +42 -0
- data/test/unit/{cms_tags → tags}/helper_test.rb +18 -6
- data/test/unit/tags/page_datetime_test.rb +44 -0
- data/test/unit/tags/page_integer_test.rb +43 -0
- data/test/unit/tags/page_rich_text.rb +43 -0
- data/test/unit/{cms_tags → tags}/page_string_test.rb +15 -5
- data/test/unit/tags/page_text_test.rb +46 -0
- data/test/unit/{cms_tags → tags}/partial_test.rb +24 -8
- data/test/unit/tags/snippet_test.rb +45 -0
- data/test/unit/view_methods_test.rb +2 -2
- metadata +95 -121
- data/app/models/cms_block.rb +0 -28
- data/app/models/cms_snippet.rb +0 -69
- data/db/cms_seeds/example.local/layouts/default.yml +0 -8
- data/db/cms_seeds/example.local/layouts/nested.yml +0 -6
- data/db/cms_seeds/example.local/pages/child.yml +0 -10
- data/db/cms_seeds/example.local/pages/child/subchild.yml +0 -14
- data/db/cms_seeds/example.local/pages/index.yml +0 -11
- data/db/cms_seeds/example.local/snippets/example.yml +0 -4
- data/lib/comfortable_mexican_sofa/cms_tag/snippet.rb +0 -18
- data/test/cms_seeds/test.host/layouts/broken.yml +0 -1
- data/test/cms_seeds/test.host/layouts/default.yml +0 -3
- data/test/cms_seeds/test.host/layouts/nested.yml +0 -4
- data/test/cms_seeds/test.host/pages/broken.yml +0 -1
- data/test/cms_seeds/test.host/pages/child.yml +0 -10
- data/test/cms_seeds/test.host/pages/child/subchild.yml +0 -10
- data/test/cms_seeds/test.host/pages/index.yml +0 -10
- data/test/cms_seeds/test.host/snippets/broken.yml +0 -1
- data/test/cms_seeds/test.host/snippets/default.yml +0 -3
- data/test/integration/rake_tasks_test.rb +0 -65
- data/test/integration/render_cms_seed_test.rb +0 -34
- data/test/unit/cms_block_test.rb +0 -43
- data/test/unit/cms_layout_test.rb +0 -179
- data/test/unit/cms_page_test.rb +0 -257
- data/test/unit/cms_site_test.rb +0 -41
- data/test/unit/cms_snippet_test.rb +0 -77
- data/test/unit/cms_tags/field_datetime_test.rb +0 -34
- data/test/unit/cms_tags/field_integer_test.rb +0 -33
- data/test/unit/cms_tags/field_string_test.rb +0 -34
- data/test/unit/cms_tags/field_text_test.rb +0 -32
- data/test/unit/cms_tags/page_datetime_test.rb +0 -34
- data/test/unit/cms_tags/page_integer_test.rb +0 -33
- data/test/unit/cms_tags/page_rich_text.rb +0 -33
- data/test/unit/cms_tags/page_text_test.rb +0 -34
- data/test/unit/cms_tags/snippet_test.rb +0 -33
- data/test/unit/cms_upload_test.rb +0 -26
data/README.md
CHANGED
@@ -85,7 +85,7 @@ Here's a number of tag variations:
|
|
85
85
|
|
86
86
|
Multiple Sites
|
87
87
|
--------------
|
88
|
-
Sofa is able to manage multiple sites from the same application. For instance: 'site-a.example.com' and 'site-b.example.com' will have distinct set of layouts, pages, snippets, etc. To enable multi-site functionality make sure you have this setting in the initializer: `config.
|
88
|
+
Sofa is able to manage multiple sites from the same application. For instance: 'site-a.example.com' and 'site-b.example.com' will have distinct set of layouts, pages, snippets, etc. To enable multi-site functionality make sure you have this setting in the initializer: `config.enable_multiple_sites = true`.
|
89
89
|
|
90
90
|
Integrating CMS with your app
|
91
91
|
-----------------------------
|
@@ -142,25 +142,15 @@ Do you have other authentication system in place (like Devise, AuthLogic, etc) a
|
|
142
142
|
|
143
143
|
You can put this module in /config/initializers/comfortable\_mexican\_sofa.rb and change authentication method: `config.authentication = 'CmsDeviseAuth'`. Now to access Sofa's admin area users will be authenticated against your existing authentication system.
|
144
144
|
|
145
|
-
Working with
|
146
|
-
|
147
|
-
|
145
|
+
Working with Fixtures
|
146
|
+
---------------------
|
147
|
+
Sofa allows you to build entire site using files instead of updating database via admin area. This significantly speeds up initial content population. To enable fixtures go to the initializer and set this: `config.enable_fixtures = true`. You may also change the folder that is used to store fixtures.
|
148
148
|
|
149
|
-
|
150
|
-
|
151
|
-
if Rails.env.development? || Rails.env.test?
|
152
|
-
ComfortableMexicanSofa.config.seed_data_path = File.expand_path('db/cms_seeds', Rails.root)
|
153
|
-
end
|
154
|
-
|
155
|
-
If you ran `rails g cms`, you should find an example set of seeds in /db/cms\_seeds directory. Please note that seeds are nested in the folder that is the hostname of your site. Each file is an YAML representation of a database entry for that layout/page/snippet.
|
149
|
+
If you run `rails g cms` you should find an example set of fixtures in [/db/cms\_fixtures](https://github.com/twg/comfortable-mexican-sofa/blob/master/db/cms_fixtures). If you run multiple sites, each set of fixtures should be inside a folder named as the hostname of the site. It's optional if you only have one site.
|
156
150
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
rake comfortable_mexican_sofa:import:all FROM=your-site.local TO=your-site.com SEED_PATH=/path/to/seeds
|
161
|
-
|
162
|
-
# from database to seeds
|
163
|
-
rake comfortable_mexican_sofa:export:all FROM=your-site.com TO=your-site.local SEED_PATH=/path/to/seeds
|
151
|
+
When fixtures are enabled, database is updated with each request, but only if fixture file is newer than the database entry. Database is also purged of items that are not defined in fixtures. So be careful not to clear out your database by mistake.
|
152
|
+
|
153
|
+
When deploying to a production server don't forget to turn off fixtures. To load them into the database just run this rake task: `rake comfortable_mexican_sofa:fixtures:import`. When running multiple sites specify which one by passing argument like this: `SITE=example.com`.
|
164
154
|
|
165
155
|
Active Components
|
166
156
|
-----------------
|
data/Rakefile
CHANGED
@@ -11,14 +11,11 @@ begin
|
|
11
11
|
require 'jeweler'
|
12
12
|
Jeweler::Tasks.new do |gem|
|
13
13
|
gem.name = 'comfortable_mexican_sofa'
|
14
|
-
gem.summary = 'ComfortableMexicanSofa is a
|
14
|
+
gem.summary = 'ComfortableMexicanSofa is a powerful micro CMS for Ruby on Rails 3 applications'
|
15
15
|
gem.description = ''
|
16
16
|
gem.email = 'oleg@theworkinggroup.ca'
|
17
17
|
gem.homepage = 'http://github.com/twg/comfortable-mexican-sofa'
|
18
18
|
gem.authors = ['Oleg Khabarov', 'The Working Group Inc']
|
19
|
-
gem.add_dependency('rails', '>=3.0.3')
|
20
|
-
gem.add_dependency('active_link_to', '>=0.0.6')
|
21
|
-
gem.add_dependency('paperclip', '>=2.3.8')
|
22
19
|
end
|
23
20
|
Jeweler::GemcutterTasks.new
|
24
21
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
@@ -13,16 +13,15 @@ class CmsAdmin::BaseController < ActionController::Base
|
|
13
13
|
protected
|
14
14
|
|
15
15
|
def load_admin_cms_site
|
16
|
-
hostname =
|
17
|
-
@cms_site =
|
18
|
-
|
19
|
-
rescue ActiveRecord::RecordNotFound
|
16
|
+
hostname = request.host.downcase
|
17
|
+
@cms_site = Cms::Site.find_by_hostname!(hostname)
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
rescue ActiveRecord::RecordNotFound
|
20
|
+
unless ComfortableMexicanSofa.config.enable_multiple_sites
|
21
|
+
if Cms::Site.count == 0
|
22
|
+
@cms_site = Cms::Site.create!(:label => 'Default Site', :hostname => hostname)
|
23
|
+
else
|
24
|
+
@cms_site = Cms::Site.first
|
26
25
|
@cms_site.update_attribute(:hostname, hostname)
|
27
26
|
end
|
28
27
|
end
|
@@ -4,8 +4,8 @@ class CmsAdmin::LayoutsController < CmsAdmin::BaseController
|
|
4
4
|
before_filter :load_cms_layout, :only => [:edit, :update, :destroy]
|
5
5
|
|
6
6
|
def index
|
7
|
-
return redirect_to :action => :new if @cms_site.
|
8
|
-
@cms_layouts = @cms_site.
|
7
|
+
return redirect_to :action => :new if @cms_site.layouts.count == 0
|
8
|
+
@cms_layouts = @cms_site.layouts.roots
|
9
9
|
end
|
10
10
|
|
11
11
|
def new
|
@@ -43,13 +43,13 @@ class CmsAdmin::LayoutsController < CmsAdmin::BaseController
|
|
43
43
|
protected
|
44
44
|
|
45
45
|
def build_cms_layout
|
46
|
-
@cms_layout = @cms_site.
|
47
|
-
@cms_layout.parent ||=
|
46
|
+
@cms_layout = @cms_site.layouts.new(params[:cms_layout])
|
47
|
+
@cms_layout.parent ||= Cms::Layout.find_by_id(params[:parent_id])
|
48
48
|
@cms_layout.content ||= '{{ cms:page:content:text }}'
|
49
49
|
end
|
50
50
|
|
51
51
|
def load_cms_layout
|
52
|
-
@cms_layout = @cms_site.
|
52
|
+
@cms_layout = @cms_site.layouts.find(params[:id])
|
53
53
|
rescue ActiveRecord::RecordNotFound
|
54
54
|
flash[:error] = 'Layout not found'
|
55
55
|
redirect_to :action => :index
|
@@ -7,8 +7,8 @@ class CmsAdmin::PagesController < CmsAdmin::BaseController
|
|
7
7
|
before_filter :build_upload_file, :only => [:new, :edit]
|
8
8
|
|
9
9
|
def index
|
10
|
-
return redirect_to :action => :new if @cms_site.
|
11
|
-
@cms_pages = [@cms_site.
|
10
|
+
return redirect_to :action => :new if @cms_site.pages.count == 0
|
11
|
+
@cms_pages = [@cms_site.pages.root].compact
|
12
12
|
end
|
13
13
|
|
14
14
|
def new
|
@@ -44,12 +44,12 @@ class CmsAdmin::PagesController < CmsAdmin::BaseController
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def form_blocks
|
47
|
-
@cms_page = @cms_site.
|
48
|
-
@cms_page.
|
47
|
+
@cms_page = @cms_site.pages.find_by_id(params[:id]) || @cms_site.pages.new
|
48
|
+
@cms_page.layout = @cms_site.layouts.find_by_id(params[:layout_id])
|
49
49
|
end
|
50
50
|
|
51
51
|
def toggle_branch
|
52
|
-
@cms_page = @cms_site.
|
52
|
+
@cms_page = @cms_site.pages.find(params[:id])
|
53
53
|
s = (session[:cms_page_tree] ||= [])
|
54
54
|
id = @cms_page.id.to_s
|
55
55
|
s.member?(id) ? s.delete(id) : s << id
|
@@ -59,7 +59,7 @@ class CmsAdmin::PagesController < CmsAdmin::BaseController
|
|
59
59
|
|
60
60
|
def reorder
|
61
61
|
(params[:cms_page] || []).each_with_index do |id, index|
|
62
|
-
if (cms_page =
|
62
|
+
if (cms_page = Cms::Page.find_by_id(id))
|
63
63
|
cms_page.update_attribute(:position, index)
|
64
64
|
end
|
65
65
|
end
|
@@ -69,26 +69,26 @@ class CmsAdmin::PagesController < CmsAdmin::BaseController
|
|
69
69
|
protected
|
70
70
|
|
71
71
|
def check_for_layouts
|
72
|
-
if
|
72
|
+
if @cms_site.layouts.count == 0
|
73
73
|
flash[:error] = 'No Layouts found. Please create one.'
|
74
74
|
redirect_to new_cms_admin_layout_path
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
def build_cms_page
|
79
|
-
@cms_page = @cms_site.
|
80
|
-
@cms_page.parent ||= (
|
81
|
-
@cms_page.
|
79
|
+
@cms_page = @cms_site.pages.new(params[:cms_page])
|
80
|
+
@cms_page.parent ||= (@cms_site.pages.find_by_id(params[:parent_id]) || @cms_site.pages.root)
|
81
|
+
@cms_page.layout ||= (@cms_page.parent && @cms_page.parent.layout || @cms_site.layouts.first)
|
82
82
|
end
|
83
83
|
|
84
84
|
def build_upload_file
|
85
|
-
@upload =
|
85
|
+
@upload = Cms::Upload.new
|
86
86
|
end
|
87
87
|
|
88
88
|
def load_cms_page
|
89
|
-
@cms_page = @cms_site.
|
89
|
+
@cms_page = @cms_site.pages.find(params[:id])
|
90
90
|
@cms_page.attributes = params[:cms_page]
|
91
|
-
@cms_page.
|
91
|
+
@cms_page.layout ||= (@cms_page.parent && @cms_page.parent.layout || @cms_site.layouts.first)
|
92
92
|
rescue ActiveRecord::RecordNotFound
|
93
93
|
flash[:error] = 'Page not found'
|
94
94
|
redirect_to :action => :index
|
@@ -96,7 +96,7 @@ protected
|
|
96
96
|
|
97
97
|
def preview_cms_page
|
98
98
|
if params[:preview]
|
99
|
-
layout = @cms_page.
|
99
|
+
layout = @cms_page.layout.app_layout.blank?? false : @cms_page.layout.app_layout
|
100
100
|
render :inline => @cms_page.content(true), :layout => layout
|
101
101
|
end
|
102
102
|
end
|
@@ -6,8 +6,8 @@ class CmsAdmin::SitesController < CmsAdmin::BaseController
|
|
6
6
|
before_filter :load_cms_site, :only => [:edit, :update, :destroy]
|
7
7
|
|
8
8
|
def index
|
9
|
-
return redirect_to :action => :new if
|
10
|
-
@cms_sites =
|
9
|
+
return redirect_to :action => :new if Cms::Site.count == 0
|
10
|
+
@cms_sites = Cms::Site.all
|
11
11
|
end
|
12
12
|
|
13
13
|
def new
|
@@ -45,12 +45,12 @@ class CmsAdmin::SitesController < CmsAdmin::BaseController
|
|
45
45
|
protected
|
46
46
|
|
47
47
|
def build_cms_site
|
48
|
-
@cms_site =
|
48
|
+
@cms_site = Cms::Site.new(params[:cms_site])
|
49
49
|
@cms_site.hostname ||= request.host.downcase
|
50
50
|
end
|
51
51
|
|
52
52
|
def load_cms_site
|
53
|
-
@cms_site =
|
53
|
+
@cms_site = Cms::Site.find(params[:id])
|
54
54
|
rescue ActiveRecord::RecordNotFound
|
55
55
|
flash[:error] = 'Site not found'
|
56
56
|
redirect_to :action => :index
|
@@ -4,8 +4,8 @@ class CmsAdmin::SnippetsController < CmsAdmin::BaseController
|
|
4
4
|
before_filter :load_cms_snippet, :only => [:edit, :update, :destroy]
|
5
5
|
|
6
6
|
def index
|
7
|
-
return redirect_to :action => :new if @cms_site.
|
8
|
-
@cms_snippets = @cms_site.
|
7
|
+
return redirect_to :action => :new if @cms_site.snippets.count == 0
|
8
|
+
@cms_snippets = @cms_site.snippets.all(:order => 'label')
|
9
9
|
end
|
10
10
|
|
11
11
|
def new
|
@@ -43,11 +43,11 @@ class CmsAdmin::SnippetsController < CmsAdmin::BaseController
|
|
43
43
|
protected
|
44
44
|
|
45
45
|
def build_cms_snippet
|
46
|
-
@cms_snippet = @cms_site.
|
46
|
+
@cms_snippet = @cms_site.snippets.new(params[:cms_snippet])
|
47
47
|
end
|
48
48
|
|
49
49
|
def load_cms_snippet
|
50
|
-
@cms_snippet = @cms_site.
|
50
|
+
@cms_snippet = @cms_site.snippets.find(params[:id])
|
51
51
|
rescue ActiveRecord::RecordNotFound
|
52
52
|
flash[:error] = 'Snippet not found'
|
53
53
|
redirect_to :action => :index
|
@@ -7,7 +7,7 @@ class CmsAdmin::UploadsController < CmsAdmin::BaseController
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def create
|
10
|
-
@cms_upload = @cms_site.
|
10
|
+
@cms_upload = @cms_site.uploads.create!(:file => params[:file])
|
11
11
|
render :partial => 'file', :object => @cms_upload
|
12
12
|
rescue ActiveRecord::RecordInvalid
|
13
13
|
render :nothing => true, :status => :bad_request
|
@@ -20,7 +20,7 @@ class CmsAdmin::UploadsController < CmsAdmin::BaseController
|
|
20
20
|
protected
|
21
21
|
|
22
22
|
def load_cms_upload
|
23
|
-
@cms_upload = @cms_site.
|
23
|
+
@cms_upload = @cms_site.uploads.find(params[:id])
|
24
24
|
rescue ActiveRecord::RecordNotFound
|
25
25
|
render :nothing => true
|
26
26
|
end
|
@@ -1,14 +1,19 @@
|
|
1
1
|
class CmsContentController < ApplicationController
|
2
2
|
|
3
3
|
before_filter :load_cms_site
|
4
|
+
before_filter :load_fixtures
|
4
5
|
before_filter :load_cms_page, :only => :render_html
|
5
6
|
before_filter :load_cms_layout, :only => [:render_css, :render_js]
|
6
7
|
|
7
8
|
caches_page :render_css, :render_js, :if => Proc.new { |c| ComfortableMexicanSofa.config.enable_caching }
|
8
9
|
|
9
10
|
def render_html(status = 200)
|
10
|
-
layout = @cms_page.
|
11
|
-
|
11
|
+
if layout = @cms_page.layout
|
12
|
+
app_layout = layout.app_layout.blank?? false : layout.app_layout
|
13
|
+
render :inline => @cms_page.content, :layout => app_layout, :status => status
|
14
|
+
else
|
15
|
+
render :text => 'Layout Not Found', :status => 404
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
def render_css
|
@@ -21,18 +26,26 @@ class CmsContentController < ApplicationController
|
|
21
26
|
|
22
27
|
protected
|
23
28
|
|
29
|
+
def load_fixtures
|
30
|
+
return unless ComfortableMexicanSofa.config.enable_fixtures
|
31
|
+
ComfortableMexicanSofa::Fixtures.sync(@cms_site)
|
32
|
+
end
|
33
|
+
|
24
34
|
def load_cms_site
|
25
|
-
@cms_site =
|
26
|
-
|
27
|
-
|
35
|
+
@cms_site = if ComfortableMexicanSofa.config.enable_multiple_sites
|
36
|
+
Cms::Site.find_by_hostname(request.host.downcase)
|
37
|
+
else
|
38
|
+
Cms::Site.first
|
39
|
+
end
|
40
|
+
render :text => 'Site Not Found', :status => 404 if !@cms_site
|
28
41
|
end
|
29
42
|
|
30
43
|
def load_cms_page
|
31
|
-
@cms_page =
|
44
|
+
@cms_page = @cms_site.pages.published.find_by_full_path!("/#{params[:cms_path]}")
|
32
45
|
return redirect_to(@cms_page.target_page.full_path) if @cms_page.target_page
|
33
46
|
|
34
47
|
rescue ActiveRecord::RecordNotFound
|
35
|
-
if @cms_page =
|
48
|
+
if @cms_page = @cms_site.pages.published.find_by_full_path('/404')
|
36
49
|
render_html(404)
|
37
50
|
else
|
38
51
|
render :text => 'Page Not Found', :status => 404
|
@@ -40,7 +53,7 @@ protected
|
|
40
53
|
end
|
41
54
|
|
42
55
|
def load_cms_layout
|
43
|
-
@cms_layout =
|
56
|
+
@cms_layout = @cms_site.layouts.find_by_slug!(params[:id])
|
44
57
|
rescue ActiveRecord::RecordNotFound
|
45
58
|
render :nothing => true, :status => 404
|
46
59
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Cms::Block < ActiveRecord::Base
|
2
|
+
|
3
|
+
set_table_name :cms_blocks
|
4
|
+
|
5
|
+
# -- Relationships --------------------------------------------------------
|
6
|
+
belongs_to :page
|
7
|
+
|
8
|
+
# -- Validations ----------------------------------------------------------
|
9
|
+
validates :label,
|
10
|
+
:presence => true,
|
11
|
+
:uniqueness => { :scope => :page_id }
|
12
|
+
|
13
|
+
end
|
@@ -1,23 +1,25 @@
|
|
1
|
-
class
|
1
|
+
class Cms::Layout < ActiveRecord::Base
|
2
|
+
|
3
|
+
set_table_name :cms_layouts
|
2
4
|
|
3
5
|
acts_as_tree
|
4
6
|
|
5
7
|
# -- Relationships --------------------------------------------------------
|
6
|
-
belongs_to :
|
7
|
-
has_many :
|
8
|
+
belongs_to :site
|
9
|
+
has_many :pages, :dependent => :nullify
|
8
10
|
|
9
11
|
# -- Callbacks ------------------------------------------------------------
|
10
12
|
after_save :clear_cache, :clear_cached_page_content
|
11
13
|
after_destroy :clear_cache, :clear_cached_page_content
|
12
14
|
|
13
15
|
# -- Validations ----------------------------------------------------------
|
14
|
-
validates :
|
16
|
+
validates :site_id,
|
15
17
|
:presence => true
|
16
18
|
validates :label,
|
17
19
|
:presence => true
|
18
20
|
validates :slug,
|
19
21
|
:presence => true,
|
20
|
-
:uniqueness => { :scope => :
|
22
|
+
:uniqueness => { :scope => :site_id },
|
21
23
|
:format => { :with => /^\w[a-z0-9_-]*$/i }
|
22
24
|
validates :content,
|
23
25
|
:presence => true
|
@@ -25,13 +27,13 @@ class CmsLayout < ActiveRecord::Base
|
|
25
27
|
|
26
28
|
# -- Class Methods --------------------------------------------------------
|
27
29
|
# Tree-like structure for layouts
|
28
|
-
def self.options_for_select(
|
30
|
+
def self.options_for_select(site, layout = nil, current_layout = nil, depth = 0, spacer = '. . ')
|
29
31
|
out = []
|
30
|
-
[current_layout ||
|
31
|
-
next if
|
32
|
-
out << [ "#{spacer*depth}#{
|
33
|
-
|
34
|
-
out += options_for_select(
|
32
|
+
[current_layout || site.layouts.roots].flatten.each do |l|
|
33
|
+
next if layout == l
|
34
|
+
out << [ "#{spacer*depth}#{l.label}", l.id ]
|
35
|
+
l.children.each do |child|
|
36
|
+
out += options_for_select(site, layout, child, depth + 1, spacer)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
return out.compact
|
@@ -46,36 +48,6 @@ class CmsLayout < ActiveRecord::Base
|
|
46
48
|
end.compact
|
47
49
|
end
|
48
50
|
|
49
|
-
# Attempting to initialize layout object from yaml file that is found in config.seed_data_path
|
50
|
-
def self.load_from_file(site, slug)
|
51
|
-
return nil if ComfortableMexicanSofa.config.seed_data_path.blank?
|
52
|
-
file_path = "#{ComfortableMexicanSofa.config.seed_data_path}/#{site.hostname}/layouts/#{slug}.yml"
|
53
|
-
return nil unless File.exists?(file_path)
|
54
|
-
attributes = YAML.load_file(file_path).symbolize_keys!
|
55
|
-
attributes[:parent] = CmsLayout.load_from_file(site, attributes[:parent])
|
56
|
-
attributes[:cms_site] = site
|
57
|
-
new(attributes)
|
58
|
-
rescue
|
59
|
-
raise "Failed to load from #{file_path}"
|
60
|
-
end
|
61
|
-
|
62
|
-
# Wrapper around load_from_file and find_by_slug
|
63
|
-
# returns layout object if loaded / found
|
64
|
-
def self.load_for_slug!(site, slug)
|
65
|
-
if ComfortableMexicanSofa.configuration.seed_data_path
|
66
|
-
load_from_file(site, slug)
|
67
|
-
else
|
68
|
-
site.cms_layouts.find_by_slug(slug)
|
69
|
-
end || raise(ActiveRecord::RecordNotFound, "CmsLayout with slug: #{slug} cannot be found")
|
70
|
-
end
|
71
|
-
|
72
|
-
# Non-blowing-up version of the method above
|
73
|
-
def self.load_for_slug(site, slug)
|
74
|
-
load_for_slug!(site, slug)
|
75
|
-
rescue ActiveRecord::RecordNotFound
|
76
|
-
nil
|
77
|
-
end
|
78
|
-
|
79
51
|
# -- Instance Methods -----------------------------------------------------
|
80
52
|
# magical merging tag is {cms:page:content} If parent layout has this tag
|
81
53
|
# defined its content will be merged. If no such tag found, parent content
|
@@ -96,8 +68,8 @@ class CmsLayout < ActiveRecord::Base
|
|
96
68
|
protected
|
97
69
|
|
98
70
|
def check_content_tag_presence
|
99
|
-
|
100
|
-
if test_page.
|
71
|
+
ComfortableMexicanSofa::Tag.process_content((test_page = site.pages.new), content)
|
72
|
+
if test_page.tags.select{|t| t.is_cms_block?}.blank?
|
101
73
|
self.errors.add(:content, 'No cms page tags defined')
|
102
74
|
end
|
103
75
|
end
|
@@ -111,7 +83,7 @@ protected
|
|
111
83
|
|
112
84
|
# Forcing page content reload
|
113
85
|
def clear_cached_page_content
|
114
|
-
self.
|
86
|
+
self.pages.each{ |page| page.save! }
|
115
87
|
self.children.each{ |child_layout| child_layout.save! }
|
116
88
|
end
|
117
89
|
|