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
@@ -0,0 +1,26 @@
|
|
1
|
+
module ::Refinery
|
2
|
+
module Admin
|
3
|
+
class PagePartsController < ::Refinery::AdminController
|
4
|
+
|
5
|
+
def new
|
6
|
+
render :partial => '/refinery/admin/pages/page_part_field', :locals => {
|
7
|
+
:part => ::Refinery::PagePart.new(:title => params[:title], :body => params[:body]),
|
8
|
+
:new_part => true,
|
9
|
+
:part_index => params[:part_index]
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def destroy
|
14
|
+
part = ::Refinery::PagePart.find(params[:id])
|
15
|
+
page = part.page
|
16
|
+
if part.destroy
|
17
|
+
page.reposition_parts!
|
18
|
+
render :text => "'#{part.title}' deleted."
|
19
|
+
else
|
20
|
+
render :text => "'#{part.title}' not deleted."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Admin
|
3
|
+
class PagesController < Refinery::AdminController
|
4
|
+
cache_sweeper Refinery::PageSweeper
|
5
|
+
|
6
|
+
crudify :'refinery/page',
|
7
|
+
:order => "lft ASC",
|
8
|
+
:include => [:translations, :children],
|
9
|
+
:paging => false
|
10
|
+
|
11
|
+
after_filter lambda{::Refinery::Page.expire_page_caching}, :only => [:update_positions]
|
12
|
+
|
13
|
+
before_filter :load_valid_templates, :only => [:edit, :new]
|
14
|
+
|
15
|
+
before_filter :restrict_access, :only => [:create, :update, :update_positions, :destroy],
|
16
|
+
:if => proc { Refinery.i18n_enabled? }
|
17
|
+
|
18
|
+
def new
|
19
|
+
@page = Refinery::Page.new(params.except(:controller, :action, :switch_locale))
|
20
|
+
Refinery::Pages.default_parts_for(@page).each_with_index do |page_part, index|
|
21
|
+
@page.parts << Refinery::PagePart.new(:title => page_part, :position => index)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def children
|
26
|
+
@page = find_page
|
27
|
+
render :layout => false
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def find_page
|
33
|
+
@page = Refinery::Page.find_by_path_or_id(params[:path], params[:id])
|
34
|
+
end
|
35
|
+
alias_method :page, :find_page
|
36
|
+
|
37
|
+
# We can safely assume ::Refinery::I18n is defined because this method only gets
|
38
|
+
# Invoked when the before_filter from the plugin is run.
|
39
|
+
def globalize!
|
40
|
+
unless action_name.to_s == 'index'
|
41
|
+
super
|
42
|
+
|
43
|
+
# Needs to take into account that slugs are translated now
|
44
|
+
# # Check whether we need to override e.g. on the pages form.
|
45
|
+
# unless params[:switch_locale] || @page.nil? || @page.new_record? || @page.slugs.where({
|
46
|
+
# :locale => Refinery::I18n.current_locale
|
47
|
+
# }).empty?
|
48
|
+
# @page.slug = @page.slugs.first if @page.slug.nil? && @page.slugs.any?
|
49
|
+
# Thread.current[:globalize_locale] = @page.slug.locale if @page.slug
|
50
|
+
# end
|
51
|
+
else
|
52
|
+
# Always display the tree of pages from the default frontend locale.
|
53
|
+
Thread.current[:globalize_locale] = params[:switch_locale].try(:to_sym) || Refinery::I18n.default_frontend_locale
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_valid_templates
|
58
|
+
@valid_layout_templates = Refinery::Pages.layout_template_whitelist &
|
59
|
+
Refinery::Pages.valid_templates('app', 'views', '{layouts,refinery/layouts}', '*html*')
|
60
|
+
|
61
|
+
@valid_view_templates = Refinery::Pages.view_template_whitelist &
|
62
|
+
Refinery::Pages.valid_templates('app', 'views', '{pages,refinery/pages}', '*html*')
|
63
|
+
end
|
64
|
+
|
65
|
+
def restrict_access
|
66
|
+
if current_refinery_user.has_role?(:translator) && !current_refinery_user.has_role?(:superuser) &&
|
67
|
+
(params[:switch_locale].blank? || params[:switch_locale] == Refinery::I18n.default_frontend_locale.to_s)
|
68
|
+
flash[:error] = t('translator_access', :scope => 'refinery.admin.pages')
|
69
|
+
redirect_to refinery.admin_pages_path
|
70
|
+
end
|
71
|
+
|
72
|
+
return true
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module ::Refinery
|
4
|
+
module Admin
|
5
|
+
class PagesDialogsController < ::Refinery::Admin::DialogsController
|
6
|
+
|
7
|
+
def link_to
|
8
|
+
# Get the switch_local variable to determine the locale we're currently editing
|
9
|
+
# Set up Globalize with our current locale
|
10
|
+
if ::Refinery.i18n_enabled?
|
11
|
+
Thread.current[:globalize_locale] = params[:switch_locale] || Refinery::I18n.default_locale
|
12
|
+
end
|
13
|
+
|
14
|
+
@pages = ::Refinery::Page.roots.paginate(:page => params[:page], :per_page => ::Refinery::Page.per_page(true))
|
15
|
+
|
16
|
+
@pages = @pages.with_globalize if ::Refinery.i18n_enabled?
|
17
|
+
|
18
|
+
if ::Refinery::Plugins.registered.names.include?('refinery_files')
|
19
|
+
@resources = Resource.paginate(:page => params[:resource_page], :per_page => Resource.per_page(true)).
|
20
|
+
order('created_at DESC')
|
21
|
+
|
22
|
+
# resource link
|
23
|
+
if params[:current_link].present?
|
24
|
+
is_resource_link = params[:current_link].include?("/system/resources")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# web address link
|
29
|
+
@web_address_text = "http://"
|
30
|
+
@web_address_text = params[:current_link] if params[:current_link].to_s =~ /^http:\/\//
|
31
|
+
@web_address_target_blank = (params[:target_blank] == "true")
|
32
|
+
|
33
|
+
# mailto link
|
34
|
+
if params[:current_link].present?
|
35
|
+
if params[:current_link] =~ /^mailto:/
|
36
|
+
@email_address_text = params[:current_link].split("mailto:")[1].split('?')[0]
|
37
|
+
end
|
38
|
+
@email_default_subject_text = params[:current_link].split('?subject=')[1] || params[:subject]
|
39
|
+
@email_default_body_text = params[:current_link].split('?body=')[1] || params[:body]
|
40
|
+
end
|
41
|
+
|
42
|
+
if params[:paginating].present?
|
43
|
+
@page_area_selected = (params[:paginating] == "your_page")
|
44
|
+
@resource_area_selected = (params[:paginating] == "resource_file")
|
45
|
+
else
|
46
|
+
@page_area_selected = (!is_resource_link and @web_address_text == "http://" and @email_address_text.blank?)
|
47
|
+
@web_address_area_selected = (@web_address_text != "http://")
|
48
|
+
@email_address_area_selected = @email_address_text.present?
|
49
|
+
@resource_area_selected = is_resource_link
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_url
|
54
|
+
begin
|
55
|
+
timeout(5) do
|
56
|
+
unless params[:url].blank?
|
57
|
+
url = URI.parse(params[:url])
|
58
|
+
if url.host.nil? && params[:url].start_with?('/')
|
59
|
+
url.host = URI.parse(request.url).host
|
60
|
+
end
|
61
|
+
|
62
|
+
result = case Net::HTTP.get_response(url)
|
63
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
64
|
+
'success'
|
65
|
+
else
|
66
|
+
'failure'
|
67
|
+
end
|
68
|
+
|
69
|
+
render :json => {:result => result}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
rescue
|
73
|
+
render :json => {:result => 'failure'}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_email
|
78
|
+
if params[:email].present?
|
79
|
+
valid = params[:email] =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
80
|
+
|
81
|
+
render :json => if valid
|
82
|
+
{:result => 'success'}
|
83
|
+
else
|
84
|
+
{:result => 'failure'}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Refinery
|
2
|
+
class PageSweeper < ActionController::Caching::Sweeper
|
3
|
+
observe Page
|
4
|
+
|
5
|
+
def after_create(page)
|
6
|
+
expire_cache
|
7
|
+
end
|
8
|
+
|
9
|
+
def after_update(page)
|
10
|
+
expire_cache
|
11
|
+
end
|
12
|
+
|
13
|
+
def after_destroy(page)
|
14
|
+
expire_cache
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def expire_cache
|
19
|
+
# TODO: Where does page_cache_directory come from??
|
20
|
+
return unless page_cache_directory
|
21
|
+
page_cache_directory = Pathname.new(page_cache_directory.to_s)
|
22
|
+
|
23
|
+
# Delete the full Cache
|
24
|
+
if (cache_root = page_cache_directory.join('refinery', 'cache', 'pages')).directory?
|
25
|
+
cache_root.rmdir
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Refinery
|
2
|
+
class PagesController < ::ApplicationController
|
3
|
+
before_filter :find_page, :except => [:preview]
|
4
|
+
|
5
|
+
# Save whole Page after delivery
|
6
|
+
after_filter { |c| c.write_cache? }
|
7
|
+
|
8
|
+
# This action is usually accessed with the root path, normally '/'
|
9
|
+
def home
|
10
|
+
render_with_templates?
|
11
|
+
end
|
12
|
+
|
13
|
+
# This action can be accessed normally, or as nested pages.
|
14
|
+
# Assuming a page named "mission" that is a child of "about",
|
15
|
+
# you can access the pages with the following URLs:
|
16
|
+
#
|
17
|
+
# GET /pages/about
|
18
|
+
# GET /about
|
19
|
+
#
|
20
|
+
# GET /pages/mission
|
21
|
+
# GET /about/mission
|
22
|
+
#
|
23
|
+
def show
|
24
|
+
if current_user_can_view_page?
|
25
|
+
if should_skip_to_first_child?
|
26
|
+
redirect_to refinery.url_for(first_live_child.url)
|
27
|
+
elsif page.link_url.present?
|
28
|
+
redirect_to page.link_url
|
29
|
+
else
|
30
|
+
if requested_friendly_id != page.friendly_id
|
31
|
+
redirect_to refinery.url_for(page.url), :status => 301
|
32
|
+
else
|
33
|
+
render_with_templates?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
error_404
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def preview
|
42
|
+
if page(fallback_to_404 = false)
|
43
|
+
# Preview existing pages
|
44
|
+
@page.attributes = params[:page]
|
45
|
+
elsif params[:page]
|
46
|
+
# Preview a non-persisted page
|
47
|
+
@page = Page.new(params[:page])
|
48
|
+
end
|
49
|
+
|
50
|
+
render_with_templates?(:action => :show)
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
|
55
|
+
def requested_friendly_id
|
56
|
+
"#{params[:path]}/#{params[:id]}".split('/').last
|
57
|
+
end
|
58
|
+
|
59
|
+
def should_skip_to_first_child?
|
60
|
+
page.skip_to_first_child && first_live_child
|
61
|
+
end
|
62
|
+
|
63
|
+
def current_user_can_view_page?
|
64
|
+
page.live? || current_refinery_user_can_access?("refinery_pages")
|
65
|
+
end
|
66
|
+
|
67
|
+
def current_refinery_user_can_access?(plugin)
|
68
|
+
refinery_user? && current_refinery_user.authorized_plugins.include?(plugin)
|
69
|
+
end
|
70
|
+
|
71
|
+
def first_live_child
|
72
|
+
page.children.order('lft ASC').live.first
|
73
|
+
end
|
74
|
+
|
75
|
+
def find_page(fallback_to_404 = true)
|
76
|
+
@page ||= case action_name
|
77
|
+
when "home"
|
78
|
+
Refinery::Page.where(:link_url => '/').first
|
79
|
+
when "show", "preview"
|
80
|
+
Refinery::Page.find_by_path_or_id(params[:path], params[:id])
|
81
|
+
end
|
82
|
+
@page || (error_404 if fallback_to_404)
|
83
|
+
end
|
84
|
+
|
85
|
+
alias_method :page, :find_page
|
86
|
+
|
87
|
+
def render_with_templates?(render_options = {})
|
88
|
+
if Refinery::Pages.use_layout_templates && page.layout_template.present?
|
89
|
+
render_options[:layout] = page.layout_template
|
90
|
+
end
|
91
|
+
if Refinery::Pages.use_view_templates && page.view_template.present?
|
92
|
+
render_options[:action] = page.view_template
|
93
|
+
end
|
94
|
+
render render_options if render_options.any?
|
95
|
+
end
|
96
|
+
|
97
|
+
def write_cache?
|
98
|
+
if Refinery::Pages.cache_pages_full
|
99
|
+
cache_page(response.body, File.join('', 'refinery', 'cache', 'pages', request.path.sub("//", "/")).to_s)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ::Refinery
|
2
|
+
module Pages
|
3
|
+
module ContentPagesHelper
|
4
|
+
# Build the html for a Refinery CMS page object by creating a ContentPagePresenter. This is a
|
5
|
+
# specialised type of ContentPresenter, so the object is then passed to render_content_presenter
|
6
|
+
# to get its html. The options are passed to that method, so see render_content_presenter for
|
7
|
+
# more details.
|
8
|
+
def render_content_page(page, options = {})
|
9
|
+
content_page_presenter = Refinery::Pages::ContentPagePresenter.new(page, page_title)
|
10
|
+
render_content_presenter(content_page_presenter, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Pass the options into a ContentPresenter object and return its html. For more
|
14
|
+
# details see Refinery::Pages::ContentPresenter (and its subclasses).
|
15
|
+
# This method also checks for template overrides. Any template rendered by the
|
16
|
+
# current action may specify content_for a section using the section's id. For this
|
17
|
+
# reason, sections should not have an ID which you would normally be using for content_for,
|
18
|
+
# so avoid common layout names such as :header, :footer, etc.
|
19
|
+
def render_content_presenter(content_page, options = {})
|
20
|
+
content_page.hide_sections(options[:hide_sections]) if options[:hide_sections]
|
21
|
+
content_page.fetch_template_overrides {|section_id| content_for(section_id)}
|
22
|
+
content_page.to_html(options[:can_use_fallback])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|