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:
2015-07-09 12:23:20 +02:00
parent 85cff0b139
commit 16cae0047d
9 changed files with 234 additions and 45 deletions

View File

@@ -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)"

View File

@@ -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

View File

@@ -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

View File

@@ -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