Revisited the format, filter and content type integration.
Now, all formats used by CMS are instances of CMS_FORMAT, mainly to prepare the admin section in order to define format by config/database. CMS_NODE_API provides all queries to access the content types, and formats, this way a module can easily alter the formats by adding a new filter. TODO: see how to integrate permission checking, to control who can use a specific format (such as full HTML).
This commit is contained in:
@@ -52,9 +52,17 @@ feature {CMS_API} -- Module Initialization
|
||||
|
||||
node_api := l_node_api
|
||||
-- Depends on {CMS_NODE_MODULE}
|
||||
|
||||
create ct
|
||||
--| For now, add all available formats to content type `ct'.
|
||||
across
|
||||
l_node_api.available_content_formats as ic
|
||||
loop
|
||||
ct.extend_format (ic.item)
|
||||
end
|
||||
l_node_api.add_content_type (ct)
|
||||
l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
|
||||
|
||||
-- Add support for CMS_BLOG, which requires a storage extension to store the optional "tags" value
|
||||
-- For now, we only have extension based on SQL statement.
|
||||
if attached {CMS_NODE_STORAGE_SQL} l_node_api.node_storage as l_sql_node_storage then
|
||||
|
||||
@@ -8,21 +8,6 @@ class
|
||||
|
||||
inherit
|
||||
CMS_NODE_TYPE [CMS_BLOG]
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (4)
|
||||
available_formats.extend (create {PLAIN_TEXT_CONTENT_FORMAT})
|
||||
available_formats.extend (create {FILTERED_HTML_CONTENT_FORMAT})
|
||||
available_formats.extend (create {FULL_HTML_CONTENT_FORMAT})
|
||||
available_formats.extend (create {CMS_EDITOR_CONTENT_FORMAT})
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
@@ -35,11 +20,6 @@ feature -- Access
|
||||
description: STRING_32 = "Content published as a blog post."
|
||||
-- Optional description
|
||||
|
||||
feature -- Access
|
||||
|
||||
available_formats: LIST [CONTENT_FORMAT]
|
||||
-- Available formats for Current type.
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node
|
||||
|
||||
@@ -36,6 +36,56 @@ feature -- Access
|
||||
deferred
|
||||
end
|
||||
|
||||
format (a_name: READABLE_STRING_8): detachable CONTENT_FORMAT
|
||||
-- Format named `a_name', if available.
|
||||
do
|
||||
across
|
||||
available_formats as ic
|
||||
until
|
||||
Result /= Void
|
||||
loop
|
||||
Result := ic.item
|
||||
if not a_name.is_case_insensitive_equal (Result.name) then
|
||||
Result := Void
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
extend_format (f: CONTENT_FORMAT)
|
||||
-- Add `f' to the list of `available_formats'
|
||||
require
|
||||
not_has_format: format (f.name) = Void
|
||||
do
|
||||
available_formats.extend (f)
|
||||
ensure
|
||||
format_added: format (f.name) /= Void
|
||||
end
|
||||
|
||||
remove_format (f: CONTENT_FORMAT)
|
||||
-- Add `f' to the list of `available_formats'
|
||||
local
|
||||
lst: like available_formats
|
||||
l_name: READABLE_STRING_GENERAL
|
||||
do
|
||||
from
|
||||
l_name := f.name
|
||||
lst := available_formats
|
||||
lst.start
|
||||
until
|
||||
lst.after
|
||||
loop
|
||||
if l_name.is_case_insensitive_equal (lst.item.name) then
|
||||
lst.remove
|
||||
else
|
||||
lst.forth
|
||||
end
|
||||
end
|
||||
ensure
|
||||
format_removed: format (f.name) = Void
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -38,10 +38,29 @@ feature {NONE} -- Initialization
|
||||
-- Initialize content type system.
|
||||
local
|
||||
ct: CMS_PAGE_NODE_TYPE
|
||||
f: CMS_FORMAT
|
||||
do
|
||||
-- Initialize built-in formats
|
||||
create available_content_formats.make (4)
|
||||
create f.make_from_format (create {PLAIN_TEXT_CONTENT_FORMAT})
|
||||
add_content_format (f)
|
||||
create f.make_from_format (create {FILTERED_HTML_CONTENT_FORMAT})
|
||||
add_content_format (f)
|
||||
create f.make_from_format (create {FULL_HTML_CONTENT_FORMAT})
|
||||
add_content_format (f)
|
||||
create f.make ("cms_editor", "CMS HTML content")
|
||||
add_content_format (f)
|
||||
|
||||
-- Initialize content types.
|
||||
create content_types.make (1)
|
||||
create content_type_webform_managers.make (1)
|
||||
create ct
|
||||
--| For now, add all available formats to content type `ct'.
|
||||
across
|
||||
available_content_formats as ic
|
||||
loop
|
||||
ct.extend_format (ic.item)
|
||||
end
|
||||
add_content_type (ct)
|
||||
add_content_type_webform_manager (create {CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
|
||||
end
|
||||
@@ -164,6 +183,31 @@ feature -- Content type webform
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Content formats
|
||||
|
||||
available_content_formats: ARRAYED_LIST [CONTENT_FORMAT]
|
||||
-- Available content formats.
|
||||
|
||||
add_content_format (f: CONTENT_FORMAT)
|
||||
-- Add content format `f' to `available_content_formats'.
|
||||
do
|
||||
available_content_formats.extend (f)
|
||||
end
|
||||
|
||||
content_format (a_name: READABLE_STRING_GENERAL): detachable CONTENT_FORMAT
|
||||
-- Format named `a_name' if available.
|
||||
do
|
||||
across
|
||||
available_content_formats as ic
|
||||
until
|
||||
Result = Void
|
||||
loop
|
||||
if a_name.is_case_insensitive_equal (ic.item.name) then
|
||||
Result := ic.item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- URL
|
||||
|
||||
new_content_path (ct: detachable CMS_CONTENT_TYPE): STRING
|
||||
|
||||
@@ -11,6 +11,22 @@ deferred class
|
||||
|
||||
inherit
|
||||
CMS_CONTENT_TYPE
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create available_formats.make (1)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
available_formats: ARRAYED_LIST [CONTENT_FORMAT]
|
||||
-- Available formats for Current type.
|
||||
|
||||
feature -- Factory
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
note
|
||||
description: "Summary description for {CMS_PAGE_NODE_TYPE}."
|
||||
description: "[
|
||||
Interface defining a CMS page type.
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -8,21 +10,6 @@ class
|
||||
|
||||
inherit
|
||||
CMS_NODE_TYPE [CMS_PAGE]
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
create {ARRAYED_LIST [like available_formats.item]} available_formats.make (4)
|
||||
available_formats.extend (create {PLAIN_TEXT_CONTENT_FORMAT})
|
||||
available_formats.extend (create {FILTERED_HTML_CONTENT_FORMAT})
|
||||
available_formats.extend (create {FULL_HTML_CONTENT_FORMAT})
|
||||
available_formats.extend (create {CMS_EDITOR_CONTENT_FORMAT})
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
@@ -35,11 +22,6 @@ feature -- Access
|
||||
description: STRING_32 = "Use basic pages for your content, such as an 'About us' page."
|
||||
-- Optional description
|
||||
|
||||
feature -- Access
|
||||
|
||||
available_formats: LIST [CONTENT_FORMAT]
|
||||
-- Available formats for Current type.
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node
|
||||
|
||||
@@ -34,9 +34,6 @@ feature -- Basic operations
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute the filter.
|
||||
local
|
||||
o: OPENID_CONSUMER
|
||||
v: OPENID_CONSUMER_VALIDATION
|
||||
|
||||
do
|
||||
api.logger.put_debug (generator + ".execute ", Void)
|
||||
|
||||
@@ -105,7 +105,6 @@ feature -- Change: User OAuth
|
||||
-- <Precursor>.
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
l_string: STRING
|
||||
do
|
||||
error_handler.reset
|
||||
sql_begin_transaction
|
||||
|
||||
113
src/kernel/content/format/cms_format.e
Normal file
113
src/kernel/content/format/cms_format.e
Normal file
@@ -0,0 +1,113 @@
|
||||
note
|
||||
description: "Summary description for {CMS_FORMAT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_FORMAT
|
||||
|
||||
inherit
|
||||
CONTENT_FORMAT
|
||||
|
||||
create
|
||||
make,
|
||||
make_from_format
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: READABLE_STRING_8; a_title: detachable READABLE_STRING_8)
|
||||
do
|
||||
default_create
|
||||
name := a_name
|
||||
set_title (a_title)
|
||||
create filters.make (0)
|
||||
end
|
||||
|
||||
make_from_format (a_format: CONTENT_FORMAT)
|
||||
do
|
||||
make (a_format.name, a_format.title)
|
||||
import_filters_from_format (a_format)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING
|
||||
-- <Precursor>
|
||||
|
||||
title: STRING
|
||||
-- <Precursor>
|
||||
|
||||
filters: ARRAYED_LIST [CONTENT_FILTER]
|
||||
-- <Precursor>
|
||||
|
||||
filter (a_name: READABLE_STRING_GENERAL): detachable CONTENT_FILTER
|
||||
-- Filter named `a_name' if any.
|
||||
do
|
||||
across
|
||||
filters as ic
|
||||
until
|
||||
Result /= Void
|
||||
loop
|
||||
if a_name.is_case_insensitive_equal (ic.item.name) then
|
||||
Result := ic.item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_title (a_title: detachable READABLE_STRING_8)
|
||||
-- Set `title' according to `a_title' or `name' if `a_title' is blank.
|
||||
do
|
||||
if a_title = Void or else a_title.is_whitespace then
|
||||
create title.make_from_string (name)
|
||||
else
|
||||
title := a_title
|
||||
end
|
||||
end
|
||||
|
||||
import_filters_from_format (f: CONTENT_FORMAT)
|
||||
do
|
||||
across
|
||||
f.filters as ic
|
||||
loop
|
||||
add_filter (ic.item)
|
||||
end
|
||||
end
|
||||
|
||||
add_filter (f: CONTENT_FILTER)
|
||||
require
|
||||
has_no_such_filter: filter (f.name) = Void
|
||||
do
|
||||
filters.extend (f)
|
||||
ensure
|
||||
has_filter: filter (f.name) = f
|
||||
end
|
||||
|
||||
remove_filter_by_name (a_name: READABLE_STRING_GENERAL)
|
||||
-- Remove filter named `a_name' if any.
|
||||
local
|
||||
lst: like filters
|
||||
do
|
||||
from
|
||||
lst := filters
|
||||
lst.start
|
||||
until
|
||||
lst.after
|
||||
loop
|
||||
if a_name.is_case_insensitive_equal (lst.item.name) then
|
||||
lst.remove
|
||||
else
|
||||
lst.forth
|
||||
end
|
||||
end
|
||||
ensure
|
||||
filter_removed: filter (a_name) = Void
|
||||
end
|
||||
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
Reference in New Issue
Block a user