comfortable_mexican_sofa 1.12.3 → 1.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -3
- data/Gemfile +4 -0
- data/LICENSE +1 -1
- data/README.md +12 -13
- data/app/assets/stylesheets/comfortable_mexican_sofa/{application.css.sass → application.sass} +0 -0
- data/app/assets/stylesheets/comfortable_mexican_sofa/{base.css.sass → base.sass} +0 -0
- data/app/assets/stylesheets/comfortable_mexican_sofa/{bootstrap_overrides.css.sass → bootstrap_overrides.sass} +0 -0
- data/app/assets/stylesheets/comfortable_mexican_sofa/{codemirror_overrides.css.sass → codemirror_overrides.sass} +0 -0
- data/app/controllers/comfy/admin/cms/base_controller.rb +11 -0
- data/app/controllers/comfy/admin/cms/files_controller.rb +5 -2
- data/app/controllers/comfy/cms/content_controller.rb +1 -1
- data/app/helpers/comfy/cms_helper.rb +82 -0
- data/app/models/comfy/cms/block.rb +40 -22
- data/app/models/comfy/cms/page.rb +28 -22
- data/app/models/comfy/cms/site.rb +13 -13
- data/app/views/comfy/admin/cms/files/index.html.haml +2 -2
- data/app/views/comfy/cms/content/render_sitemap.xml.builder +3 -3
- data/comfortable_mexican_sofa.gemspec +0 -1
- data/config/environments/test.rb +3 -1
- data/db/upgrade_migrations/08_upgrade_to_1_12_0.rb +8 -2
- data/lib/comfortable_mexican_sofa.rb +0 -1
- data/lib/comfortable_mexican_sofa/engine.rb +0 -1
- data/lib/comfortable_mexican_sofa/extensions/cms_manageable.rb +11 -11
- data/lib/comfortable_mexican_sofa/fixture/page.rb +19 -18
- data/lib/comfortable_mexican_sofa/version.rb +1 -1
- data/lib/comfortable_mexican_sofa/view_hooks.rb +5 -4
- data/lib/generators/comfy/cms/cms_generator.rb +1 -1
- data/lib/generators/comfy/scaffold/templates/tests/controller.rb +2 -2
- data/test/controllers/comfy/admin/cms/files_controller_test.rb +2 -2
- data/test/controllers/comfy/admin/cms/layouts_controller_test.rb +2 -2
- data/test/controllers/comfy/admin/cms/pages_controller_test.rb +6 -6
- data/test/controllers/comfy/admin/cms/sites_controller_test.rb +3 -3
- data/test/controllers/comfy/admin/cms/snippets_controller_test.rb +2 -2
- data/test/controllers/comfy/cms/content_controller_test.rb +13 -4
- data/test/fixtures/generators/scaffold/tests/controller.rb +2 -2
- data/test/gemfiles/Gemfile.rails.4.0 +2 -2
- data/test/gemfiles/Gemfile.rails.4.1 +2 -2
- data/test/gemfiles/Gemfile.rails.4.2 +23 -0
- data/test/gemfiles/Gemfile.rails.master +2 -2
- data/test/generators/cms_generator_test.rb +2 -1
- data/test/{lib/view_methods_test.rb → helpers/cms_helper_test.rb} +23 -23
- data/test/integration/fixtures_test.rb +12 -12
- data/test/lib/configuration_test.rb +1 -0
- data/test/lib/fixtures/pages_test.rb +39 -38
- data/test/lib/tags/collection_test.rb +18 -18
- data/test/lib/tags/field_datetime_test.rb +5 -5
- data/test/lib/tags/page_datetime_test.rb +5 -5
- data/test/lib/tags/page_files_test.rb +29 -26
- data/test/models/block_test.rb +59 -25
- data/test/models/page_test.rb +53 -44
- data/test/test_helper.rb +16 -13
- metadata +10 -23
- data/lib/comfortable_mexican_sofa/view_methods.rb +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b57d6be9adeefcfafd8dfa2e17eb50bc7882799
|
4
|
+
data.tar.gz: 99b0f0e6a6d16000087dbebdba62a11e923c9c02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb615a6907113332bcbe625766244eb321bca48cbce4d2336247bbfa8517420493af807425ff74c03b42b71cc49c834a4742d09a8793986d69bff074048179e2
|
7
|
+
data.tar.gz: 67770c64c90a8de4faeab88a0b05be01b6a2e55ca53f89748ba693f0b2a6271f8954c096e92bfa33daebfca2dd6d7a655d91be553e809699024656b8948861a5
|
data/.travis.yml
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
language: ruby
|
2
|
+
before_install:
|
3
|
+
- gem install bundler
|
2
4
|
before_script:
|
3
5
|
- rake db:migrate
|
4
6
|
script:
|
@@ -6,15 +8,19 @@ script:
|
|
6
8
|
rvm:
|
7
9
|
- 1.9.3
|
8
10
|
- 2.0.0
|
9
|
-
- 2.1.
|
11
|
+
- 2.1.5
|
12
|
+
- 2.2.0
|
10
13
|
gemfile:
|
11
14
|
- test/gemfiles/Gemfile.rails.4.0
|
12
15
|
- test/gemfiles/Gemfile.rails.4.1
|
13
|
-
- test/gemfiles/Gemfile.rails.
|
16
|
+
- test/gemfiles/Gemfile.rails.4.2
|
14
17
|
branches:
|
15
18
|
only:
|
16
19
|
- master
|
17
20
|
matrix:
|
18
21
|
fast_finish: true
|
22
|
+
include:
|
23
|
+
- rvm: 2.2.0
|
24
|
+
gemfile: test/gemfiles/Gemfile.rails.master
|
19
25
|
allow_failures:
|
20
|
-
- gemfile: test/gemfiles/Gemfile.rails.master
|
26
|
+
- gemfile: test/gemfiles/Gemfile.rails.master
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# ComfortableMexicanSofa
|
2
|
-
[![Gem Version](https://
|
2
|
+
[![Gem Version](https://img.shields.io/gem/v/comfortable_mexican_sofa.svg?style=flat)](http://rubygems.org/gems/comfortable_mexican_sofa) [![Gem Downloads](https://img.shields.io/gem/dt/comfortable_mexican_sofa.svg?style=flat)](http://rubygems.org/gems/comfortable_mexican_sofa) [![Build Status](https://img.shields.io/travis/comfy/comfortable-mexican-sofa.svg?style=flat)](https://travis-ci.org/comfy/comfortable-mexican-sofa) [![Dependency Status](https://img.shields.io/gemnasium/comfy/comfortable-mexican-sofa.svg?style=flat)](https://gemnasium.com/comfy/comfortable-mexican-sofa) [![Code Climate](https://img.shields.io/codeclimate/github/comfy/comfortable-mexican-sofa.svg?style=flat)](https://codeclimate.com/github/comfy/comfortable-mexican-sofa) [![Coverage Status](https://img.shields.io/coveralls/comfy/comfortable-mexican-sofa.svg?style=flat)](https://coveralls.io/r/comfy/comfortable-mexican-sofa?branch=master)
|
3
3
|
|
4
4
|
ComfortableMexicanSofa is a powerful Rails 4 CMS Engine
|
5
5
|
|
@@ -17,17 +17,17 @@ ComfortableMexicanSofa is a powerful Rails 4 CMS Engine
|
|
17
17
|
## Installation
|
18
18
|
|
19
19
|
Add gem definition to your Gemfile:
|
20
|
-
|
20
|
+
|
21
21
|
```ruby
|
22
22
|
gem 'comfortable_mexican_sofa', '~> 1.12.0'
|
23
|
-
```
|
23
|
+
```
|
24
24
|
|
25
25
|
Then from the Rails project's root run:
|
26
|
-
|
26
|
+
|
27
27
|
bundle install
|
28
28
|
rails generate comfy:cms
|
29
29
|
rake db:migrate
|
30
|
-
|
30
|
+
|
31
31
|
Now take a look inside your `config/routes.rb` file. You'll see where routes attach for the admin area and content serving. Make sure that content serving route appears as a very last item.
|
32
32
|
|
33
33
|
```ruby
|
@@ -40,7 +40,7 @@ When upgrading from the older version please take a look at [Upgrading Comfortab
|
|
40
40
|
### Installation for Rails 3
|
41
41
|
|
42
42
|
For Rails 3 apps feel free to use [1.8 release](https://github.com/comfy/comfortable-mexican-sofa/tree/1.8)
|
43
|
-
|
43
|
+
|
44
44
|
```ruby
|
45
45
|
gem 'comfortable_mexican_sofa', '~> 1.8.0'
|
46
46
|
```
|
@@ -54,7 +54,7 @@ Default username and password is 'username' and 'password'. You probably want to
|
|
54
54
|
Before creating pages and populating them with content we need to create a Site. Site defines a hostname, content path and its language.
|
55
55
|
|
56
56
|
After creating a Site, you need to make a Layout. Layout is the template of your pages; it defines some reusable content (like header and footer, for example) and places where the content goes. A very simple layout can look like this:
|
57
|
-
|
57
|
+
|
58
58
|
```html
|
59
59
|
<html>
|
60
60
|
<body>
|
@@ -74,19 +74,18 @@ For more information please refer to [Wiki](https://github.com/comfy/comfortable
|
|
74
74
|
|
75
75
|
#### Dependencies
|
76
76
|
|
77
|
-
|
77
|
+
* Install [ImageMagick](http://www.imagemagick.org/) for [paperclip](https://github.com/thoughtbot/paperclip)'s image processing
|
78
|
+
* Make sure that Gemfile has either [kaminari](https://github.com/amatsuda/kaminari) or [will_paginate](https://github.com/mislav/will_paginate)
|
78
79
|
|
79
80
|
#### Help and Contact
|
80
81
|
|
81
82
|
GoogleGroups: http://groups.google.com/group/comfortable-mexican-sofa
|
83
|
+
|
82
84
|
Twitter: [@GroceryBagHead](http://twitter.com/#!/GroceryBagHead)
|
83
85
|
|
84
86
|
---
|
85
87
|
|
86
|
-
ComfortableMexicanSofa is released under the [MIT license](https://github.com/comfy/comfortable-mexican-sofa/raw/master/LICENSE)
|
88
|
+
ComfortableMexicanSofa is released under the [MIT license](https://github.com/comfy/comfortable-mexican-sofa/raw/master/LICENSE)
|
87
89
|
|
88
|
-
Copyright 2009-
|
89
|
-
|
90
|
-
---
|
90
|
+
Copyright 2009-2015 Oleg Khabarov
|
91
91
|
|
92
|
-
DOGE: DMTBhZjcgUZunCKMpKCJogBXBhQx2h7h5c
|
data/app/assets/stylesheets/comfortable_mexican_sofa/{application.css.sass → application.sass}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -52,4 +52,15 @@ protected
|
|
52
52
|
flash.now[:danger] = I18n.t('comfy.admin.cms.base.fixtures_enabled')
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
# Wrapper to deal with WillPaginate vs Kaminari nonsense
|
57
|
+
def comfy_paginate(scope, per_page = 50)
|
58
|
+
if defined?(WillPaginate)
|
59
|
+
scope.paginate(:page => params[:page], :per_page => per_page)
|
60
|
+
elsif defined?(Kaminari)
|
61
|
+
scope.page(params[:page]).per(per_page)
|
62
|
+
else
|
63
|
+
scope
|
64
|
+
end
|
65
|
+
end
|
55
66
|
end
|
@@ -7,8 +7,11 @@ class Comfy::Admin::Cms::FilesController < Comfy::Admin::Cms::BaseController
|
|
7
7
|
before_action :authorize
|
8
8
|
|
9
9
|
def index
|
10
|
-
|
11
|
-
.
|
10
|
+
files_scope = @site.files.not_page_file
|
11
|
+
.includes(:categories)
|
12
|
+
.for_category(params[:category])
|
13
|
+
.order('comfy_cms_files.position')
|
14
|
+
@files = comfy_paginate(files_scope, 50)
|
12
15
|
end
|
13
16
|
|
14
17
|
def new
|
@@ -12,7 +12,7 @@ class Comfy::Cms::ContentController < Comfy::Cms::BaseController
|
|
12
12
|
|
13
13
|
def show
|
14
14
|
if @cms_page.target_page.present?
|
15
|
-
redirect_to @cms_page.target_page.url
|
15
|
+
redirect_to @cms_page.target_page.url(:relative)
|
16
16
|
else
|
17
17
|
respond_to do |format|
|
18
18
|
format.html { render_page }
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Comfy::CmsHelper
|
2
|
+
|
3
|
+
# Wrapper around ComfortableMexicanSofa::FormBuilder
|
4
|
+
def comfy_form_for(record, options = {}, &proc)
|
5
|
+
options[:builder] = ComfortableMexicanSofa::FormBuilder
|
6
|
+
options[:layout] ||= :horizontal
|
7
|
+
bootstrap_form_for(record, options, &proc)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Injects some content somewhere inside cms admin area
|
11
|
+
def cms_hook(name, options = {})
|
12
|
+
ComfortableMexicanSofa::ViewHooks.render(name, self, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Content of a snippet. Examples:
|
16
|
+
# cms_snippet_content(:my_snippet)
|
17
|
+
# <%= cms_snippet_content(:my_snippet) do %>
|
18
|
+
# Default content can go here.
|
19
|
+
# <% end %>
|
20
|
+
def cms_snippet_content(identifier, cms_site = @cms_site, &block)
|
21
|
+
unless cms_site
|
22
|
+
host, path = request.host.downcase, request.fullpath if respond_to?(:request) && request
|
23
|
+
cms_site = Comfy::Cms::Site.find_site(host, path)
|
24
|
+
end
|
25
|
+
return '' unless cms_site
|
26
|
+
|
27
|
+
snippet = cms_site.snippets.find_by_identifier(identifier)
|
28
|
+
|
29
|
+
if !snippet && block_given?
|
30
|
+
snippet = cms_site.snippets.create(
|
31
|
+
:identifier => identifier,
|
32
|
+
:label => identifier.to_s.titleize,
|
33
|
+
:content => capture(&block)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
snippet ? snippet.content : ''
|
38
|
+
end
|
39
|
+
|
40
|
+
# Same as cms_snippet_content but cms tags will be expanded
|
41
|
+
def cms_snippet_render(identifier, cms_site = @cms_site, &block)
|
42
|
+
return '' unless cms_site
|
43
|
+
content = cms_snippet_content(identifier, cms_site, &block)
|
44
|
+
render :inline => ComfortableMexicanSofa::Tag.process_content(
|
45
|
+
cms_site.pages.build, ComfortableMexicanSofa::Tag.sanitize_irb(content)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Content of a page block. This is how you get content from page:field
|
50
|
+
# Example:
|
51
|
+
# cms_block_content(:left_column, CmsPage.first)
|
52
|
+
# cms_block_content(:left_column) # if @cms_page is present
|
53
|
+
def cms_block_content(identifier, blockable = @cms_page)
|
54
|
+
tag = blockable && (block = blockable.blocks.find_by_identifier(identifier)) && block.tag
|
55
|
+
return '' unless tag
|
56
|
+
tag.content
|
57
|
+
end
|
58
|
+
|
59
|
+
# For those times when we need to render content that shouldn't be renderable
|
60
|
+
# Example: {{cms:field}} tags
|
61
|
+
def cms_block_content_render(identifier, blockable = @cms_page)
|
62
|
+
tag = blockable && (block = blockable.blocks.find_by_identifier(identifier)) && block.tag
|
63
|
+
return '' unless tag
|
64
|
+
render :inline => ComfortableMexicanSofa::Tag.process_content(blockable, tag.content)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Same as cms_block_content but with cms tags expanded
|
68
|
+
def cms_block_render(identifier, blockable = @cms_page)
|
69
|
+
tag = blockable && (block = blockable.blocks.find_by_identifier(identifier)) && block.tag
|
70
|
+
return '' unless tag
|
71
|
+
render :inline => ComfortableMexicanSofa::Tag.process_content(blockable, tag.render)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Wrapper to deal with Kaminari vs WillPaginate
|
75
|
+
def comfy_paginate(collection)
|
76
|
+
if defined?(WillPaginate)
|
77
|
+
will_paginate collection
|
78
|
+
elsif defined?(Kaminari)
|
79
|
+
paginate collection, :theme => 'comfy'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -1,45 +1,63 @@
|
|
1
1
|
class Comfy::Cms::Block < ActiveRecord::Base
|
2
2
|
self.table_name = 'comfy_cms_blocks'
|
3
|
-
|
3
|
+
|
4
|
+
FILE_CLASSES = %w(ActionDispatch::Http::UploadedFile Rack::Test::UploadedFile File).freeze
|
5
|
+
|
6
|
+
serialize :content
|
7
|
+
|
8
|
+
attr_accessor :temp_files
|
9
|
+
|
4
10
|
# -- Relationships --------------------------------------------------------
|
5
11
|
belongs_to :blockable,
|
6
12
|
:polymorphic => true
|
7
13
|
has_many :files,
|
8
|
-
:autosave
|
9
|
-
:dependent
|
10
|
-
|
11
|
-
# -- Callbacks ------------------------------------------------------------
|
12
|
-
before_save :prepare_files
|
13
|
-
|
14
|
+
:autosave => true,
|
15
|
+
:dependent => :destroy
|
16
|
+
|
14
17
|
# -- Validations ----------------------------------------------------------
|
15
18
|
validates :identifier,
|
16
19
|
:presence => true,
|
17
20
|
:uniqueness => { :scope => [:blockable_type, :blockable_id] }
|
18
|
-
|
21
|
+
|
22
|
+
# -- Callbacks ------------------------------------------------------------
|
23
|
+
before_save :prepare_files
|
24
|
+
|
19
25
|
# -- Instance Methods -----------------------------------------------------
|
20
26
|
# Tag object that is using this block
|
21
27
|
def tag
|
22
28
|
@tag ||= blockable.tags(:reload).detect{|t| t.is_cms_block? && t.identifier == identifier}
|
23
29
|
end
|
24
|
-
|
30
|
+
|
31
|
+
# Intercepting assigns as we can't cram files into content directly anymore
|
32
|
+
def content=(value)
|
33
|
+
self.temp_files = [value].flatten.select do |f|
|
34
|
+
FILE_CLASSES.member?(f.class.name)
|
35
|
+
end
|
36
|
+
|
37
|
+
# correctly triggering dirty
|
38
|
+
value = nil if self.temp_files.present?
|
39
|
+
write_attribute(:content, value)
|
40
|
+
self.content_will_change! if self.temp_files.present?
|
41
|
+
end
|
42
|
+
|
25
43
|
protected
|
26
|
-
|
44
|
+
|
45
|
+
# If we're passing actual files into content attribute, let's build them.
|
27
46
|
def prepare_files
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
return if temp_files.blank?
|
33
|
-
|
47
|
+
return if self.temp_files.blank?
|
48
|
+
|
34
49
|
# only accepting one file if it's PageFile. PageFiles will take all
|
35
50
|
single_file = self.tag.instance_of?(ComfortableMexicanSofa::Tag::PageFile)
|
36
|
-
temp_files = [temp_files.first].compact if single_file
|
37
|
-
|
38
|
-
temp_files.each do |file|
|
51
|
+
self.temp_files = [self.temp_files.first].compact if single_file
|
52
|
+
|
53
|
+
self.temp_files.each do |file|
|
39
54
|
self.files.collect{|f| f.mark_for_destruction } if single_file
|
40
|
-
|
55
|
+
|
56
|
+
self.files.build(
|
57
|
+
:site => self.blockable.site,
|
58
|
+
:dimensions => self.tag.try(:dimensions),
|
59
|
+
:file => file
|
60
|
+
)
|
41
61
|
end
|
42
|
-
|
43
|
-
self.content = nil unless self.content.is_a?(String)
|
44
62
|
end
|
45
63
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class Comfy::Cms::Page < ActiveRecord::Base
|
4
4
|
self.table_name = 'comfy_cms_pages'
|
5
|
-
|
5
|
+
|
6
6
|
cms_acts_as_tree :counter_cache => :children_count
|
7
7
|
cms_is_categorized
|
8
8
|
cms_is_mirrored
|
@@ -14,7 +14,7 @@ class Comfy::Cms::Page < ActiveRecord::Base
|
|
14
14
|
belongs_to :layout
|
15
15
|
belongs_to :target_page,
|
16
16
|
:class_name => 'Comfy::Cms::Page'
|
17
|
-
|
17
|
+
|
18
18
|
# -- Callbacks ------------------------------------------------------------
|
19
19
|
before_validation :assigns_label,
|
20
20
|
:assign_parent,
|
@@ -23,9 +23,9 @@ class Comfy::Cms::Page < ActiveRecord::Base
|
|
23
23
|
before_create :assign_position
|
24
24
|
after_save :sync_child_full_paths!
|
25
25
|
after_find :unescape_slug_and_path
|
26
|
-
|
26
|
+
|
27
27
|
# -- Validations ----------------------------------------------------------
|
28
|
-
validates :site_id,
|
28
|
+
validates :site_id,
|
29
29
|
:presence => true
|
30
30
|
validates :label,
|
31
31
|
:presence => true
|
@@ -37,11 +37,11 @@ class Comfy::Cms::Page < ActiveRecord::Base
|
|
37
37
|
:presence => true
|
38
38
|
validate :validate_target_page
|
39
39
|
validate :validate_format_of_unescaped_slug
|
40
|
-
|
40
|
+
|
41
41
|
# -- Scopes ---------------------------------------------------------------
|
42
42
|
default_scope -> { order('comfy_cms_pages.position') }
|
43
43
|
scope :published, -> { where(:is_published => true) }
|
44
|
-
|
44
|
+
|
45
45
|
# -- Class Methods --------------------------------------------------------
|
46
46
|
# Tree-like structure for pages
|
47
47
|
def self.options_for_select(site, page = nil, current_page = nil, depth = 0, exclude_self = true, spacer = '. . ')
|
@@ -51,49 +51,55 @@ class Comfy::Cms::Page < ActiveRecord::Base
|
|
51
51
|
current_page.children.each do |child|
|
52
52
|
out += options_for_select(site, page, child, depth + 1, exclude_self, spacer)
|
53
53
|
end if current_page.children_count.nonzero?
|
54
|
-
return out.compact
|
54
|
+
return out.compact
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# -- Instance Methods -----------------------------------------------------
|
58
58
|
# For previewing purposes sometimes we need to have full_path set. This
|
59
59
|
# full path take care of the pages and its childs but not of the site path
|
60
60
|
def full_path
|
61
61
|
self.read_attribute(:full_path) || self.assign_full_path
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
# Somewhat unique method of identifying a page that is not a full_path
|
65
65
|
def identifier
|
66
66
|
self.parent_id.blank?? 'index' : self.full_path[1..-1].slugify
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
# Full url for a page
|
70
|
-
def url
|
70
|
+
def url(relative = false)
|
71
71
|
public_cms_path = ComfortableMexicanSofa.config.public_cms_path || '/'
|
72
|
-
|
72
|
+
if relative
|
73
|
+
[public_cms_path, self.site.path, self.full_path].join('/').squeeze('/')
|
74
|
+
else
|
75
|
+
'//' + [self.site.hostname, public_cms_path, self.site.path, self.full_path].join('/').squeeze('/')
|
76
|
+
end
|
73
77
|
end
|
74
|
-
|
78
|
+
|
75
79
|
protected
|
76
|
-
|
80
|
+
|
77
81
|
def assigns_label
|
78
82
|
self.label = self.label.blank?? self.slug.try(:titleize) : self.label
|
79
83
|
end
|
80
|
-
|
84
|
+
|
81
85
|
def assign_parent
|
82
86
|
return unless site
|
83
87
|
self.parent ||= site.pages.root unless self == site.pages.root || site.pages.count == 0
|
84
88
|
end
|
85
|
-
|
89
|
+
|
86
90
|
def assign_full_path
|
87
|
-
self.full_path = self.parent ?
|
91
|
+
self.full_path = self.parent ?
|
92
|
+
[CGI::escape(self.parent.full_path).gsub('%2F', '/'), self.slug].join('/').squeeze('/') :
|
93
|
+
'/'
|
88
94
|
end
|
89
|
-
|
95
|
+
|
90
96
|
def assign_position
|
91
97
|
return unless self.parent
|
92
98
|
return if self.position.to_i > 0
|
93
99
|
max = self.parent.children.maximum(:position)
|
94
100
|
self.position = max ? max + 1 : 0
|
95
101
|
end
|
96
|
-
|
102
|
+
|
97
103
|
def validate_target_page
|
98
104
|
return unless self.target_page
|
99
105
|
p = self
|
@@ -101,13 +107,13 @@ protected
|
|
101
107
|
return self.errors.add(:target_page_id, 'Invalid Redirect') if (p = p.target_page) == self
|
102
108
|
end
|
103
109
|
end
|
104
|
-
|
110
|
+
|
105
111
|
def validate_format_of_unescaped_slug
|
106
112
|
return unless slug.present?
|
107
113
|
unescaped_slug = CGI::unescape(self.slug)
|
108
114
|
errors.add(:slug, :invalid) unless unescaped_slug =~ /^\p{Alnum}[\.\p{Alnum}\p{Mark}_-]*$/i
|
109
115
|
end
|
110
|
-
|
116
|
+
|
111
117
|
# Forcing re-saves for child pages so they can update full_paths
|
112
118
|
def sync_child_full_paths!
|
113
119
|
return unless full_path_changed?
|
@@ -127,5 +133,5 @@ protected
|
|
127
133
|
self.slug = CGI::unescape(self.slug) unless self.slug.nil?
|
128
134
|
self.full_path = CGI::unescape(self.full_path) unless self.full_path.nil?
|
129
135
|
end
|
130
|
-
|
136
|
+
|
131
137
|
end
|