diff --git a/examples/demo/demo-safe.ecf b/examples/demo/demo-safe.ecf index 906a38f..2a471ef 100644 --- a/examples/demo/demo-safe.ecf +++ b/examples/demo/demo-safe.ecf @@ -1,83 +1,83 @@ - -Example/demo for Eiffel ROC CMS library - - - /EIFGENs$ - /CVS$ - /.svn$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Example/demo for Eiffel ROC CMS library + + + /EIFGENs$ + /CVS$ + /.svn$ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/demo/modules/blog/cms_blog_module.e b/examples/demo/modules/blog/cms_blog_module.e index ecbba0d..4bea68b 100644 --- a/examples/demo/modules/blog/cms_blog_module.e +++ b/examples/demo/modules/blog/cms_blog_module.e @@ -117,18 +117,18 @@ feature -- Access: router -- Let the class BLOG_HANDLER handle the requests on "/blogs" create l_uri_mapping.make_trailing_slash_ignored ("/blogs", l_blog_handler) - a_router.map_with_request_methods (l_uri_mapping, a_router.methods_get) + a_router.map (l_uri_mapping, a_router.methods_get) -- We can add a page number after /blogs/ to get older posts - a_router.handle_with_request_methods ("/blogs/page/{page}", l_blog_handler, a_router.methods_get) + a_router.handle ("/blogs/page/{page}", l_blog_handler, a_router.methods_get) -- If a user id is given route with blog user handler --| FIXME: maybe /user/{user}/blogs/ would be better. - a_router.handle_with_request_methods ("/blogs/user/{user}", l_blog_user_handler, a_router.methods_get) + a_router.handle ("/blogs/user/{user}", l_blog_user_handler, a_router.methods_get) -- If a user id is given we also want to allow different pages --| FIXME: what about /user/{user}/blogs/?page={page} ? - a_router.handle_with_request_methods ("/blogs/user/{user}/page/{page}", l_blog_user_handler, a_router.methods_get) + a_router.handle ("/blogs/user/{user}/page/{page}", l_blog_user_handler, a_router.methods_get) end diff --git a/examples/demo/modules/blog/handler/blog_user_handler.e b/examples/demo/modules/blog/handler/blog_user_handler.e index 961fe35..de1997f 100644 --- a/examples/demo/modules/blog/handler/blog_user_handler.e +++ b/examples/demo/modules/blog/handler/blog_user_handler.e @@ -86,8 +86,6 @@ feature -- Query -- User id from path /blogs/{user}. -- Unsigned integer since negative ids are not allowed. -- If no valid id can be read it returns -1 - local - s: STRING do Result := -1 if attached {WSF_STRING} req.path_parameter ("user") as l_user_id then diff --git a/examples/demo/modules/demo/cms_demo_module.e b/examples/demo/modules/demo/cms_demo_module.e index 0bef50d..a857a66 100644 --- a/examples/demo/modules/demo/cms_demo_module.e +++ b/examples/demo/modules/demo/cms_demo_module.e @@ -83,8 +83,8 @@ feature -- Access: router setup_router (a_router: WSF_ROUTER; a_api: CMS_API) -- do - map_uri_template_agent (a_router, "/demo/", agent handle_demo (?,?,a_api)) - map_uri_template_agent (a_router, "/demo/{id}", agent handle_demo_entry (?,?,a_api)) + map_uri_template_agent (a_router, "/demo/", agent handle_demo (?,?,a_api), Void) + map_uri_template_agent (a_router, "/demo/{id}", agent handle_demo_entry (?,?,a_api), Void) end feature -- Hooks @@ -144,42 +144,24 @@ feature -- Handler feature -- Mapping helper: uri template - map_uri_template (a_router: WSF_ROUTER; a_tpl: STRING; h: WSF_URI_TEMPLATE_HANDLER) - -- Map `h' as handler for `a_tpl' - require - a_tpl_attached: a_tpl /= Void - h_attached: h /= Void - do - map_uri_template_with_request_methods (a_router, a_tpl, h, Void) - end - - map_uri_template_with_request_methods (a_router: WSF_ROUTER; a_tpl: READABLE_STRING_8; h: WSF_URI_TEMPLATE_HANDLER; rqst_methods: detachable WSF_REQUEST_METHODS) + map_uri_template (a_router: WSF_ROUTER; a_tpl: READABLE_STRING_8; h: WSF_URI_TEMPLATE_HANDLER; rqst_methods: detachable WSF_REQUEST_METHODS) -- Map `h' as handler for `a_tpl' for request methods `rqst_methods'. require a_tpl_attached: a_tpl /= Void h_attached: h /= Void do - a_router.map_with_request_methods (create {WSF_URI_TEMPLATE_MAPPING}.make (a_tpl, h), rqst_methods) + a_router.map (create {WSF_URI_TEMPLATE_MAPPING}.make (a_tpl, h), rqst_methods) end feature -- Mapping helper: uri template agent - map_uri_template_agent (a_router: WSF_ROUTER; a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]) - -- Map `proc' as handler for `a_tpl' - require - a_tpl_attached: a_tpl /= Void - proc_attached: proc /= Void - do - map_uri_template_agent_with_request_methods (a_router, a_tpl, proc, Void) - end - - map_uri_template_agent_with_request_methods (a_router: WSF_ROUTER; a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_REQUEST_METHODS) + map_uri_template_agent (a_router: WSF_ROUTER; a_tpl: READABLE_STRING_8; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_REQUEST_METHODS) -- Map `proc' as handler for `a_tpl' for request methods `rqst_methods'. require a_tpl_attached: a_tpl /= Void proc_attached: proc /= Void do - map_uri_template_with_request_methods (a_router, a_tpl, create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (proc), rqst_methods) + map_uri_template (a_router, a_tpl, create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (proc), rqst_methods) end end diff --git a/examples/demo/site/config/cms.ini b/examples/demo/site/config/cms.ini index f434169..822b9e2 100644 --- a/examples/demo/site/config/cms.ini +++ b/examples/demo/site/config/cms.ini @@ -1,6 +1,7 @@ [layout] root-dir=site/www -themes-dir=site/themes +#themes-dir=site/themes +#modules-dir=site/modules [site] name=Eiffel CMS diff --git a/modules/auth/cms_authentication_email_service_parameters.e b/modules/auth/cms_authentication_email_service_parameters.e index 5db145c..e9f2e91 100644 --- a/modules/auth/cms_authentication_email_service_parameters.e +++ b/modules/auth/cms_authentication_email_service_parameters.e @@ -31,7 +31,7 @@ feature {NONE} -- Initialization admin_email := l_site_name + " <" + admin_email +">" end - if attached {CONFIG_READER} a_cms_api.module_configuration ("login", Void) as cfg then + if attached {CONFIG_READER} a_cms_api.module_configuration_by_name ("login", Void) as cfg then if attached cfg.text_item ("smtp") as l_smtp then -- Overwrite global smtp setting if any. smtp_server := utf.utf_32_string_to_utf_8_string_8 (l_smtp) diff --git a/modules/auth/cms_authentication_module.e b/modules/auth/cms_authentication_module.e index 21fc490..20a9f84 100644 --- a/modules/auth/cms_authentication_module.e +++ b/modules/auth/cms_authentication_module.e @@ -529,7 +529,8 @@ feature {NONE} -- Helpers do create p.make_from_string ("templates") p := p.extended ("block_").appended (a_block_id).appended_with_extension ("tpl") - p := a_response.module_resource_path (Current, p) + + p := a_response.api.module_theme_resource_location (Current, p) if p /= Void then if attached p.entry as e then create Result.make (a_block_id, Void, p.parent, e) diff --git a/modules/node/node_module.e b/modules/node/node_module.e index 1f495d3..c162e4b 100644 --- a/modules/node/node_module.e +++ b/modules/node/node_module.e @@ -149,26 +149,26 @@ feature -- Access: router -- TODO: for now, focused only on web interface, add REST api later. [2015-April-29] create l_node_handler.make (a_api, a_node_api) create l_uri_mapping.make_trailing_slash_ignored ("/node", l_node_handler) - a_router.map_with_request_methods (l_uri_mapping, a_router.methods_get_post) + a_router.map (l_uri_mapping, a_router.methods_get_post) - a_router.handle_with_request_methods ("/node/add/{type}", l_node_handler, a_router.methods_get_post) - a_router.handle_with_request_methods ("/node/{id}/edit", l_node_handler, a_router.methods_get_post) - a_router.handle_with_request_methods ("/node/{id}/delete", l_node_handler, a_router.methods_get_post) - a_router.handle_with_request_methods ("/node/{id}/trash", l_node_handler, a_router.methods_get_post) + a_router.handle ("/node/add/{type}", l_node_handler, a_router.methods_get_post) + a_router.handle ("/node/{id}/edit", l_node_handler, a_router.methods_get_post) + a_router.handle ("/node/{id}/delete", l_node_handler, a_router.methods_get_post) + a_router.handle ("/node/{id}/trash", l_node_handler, a_router.methods_get_post) - a_router.handle_with_request_methods ("/node/{id}", l_node_handler, a_router.methods_get) + a_router.handle ("/node/{id}", l_node_handler, a_router.methods_get) -- For now: no REST API handling... a_router.methods_get_put_delete + a_router.methods_get_post) -- Nodes create l_nodes_handler.make (a_api, a_node_api) create l_uri_mapping.make_trailing_slash_ignored ("/nodes", l_nodes_handler) - a_router.map_with_request_methods (l_uri_mapping, a_router.methods_get) + a_router.map (l_uri_mapping, a_router.methods_get) --Trash create l_trash_handler.make (a_api, a_node_api) create l_uri_mapping.make_trailing_slash_ignored ("/trash", l_trash_handler) - a_router.map_with_request_methods (l_uri_mapping, a_router.methods_get) + a_router.map (l_uri_mapping, a_router.methods_get) end diff --git a/src/configuration/cms_default_setup.e b/src/configuration/cms_default_setup.e index 64ec4b0..1bf8f6a 100644 --- a/src/configuration/cms_default_setup.e +++ b/src/configuration/cms_default_setup.e @@ -61,11 +61,18 @@ feature {NONE} -- Initialization -- Can be also used to precise the "From:" value for email. site_email := text_item_or_default ("site.email", "webmaster") - -- Location for theme folders. + -- Location for modules folders. + if attached text_item ("modules-dir") as s then + create modules_location.make_from_string (s) + else + modules_location := environment.modules_path + end + + -- Location for themes folders. if attached text_item ("themes-dir") as s then create themes_location.make_from_string (s) else - themes_location := environment.www_path.extended ("themes") + themes_location := environment.themes_path end -- Selected theme's name @@ -76,7 +83,6 @@ feature {NONE} -- Initialization end compute_theme_location - compute_theme_assets_location end initialize_storages @@ -163,15 +169,4 @@ feature -- Theme: Compute location theme_location := themes_location.extended (theme_name) end - compute_theme_assets_location - -- assets (js, css, images, etc) - -- Not used at the moment. - do - debug ("refactor_fixme") - fixme ("Check if we really need it") - end - -- Check how to get this path from the CMS_THEME information. - theme_assets_location := theme_location.extended ("assets") - end - end diff --git a/src/configuration/cms_environment.e b/src/configuration/cms_environment.e index 2feeceb..f31b31c 100644 --- a/src/configuration/cms_environment.e +++ b/src/configuration/cms_environment.e @@ -23,15 +23,35 @@ create feature -- Access - theme_path: PATH + site_path: PATH + -- Directory containing the site. + --| For now, an alias for `path'. + do + Result := path + end + + modules_path: PATH -- Directory for templates (HTML, etc). local p: detachable PATH do - p := internal_theme_path + p := internal_modules_path if p = Void then - p := www_path.extended ("theme") - internal_theme_path := p + p := site_path.extended ("modules") + internal_modules_path := p + end + Result := p + end + + themes_path: PATH + -- Directory for cms themes. + local + p: detachable PATH + do + p := internal_themes_path + if p = Void then + p := site_path.extended ("themes") + internal_themes_path := p end Result := p end @@ -58,7 +78,9 @@ feature -- Access feature {NONE} -- Implementation - internal_theme_path: detachable like theme_path + internal_modules_path: detachable like modules_path + + internal_themes_path: detachable like themes_path internal_cms_config_ini_path: detachable like cms_config_ini_path diff --git a/src/configuration/cms_setup.e b/src/configuration/cms_setup.e index 1b53010..7537e47 100644 --- a/src/configuration/cms_setup.e +++ b/src/configuration/cms_setup.e @@ -90,7 +90,10 @@ feature -- Query deferred end -feature -- Access: Theme +feature -- Access: Theme + + modules_location: PATH + -- Path to modules. themes_location: PATH -- Path to themes. @@ -98,9 +101,6 @@ feature -- Access: Theme theme_location: PATH -- Path to a active theme. - theme_assets_location: PATH - -- Path to a active theme assets folder. - theme_information_location: PATH -- Active theme informations. do diff --git a/src/service/cms_api.e b/src/service/cms_api.e index 97387fd..697c5d0 100644 --- a/src/service/cms_api.e +++ b/src/service/cms_api.e @@ -152,11 +152,8 @@ feature -- Query: module -- Enabled module typed `a_type', if any. --| usage: if attached module ({FOO_MODULE}) as mod then ... local --- t: STRING_8 l_type: TYPE [detachable CMS_MODULE] do --- t := type_name_without_annotation (a_type) - across setup.modules as ic until @@ -173,8 +170,6 @@ feature -- Query: module attached a_type.attempt (Result) and then attached l_type.generating_type.attempt (a_type) then -- Found --- elseif t.same_string (type_name_without_annotation (l_type)) then --- -- Found else Result := Void end @@ -322,55 +317,41 @@ feature {NONE}-- Implemenation internal_user_api: detachable like user_api -- Cached value for `user_api'. - type_name_without_annotation (a_type: TYPE [detachable ANY]): STRING - -- Type name for `a_type, without any annotation. - -- Used by `module' to search by type. - local - i,j,n: INTEGER - c: CHARACTER +feature -- Environment/ theme + + theme_location: PATH + -- Active theme location. do - create Result.make_from_string (a_type.name) - from - i := 1 - n := Result.count - until - i > n - loop - c := Result[i] - if c = '!' or c = '?' then - Result.remove (i) - n := n - 1 - elseif c.is_lower then - j := Result.index_of (' ', i + 1) - if j > 0 then - Result.remove_substring (i, j) - n := n - (j - i) - end - else - i := i + 1 - end - end - if Result.starts_with ("!") or Result.starts_with ("?") then - Result.remove_head (1) - elseif Result.starts_with ("detachable ") then - Result.remove_head (11) - end + Result := setup.theme_location end -feature -- Environment + theme_assets_location: PATH + -- assets (js, css, images, etc). + do + debug ("refactor_fixme") + fixme ("Check if we really need it") + end + -- Check how to get this path from the CMS_THEME information. + Result := theme_location.extended ("assets") + end - module_configuration (a_module_name: READABLE_STRING_GENERAL; a_name: detachable READABLE_STRING_GENERAL): detachable CONFIG_READER +feature -- Environment/ module + + module_configuration_by_name (a_module_name: READABLE_STRING_GENERAL; a_name: detachable READABLE_STRING_GENERAL): detachable CONFIG_READER -- Configuration reader for `a_module', and if `a_name' is set, using name `a_name'. local - p, l_path: PATH + p, l_path: detachable PATH + l_name: READABLE_STRING_GENERAL ut: FILE_UTILITIES do - p := setup.environment.config_path.extended ("modules").extended (a_module_name) if a_name = Void then - p := p.extended (a_module_name) + l_name := a_module_name else - p := p.extended (a_name) + l_name := a_name end + + p := module_location_by_name (a_module_name).extended ("config").extended (l_name) + l_path := p.appended_with_extension ("json") if ut.file_path_exists (l_path) then create {JSON_CONFIG} Result.make_from_file (l_path) @@ -382,13 +363,72 @@ feature -- Environment end if Result = Void and a_name /= Void then -- Use sub config from default? - if attached {CONFIG_READER} module_configuration (a_module_name, Void) as cfg then + if attached {CONFIG_READER} module_configuration_by_name (a_module_name, Void) as cfg then Result := cfg.sub_config (a_name) else - -- Maybe try to use the global cms.ini ? + -- Maybe try to use the global cms.ini ? end end end + modules_location: PATH + -- Directory containing cms modules. + do + Result := setup.modules_location + end + + module_location (a_module: CMS_MODULE): PATH + -- Location associated with `a_module'. + do + Result := module_location_by_name (a_module.name) + end + + module_location_by_name (a_module_name: READABLE_STRING_GENERAL): PATH + -- Location associated with `a_module_name'. + do + Result := modules_location.extended (a_module_name) + end + + module_resource_location (a_module: CMS_MODULE; a_resource: PATH): PATH + -- Location of resource `a_resource' for `a_module'. + do + --| site/modules/$modname/$a_name.json + Result := module_location (a_module).extended_path (a_resource) + end + +feature -- Environment/ modules and theme + + module_theme_resource_location (a_module: CMS_MODULE; a_resource: PATH): detachable PATH + -- Theme resource location of `a_resource' for module `a_module', if exists. + -- By default, located under the module location folder, but could be overriden + -- from files located under modules subfolder of active `theme_location'. + --| First search in themes/$theme/modules/$a_module.name/$a_resource, + --| and if not found then search in + --| modules/$a_module_name/$a_resource. + local + ut: FILE_UTILITIES + do + -- Check first in selected theme folder. + Result := module_theme_location (a_module).extended_path (a_resource) + if not ut.file_path_exists (Result) then + -- And if not found, look into site/modules/$a_module.name/.... folders. + Result := module_resource_location (a_module, a_resource) + if not ut.file_path_exists (Result) then + Result := Void + end + end + end + + module_theme_location (a_module: CMS_MODULE): PATH + -- Location for overriden files associated with `a_module_name'. + do + Result := theme_location.extended ("modules").extended (a_module.name) + end + + module_configuration (a_module: CMS_MODULE; a_name: detachable READABLE_STRING_GENERAL): detachable CONFIG_READER + do + Result := module_configuration_by_name (a_module.name, a_name) + end + end diff --git a/src/service/cms_execution.e b/src/service/cms_execution.e index efef048..e652f3e 100644 --- a/src/service/cms_execution.e +++ b/src/service/cms_execution.e @@ -156,7 +156,7 @@ feature -- Settings: router do api.logger.put_information (generator + ".configure_api_file_handler", Void) - create fhdl.make_hidden_with_path (setup.theme_assets_location) + create fhdl.make_hidden_with_path (api.theme_assets_location) fhdl.disable_index fhdl.set_not_found_handler (agent (ia_uri: READABLE_STRING_8; ia_req: WSF_REQUEST; ia_res: WSF_RESPONSE) do @@ -253,7 +253,7 @@ feature -- Execution r: NOT_FOUND_ERROR_CMS_RESPONSE f: WSF_FILE_RESPONSE do - p := api.setup.theme_assets_location.extended ("favicon.ico") + p := api.theme_assets_location.extended ("favicon.ico") if ut.file_path_exists (p) then create f.make_with_path (p) res.send (f) diff --git a/src/service/response/cms_response.e b/src/service/response/cms_response.e index 9afb6da..9a17b32 100644 --- a/src/service/response/cms_response.e +++ b/src/service/response/cms_response.e @@ -152,39 +152,6 @@ feature -- API Result := api.formats end -feature -- Module - - module_resource_path (a_module: CMS_MODULE; a_resource: PATH): detachable PATH - -- Resource path of `a_resource' for module `a_module', if resource exists. - local - rp: PATH - ut: FILE_UTILITIES - do - -- Check first in selected theme folder. - rp := module_assets_theme_location (a_module) - Result := rp.extended_path (a_resource) - if not ut.file_path_exists (Result) then - -- And if not found, look into site/modules/$a_module.name/.... folders. - rp := module_assets_location (a_module) - Result := rp.extended_path (a_resource) - if not ut.file_path_exists (Result) then - Result := Void - end - end - end - - module_assets_location (a_module: CMS_MODULE): PATH - -- Location for the assets associated with `a_module'. - do - Result := setup.environment.path.extended ("modules").extended (a_module.name) - end - - module_assets_theme_location (a_module: CMS_MODULE): PATH - -- Location for the assets associated with `a_module'. - do - Result := setup.theme_location.extended ("modules").extended (a_module.name) - end - feature -- URL utilities is_front: BOOLEAN