Initial CMS API commmit.

This commit is contained in:
jvelilla
2014-10-01 12:17:39 -03:00
parent 588827b495
commit 27a11f2eea
170 changed files with 12459 additions and 14 deletions

0
cms/Readme.md Normal file
View File

25
cms/cms.ecf Normal file
View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="cms" uuid="8CC0D052-57D1-4CAA-AFF1-448FA290734B" library_target="cms">
<target name="cms">
<root all_classes="true"/>
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf" readonly="false"/>
<library name="layout" location="..\layout\layout.ecf"/>
<library name="persistence_mysql" location="..\persistence\implementation\mysql\persistence_mysql.ecf" readonly="false"/>
<library name="smarty" location="$ISE_LIBRARY\contrib\library\text\template\smarty\smarty-safe.ecf" readonly="false"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
</cluster>
</target>
</system>

View File

@@ -0,0 +1,298 @@
class
CMS_CONFIGURATION
inherit
ANY
SHARED_EXECUTION_ENVIRONMENT
export
{NONE} all
end
create
make
feature {NONE} -- Initialization
make (a_layout: CMS_LAYOUT)
-- Initialize `Current'.
local
p: PATH
do
layout := a_layout
create options.make_equal (10)
configuration_location := layout.cms_config_ini_path
import_from_path (layout.cms_config_ini_path)
analyze
end
analyze
do
get_root_location
get_var_location
get_themes_location
get_files_location
end
feature -- Access
configuration_location: detachable PATH
option (a_name: READABLE_STRING_GENERAL): detachable ANY
do
Result := options.item (a_name)
end
options: STRING_TABLE [STRING_32]
feature -- Conversion
append_to_string (s: STRING)
local
utf: UTF_CONVERTER
do
s.append ("Options:%N")
across
options as c
loop
s.append (c.key.to_string_8)
s.append_character ('=')
utf.string_32_into_utf_8_string_8 (c.item, s)
s.append_character ('%N')
end
s.append ("Specific:%N")
s.append ("root_location=" + root_location.utf_8_name + "%N")
s.append ("var_location=" + var_location.utf_8_name + "%N")
s.append ("files_location=" + files_location.utf_8_name + "%N")
s.append ("themes_location=" + themes_location.utf_8_name + "%N")
end
feature -- Element change
set_option (a_name: READABLE_STRING_GENERAL; a_value: STRING_32)
do
options.force (a_value, a_name.as_string_8)
end
feature -- Access
var_location: PATH
root_location: PATH
files_location: PATH
themes_location: PATH
theme_name (dft: detachable like theme_name): READABLE_STRING_8
do
if attached options.item ("theme") as s then
Result := s
elseif dft /= Void then
Result := dft
else
Result := "default"
end
end
site_id: READABLE_STRING_8
do
if attached options.item ("site.id") as s then
Result := s
else
Result := "_EWF_CMS_NO_ID_"
end
end
site_name (dft: like site_name): READABLE_STRING_8
do
if attached options.item ("site.name") as s then
Result := s
else
Result := dft
end
end
site_url (dft: like site_url): READABLE_STRING_8
do
if attached options.item ("site.url") as s then
Result := s
else
Result := dft
end
if Result /= Void then
if Result.is_empty then
-- ok
elseif not Result.ends_with ("/") then
Result := Result + "/"
end
end
end
site_script_url (dft: like site_script_url): detachable READABLE_STRING_8
do
if attached options.item ("site.script_url") as s then
Result := s
else
Result := dft
end
if Result /= Void then
if Result.is_empty then
elseif not Result.ends_with ("/") then
Result := Result + "/"
end
end
end
site_email (dft: like site_email): READABLE_STRING_8
do
if attached options.item ("site.email") as s then
Result := s
else
Result := dft
end
end
feature -- Change
get_var_location
local
utf: UTF_CONVERTER
do
if attached options.item ("var-dir") as s then
create var_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
var_location := execution_environment.current_working_path
end
end
get_root_location
local
utf: UTF_CONVERTER
do
root_location := layout.www_path
end
get_files_location
local
utf: UTF_CONVERTER
do
if attached options.item ("files-dir") as s then
create files_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
create files_location.make_from_string ("files")
end
end
get_themes_location
local
utf: UTF_CONVERTER
do
if attached options.item ("themes-dir") as s then
create themes_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
themes_location := root_location.extended ("themes")
end
end
feature {NONE} -- Implementation
import_from_file (fn: READABLE_STRING_GENERAL)
do
import_from_path (create {PATH}.make_from_string (fn))
end
import_from_path (a_filename: PATH)
-- Import ini file content
local
f: PLAIN_TEXT_FILE
l,v: STRING_8
p: INTEGER
do
create f.make_with_path (a_filename)
if f.exists and f.is_readable then
f.open_read
from
f.read_line
until
f.exhausted
loop
l := f.last_string
l.left_adjust
if not l.is_empty then
if l[1] = '#' then
-- commented line
else
p := l.index_of ('=', 1)
if p > 1 then
v := l.substring (p + 1, l.count)
l.keep_head (p - 1)
v.left_adjust
v.right_adjust
l.right_adjust
if l.is_case_insensitive_equal ("@include") then
import_from_file (resolved_string (v))
else
set_option (l.as_lower, resolved_string (v))
end
end
end
end
f.read_line
end
f.close
end
end
feature {NONE} -- Environment
resolved_string (s: READABLE_STRING_8): STRING_32
-- Resolved `s' using `options' or else environment variables.
local
i,n,b,e: INTEGER
k: detachable READABLE_STRING_8
do
from
i := 1
n := s.count
create Result.make (s.count)
until
i > n
loop
if i + 1 < n and then s[i] = '$' and then s[i+1] = '{' then
b := i + 2
e := s.index_of ('}', b) - 1
if e > 0 then
k := s.substring (b, e)
if attached option (k) as v then
if attached {READABLE_STRING_32} v as s32 then
Result.append (s32)
else
Result.append (v.out)
end
i := e + 1
elseif attached execution_environment.item (k) as v then
Result.append (v)
i := e + 1
else
Result.extend (s[i])
end
else
Result.extend (s[i])
end
else
Result.extend (s[i])
end
i := i + 1
end
end
feature -- Implementation
layout: CMS_LAYOUT
-- Cms layout
end

View File

@@ -0,0 +1,14 @@
note
description: "Summary description for {CMS_CUSTOM_SETUP}."
date: "$Date$"
revision: "$Revision$"
class
CMS_CUSTOM_SETUP
inherit
CMS_DEFAULT_SETUP
create
make
end

View File

@@ -0,0 +1,123 @@
note
description: "Summary description for {CMS_DEFAULT_SETUP}."
date: "$Date$"
revision: "$Revision$"
class
CMS_DEFAULT_SETUP
inherit
CMS_SETUP
REFACTORING_HELPER
create
make
feature {NONE} -- Initialization
make (a_layout: CMS_LAYOUT)
do
layout := a_layout
create configuration.make (layout)
site_id := configuration.site_id
site_url := configuration.site_url ("")
site_name := configuration.site_name ("EWF::CMS")
site_email := configuration.site_email ("webmaster")
site_dir := configuration.root_location
site_var_dir := configuration.var_location
files_location := configuration.files_location
themes_location := configuration.themes_location
theme_name := configuration.theme_name ("default")
compute_theme_location
compute_theme_resource_location
initialize
end
initialize
do
build_api_service
build_auth_engine
build_mailer
build_modules
end
feature -- Access
modules: ARRAYED_LIST [CMS_MODULE]
-- List of possible modules
is_html: BOOLEAN
-- <Precursor>
do
-- Enable change the mode
Result := (create {CMS_JSON_CONFIGURATION}).is_html_mode(layout.application_config_path)
end
is_web: BOOLEAN
-- <Precursor>
do
Result := (create {CMS_JSON_CONFIGURATION}).is_web_mode(layout.application_config_path)
end
feature {NONE} -- Initialization
build_modules
-- Core modules. (User, Admin, Node)
-- At the moment only node is supported.
local
m: CMS_MODULE
do
create modules.make (3)
-- -- Core
-- create {USER_MODULE} m.make
-- m.enable
-- modules.extend (m)
-- create {ADMIN_MODULE} m.make
-- m.enable
-- modules.extend (m)
create {NODE_MODULE} m.make (Current)
m.enable
modules.extend (m)
end
build_api_service
local
dn: PATH
l_database: DATABASE_CONNECTION
do
to_implement ("Refactor database setup")
if attached (create {JSON_CONFIGURATION}).new_database_configuration (layout.application_config_path) as l_database_config then
create {DATABASE_CONNECTION_MYSQL} l_database.login_with_connection_string (l_database_config.connection_string)
create api_service.make (create {CMS_STORAGE_MYSQL}.make (l_database))
else
create {DATABASE_CONNECTION_NULL} l_database.make_common
create api_service.make (create {CMS_STORAGE_NULL})
end
end
build_auth_engine
do
to_implement ("Not implemented authentication")
end
build_mailer
do
to_implement ("Not implemented mailer")
end
feature -- Change
add_module (m: CMS_MODULE)
-- Add a module `m' to the list of modules `modules'.
do
modules.force (m)
end
end

View File

@@ -0,0 +1,47 @@
note
description: "Summary description for {CMS_JSON_CONFIGURATION}."
date: "$Date$"
revision: "$Revision$"
class
CMS_JSON_CONFIGURATION
inherit
JSON_CONFIGURATION
feature -- Access
is_html_mode (a_path: PATH): BOOLEAN
-- Is the server running on web mode?
local
l_parser: JSON_PARSER
do
if attached json_file_from (a_path) as json_file then
l_parser := new_json_parser (json_file)
if attached {JSON_OBJECT} l_parser.parse as jv and then l_parser.is_parsed and then
attached {JSON_OBJECT} jv.item ("server") as l_server and then
attached {JSON_STRING} l_server.item ("mode") as l_mode then
Result := l_mode.item.is_case_insensitive_equal_general ("html")
end
end
end
is_web_mode (a_path: PATH): BOOLEAN
-- Is the server running on web mode?
local
l_parser: JSON_PARSER
do
if attached json_file_from (a_path) as json_file then
l_parser := new_json_parser (json_file)
if attached {JSON_OBJECT} l_parser.parse as jv and then l_parser.is_parsed and then
attached {JSON_OBJECT} jv.item ("server") as l_server and then
attached {JSON_STRING} l_server.item ("mode") as l_mode then
Result := l_mode.item.is_case_insensitive_equal_general ("web")
end
end
end
end

View File

@@ -0,0 +1,32 @@
note
description: "Summary description for {CMS_LAYOUT}."
date: "$Date$"
revision: "$Revision$"
class
CMS_LAYOUT
inherit
APPLICATION_LAYOUT
create
make_default,
make_with_path
feature -- Access
theme_path: PATH
-- Directory for templates (HTML, etc).
once
Result := www_path.extended ("theme")
end
cms_config_ini_path: PATH
-- Database Configuration file path.
once
Result := config_path.extended ("cms.ini")
end
end

View File

@@ -0,0 +1,85 @@
note
description: "Summary description for {CMS_SETUP}."
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_SETUP
feature -- Access
configuration: CMS_CONFIGURATION
-- cms configuration.
layout: CMS_LAYOUT
-- CMS layout.
api_service: CMS_API_SERVICE
-- cms api service.
modules: LIST[CMS_MODULE]
-- Possible list of modules.
-- |If we remove Modules from setup.
-- |we can let the CMS_SERVICE define the basic modules.
deferred
end
is_html: BOOLEAN
-- api with progresive enhacements css and js, server side rendering.
deferred
end
is_web: BOOLEAN
-- web: Web Site with progresive enhacements css and js and Ajax calls.
deferred
end
feature -- Access: Site
site_id: READABLE_STRING_8
site_name: READABLE_STRING_32
site_email: READABLE_STRING_8
site_url: READABLE_STRING_8
site_dir: PATH
site_var_dir: PATH
files_location: PATH
feature -- Access:Theme
themes_location: PATH
theme_location: PATH
theme_resource_location: PATH
--
theme_information_location: PATH
-- theme informations.
do
Result := theme_location.extended ("theme.info")
end
theme_name: READABLE_STRING_32
-- theme name
feature -- Compute location
compute_theme_location
do
theme_location := themes_location.extended (theme_name)
end
compute_theme_resource_location
-- assets (js, css, images, etc)
-- Not used at the moment.
do
theme_resource_location := theme_location
end
end

View File

@@ -0,0 +1,183 @@
note
description: "Summary description for {CMS_HTML_PAGE}."
date: "$Date$"
revision: "$Revision$"
class
CMS_HTML_PAGE
create
make,
make_typed
feature {NONE} -- Initialization
make_typed (a_type: like type)
-- Make current page with optional page type `a_type'.
do
make
type := a_type
end
make
do
create regions.make (5)
language := "en"
status_code := {HTTP_STATUS_CODE}.ok
create header.make
create {ARRAYED_LIST [STRING]} head_lines.make (5)
header.put_content_type_text_html
create variables.make (0)
end
feature -- Access
type: detachable READABLE_STRING_8
-- Optional page type.
-- such as "front", "about", ... that could be customized by themes.
title: detachable STRING
language: STRING
head_lines: LIST [STRING]
head_lines_to_string: STRING
do
create Result.make_empty
across
head_lines as h
loop
Result.append (h.item)
Result.append_character ('%N')
end
end
variables: STRING_TABLE [detachable ANY]
feature -- Status
status_code: INTEGER
feature -- Header
header: HTTP_HEADER
feature -- Region
regions: HASH_TABLE [STRING_8, STRING_8]
-- header
-- content
-- footer
-- could have sidebar first, sidebar second, ...
region (n: STRING_8): STRING_8
do
if attached regions.item (n) as r then
Result := r
else
Result := ""
debug
Result := "{{" + n + "}}"
end
end
end
header_region: STRING_8
do
Result := region ("header")
end
content_region: STRING_8
do
Result := region ("content")
end
footer_region: STRING_8
do
Result := region ("content")
end
feature -- Element change
register_variable (a_value: detachable ANY; k: READABLE_STRING_GENERAL)
do
variables.force (a_value, k)
end
add_to_region (s: STRING; k: STRING)
local
r: detachable STRING
do
r := regions.item (k)
if r = Void then
create r.make_from_string (s)
set_region (r, k)
else
r.append (s)
end
end
add_to_header_region (s: STRING)
do
add_to_region (s, "header")
end
add_to_content_region (s: STRING)
do
add_to_region (s, "content")
end
add_to_footer_region (s: STRING)
do
add_to_region (s, "footer")
end
set_region (s: STRING; k: STRING)
do
regions.force (s, k)
end
set_header_region (s: STRING)
do
set_region (s, "header")
end
set_content_region (s: STRING)
do
set_region (s, "content")
end
set_footer_region (s: STRING)
do
set_region (s, "footer")
end
feature -- Element change
set_status_code (c: like status_code)
do
status_code := c
end
set_language (s: like language)
do
language := s
end
set_title (s: like title)
do
title := s
end
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,48 @@
note
description: "Summary description for {WSF_CMS_MODULE}."
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_MODULE
feature -- Access
is_enabled: BOOLEAN
name: STRING
description: STRING
package: STRING
version: STRING
feature -- Router
router: WSF_ROUTER
-- Router configuration.
deferred
end
feature -- Settings
enable
do
is_enabled := True
end
disable
do
is_enabled := False
end
feature -- Hooks
help_text (a_path: STRING): STRING
do
create Result.make_empty
end
end

View File

@@ -0,0 +1,189 @@
note
description: "Summary description for {NEW_CONTENT_HANDLER}."
date: "$Date$"
revision: "$Revision$"
class
NODE_CONTENT_HANDLER
inherit
CMS_HANDLER
WSF_FILTER
WSF_URI_HANDLER
rename
execute as uri_execute,
new_mapping as new_uri_mapping
end
WSF_URI_TEMPLATE_HANDLER
rename
execute as uri_template_execute,
new_mapping as new_uri_template_mapping
select
new_uri_template_mapping
end
WSF_RESOURCE_HANDLER_HELPER
redefine
do_get,
do_post,
do_put
end
REFACTORING_HELPER
create
make
feature -- execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
execute_next (req, res)
end
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
uri_template_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
l_page: CMS_RESPONSE
do
if attached current_user_name (req) then
-- Existing node
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
create {NODE_VIEW_CMS_RESPONSE} l_page.make (req, res, setup, "modules/node_content")
l_page.add_variable (l_node.content, "content")
l_page.add_variable (l_id.value, "id")
l_page.execute
else
do_error (req, res, l_id)
end
else
-- Todo extract method
to_implement ("Check how to implemet API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
do_post (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
u_node: CMS_NODE
do
if attached current_user_name (req) then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
if l_method.is_case_insensitive_equal ("PUT") then
do_put (req, res)
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
end
else
do_error (req, res, l_id)
end
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
u_node: CMS_NODE
-- l_page: ROC_RESPONSE
do
to_implement ("Check if user has permissions")
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
u_node := extract_data_form (req)
u_node.set_id (l_id.integer_value)
api_service.update_node_content (l_user.id, u_node.id, u_node.content)
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
end
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
feature -- Error
do_error (req: WSF_REQUEST; res: WSF_RESPONSE; a_id: WSF_STRING)
-- Handling error.
local
do
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- if a_id.is_integer then
-- -- resource not found
-- l_page.set_value ("404", "code")
-- else
-- -- bad request
-- l_page.set_value ("400", "code")
-- end
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to(res)
end
feature -- {NONE} Form data
extract_data_form (req: WSF_REQUEST): CMS_NODE
-- Extract request form data and build a object
-- Node
do
create Result.make ("", "", "")
if attached {WSF_STRING}req.form_parameter ("content") as l_content then
Result.set_content (l_content.value)
end
end
end

View File

@@ -0,0 +1,221 @@
note
description: "Summary description for {NODE_HANDLER}."
date: "$Date$"
revision: "$Revision$"
class
NODE_HANDLER
inherit
CMS_HANDLER
WSF_FILTER
WSF_URI_HANDLER
rename
execute as uri_execute,
new_mapping as new_uri_mapping
end
WSF_URI_TEMPLATE_HANDLER
rename
execute as uri_template_execute,
new_mapping as new_uri_template_mapping
select
new_uri_template_mapping
end
WSF_RESOURCE_HANDLER_HELPER
redefine
do_get,
do_post,
do_put,
do_delete
end
REFACTORING_HELPER
create
make
feature -- execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
execute_next (req, res)
end
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
uri_template_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
l_page: CMS_RESPONSE
do
-- Existing node
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
create {NODE_VIEW_CMS_RESPONSE} l_page.make (req, res, setup,"modules/node")
l_page.add_variable (l_node, "node")
l_page.execute
else
do_error (req, res, l_id)
end
else
-- Factory
new_node (req, res)
end
end
do_post (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
u_node: CMS_NODE
l_page: CMS_RESPONSE
do
to_implement ("Check user permissions!!!")
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
if l_method.is_case_insensitive_equal ("DELETE") then
do_delete (req, res)
elseif l_method.is_case_insensitive_equal ("PUT") then
do_put (req, res)
else
to_implement ("Implement specific responses for 500 pages")
create {NODE_VIEW_CMS_RESPONSE} l_page.make (req, res, setup, "master2/error")
l_page.add_variable ("500", "code")
l_page.add_variable (req.absolute_script_url (req.path_info), "request")
l_page.execute
end
end
else
do_error (req, res, l_id)
end
else
-- New node
u_node := extract_data_form (req)
u_node.set_author (l_user)
api_service.new_node (u_node)
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
u_node: CMS_NODE
do
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
u_node := extract_data_form (req)
u_node.set_id (l_id.integer_value)
api_service.update_node (l_user.id,u_node)
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
end
else
-- Internal server error
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
do
if attached current_user_name (req) then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
api_service.delete_node (l_id.integer_value)
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
end
else
-- Internal server error
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
feature -- Error
do_error (req: WSF_REQUEST; res: WSF_RESPONSE; a_id: WSF_STRING)
-- Handling error.
local
l_page: CMS_RESPONSE
do
to_implement ("Not implemented")
-- create l_page.make (req, "master2/error.tpl")
-- if a_id.is_integer then
-- -- resource not found
-- l_page.set_value ("404", "code")
-- else
-- -- bad request
-- l_page.set_value ("400", "code")
-- end
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
feature {NONE} -- Node
new_node (req: WSF_REQUEST; res: WSF_RESPONSE)
local
l_page: CMS_RESPONSE
do
if attached current_user_name (req) then
create {NODE_VIEW_CMS_RESPONSE} l_page.make (req, res, setup, "modules/node")
l_page.add_variable (setup.is_html, "html")
l_page.add_variable (setup.is_web, "web")
l_page.execute
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
feature -- {NONE} Form data
extract_data_form (req: WSF_REQUEST): CMS_NODE
-- Extract request form data and build a object
-- Node
do
create Result.make ("", "", "")
if attached {WSF_STRING} req.form_parameter ("title") as l_title then
Result.set_title (l_title.value)
end
if attached {WSF_STRING} req.form_parameter ("summary") as l_summary then
Result.set_summary (l_summary.value)
end
if attached {WSF_STRING} req.form_parameter ("content") as l_content then
Result.set_content (l_content.value)
end
end
end

View File

@@ -0,0 +1,189 @@
note
description: "Summary description for {NODE_SUMMARY_HANDLER}."
date: "$Date$"
revision: "$Revision$"
class
NODE_SUMMARY_HANDLER
inherit
CMS_HANDLER
WSF_FILTER
WSF_URI_HANDLER
rename
execute as uri_execute,
new_mapping as new_uri_mapping
end
WSF_URI_TEMPLATE_HANDLER
rename
execute as uri_template_execute,
new_mapping as new_uri_template_mapping
select
new_uri_template_mapping
end
WSF_RESOURCE_HANDLER_HELPER
redefine
do_get,
do_post,
do_put
end
REFACTORING_HELPER
create
make
feature -- execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
execute_next (req, res)
end
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
uri_template_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
l_page: CMS_RESPONSE
do
if attached current_user_name (req) then
-- Existing node
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
create {NODE_VIEW_CMS_RESPONSE} l_page.make (req, res, setup, "modules/node_summary")
l_page.add_variable (setup.is_html, "html")
l_page.add_variable (setup.is_web, "web")
l_page.add_variable (l_node.summary, "summary")
l_page.add_variable (l_id.value, "id")
l_page.execute
else
do_error (req, res, l_id)
end
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
do_post (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
u_node: CMS_NODE
do
if attached current_user_name (req) then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
if l_method.is_case_insensitive_equal ("PUT") then
do_put (req, res)
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
end
else
do_error (req, res, l_id)
end
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
u_node: CMS_NODE
do
to_implement ("Check if user has permissions!!!")
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
u_node := extract_data_form (req)
u_node.set_id (l_id.integer_value)
api_service.update_node_summary (l_user.id,u_node.id, u_node.summary)
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
end
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
feature -- Error
do_error (req: WSF_REQUEST; res: WSF_RESPONSE; a_id: WSF_STRING)
-- Handling error.
local
-- l_page: ROC_RESPONSE
do
-- create l_page.make (req, "master2/error.tpl")
-- if a_id.is_integer then
-- -- resource not found
-- l_page.set_value ("404", "code")
-- else
-- -- bad request
-- l_page.set_value ("400", "code")
-- end
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to(res)
end
feature -- {NONE} Form data
extract_data_form (req: WSF_REQUEST): CMS_NODE
-- Extract request form data and build a object
-- Node
do
create Result.make ("", "", "")
if attached {WSF_STRING}req.form_parameter ("summary") as l_summary then
Result.set_summary (l_summary.value)
end
end
end

View File

@@ -0,0 +1,187 @@
note
description: "Summary description for {NODE_TITLE_HANDLER}."
date: "$Date$"
revision: "$Revision$"
class
NODE_TITLE_HANDLER
inherit
CMS_HANDLER
WSF_FILTER
WSF_URI_HANDLER
rename
execute as uri_execute,
new_mapping as new_uri_mapping
end
WSF_URI_TEMPLATE_HANDLER
rename
execute as uri_template_execute,
new_mapping as new_uri_template_mapping
select
new_uri_template_mapping
end
WSF_RESOURCE_HANDLER_HELPER
redefine
do_get,
do_post,
do_put
end
REFACTORING_HELPER
create
make
feature -- execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
execute_next (req, res)
end
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
uri_template_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
l_page: CMS_RESPONSE
do
if attached current_user_name (req) as l_user then
-- Existing node
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
create {NODE_VIEW_CMS_RESPONSE} l_page.make (req, res, setup, "modules/node_title")
l_page.add_variable (setup.is_html, "html")
l_page.add_variable (setup.is_web, "web")
l_page.add_variable (l_node.title, "title")
l_page.add_variable (l_id.value, "id")
l_page.execute
else
do_error (req, res, l_id)
end
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
do_post (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
u_node: CMS_NODE
do
if attached current_user_name (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
if l_method.is_case_insensitive_equal ("PUT") then
do_put (req, res)
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
end
else
do_error (req, res, l_id)
end
else
to_implement ("Check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
local
u_node: CMS_NODE
do
to_implement ("Check if user has permissions")
if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
u_node := extract_data_form (req)
u_node.set_id (l_id.integer_value)
api_service.update_node_title (l_user.id,u_node.id, u_node.title)
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
else
do_error (req, res, l_id)
end
else
to_implement ("check how to implement API error")
-- create l_page.make (req, "master2/error.tpl")
-- l_page.set_value ("500", "code")
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
end
end
feature -- Error
do_error (req: WSF_REQUEST; res: WSF_RESPONSE; a_id: WSF_STRING)
-- Handling error.
local
do
to_implement ("Check how to add API error")
-- create l_page.make (req, "master2/error.tpl")
-- if a_id.is_integer then
-- -- resource not found
-- l_page.set_value ("404", "code")
-- else
-- -- bad request
-- l_page.set_value ("400", "code")
-- end
-- l_page.set_value (req.absolute_script_url (req.path_info), "request")
-- l_page.send_to (res)
end
feature -- {NONE} Form data
extract_data_form (req: WSF_REQUEST): CMS_NODE
-- Extract request form data and build a object
-- Node
do
create Result.make ("", "", "")
if attached {WSF_STRING} req.form_parameter ("title") as l_title then
Result.set_title (l_title.value)
end
end
end

View File

@@ -0,0 +1,52 @@
note
description: "Summary description for {NODES_HANDLER}."
date: "$Date$"
revision: "$Revision$"
class
NODES_HANDLER
inherit
CMS_HANDLER
WSF_FILTER
WSF_URI_HANDLER
rename
execute as uri_execute,
new_mapping as new_uri_mapping
end
WSF_RESOURCE_HANDLER_HELPER
redefine
do_get
end
REFACTORING_HELPER
create
make
feature -- execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
execute_next (req, res)
end
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
do
(create {NODES_VIEW_CMS_RESPONSE}.make (req, res, setup,"modules/nodes")).execute
end
end

View File

@@ -0,0 +1,129 @@
note
description: "Summary description for {CMS_MODULE}."
date: "$Date$"
revision: "$Revision$"
class
NODE_MODULE
inherit
CMS_MODULE
create
make
feature {NONE} -- Initialization
make (a_config: CMS_SETUP)
do
name := "node"
version := "1.0"
description := "Service to manage content based on 'node'"
package := "core"
config := a_config
setup_router
enable
end
feature -- Access
router: WSF_ROUTER
-- Node router.
config: CMS_SETUP
-- Node configuration.
feature -- Implementation
setup_router
-- Setup `router'.
local
fhdl: WSF_FILE_SYSTEM_HANDLER
do
create router.make (5)
configure_api_node
configure_api_nodes
configure_api_node_title
configure_api_node_summary
configure_api_node_content
end
feature -- Configure Node Resources Routes
configure_api_node
local
l_node_handler: NODE_HANDLER
l_methods: WSF_REQUEST_METHODS
do
create l_node_handler.make (config)
create l_methods
l_methods.enable_get
l_methods.enable_post
l_methods.enable_put
router.handle_with_request_methods ("/node", l_node_handler, l_methods)
create l_node_handler.make (config)
create l_methods
l_methods.enable_get
l_methods.enable_post
l_methods.enable_put
l_methods.enable_delete
router.handle_with_request_methods ("/node/{id}", l_node_handler, l_methods)
end
configure_api_nodes
local
l_nodes_handler: NODES_HANDLER
l_methods: WSF_REQUEST_METHODS
do
create l_nodes_handler.make (config)
create l_methods
l_methods.enable_get
router.handle_with_request_methods ("/nodes", l_nodes_handler, l_methods)
end
configure_api_node_summary
local
l_report_handler: NODE_SUMMARY_HANDLER
l_methods: WSF_REQUEST_METHODS
do
create l_report_handler.make (config)
create l_methods
l_methods.enable_get
l_methods.enable_post
l_methods.enable_put
router.handle_with_request_methods ("/node/{id}/summary", l_report_handler, l_methods)
end
configure_api_node_title
local
l_report_handler: NODE_TITLE_HANDLER
l_methods: WSF_REQUEST_METHODS
do
create l_report_handler.make (config)
create l_methods
l_methods.enable_get
l_methods.enable_post
l_methods.enable_put
router.handle_with_request_methods ("/node/{id}/title", l_report_handler, l_methods)
end
configure_api_node_content
local
l_report_handler: NODE_CONTENT_HANDLER
l_methods: WSF_REQUEST_METHODS
do
create l_report_handler.make (config)
create l_methods
l_methods.enable_get
l_methods.enable_post
l_methods.enable_put
router.handle_with_request_methods ("/node/{id}/content", l_report_handler, l_methods)
end
end

View File

@@ -0,0 +1,37 @@
note
description: "Summary description for {NODE_VIEW_CMS_RESPONSE}."
date: "$Date$"
revision: "$Revision$"
class
NODE_VIEW_CMS_RESPONSE
inherit
CMS_RESPONSE
redefine
custom_prepare
end
create
make
feature -- Generation
custom_prepare (page: CMS_HTML_PAGE)
do
if attached variables as l_variables then
across l_variables as c loop page.register_variable (c.item, c.key) end
end
end
feature -- Execution
process
-- Computed response message.
do
set_title ("List of Nodes")
set_page_title (Void)
end
end

View File

@@ -0,0 +1,35 @@
note
description: "Summary description for {NODE_VIEW_CMS_RESPONSE}."
date: "$Date$"
revision: "$Revision$"
class
NODES_VIEW_CMS_RESPONSE
inherit
CMS_RESPONSE
redefine
custom_prepare
end
create
make
feature -- Generation
custom_prepare (page: CMS_HTML_PAGE)
do
page.register_variable (setup.api_service.nodes, "nodes")
end
feature -- Execution
process
-- Computed response message.
do
set_title ("List of Nodes")
set_page_title (Void)
end
end

View File

@@ -0,0 +1,127 @@
note
description: "Summary description for {CMS_API_SERVICE}."
date: "$Date$"
revision: "$Revision$"
class
CMS_API_SERVICE
inherit
SHARED_ERROR
REFACTORING_HELPER
create make
feature -- Initialize
make (a_storage: CMS_STORAGE)
-- Create the API service with an storege `a_storage'.
do
storage := a_storage
set_successful
ensure
storage_set: storage = a_storage
end
feature -- Access
login_valid (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN
local
l_security: SECURITY_PROVIDER
do
Result := storage.is_valid_credential (l_auth_login, l_auth_password)
end
feature -- Access: Node
nodes: LIST[CMS_NODE]
-- List of nodes.
do
fixme ("Implementation")
Result := storage.recent_nodes (0, 10)
end
recent_nodes (a_offset, a_rows: INTEGER): LIST[CMS_NODE]
-- List of the `a_rows' most recent nodes starting from `a_offset'.
do
Result := storage.recent_nodes (a_offset, a_rows)
end
node (a_id: INTEGER_64): detachable CMS_NODE
-- Node by ID.
do
fixme ("Check preconditions")
Result := storage.node (a_id)
end
feature -- Change: Node
new_node (a_node: CMS_NODE)
-- Add a new node
do
storage.save_node (a_node)
end
delete_node (a_id: INTEGER_64)
do
storage.delete_node (a_id)
end
update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE)
do
storage.update_node (a_id,a_node)
end
update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
do
fixme ("Check preconditions")
storage.update_node_title (a_id,a_node_id,a_title)
end
update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
do
fixme ("Check preconditions")
storage.update_node_summary (a_id,a_node_id, a_summary)
end
update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
do
fixme ("Check preconditions")
storage.update_node_content (a_id,a_node_id, a_content)
end
feature -- Access: User
user_by_name (a_username: READABLE_STRING_32): detachable CMS_USER
do
Result := storage.user_by_name (a_username)
end
feature -- Change User
new_user (a_user: CMS_USER)
-- Add a new user `a_user'.
do
if
attached a_user.password as l_password and then
attached a_user.email as l_email
then
storage.save_user (a_user)
else
fixme ("Add error")
end
end
feature {NONE} -- Implemenataion
storage: CMS_STORAGE
-- Persistence storage
end

View File

@@ -0,0 +1,58 @@
note
description: "Summary description for {CMS_REQUEST_UTIL}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_REQUEST_UTIL
inherit
REFACTORING_HELPER
feature -- User
current_user_name (req: WSF_REQUEST): detachable READABLE_STRING_32
-- Current user name or Void in case of Guest users.
note
EIS: "src=eiffel:?class=AUTHENTICATION_FILTER&feature=execute"
do
if attached {CMS_USER} current_user (req) as l_user then
Result := l_user.name
end
fixme ("Workaround to add nodes!!!")
Result := "admin" -- Workaround
end
current_user (req: WSF_REQUEST): detachable CMS_USER
-- Current user or Void in case of Guest user.
note
EIS: "eiffel:?class=AUTHENTICATION_FILTER&feature=execute"
do
if attached {CMS_USER} req.execution_variable ("user") as l_user then
Result := l_user
end
end
feature -- Media Type
current_media_type (req: WSF_REQUEST): detachable READABLE_STRING_32
-- Current media type or Void if it's not acceptable.
do
if attached {STRING} req.execution_variable ("media_type") as l_type then
Result := l_type
end
end
feature -- Absolute Host
absolute_host (req: WSF_REQUEST; a_path:STRING): STRING
do
Result := req.absolute_script_url (a_path)
if Result.last_index_of ('/', Result.count) = Result.count then
Result.remove_tail (1)
end
end
end

View File

@@ -0,0 +1,149 @@
note
description: "[
This class implements the CMS service
It could be used to implement the main EWF service, or
even for a specific handler.
]"
class
CMS_SERVICE
inherit
WSF_ROUTED_SKELETON_SERVICE
undefine
requires_proxy
redefine
execute_default
end
WSF_NO_PROXY_POLICY
WSF_URI_HELPER_FOR_ROUTED_SERVICE
WSF_URI_TEMPLATE_HELPER_FOR_ROUTED_SERVICE
REFACTORING_HELPER
SHARED_LOGGER
create
make
feature {NONE} -- Initialization
make (a_setup: CMS_SETUP)
do
setup := a_setup
configuration := a_setup.configuration
modules := a_setup.modules
initialize_auth_engine
initialize_mailer
initialize_router
initialize_modules
end
initialize_users
do
to_implement ("To Implement initialize users")
end
initialize_mailer
do
to_implement ("To Implement mailer")
end
setup_router
do
configure_api_root
end
initialize_modules
-- Intialize modules, import router definitions
-- from enabled modules.
do
log.write_debug (generator + ".initialize_modules")
across
modules as m
loop
if m.item.is_enabled then
router.import (m.item.router)
end
end
configure_api_file_handler
end
initialize_auth_engine
do
to_implement ("To Implement authentication engine")
end
configure_api_root
local
l_root_handler: CMS_ROOT_HANDLER
l_methods: WSF_REQUEST_METHODS
do
log.write_debug (generator + ".configure_api_root")
create l_root_handler.make (setup)
create l_methods
l_methods.enable_get
router.handle_with_request_methods ("/", l_root_handler, l_methods)
end
configure_api_file_handler
local
fhdl: WSF_FILE_SYSTEM_HANDLER
do
log.write_debug (generator + ".configure_api_file_handler")
create fhdl.make_hidden_with_path (setup.layout.www_path)
fhdl.disable_index
fhdl.set_not_found_handler (agent (ia_uri: READABLE_STRING_8; ia_req: WSF_REQUEST; ia_res: WSF_RESPONSE)
do
execute_default (ia_req, ia_res)
end)
router.handle_with_request_methods ("/", fhdl, router.methods_GET)
end
feature -- Access
setup: CMS_SETUP
-- CMS setup.
configuration: CMS_CONFIGURATION
-- CMS configuration.
-- | Maybe we can compute it (using `setup') instead of using memory.
modules: LIST [CMS_MODULE]
-- List of possible modules.
-- | Maybe we can compute it (using `setup') instead of using memory.
feature -- Logging
feature -- Notification
feature -- Execution
execute_default (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Default request handler if no other are relevant
local
do
fixme ("To Implement")
end
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,36 @@
note
description: "Summary description for {CMS_HANDLER}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_HANDLER
inherit
CMS_REQUEST_UTIL
SHARED_LOGGER
REFACTORING_HELPER
feature {NONE} -- Initialization
make (a_setup: CMS_SETUP)
do
setup := a_setup
end
feature -- Setup
setup: CMS_SETUP
feature -- API Service
api_service: CMS_API_SERVICE
do
Result := setup.api_service
end
end

View File

@@ -0,0 +1,54 @@
note
description: "Summary description for {CMS_ROOT_HANDLER}."
date: "$Date$"
revision: "$Revision$"
class
CMS_ROOT_HANDLER
inherit
CMS_HANDLER
WSF_FILTER
WSF_URI_HANDLER
rename
execute as uri_execute,
new_mapping as new_uri_mapping
end
WSF_RESOURCE_HANDLER_HELPER
redefine
do_get
end
REFACTORING_HELPER
create
make
feature -- execute
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
execute_next (req, res)
end
uri_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
do
(create {HOME_CMS_RESPONSE}.make (req, res, setup,"layout2")).execute
end
end

View File

@@ -0,0 +1,62 @@
note
description: "Summary description for {CMS_GENERIC_RESPONSE}."
date: "$Date$"
revision: "$Revision$"
class
CMS_GENERIC_RESPONSE
feature -- Responses
new_response_redirect (req: WSF_REQUEST; res: WSF_RESPONSE; a_location: READABLE_STRING_32)
-- Redirect to `a_location'
local
h: HTTP_HEADER
do
create h.make
h.put_content_type_text_html
h.put_current_date
h.put_location (a_location)
res.set_status_code ({HTTP_STATUS_CODE}.see_other)
res.put_header_text (h.string)
end
new_response_authenticate (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Handle authenticate.
local
h: HTTP_HEADER
do
create h.make
h.put_content_type_text_html
h.put_current_date
h.put_header_key_value ({HTTP_HEADER_NAMES}.header_www_authenticate, "Basic realm=%"CMS-User%"")
res.set_status_code ({HTTP_STATUS_CODE}.unauthorized)
res.put_header_text (h.string)
end
new_response_denied (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Handle access denied.
local
h: HTTP_HEADER
do
create h.make
h.put_content_type_text_html
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.unauthorized)
res.put_header_text (h.string)
end
new_response_unauthorized (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Handle not authorized.
local
h: HTTP_HEADER
output: STRING
do
create h.make
h.put_content_type_text_html
h.put_current_date
res.set_status_code ({HTTP_STATUS_CODE}.forbidden)
res.put_header_text (h.string)
end
end

View File

@@ -0,0 +1,177 @@
note
description: "Generic CMS Response, place to add HOOKS features as collaborators."
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_RESPONSE
inherit
CMS_REQUEST_UTIL
REFACTORING_HELPER
feature {NONE} -- Initialization
make (req: WSF_REQUEST; res: WSF_RESPONSE; a_setup: like setup; a_template: like template)
do
status_code := {HTTP_STATUS_CODE}.ok
setup := a_setup
request := req
response := res
template := a_template
create header.make
initialize
end
initialize
do
get_theme
end
feature -- Access
request: WSF_REQUEST
response: WSF_RESPONSE
setup: CMS_SETUP
-- Current setup
status_code: INTEGER
header: WSF_HEADER
title: detachable READABLE_STRING_32
page_title: detachable READABLE_STRING_32
-- Page title
main_content: detachable STRING_8
template: READABLE_STRING_32
-- Current template.
feature -- Element change
set_title (t: like title)
do
title := t
set_page_title (t)
end
set_page_title (t: like page_title)
do
page_title := t
end
set_main_content (s: like main_content)
do
main_content := s
end
feature -- Theme
theme: CMS_THEME
-- Current theme
get_theme
local
l_info: CMS_THEME_INFORMATION
do
if attached setup.theme_information_location as fn then
create l_info.make (fn)
else
create l_info.make_default
end
if l_info.engine.is_case_insensitive_equal_general ("smarty") then
create {SMARTY_CMS_THEME} theme.make (setup, l_info, template)
else
create {DEFAULT_CMS_THEME} theme.make (setup, l_info)
end
end
feature -- Generation
prepare (page: CMS_HTML_PAGE)
do
common_prepare (page)
custom_prepare (page)
end
common_prepare (page: CMS_HTML_PAGE)
do
fixme ("Fix generacion common")
page.register_variable (request.absolute_script_url (""), "host")
page.register_variable (setup.is_web, "web")
page.register_variable (setup.is_html, "html")
if attached current_user_name (request) as l_user then
page.register_variable (l_user, "user")
end
end
custom_prepare (page: CMS_HTML_PAGE)
do
end
feature -- Custom Variables
variables: detachable STRING_TABLE[ANY]
-- Custom variables to feed the templates.
feature -- Element change: Add custom variables.
add_variable (a_element: ANY; a_key:READABLE_STRING_32)
local
l_variables: like variables
do
l_variables := variables
if l_variables = Void then
create l_variables.make (5)
variables := l_variables
end
l_variables.force (a_element, a_key)
end
feature -- Execution
execute
do
begin
process
terminate
end
feature {NONE} -- Execution
begin
do
end
process
deferred
end
frozen terminate
local
cms_page: CMS_HTML_PAGE
page: CMS_HTML_PAGE_RESPONSE
do
create cms_page.make
prepare (cms_page)
create page.make (theme.page_html (cms_page))
page.set_status_code (status_code)
response.send (page)
on_terminated
end
on_terminated
do
end
end

View File

@@ -0,0 +1,35 @@
note
description: "Summary description for {HOME_CMS_RESPONSE}."
date: "$Date$"
revision: "$Revision$"
class
HOME_CMS_RESPONSE
inherit
CMS_RESPONSE
redefine
custom_prepare
end
create
make
feature -- Generation
custom_prepare (page: CMS_HTML_PAGE)
do
page.register_variable (setup.api_service.recent_nodes (0, 5), "nodes")
end
feature -- Execution
process
-- Computed response message.
do
set_title ("Home")
set_page_title (Void)
end
end

View File

@@ -0,0 +1,77 @@
note
description: "Summary description for {CMS_HTML_PAGE_RESPONSE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_HTML_PAGE_RESPONSE
inherit
WSF_RESPONSE_MESSAGE
create
make
feature {NONE} -- Initialization
make (a_html: like html)
do
html := a_html
status_code := {HTTP_STATUS_CODE}.ok
create header.make
header.put_content_type_text_html
end
feature -- Status
status_code: INTEGER
feature -- Header
header: HTTP_HEADER
feature -- Html access
html: STRING
feature -- Element change
set_status_code (c: like status_code)
do
status_code := c
end
feature {WSF_RESPONSE} -- Output
send_to (res: WSF_RESPONSE)
local
h: like header
s: STRING_8
do
h := header
res.set_status_code (status_code)
s := html
if not h.has_content_length then
h.put_content_length (s.count)
end
if not h.has_content_type then
h.put_content_type_text_html
end
res.put_header_text (h.string)
res.put_string (s)
end
note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,13 @@
note
description: "Summary description for {WSF_CMS_HTML_TEMPLATE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_HTML_TEMPLATE
inherit
CMS_TEMPLATE
end

View File

@@ -0,0 +1,12 @@
note
description: "Summary description for {CMS_PAGE_TEMPLATE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_PAGE_TEMPLATE
inherit
CMS_TEMPLATE
end

View File

@@ -0,0 +1,37 @@
note
description: "Summary description for {WSF_CMS_PAGE_TEMPLATE}."
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_TEMPLATE
feature -- Access
theme: CMS_THEME
deferred
end
variables: STRING_TABLE [detachable ANY]
deferred
end
prepare (page: CMS_HTML_PAGE)
deferred
end
to_html (page: CMS_HTML_PAGE): STRING
deferred
end
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

48
cms/src/theme/cms_theme.e Normal file
View File

@@ -0,0 +1,48 @@
note
description: "Summary description for {WSF_CMS_THEME}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_THEME
feature {NONE} -- Access
setup: CMS_SETUP
feature -- Access
name: STRING
deferred
end
regions: ARRAY [STRING]
deferred
end
page_template: CMS_TEMPLATE
deferred
end
feature -- Conversion
page_html (page: CMS_HTML_PAGE): STRING_8
-- Render `page' as html.
deferred
end
feature {NONE} -- Implementation
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,135 @@
note
description: "Summary description for {CMS_THEME_INFORMATION}."
date: "$Date$"
revision: "$Revision$"
class
CMS_THEME_INFORMATION
create
make,
make_default
feature {NONE} -- Initialization
make_default
do
engine := {STRING_32} "default"
create items.make_caseless (1)
create regions.make (5)
across
(<<"header", "content", "footer", "first_sidebar", "second_sidebar">>) as ic
loop
regions.force (ic.item, ic.item)
end
end
make (fn: PATH)
local
f: PLAIN_TEXT_FILE
s: STRING_8
h,k: STRING_8
v: STRING_32
i: INTEGER
utf: UTF_CONVERTER
l_engine: detachable READABLE_STRING_32
done: BOOLEAN
do
make_default
create f.make_with_path (fn)
if f.exists and then f.is_access_readable then
f.open_read
from
until
done or f.exhausted or f.end_of_file
loop
f.read_line_thread_aware
s := f.last_string
s.left_adjust
if
s.is_empty
or else s.starts_with_general (";")
or else s.starts_with_general ("#")
or else s.starts_with_general ("--")
then
-- Ignore
else
i := s.index_of ('=', 1)
if i > 0 then
h := s.substring (1, i - 1)
h.left_adjust
h.right_adjust
if h.is_case_insensitive_equal_general ("engine") then
s.remove_head (i)
s.right_adjust
v := utf.utf_8_string_8_to_string_32 (s)
l_engine := v
elseif h.starts_with_general ("regions[") and h[h.count] = ']' then
s.remove_head (i)
s.right_adjust
v := utf.utf_8_string_8_to_string_32 (s)
i := h.index_of ('[', 1)
k := h.substring (i + 1, h.count - 1)
k.left_adjust
k.right_adjust
if k.starts_with_general ("-") then
--| If name is prefixed by "-"
--| remove the related region
--| If name is "-*", clear all regions.
if k.is_case_insensitive_equal_general ("-*") then
regions.wipe_out
else
k.remove_head (1)
regions.remove (k)
end
else
regions.force (v, k)
end
else
s.remove_head (i)
s.right_adjust
v := utf.utf_8_string_8_to_string_32 (s)
end
items.force (v, h)
end
end
end
f.close
end
if l_engine /= Void and then not l_engine.is_empty then
engine := l_engine
end
end
feature -- Access
engine: STRING_32
-- Template engine.
--| Could be: default, smarty, ...
regions: STRING_TABLE [READABLE_STRING_GENERAL]
-- Regions available in this theme
item (k: READABLE_STRING_GENERAL): detachable STRING_32
-- Item associated with name `k' if any.
do
Result := items[k]
end
items: STRING_TABLE [STRING_32]
-- Items indexed by key name.
invariant
engine_set: not engine.is_empty
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,75 @@
note
description: "Summary description for {DEFAULT_CMS_TEMPLATE}."
date: "$Date$"
revision: "$Revision$"
deferred class
DEFAULT_CMS_TEMPLATE
inherit
CMS_TEMPLATE
feature {NONE} -- Implementation
apply_template_engine (s: STRING_8)
local
p,n: INTEGER
k: STRING
sv: detachable STRING
do
from
n := s.count
p := 1
until
p = 0
loop
p := s.index_of ('$', p)
if p > 0 then
k := next_identifier (s, p + 1)
s.remove_substring (p, p + k.count)
sv := Void
if attached variables.item (k) as l_value then
if attached {STRING_8} l_value as s8 then
sv := s8
elseif attached {STRING_32} l_value as s32 then
sv := s32.as_string_8 -- FIXME: use html encoder
else
sv := l_value.out
end
s.insert_string (sv, p)
p := p + sv.count
else
debug
s.insert_string ("$" + k, p)
end
end
end
end
end
next_identifier (s: STRING; a_index: INTEGER): STRING
local
i: INTEGER
do
from
i := a_index
until
not (s[i].is_alpha_numeric or s[i] = '_' or s[i] = '.')
loop
i := i + 1
end
Result := s.substring (a_index, i - 1)
end
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,100 @@
note
description: "Summary description for {CMS_HTML_TEMPLATE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
DEFAULT_CMS_HTML_TEMPLATE
inherit
CMS_HTML_TEMPLATE
DEFAULT_CMS_TEMPLATE
create
make
feature {NONE} -- Initialization
make (t: DEFAULT_CMS_THEME)
do
theme := t
create variables.make (0)
end
variables: STRING_TABLE [detachable ANY]
feature -- Access
register (v: STRING_8; k: STRING_8)
do
variables.force (v, k)
end
theme: DEFAULT_CMS_THEME
prepare (page: CMS_HTML_PAGE)
do
variables.make (10)
across
page.variables as ic
loop
variables.force (ic.item, ic.key)
end
if attached page.title as l_title then
variables.force (l_title, "title")
variables.force (l_title, "head_title")
else
variables.force ("", "title")
variables.force ("", "head_title")
end
variables.force (page.language, "language")
variables.force (page.head_lines_to_string, "head_lines")
end
to_html (page: CMS_HTML_PAGE): STRING
do
-- Process html generation
create Result.make_from_string (template)
apply_template_engine (Result)
end
feature {NONE} -- Implementation
template: STRING
once
Result := "[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$language" lang="$language" version="XHTML+RDFa 1.0" dir="ltr">
<head>
$head
<title>$head_title</title>
$styles
$scripts
$head_lines
</head>
<body class="$body_classes" $body_attributes>
$page_top
$page
$page_bottom
</body>
</html>
]"
end
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,102 @@
note
description: "Summary description for {CMS_PAGE_TEMPLATE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
DEFAULT_CMS_PAGE_TEMPLATE
inherit
CMS_PAGE_TEMPLATE
DEFAULT_CMS_TEMPLATE
create
make
feature {NONE} -- Initialization
make (t: DEFAULT_CMS_THEME)
do
theme := t
create variables.make (0)
end
variables: STRING_TABLE [detachable ANY]
feature -- Access
theme: DEFAULT_CMS_THEME
prepare (page: CMS_HTML_PAGE)
do
variables.make (10)
across
page.variables as ic
loop
variables.force (ic.item, ic.key)
end
if attached page.title as l_title then
variables.force (l_title, "title")
else
variables.force ("", "title")
end
across
theme.regions as r
loop
variables.force (page.region (r.item), r.item)
end
end
to_html (page: CMS_HTML_PAGE): STRING
do
-- Process html generation
create Result.make_from_string (template)
apply_template_engine (Result)
end
feature -- Registration
register (v: STRING_8; k: STRING_8)
do
variables.force (v, k)
end
feature {NONE} -- Implementation
template: STRING
once
Result := "[
<div id="page-wrapper">
<div id="page">
<div id="header">
$header
</div>
<div id="main-wrapper">
<div id="main">
<div id="first_sidebar" class="sidebar $first_sidebar_css_class">$first_sidebar</div>
<div id="content" class="$content_css_class">$content</div>
<div id="second_sidebar" class="sidebar $second_sidebar_css_class">$second_sidebar</div>
</div>
</div>
<div id="footer">$footer</div>
</div>
</div>
]"
end
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,96 @@
note
description: "Summary description for {CMS_THEME}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
DEFAULT_CMS_THEME
inherit
CMS_THEME
create
make
feature {NONE} -- Initialization
make (a_setup: like setup; a_info: like information)
do
setup := a_setup
information := a_info
end
information: CMS_THEME_INFORMATION
feature -- Access
name: STRING = "CMS"
regions: ARRAY [STRING]
once
Result := <<"header", "content", "footer", "first_sidebar", "second_sidebar">>
end
html_template: DEFAULT_CMS_HTML_TEMPLATE
local
tpl: like internal_html_template
do
tpl := internal_html_template
if tpl = Void then
create tpl.make (Current)
internal_html_template := tpl
end
Result := tpl
end
page_template: DEFAULT_CMS_PAGE_TEMPLATE
local
tpl: like internal_page_template
do
tpl := internal_page_template
if tpl = Void then
create tpl.make (Current)
internal_page_template := tpl
end
Result := tpl
end
feature -- Conversion
prepare (page: CMS_HTML_PAGE)
do
-- page.add_style (url ("/theme/style.css", Void), Void)
end
page_html (page: CMS_HTML_PAGE): STRING_8
local
l_content: STRING_8
do
prepare (page)
page_template.prepare (page)
l_content := page_template.to_html (page)
html_template.prepare (page)
html_template.register (l_content, "page")
Result := html_template.to_html (page)
end
feature {NONE} -- Internal
internal_page_template: detachable like page_template
internal_html_template: detachable like html_template
invariant
attached internal_page_template as inv_p implies inv_p.theme = Current
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,134 @@
note
description: "Summary description for {CMS_PAGE_TEMPLATE}."
date: "$Date$"
revision: "$Revision$"
class
SMARTY_CMS_PAGE_TEMPLATE
inherit
CMS_PAGE_TEMPLATE
SHARED_TEMPLATE_CONTEXT
create
make
feature {NONE} -- Initialization
make (tpl: READABLE_STRING_GENERAL; t: SMARTY_CMS_THEME)
do
theme := t
create variables.make (0)
template_name := tpl
end
variables: STRING_TABLE [detachable ANY]
feature -- Access
template_name: READABLE_STRING_GENERAL
theme: SMARTY_CMS_THEME
prepare (page: CMS_HTML_PAGE)
do
variables.make (10)
across
page.variables as ic
loop
variables.force (ic.item, ic.key)
end
if attached page.title as l_title then
variables.force (l_title, "title")
variables.force (l_title, "head_title")
else
variables.force ("", "title")
variables.force ("", "head_title")
end
variables.force (page.language, "language")
variables.force (page.head_lines_to_string, "head_lines")
across
theme.regions as r
loop
variables.force (page.region (r.item), r.item)
end
end
to_html (page: CMS_HTML_PAGE): STRING
local
tpl: detachable TEMPLATE_FILE
ut: FILE_UTILITIES
p: detachable PATH
n: STRING_32
do
-- Process html generation
template_context.set_template_folder (theme.templates_directory)
template_context.disable_verbose
debug ("smarty")
template_context.enable_verbose
end
p := template_context.template_folder
if p = Void then
create p.make_current
end
if attached page.type as l_page_type then
create n.make_from_string_general (l_page_type)
n.append_character ('-')
n.append_string_general (template_name)
n.append_string_general (".tpl")
if ut.file_path_exists (p.extended (n)) then
create tpl.make_from_file (n)
end
end
if tpl = Void then
create n.make_from_string_general (template_name)
n.append_string_general (".tpl")
if ut.file_path_exists (p.extended (n)) then
create tpl.make_from_file (n)
end
end
if tpl /= Void then
across
variables as ic
loop
tpl.add_value (ic.item, ic.key)
end
debug ("cms")
template_context.enable_verbose
end
tpl.analyze
tpl.get_output
if attached tpl.output as l_output then
Result := l_output
else
create Result.make_from_string ("ERROR: template issue.")
end
else
create Result.make_from_string ("ERROR: template issue.")
end
end
feature -- Registration
register (v: STRING_8; k: STRING_8)
do
variables.force (v, k)
end
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,104 @@
note
description: "Summary description for {SMARTY_CMS_THEME}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
SMARTY_CMS_THEME
inherit
CMS_THEME
create
make
feature {NONE} -- Initialization
make (a_setup: like setup; a_info: like information; a_template: like template)
do
setup := a_setup
information := a_info
template := a_template
if attached a_info.item ("template_dir") as s then
templates_directory := a_setup.theme_location.extended (s)
else
templates_directory := a_setup.theme_location
end
ensure
setup_set: setup = a_setup
information_set: information = a_info
template_set: template = a_template
end
feature -- Access
name: STRING = "smarty-CMS"
template: STRING;
templates_directory: PATH
information: CMS_THEME_INFORMATION
regions: ARRAY [STRING]
local
i: INTEGER
utf: UTF_CONVERTER
once
if attached information.regions as tb and then not tb.is_empty then
i := 1
create Result.make_filled ("", i, i + tb.count - 1)
across
tb as ic
loop
Result.force (utf.utf_32_string_to_utf_8_string_8 (ic.key), i) -- NOTE: UTF-8 encoded !
i := i + 1
end
else
Result := <<"header", "content", "footer", "first_sidebar", "second_sidebar">>
end
end
page_template: SMARTY_CMS_PAGE_TEMPLATE
local
tpl: like internal_page_template
do
tpl := internal_page_template
if tpl = Void then
create tpl.make (template, Current)
internal_page_template := tpl
end
Result := tpl
end
feature -- Conversion
prepare (page: CMS_HTML_PAGE)
do
end
page_html (page: CMS_HTML_PAGE): STRING_8
do
prepare (page)
page_template.prepare (page)
Result := page_template.to_html (page)
end
feature {NONE} -- Internal
internal_page_template: detachable like page_template
invariant
attached internal_page_template as inv_p implies inv_p.theme = Current
note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

4
examples/Readme.md Normal file
View File

@@ -0,0 +1,4 @@
Examples CMS: examples
api: API is a simple example showing how to build a custom CMS using EWF.
roc_api: api build using a CMS library using modules, themes, etc.

View File

@@ -1,2 +1,2 @@
port=7070
port=8088
#verbose=true

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="roc_api" uuid="8B2873E9-8E2A-4490-8B6C-1122B579FD1D" library_target="roc_api">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="api" uuid="8B2873E9-8E2A-4490-8B6C-1122B579FD1D" library_target="api">
<target name="common" abstract="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
@@ -16,12 +16,12 @@
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="conneg" location="$ISE_LIBRARY\contrib\library\network\protocol\content_negotiation\conneg-safe.ecf"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
<library name="persistence_mysql" location="..\persistence\implementation\mysql\persistence_mysql.ecf" readonly="false"/>
<library name="persistence_mysql" location="..\..\persistence\implementation\mysql\persistence_mysql.ecf" readonly="false"/>
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\network\authentication\http_authorization\http_authorization-safe.ecf" readonly="false"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf" readonly="false"/>
<library name="layout" location="..\layout\layout.ecf"/>
<library name="layout" location="..\..\layout\layout.ecf"/>
<library name="logging" location="$ISE_LIBRARY\library\runtime\logging\logging-safe.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
<library name="process" location="$ISE_LIBRARY\library\process\process-safe.ecf"/>
@@ -29,7 +29,7 @@
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/>
</target>
<target name="roc_api_any" extends="common">
<target name="api_any" extends="common">
<root class="ROC_SERVER" feature="make_and_launch"/>
<library name="cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\connector\cgi-safe.ecf"/>
<library name="libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\connector\libfcgi-safe.ecf"/>
@@ -37,19 +37,19 @@
<cluster name="launcher" location=".\launcher\any\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="roc_api_nino" extends="common">
<target name="api_nino" extends="common">
<root class="ROC_SERVER" feature="make_and_launch"/>
<library name="default_nino" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\nino-safe.ecf"/>
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="roc_api_cgi" extends="common">
<target name="api_cgi" extends="common">
<root class="ROC_SERVER" feature="make_and_launch"/>
<library name="default_cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\cgi-safe.ecf"/>
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="roc_api_libfcgi" extends="common">
<target name="api_libfcgi" extends="common">
<root class="ROC_SERVER" feature="make_and_launch"/>
<library name="cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\connector\cgi-safe.ecf"/>
<library name="default_libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\libfcgi-safe.ecf"/>
@@ -60,7 +60,7 @@
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<!-- <target name="roc_api_test" extends="common">
<!-- <target name="api_test" extends="common">
<root class="APPLICATION_TEST" feature="make"/>
<library name="default_nino" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\nino-safe.ecf"/>
<library name="ewsgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\ewsgi\ewsgi-safe.ecf" readonly="false">
@@ -77,6 +77,6 @@
<cluster name="test" location="test\" recursive="true"/>
</target>
-->
<target name="roc_api" extends="roc_api_nino">
<target name="api" extends="api_nino">
</target>
</system>

View File

@@ -0,0 +1,32 @@
{
"database": {
"datasource": {
"driver": "MySQL",
"environment": "development"
},
"environments": {
"test": {
"connection_string":"Server=localhost;Port=3306;Database=cms_dev;Uid=root;Pwd=;"
},
"development": {
"connection_string":"Server=localhost;Port=3306;Database=cms_dev;Uid=root;Pwd=;"
},
"production": {
"connection_string":""
}
}
},
"smtp": {
"server": "localhost"
},
"logger": {
"level":"debug",
"backup_count":"4"
},
"server": {
"mode":"html"
}
}

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Some files were not shown because too many files have changed in this diff Show More