Skip to content

Commit

Permalink
[#566] Add page_header to Template API
Browse files Browse the repository at this point in the history
* New method 'page_header' can be used in place of page_title within the body of a CMS template.
* Deprecated usage of 'page_title' to set the page title.

When used, editor can change the page title in context, rather than having to edit the properties.
  • Loading branch information
peakpg committed Mar 19, 2013
1 parent 0b86c36 commit 285dff8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
35 changes: 22 additions & 13 deletions app/helpers/cms/page_helper.rb
@@ -1,5 +1,6 @@
module Cms

# Deprecated in 4.0. Remove in 4.1
module DeprecatedBehavior

# Add the code to render the CMS toolbar.
Expand All @@ -8,6 +9,11 @@ def cms_toolbar
ActiveSupport::Deprecation.warn "The cms_toolbar helper is deprecated and no longer necessary. You can safely remove <%= cms_toolbar %> from templates.", caller
return ""
end

def deprecated_set_page_title_usage(args)
ActiveSupport::Deprecation.warn "Calling page_title('#{args.first}') is deprecated and will be remove in 4.1. Call use_page_title('#{args.first}') instead.", caller
use_page_title args.first
end
end

module PageHelper
Expand All @@ -32,32 +38,35 @@ def cms_content_editor
# Outputs the title for this page. Used by both internal CMS pages, as well as page templates. Call use_page_title to
# change this value.
#
# @param [String] If provided, this is the name of the page to set. (Deprecated in 4.0)
# @param [String] If provided, this is the name of the page to set. (This usage is deprecated in 4.0 and will be removed in 4.1)
# @return [String] The title of the page.
def page_title(*args)
if args.first
ActiveSupport::Deprecation.warn "Calling page_title('#{args.first}') is deprecated and will be remove in 4.1. Call use_page_title('#{args.first}') instead.", caller
use_page_title args.first
deprecated_set_page_title_usage(args)
else
@page_title ? @page_title : current_page.page_title
end
end

# Allows Views to set what will be displayed as the <title> element for Page Templates (and Cms admin pages.)
#
# Named use_page_title rather than page_title= because ruby will create local variable if you call <%= page_title = "Sometthing" %>
def use_page_title(title)
@page_title = title
end

# Returns the Page title in an In Context editable area.
#
# Use for h1/h2 elements. Use page_title for title elements.
def editable_page_title()
options = {id: 'page_title', contenteditable: true, data: {attribute: "title", content_name: "page", id: current_page.id, page_id: current_page.id}}
content_tag "div", page_title, options
def page_header()
if (current_user.able_to_modify?(current_page))
options = {id: 'page_title', contenteditable: true, data: {attribute: "title", content_name: "page", id: current_page.id, page_id: current_page.id}}
content_tag "div", page_title, options
else
page_title
end
end

# Allows Views to set what will be displayed as the <title> element for Page Templates (and Cms admin pages.)
#
def use_page_title(title)
# Implementation note: This method is named use_page_title rather than page_title= because ruby will create a
# local variable if you call <%= page_title = "A New Page Name" %>
@page_title = title
end

def current_page
@page
Expand Down
2 changes: 1 addition & 1 deletion app/models/cms/templates.rb
Expand Up @@ -19,7 +19,7 @@ def self.default_body
<div id="wrapper" style="width: 700px; margin: 0 auto; text-align: left; padding: 30px">
Breadcrumbs: <%= render_breadcrumbs %>
Main Menu: <%= render_menu %>
<h1><%= page_title %></h1>
<h1><%= page_header %></h1>
<%= container :main %>
</div>
</body>
Expand Down
4 changes: 3 additions & 1 deletion task_ckeditor.md
Expand Up @@ -11,14 +11,16 @@
* Remove blocks from page - Editors can select a block then remove it from the page via a button on the editor. Users will be prompted before its removed.
* Reorder content - Can move content blocks up or down within a page. Page will refresh after moving.
* Edit Page titles - Page title can be edited directly from the header.
* New Template API Method: page_header(). Used for h1/h2 etc, this will output an editable page title element (for logging in users).

### Deprecations

* page_title("Some Name") is deprecated in favor of use_page_title("Some Name") for overriding a page title. This will be remove in 4.1.

### ToDo

* Refactor editable vs page_title
* [BUG] Updating the page_header does not immediately update the <title> element.
* [BUG] If you edit the page title, then tab to save, it resets the page title to blank.
* [Minor] Block Orders - Disable button based on position (i.e. Can't move first block up, last block down)
* [BUG] Adding the same block twice to a page screws things up.
* [BUG] Editing a block, then moving a block will throw an error. (Connector ids change between page versions)[Suggest: After editting block, replace container with new content)
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/views/layouts/templates/default.html.erb
Expand Up @@ -9,7 +9,7 @@
<div id="wrapper" style="width: 700px; margin: 0 auto; text-align: left; padding: 30px">
Breadcrumbs: <%= render_breadcrumbs %>
Main Menu: <%= render_menu %>
<h1><%= editable_page_title %></h1>
<h1><%= page_header %></h1>
<%= container :main %>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/views/layouts/templates/homepage.html.erb
Expand Up @@ -16,7 +16,7 @@
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<!-- AddThis Button END -->
<h1><%= editable_page_title %></h1>
<h1><%= page_header %></h1>
<div class="main-image"></div>
<div class="pad">
<%= container :main_intro %>
Expand Down

0 comments on commit 285dff8

Please sign in to comment.