refinerycms-pages 1.0.11 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/refinery/admin/page_parts_controller.rb +26 -0
- data/app/controllers/refinery/admin/pages_controller.rb +77 -0
- data/app/controllers/refinery/admin/pages_dialogs_controller.rb +91 -0
- data/app/controllers/refinery/page_sweeper.rb +29 -0
- data/app/controllers/refinery/pages_controller.rb +103 -0
- data/app/helpers/refinery/pages/content_pages_helper.rb +26 -0
- data/app/helpers/refinery/pages_helper.rb +4 -0
- data/app/models/refinery/page.rb +467 -0
- data/app/models/refinery/page_part.rb +33 -0
- data/app/presenters/refinery/page_presenter.rb +7 -0
- data/app/views/admin/pages/_sortable_list.html.erb +7 -4
- data/app/views/{admin → refinery/admin}/pages/_actions.html.erb +5 -4
- data/app/views/refinery/admin/pages/_form.html.erb +63 -0
- data/app/views/{admin → refinery/admin}/pages/_form_advanced_options.html.erb +35 -16
- data/app/views/refinery/admin/pages/_form_advanced_options_seo.html.erb +3 -0
- data/app/views/{admin → refinery/admin}/pages/_form_fields_after_title.html.erb +0 -0
- data/app/views/{admin → refinery/admin}/pages/_form_new_page_parts.html.erb +5 -7
- data/app/views/{admin → refinery/admin}/pages/_form_page_parts.html.erb +19 -11
- data/app/views/{admin → refinery/admin}/pages/_locale_picker.html.erb +3 -3
- data/app/views/refinery/admin/pages/_page.html.erb +48 -0
- data/app/views/{admin → refinery/admin}/pages/_page_part_field.html.erb +1 -1
- data/app/views/refinery/admin/pages/_records.html.erb +14 -0
- data/app/views/refinery/admin/pages/_sortable_list.html.erb +4 -0
- data/app/views/refinery/admin/pages/children.html.erb +1 -0
- data/app/views/refinery/admin/pages/edit.html.erb +1 -0
- data/app/views/refinery/admin/pages/index.html.erb +9 -0
- data/app/views/refinery/admin/pages/new.html.erb +1 -0
- data/app/views/refinery/admin/pages_dialogs/_page_link.html.erb +20 -0
- data/app/views/{admin → refinery/admin}/pages_dialogs/link_to.html.erb +31 -36
- data/app/views/refinery/pages/home.html.erb +1 -0
- data/app/views/refinery/pages/show.html.erb +1 -0
- data/config/locales/bg.yml +81 -73
- data/config/locales/cs.yml +71 -72
- data/config/locales/da.yml +69 -72
- data/config/locales/de.yml +69 -72
- data/config/locales/el.yml +70 -72
- data/config/locales/en.yml +88 -73
- data/config/locales/es.yml +70 -73
- data/config/locales/fi.yml +70 -73
- data/config/locales/fr.yml +69 -72
- data/config/locales/it.yml +92 -89
- data/config/locales/ja.yml +72 -0
- data/config/locales/ko.yml +83 -0
- data/config/locales/lt.yml +71 -73
- data/config/locales/lv.yml +71 -74
- data/config/locales/nb.yml +69 -72
- data/config/locales/nl.yml +68 -71
- data/config/locales/pl.yml +70 -73
- data/config/locales/pt-BR.yml +70 -73
- data/config/locales/pt-PT.yml +75 -0
- data/config/locales/rs.yml +69 -72
- data/config/locales/ru.yml +77 -96
- data/config/locales/sk.yml +69 -72
- data/config/locales/sl.yml +68 -71
- data/config/locales/sv.yml +69 -72
- data/config/locales/vi.yml +69 -72
- data/config/locales/zh-CN.yml +75 -72
- data/config/locales/zh-TW.yml +69 -72
- data/config/routes.rb +10 -5
- data/db/migrate/20100913234708_create_refinerycms_pages_schema.rb +49 -43
- data/db/seeds.rb +41 -0
- data/lib/generators/refinery/pages/pages_generator.rb +21 -0
- data/lib/generators/refinery/pages/templates/config/initializers/refinery/pages.rb.erb +44 -0
- data/lib/refinery/pages/admin/instance_methods.rb +10 -8
- data/lib/refinery/pages/configuration.rb +44 -0
- data/lib/refinery/pages/content_page_presenter.rb +33 -0
- data/lib/refinery/pages/content_presenter.rb +56 -0
- data/lib/refinery/pages/engine.rb +73 -0
- data/lib/refinery/pages/instance_methods.rb +12 -26
- data/lib/refinery/pages/page_part_section_presenter.rb +19 -0
- data/lib/refinery/pages/section_presenter.rb +69 -0
- data/lib/{pages/tabs.rb → refinery/pages/tab.rb} +0 -0
- data/lib/refinery/pages/title_section_presenter.rb +14 -0
- data/lib/refinery/pages/type.rb +17 -0
- data/lib/refinery/pages/types.rb +32 -0
- data/lib/refinery/pages.rb +55 -0
- data/lib/refinerycms-pages.rb +1 -61
- data/refinerycms-pages.gemspec +17 -118
- data/spec/factories/pages.rb +5 -0
- data/spec/helpers/refinery/pages/content_pages_helper_spec.rb +44 -0
- data/spec/lib/generators/refinery/pages/pages_generator_spec.rb +29 -0
- data/spec/lib/pages/content_page_presenter_spec.rb +43 -0
- data/spec/lib/pages/content_presenter_spec.rb +97 -0
- data/spec/lib/pages/page_part_section_presenter_spec.rb +35 -0
- data/spec/lib/pages/section_presenter_spec.rb +86 -0
- data/spec/lib/pages/title_section_presenter_spec.rb +21 -0
- data/spec/lib/pages_spec.rb +26 -0
- data/spec/models/refinery/page_spec.rb +415 -0
- data/spec/requests/refinery/admin/pages_spec.rb +581 -0
- data/spec/requests/refinery/pages_spec.rb +302 -0
- metadata +162 -153
- data/app/controllers/admin/page_parts_controller.rb +0 -24
- data/app/controllers/admin/pages_controller.rb +0 -68
- data/app/controllers/admin/pages_dialogs_controller.rb +0 -85
- data/app/controllers/pages_controller.rb +0 -33
- data/app/helpers/pages_helper.rb +0 -2
- data/app/models/page.rb +0 -391
- data/app/models/page_part.rb +0 -29
- data/app/presenters/page_presenter.rb +0 -7
- data/app/views/admin/pages/_form.html.erb +0 -61
- data/app/views/admin/pages/_form_advanced_options_seo.html.erb +0 -4
- data/app/views/admin/pages/_page.html.erb +0 -33
- data/app/views/admin/pages/_records.html.erb +0 -14
- data/app/views/admin/pages/edit.html.erb +0 -1
- data/app/views/admin/pages/index.html.erb +0 -11
- data/app/views/admin/pages/new.html.erb +0 -1
- data/app/views/admin/pages_dialogs/_page_link.html.erb +0 -14
- data/app/views/pages/home.html.erb +0 -1
- data/app/views/pages/show.html.erb +0 -1
- data/config/locales/jp.yml +0 -75
- data/config/locales/lolcat.yml +0 -76
- data/db/migrate/20101214040815_translate_page_plugin.rb +0 -29
- data/db/migrate/20101216194133_remove_cached_slug_from_pages.rb +0 -11
- data/db/migrate/20110307025652_translate_custom_title_on_pages.rb +0 -26
- data/db/migrate/20110314213540_remove_translated_fields_from_pages.rb +0 -13
- data/db/migrate/20110329080451_create_seo_meta.rb +0 -89
- data/db/seeds/pages.rb +0 -42
- data/features/manage_pages.feature +0 -48
- data/features/step_definitions/page_steps.rb +0 -72
- data/features/support/paths.rb +0 -28
- data/features/translate_pages.feature +0 -40
- data/features/visit_pages.feature +0 -68
- data/lib/gemspec.rb +0 -40
- data/lib/generators/refinerycms_pages_generator.rb +0 -8
- data/lib/pages/marketable_routes.rb +0 -12
- data/spec/models/page_spec.rb +0 -235
@@ -1,24 +0,0 @@
|
|
1
|
-
module Admin
|
2
|
-
class PagePartsController < Admin::BaseController
|
3
|
-
|
4
|
-
def new
|
5
|
-
render :partial => "/admin/pages/page_part_field", :locals => {
|
6
|
-
:part => PagePart.new(:title => params[:title], :body => params[:body]),
|
7
|
-
:new_part => true,
|
8
|
-
:part_index => params[:part_index]
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
def destroy
|
13
|
-
part = PagePart.find(params[:id])
|
14
|
-
page = part.page
|
15
|
-
if part.destroy
|
16
|
-
page.reposition_parts!
|
17
|
-
render :text => "'#{part.title}' deleted."
|
18
|
-
else
|
19
|
-
render :text => "'#{part.title}' not deleted."
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module Admin
|
2
|
-
class PagesController < Admin::BaseController
|
3
|
-
|
4
|
-
crudify :page,
|
5
|
-
:conditions => nil,
|
6
|
-
:order => "lft ASC",
|
7
|
-
:include => [:slugs, :translations, :children],
|
8
|
-
:paging => false
|
9
|
-
|
10
|
-
rescue_from FriendlyId::ReservedError, :with => :show_errors_for_reserved_slug
|
11
|
-
|
12
|
-
after_filter lambda{::Page.expire_page_caching}, :only => [:update_positions]
|
13
|
-
|
14
|
-
before_filter :restrict_access, :only => [:create, :update, :update_positions, :destroy], :if => proc {|c|
|
15
|
-
::Refinery.i18n_enabled?
|
16
|
-
}
|
17
|
-
|
18
|
-
def new
|
19
|
-
@page = Page.new
|
20
|
-
Page.default_parts.each_with_index do |page_part, index|
|
21
|
-
@page.parts << PagePart.new(:title => page_part, :position => index)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
protected
|
26
|
-
|
27
|
-
# We can safely assume Refinery::I18n is defined because this method only gets
|
28
|
-
# Invoked when the before_filter from the plugin is run.
|
29
|
-
def globalize!
|
30
|
-
unless action_name.to_s == 'index'
|
31
|
-
super
|
32
|
-
|
33
|
-
# Check whether we need to override e.g. on the pages form.
|
34
|
-
unless params[:switch_locale] || @page.nil? || @page.new_record? || @page.slugs.where({
|
35
|
-
:locale => Refinery::I18n.current_locale
|
36
|
-
}).nil?
|
37
|
-
@page.slug = @page.slugs.first if @page.slug.nil? && @page.slugs.any?
|
38
|
-
Thread.current[:globalize_locale] = @page.slug.locale if @page.slug
|
39
|
-
end
|
40
|
-
else
|
41
|
-
# Always display the tree of pages from the default frontend locale.
|
42
|
-
Thread.current[:globalize_locale] = params[:switch_locale].try(:to_sym) || ::Refinery::I18n.default_frontend_locale
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def show_errors_for_reserved_slug(exception)
|
47
|
-
flash[:error] = t('reserved_system_word', :scope => 'admin.pages')
|
48
|
-
if action_name == 'update'
|
49
|
-
find_page
|
50
|
-
render :edit
|
51
|
-
else
|
52
|
-
@page = Page.new(params[:page])
|
53
|
-
render :new
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def restrict_access
|
58
|
-
if current_user.has_role?(:translator) && !current_user.has_role?(:superuser) &&
|
59
|
-
(params[:switch_locale].blank? || params[:switch_locale] == ::Refinery::I18n.default_frontend_locale.to_s)
|
60
|
-
flash[:error] = t('translator_access', :scope => 'admin.pages')
|
61
|
-
redirect_to :action => 'index' and return
|
62
|
-
end
|
63
|
-
|
64
|
-
return true
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
|
3
|
-
module Admin
|
4
|
-
class PagesDialogsController < Admin::DialogsController
|
5
|
-
|
6
|
-
def link_to
|
7
|
-
@pages = Page.paginate :page => params[:page],
|
8
|
-
:conditions => {:parent_id => nil},
|
9
|
-
:order => 'position ASC',
|
10
|
-
:per_page => Page.per_page(dialog=true)
|
11
|
-
|
12
|
-
if ::Refinery::Plugins.registered.names.include?('refinery_files')
|
13
|
-
@resources = Resource.paginate :page => params[:resource_page],
|
14
|
-
:order => 'created_at DESC',
|
15
|
-
:per_page => Resource.per_page(dialog=true)
|
16
|
-
|
17
|
-
# resource link
|
18
|
-
if params[:current_link].present?
|
19
|
-
is_resource_link = params[:current_link].include?("/system/resources")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# web address link
|
24
|
-
@web_address_text = "http://"
|
25
|
-
@web_address_text = params[:current_link] if params[:current_link].to_s =~ /^http:\/\//
|
26
|
-
@web_address_target_blank = (params[:target_blank] == "true")
|
27
|
-
|
28
|
-
# mailto link
|
29
|
-
if params[:current_link].present?
|
30
|
-
if params[:current_link] =~ /^mailto:/
|
31
|
-
@email_address_text = params[:current_link].split("mailto:")[1].split('?')[0]
|
32
|
-
end
|
33
|
-
@email_default_subject_text = params[:current_link].split('?subject=')[1] || params[:subject]
|
34
|
-
@email_default_body_text = params[:current_link].split('?body=')[1] || params[:body]
|
35
|
-
end
|
36
|
-
|
37
|
-
if params[:paginating].present?
|
38
|
-
@page_area_selected = (params[:paginating] == "your_page")
|
39
|
-
@resource_area_selected = (params[:paginating] == "resource_file")
|
40
|
-
else
|
41
|
-
@page_area_selected = (!is_resource_link and @web_address_text == "http://" and @email_address_text.blank?)
|
42
|
-
@web_address_area_selected = (@web_address_text != "http://")
|
43
|
-
@email_address_area_selected = @email_address_text.present?
|
44
|
-
@resource_area_selected = is_resource_link
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_url
|
49
|
-
begin
|
50
|
-
timeout(5) do
|
51
|
-
unless params[:url].blank?
|
52
|
-
url = URI.parse(params[:url])
|
53
|
-
if url.host.nil? && params[:url].start_with?('/')
|
54
|
-
url.host = URI.parse(request.url).host
|
55
|
-
end
|
56
|
-
|
57
|
-
result = case Net::HTTP.get_response(url)
|
58
|
-
when Net::HTTPSuccess, Net::HTTPRedirection
|
59
|
-
'success'
|
60
|
-
else
|
61
|
-
'failure'
|
62
|
-
end
|
63
|
-
|
64
|
-
render :json => {:result => result}
|
65
|
-
end
|
66
|
-
end
|
67
|
-
rescue
|
68
|
-
render :json => {:result => 'failure'}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_email
|
73
|
-
unless params[:email].blank?
|
74
|
-
valid = params[:email] =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
75
|
-
|
76
|
-
render :json => if valid
|
77
|
-
{:result => 'success'}
|
78
|
-
else
|
79
|
-
{:result => 'failure'}
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
class PagesController < ApplicationController
|
2
|
-
|
3
|
-
# This action is usually accessed with the root path, normally '/'
|
4
|
-
def home
|
5
|
-
error_404 unless (@page = Page.where(:link_url => '/').first).present?
|
6
|
-
end
|
7
|
-
|
8
|
-
# This action can be accessed normally, or as nested pages.
|
9
|
-
# Assuming a page named "mission" that is a child of "about",
|
10
|
-
# you can access the pages with the following URLs:
|
11
|
-
#
|
12
|
-
# GET /pages/about
|
13
|
-
# GET /about
|
14
|
-
#
|
15
|
-
# GET /pages/mission
|
16
|
-
# GET /about/mission
|
17
|
-
#
|
18
|
-
def show
|
19
|
-
@page = Page.find("#{params[:path]}/#{params[:id]}".split('/').last)
|
20
|
-
|
21
|
-
if @page.try(:live?) || (refinery_user? && current_user.authorized_plugins.include?("refinery_pages"))
|
22
|
-
# if the admin wants this to be a "placeholder" page which goes to its first child, go to that instead.
|
23
|
-
if @page.skip_to_first_child && (first_live_child = @page.children.order('lft ASC').live.first).present?
|
24
|
-
redirect_to first_live_child.url and return
|
25
|
-
elsif @page.link_url.present?
|
26
|
-
redirect_to @page.link_url and return
|
27
|
-
end
|
28
|
-
else
|
29
|
-
error_404
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
data/app/helpers/pages_helper.rb
DELETED
data/app/models/page.rb
DELETED
@@ -1,391 +0,0 @@
|
|
1
|
-
require 'globalize3'
|
2
|
-
|
3
|
-
class Page < ActiveRecord::Base
|
4
|
-
|
5
|
-
# when a dialog pops up to link to a page, how many pages per page should there be
|
6
|
-
PAGES_PER_DIALOG = 14
|
7
|
-
|
8
|
-
# when listing pages out in the admin area, how many pages should show per page
|
9
|
-
PAGES_PER_ADMIN_INDEX = 20
|
10
|
-
|
11
|
-
# when collecting the pages path how is each of the pages seperated?
|
12
|
-
PATH_SEPARATOR = " - "
|
13
|
-
|
14
|
-
if self.respond_to?(:translates)
|
15
|
-
translates :title, :custom_title, :meta_keywords, :meta_description, :browser_title, :include => :seo_meta
|
16
|
-
|
17
|
-
# Set up support for meta tags through translations.
|
18
|
-
if defined?(::Page::Translation)
|
19
|
-
attr_accessible :title
|
20
|
-
# set allowed attributes for mass assignment
|
21
|
-
::Page::Translation.send :attr_accessible, :browser_title, :meta_description,
|
22
|
-
:meta_keywords, :locale
|
23
|
-
|
24
|
-
if ::Page::Translation.table_exists?
|
25
|
-
# Instruct the Translation model to have meta tags.
|
26
|
-
::Page::Translation.send :is_seo_meta
|
27
|
-
|
28
|
-
fields = ::SeoMeta.attributes.keys.reject{|f|
|
29
|
-
self.column_names.map(&:to_sym).include?(f)
|
30
|
-
}.map{|a| [a, :"#{a}="]}.flatten
|
31
|
-
delegate *(fields << {:to => :translation})
|
32
|
-
before_save {|m| m.translation.save}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
before_create :ensure_locale, :if => proc { |c|
|
37
|
-
::Refinery.i18n_enabled?
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
attr_accessible :id, :deletable, :link_url, :menu_match, :meta_keywords,
|
42
|
-
:skip_to_first_child, :position, :show_in_menu, :draft,
|
43
|
-
:parts_attributes, :browser_title, :meta_description,
|
44
|
-
:custom_title_type, :parent_id, :custom_title,
|
45
|
-
:created_at, :updated_at, :page_id
|
46
|
-
|
47
|
-
attr_accessor :locale # to hold temporarily
|
48
|
-
validates :title, :presence => true
|
49
|
-
|
50
|
-
# Docs for acts_as_nested_set https://github.com/collectiveidea/awesome_nested_set
|
51
|
-
acts_as_nested_set :dependent => :destroy # rather than :delete_all
|
52
|
-
|
53
|
-
# Docs for friendly_id http://github.com/norman/friendly_id
|
54
|
-
has_friendly_id :title, :use_slug => true,
|
55
|
-
:default_locale => (::Refinery::I18n.default_frontend_locale rescue :en),
|
56
|
-
:reserved_words => %w(index new session login logout users refinery admin images wymiframe),
|
57
|
-
:approximate_ascii => RefinerySetting.find_or_set(:approximate_ascii, false, :scoping => "pages"),
|
58
|
-
:strip_non_ascii => RefinerySetting.find_or_set(:strip_non_ascii, false, :scoping => "pages")
|
59
|
-
|
60
|
-
has_many :parts,
|
61
|
-
:class_name => "PagePart",
|
62
|
-
:order => "position ASC",
|
63
|
-
:inverse_of => :page,
|
64
|
-
:dependent => :destroy,
|
65
|
-
:include => ((:translations) if defined?(::PagePart::Translation))
|
66
|
-
|
67
|
-
accepts_nested_attributes_for :parts, :allow_destroy => true
|
68
|
-
|
69
|
-
# Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
|
70
|
-
acts_as_indexed :fields => [:title, :meta_keywords, :meta_description,
|
71
|
-
:custom_title, :browser_title, :all_page_part_content]
|
72
|
-
|
73
|
-
before_destroy :deletable?
|
74
|
-
after_save :reposition_parts!, :invalidate_cached_urls, :expire_page_caching
|
75
|
-
after_destroy :expire_page_caching
|
76
|
-
|
77
|
-
# Wrap up the logic of finding the pages based on the translations table.
|
78
|
-
if defined?(::Page::Translation)
|
79
|
-
def self.with_globalize(conditions = {})
|
80
|
-
conditions = {:locale => Globalize.locale}.merge(conditions)
|
81
|
-
globalized_conditions = {}
|
82
|
-
conditions.keys.each do |key|
|
83
|
-
if (translated_attribute_names.map(&:to_s) | %w(locale)).include?(key.to_s)
|
84
|
-
globalized_conditions["#{self.translation_class.table_name}.#{key}"] = conditions.delete(key)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
# A join implies readonly which we don't really want.
|
88
|
-
joins(:translations).where(globalized_conditions).where(conditions).readonly(false)
|
89
|
-
end
|
90
|
-
else
|
91
|
-
def self.with_globalize(conditions = {})
|
92
|
-
where(conditions)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
scope :live, where(:draft => false)
|
97
|
-
scope :by_title, proc {|t| with_globalize(:title => t)}
|
98
|
-
|
99
|
-
# Shows all pages with :show_in_menu set to true, but it also
|
100
|
-
# rejects any page that has not been translated to the current locale.
|
101
|
-
# This works using a query against the translated content first and then
|
102
|
-
# using all of the page_ids we further filter against this model's table.
|
103
|
-
scope :in_menu, proc { where(:show_in_menu => true).with_globalize }
|
104
|
-
|
105
|
-
# Am I allowed to delete this page?
|
106
|
-
# If a link_url is set we don't want to break the link so we don't allow them to delete
|
107
|
-
# If deletable is set to false then we don't allow this page to be deleted. These are often Refinery system pages
|
108
|
-
def deletable?
|
109
|
-
deletable && link_url.blank? and menu_match.blank?
|
110
|
-
end
|
111
|
-
|
112
|
-
# Repositions the child page_parts that belong to this page.
|
113
|
-
# This ensures that they are in the correct 0,1,2,3,4... etc order.
|
114
|
-
def reposition_parts!
|
115
|
-
parts.each_with_index do |part, index|
|
116
|
-
part.update_attribute(:position, index)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# Before destroying a page we check to see if it's a deletable page or not
|
121
|
-
# Refinery system pages are not deletable.
|
122
|
-
def destroy
|
123
|
-
return super if deletable?
|
124
|
-
|
125
|
-
unless Rails.env.test?
|
126
|
-
# give useful feedback when trying to delete from console
|
127
|
-
puts "This page is not deletable. Please use .destroy! if you really want it deleted "
|
128
|
-
puts "unset .link_url," if link_url.present?
|
129
|
-
puts "unset .menu_match," if menu_match.present?
|
130
|
-
puts "set .deletable to true" unless deletable
|
131
|
-
end
|
132
|
-
|
133
|
-
return false
|
134
|
-
end
|
135
|
-
|
136
|
-
# If you want to destroy a page that is set to be not deletable this is the way to do it.
|
137
|
-
def destroy!
|
138
|
-
self.menu_match = nil
|
139
|
-
self.link_url = nil
|
140
|
-
self.deletable = true
|
141
|
-
|
142
|
-
destroy
|
143
|
-
end
|
144
|
-
|
145
|
-
# Used for the browser title to get the full path to this page
|
146
|
-
# It automatically prints out this page title and all of it's parent page titles joined by a PATH_SEPARATOR
|
147
|
-
def path(options = {})
|
148
|
-
# Override default options with any supplied.
|
149
|
-
options = {:reversed => true}.merge(options)
|
150
|
-
|
151
|
-
unless parent_id.nil?
|
152
|
-
parts = [title, parent.path(options)]
|
153
|
-
parts.reverse! if options[:reversed]
|
154
|
-
parts.join(PATH_SEPARATOR)
|
155
|
-
else
|
156
|
-
title
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# When this page is rendered in the navigation, where should it link?
|
161
|
-
# If a custom "link_url" is set, it uses that otherwise it defaults to a normal page URL.
|
162
|
-
# The "link_url" is often used to link to a plugin rather than a page.
|
163
|
-
#
|
164
|
-
# For example if I had a "Contact" page I don't want it to just render a contact us page
|
165
|
-
# I want it to show the Inquiries form so I can collect inquiries. So I would set the "link_url"
|
166
|
-
# to "/contact"
|
167
|
-
def url
|
168
|
-
if link_url.present?
|
169
|
-
link_url_localised?
|
170
|
-
elsif self.class.use_marketable_urls?
|
171
|
-
with_locale_param url_marketable
|
172
|
-
elsif to_param.present?
|
173
|
-
with_locale_param url_normal
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def link_url_localised?
|
178
|
-
return link_url unless ::Refinery.i18n_enabled?
|
179
|
-
|
180
|
-
current_url = link_url
|
181
|
-
|
182
|
-
if current_url =~ %r{^/} && ::Refinery::I18n.current_frontend_locale != ::Refinery::I18n.default_frontend_locale
|
183
|
-
current_url = "/#{::Refinery::I18n.current_frontend_locale}#{current_url}"
|
184
|
-
end
|
185
|
-
|
186
|
-
current_url
|
187
|
-
end
|
188
|
-
|
189
|
-
def url_marketable
|
190
|
-
# :id => nil is important to prevent any other params[:id] from interfering with this route.
|
191
|
-
url_normal.merge(:path => nested_url, :id => nil)
|
192
|
-
end
|
193
|
-
|
194
|
-
def url_normal
|
195
|
-
{:controller => '/pages', :action => 'show', :path => nil, :id => to_param}
|
196
|
-
end
|
197
|
-
|
198
|
-
def with_locale_param(url_hash)
|
199
|
-
if self.class.different_frontend_locale?
|
200
|
-
url_hash.update(:locale => ::Refinery::I18n.current_frontend_locale)
|
201
|
-
end
|
202
|
-
url_hash
|
203
|
-
end
|
204
|
-
|
205
|
-
# Returns an array with all ancestors to_param, allow with its own
|
206
|
-
# Ex: with an About page and a Mission underneath,
|
207
|
-
# Page.find('mission').nested_url would return:
|
208
|
-
#
|
209
|
-
# ['about', 'mission']
|
210
|
-
#
|
211
|
-
def nested_url
|
212
|
-
Rails.cache.fetch(url_cache_key) { uncached_nested_url }
|
213
|
-
end
|
214
|
-
|
215
|
-
def uncached_nested_url
|
216
|
-
[parent.try(:nested_url), to_param].compact.flatten
|
217
|
-
end
|
218
|
-
|
219
|
-
# Returns the string version of nested_url, i.e., the path that should be generated
|
220
|
-
# by the router
|
221
|
-
def nested_path
|
222
|
-
Rails.cache.fetch(path_cache_key) { ['', nested_url].join('/') }
|
223
|
-
end
|
224
|
-
|
225
|
-
def path_cache_key
|
226
|
-
[cache_key, 'nested_path'].join('#')
|
227
|
-
end
|
228
|
-
|
229
|
-
def url_cache_key
|
230
|
-
[cache_key, 'nested_url'].join('#')
|
231
|
-
end
|
232
|
-
|
233
|
-
def cache_key
|
234
|
-
[Refinery.base_cache_key, ::I18n.locale, to_param].compact.join('/')
|
235
|
-
end
|
236
|
-
|
237
|
-
# Returns true if this page is "published"
|
238
|
-
def live?
|
239
|
-
not draft?
|
240
|
-
end
|
241
|
-
|
242
|
-
# Return true if this page can be shown in the navigation.
|
243
|
-
# If it's a draft or is set to not show in the menu it will return false.
|
244
|
-
def in_menu?
|
245
|
-
live? && show_in_menu?
|
246
|
-
end
|
247
|
-
|
248
|
-
def not_in_menu?
|
249
|
-
not in_menu?
|
250
|
-
end
|
251
|
-
|
252
|
-
# Returns true if this page is the home page or links to it.
|
253
|
-
def home?
|
254
|
-
link_url == '/'
|
255
|
-
end
|
256
|
-
|
257
|
-
# Returns all visible sibling pages that can be rendered for the menu
|
258
|
-
def shown_siblings
|
259
|
-
siblings.reject(&:not_in_menu?)
|
260
|
-
end
|
261
|
-
|
262
|
-
def to_refinery_menu_item
|
263
|
-
{
|
264
|
-
:id => id,
|
265
|
-
:lft => lft,
|
266
|
-
:menu_match => menu_match,
|
267
|
-
:parent_id => parent_id,
|
268
|
-
:rgt => rgt,
|
269
|
-
:title => (page_title if respond_to?(:page_title)) || title,
|
270
|
-
:type => self.class.name,
|
271
|
-
:url => url
|
272
|
-
}
|
273
|
-
end
|
274
|
-
|
275
|
-
class << self
|
276
|
-
# Accessor to find out the default page parts created for each new page
|
277
|
-
def default_parts
|
278
|
-
RefinerySetting.find_or_set(:default_page_parts, ["Body", "Side Body"])
|
279
|
-
end
|
280
|
-
|
281
|
-
# Wraps up all the checks that we need to do to figure out whether
|
282
|
-
# the current frontend locale is different to the current one set by ::I18n.locale.
|
283
|
-
# This terminates in a false if i18n engine is not defined or enabled.
|
284
|
-
def different_frontend_locale?
|
285
|
-
::Refinery.i18n_enabled? && ::Refinery::I18n.current_frontend_locale != ::I18n.locale
|
286
|
-
end
|
287
|
-
|
288
|
-
# Returns how many pages per page should there be when paginating pages
|
289
|
-
def per_page(dialog = false)
|
290
|
-
dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX
|
291
|
-
end
|
292
|
-
|
293
|
-
def use_marketable_urls?
|
294
|
-
RefinerySetting.find_or_set(:use_marketable_urls, true, :scoping => 'pages')
|
295
|
-
end
|
296
|
-
|
297
|
-
def expire_page_caching
|
298
|
-
begin
|
299
|
-
Rails.cache.delete_matched(/.*pages.*/)
|
300
|
-
rescue NotImplementedError
|
301
|
-
Rails.cache.clear
|
302
|
-
warn "**** [REFINERY] The cache store you are using is not compatible with Rails.cache#delete_matched - clearing entire cache instead ***"
|
303
|
-
end
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
# Accessor method to get a page part from a page.
|
308
|
-
# Example:
|
309
|
-
#
|
310
|
-
# Page.first.content_for(:body)
|
311
|
-
#
|
312
|
-
# Will return the body page part of the first page.
|
313
|
-
def content_for(part_title)
|
314
|
-
part = self.parts.detect do |part|
|
315
|
-
part.title.present? and #protecting against the problem that occurs when have nil title
|
316
|
-
part.title == part_title.to_s or
|
317
|
-
part.title.downcase.gsub(" ", "_") == part_title.to_s.downcase.gsub(" ", "_")
|
318
|
-
end
|
319
|
-
|
320
|
-
part.try(:body)
|
321
|
-
end
|
322
|
-
|
323
|
-
def [](part_title)
|
324
|
-
# Allow for calling attributes with [] shorthand (eg page[:parent_id])
|
325
|
-
return super if self.respond_to?(part_title.to_s.to_sym) or self.attributes.has_key?(part_title.to_s)
|
326
|
-
|
327
|
-
Refinery.deprecate({
|
328
|
-
:what => "page[#{part_title.inspect}]",
|
329
|
-
:when => '1.1',
|
330
|
-
:replacement => "page.content_for(#{part_title.inspect})",
|
331
|
-
:caller => caller
|
332
|
-
})
|
333
|
-
|
334
|
-
content_for(part_title)
|
335
|
-
end
|
336
|
-
|
337
|
-
# In the admin area we use a slightly different title to inform the which pages are draft or hidden pages
|
338
|
-
def title_with_meta
|
339
|
-
title = if self.title.nil?
|
340
|
-
[::Page::Translation.where(:page_id => self.id, :locale => Globalize.locale).first.try(:title).to_s]
|
341
|
-
else
|
342
|
-
[self.title.to_s]
|
343
|
-
end
|
344
|
-
|
345
|
-
title << "<em>(#{::I18n.t('hidden', :scope => 'admin.pages.page')})</em>" unless show_in_menu?
|
346
|
-
title << "<em>(#{::I18n.t('draft', :scope => 'admin.pages.page')})</em>" if draft?
|
347
|
-
|
348
|
-
title.join(' ')
|
349
|
-
end
|
350
|
-
|
351
|
-
# Used to index all the content on this page so it can be easily searched.
|
352
|
-
def all_page_part_content
|
353
|
-
parts.collect {|p| p.body}.join(" ")
|
354
|
-
end
|
355
|
-
|
356
|
-
##
|
357
|
-
# Protects generated slugs from title if they are in the list of reserved words
|
358
|
-
# This applies mostly to plugin-generated pages.
|
359
|
-
#
|
360
|
-
# Returns the sluggified string
|
361
|
-
def normalize_friendly_id(slug_string)
|
362
|
-
slug_string.gsub!('_', '-')
|
363
|
-
sluggified = super
|
364
|
-
if self.class.use_marketable_urls? && self.class.friendly_id_config.reserved_words.include?(sluggified)
|
365
|
-
sluggified << "-page"
|
366
|
-
end
|
367
|
-
sluggified
|
368
|
-
end
|
369
|
-
|
370
|
-
private
|
371
|
-
|
372
|
-
def invalidate_cached_urls
|
373
|
-
return true unless self.class.use_marketable_urls?
|
374
|
-
|
375
|
-
[self, children].flatten.each do |page|
|
376
|
-
Rails.cache.delete(page.url_cache_key)
|
377
|
-
Rails.cache.delete(page.path_cache_key)
|
378
|
-
end
|
379
|
-
end
|
380
|
-
alias_method :invalidate_child_cached_url, :invalidate_cached_urls
|
381
|
-
|
382
|
-
def ensure_locale
|
383
|
-
unless self.translations.present?
|
384
|
-
self.translations.build :locale => ::Refinery::I18n.default_frontend_locale
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
def expire_page_caching
|
389
|
-
self.class.expire_page_caching
|
390
|
-
end
|
391
|
-
end
|
data/app/models/page_part.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
class PagePart < ActiveRecord::Base
|
2
|
-
|
3
|
-
attr_accessible :title, :content, :position, :body, :created_at,
|
4
|
-
:updated_at, :page_id
|
5
|
-
belongs_to :page
|
6
|
-
|
7
|
-
validates :title, :presence => true
|
8
|
-
alias_attribute :content, :body
|
9
|
-
|
10
|
-
translates :body if respond_to?(:translates)
|
11
|
-
|
12
|
-
def to_param
|
13
|
-
"page_part_#{title.downcase.gsub(/\W/, '_')}"
|
14
|
-
end
|
15
|
-
|
16
|
-
before_save :normalise_text_fields
|
17
|
-
if defined?(::PagePart::Translation)
|
18
|
-
::PagePart::Translation.module_eval do
|
19
|
-
attr_accessible :locale
|
20
|
-
end
|
21
|
-
end
|
22
|
-
protected
|
23
|
-
def normalise_text_fields
|
24
|
-
unless body.blank? or body =~ /^\</
|
25
|
-
self.body = "<p>#{body.gsub("\r\n\r\n", "</p><p>").gsub("\r\n", "<br/>")}</p>"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|