New design for self documented router.
The documentation is built only on demand. A mapping entry can be hidden for the documentation One can change the status code when building itself the WSF_ROUTER_SELF_DOCUMENTATION_MESSAGE
This commit is contained in:
@@ -0,0 +1,52 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {WSF_ROUTER_MAPPING_DOCUMENTATION}."
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
WSF_ROUTER_MAPPING_DOCUMENTATION
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make (m: like mapping)
|
||||||
|
do
|
||||||
|
mapping := m
|
||||||
|
create {STRING_32} description.make_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Status report
|
||||||
|
|
||||||
|
is_hidden: BOOLEAN
|
||||||
|
-- Hide this mapping from any self documentation?
|
||||||
|
-- Default=False
|
||||||
|
|
||||||
|
is_empty: BOOLEAN
|
||||||
|
-- Is Current empty?
|
||||||
|
-- i.e: does not carry any information.
|
||||||
|
do
|
||||||
|
Result := description.is_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Access
|
||||||
|
|
||||||
|
mapping: WSF_ROUTER_MAPPING
|
||||||
|
-- Associated mapping
|
||||||
|
|
||||||
|
description: STRING_32
|
||||||
|
|
||||||
|
feature -- Change
|
||||||
|
|
||||||
|
set_is_hidden (b: BOOLEAN)
|
||||||
|
do
|
||||||
|
is_hidden := b
|
||||||
|
end
|
||||||
|
|
||||||
|
add_description (d: READABLE_STRING_GENERAL)
|
||||||
|
do
|
||||||
|
description.append_string_general (d)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -21,6 +21,7 @@ feature {NONE} -- Initialization
|
|||||||
make (req: WSF_REQUEST; a_router: WSF_ROUTER)
|
make (req: WSF_REQUEST; a_router: WSF_ROUTER)
|
||||||
-- Make Current for request `req' and router `a_router'
|
-- Make Current for request `req' and router `a_router'
|
||||||
do
|
do
|
||||||
|
status_code := {HTTP_STATUS_CODE}.ok
|
||||||
request := req
|
request := req
|
||||||
router := a_router
|
router := a_router
|
||||||
end
|
end
|
||||||
@@ -31,13 +32,21 @@ feature {NONE} -- Initialization
|
|||||||
--| note: it could be "/doc" or "/api/doc" or ...
|
--| note: it could be "/doc" or "/api/doc" or ...
|
||||||
do
|
do
|
||||||
make (req, a_router)
|
make (req, a_router)
|
||||||
if a_resource /= Void and then attached a_router.base_url as l_base_url then
|
if a_resource /= Void then
|
||||||
resource := l_base_url + a_resource
|
if attached a_router.base_url as l_base_url then
|
||||||
|
resource := l_base_url + a_resource
|
||||||
|
else
|
||||||
|
resource := a_resource
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
|
status_code: INTEGER
|
||||||
|
-- Associated status code
|
||||||
|
-- Default is Ok
|
||||||
|
|
||||||
request: WSF_REQUEST
|
request: WSF_REQUEST
|
||||||
|
|
||||||
router: WSF_ROUTER
|
router: WSF_ROUTER
|
||||||
@@ -57,6 +66,13 @@ feature -- Properties
|
|||||||
|
|
||||||
feature -- Change
|
feature -- Change
|
||||||
|
|
||||||
|
set_status_code (c: like status_code)
|
||||||
|
require
|
||||||
|
c_positive_or_zero: c >= 0
|
||||||
|
do
|
||||||
|
status_code := c
|
||||||
|
end
|
||||||
|
|
||||||
set_header (v: like header)
|
set_header (v: like header)
|
||||||
do
|
do
|
||||||
header := v
|
header := v
|
||||||
@@ -97,8 +113,10 @@ feature {WSF_RESPONSE} -- Output
|
|||||||
l_description.append ("[
|
l_description.append ("[
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.mappingresource { color: #00f; }
|
.mappingresource { color: #00f; }
|
||||||
.mappingdoc { color: #900; }
|
.mappingdoc { color: #900; float: right}
|
||||||
.handlerdoc { white-space: pre; }
|
.handlerdoc { white-space: pre; }
|
||||||
|
ul.mapping { margin: 0; padding: 5px; list-style-type: none; }
|
||||||
|
ul.mapping>li { margin-bottom: 5px; padding-left: 5px; border-left: solid 3px #ccc; border-top: dotted 1px #ccc; }
|
||||||
div#footer { padding: 10px; width: 100%; margin-top: 20px; border-top: 1px dotted #999; color: #999; text-align: center; }
|
div#footer { padding: 10px; width: 100%; margin-top: 20px; border-top: 1px dotted #999; color: #999; text-align: center; }
|
||||||
</style>
|
</style>
|
||||||
]")
|
]")
|
||||||
@@ -141,12 +159,12 @@ feature {WSF_RESPONSE} -- Output
|
|||||||
l_description.append ("<a href=%""+ doc_url ("") + "%">Index</a><br/>")
|
l_description.append ("<a href=%""+ doc_url ("") + "%">Index</a><br/>")
|
||||||
end
|
end
|
||||||
if attached router.item_associated_with_resource (l_api_resource, Void) as l_api_item then
|
if attached router.item_associated_with_resource (l_api_resource, Void) as l_api_item then
|
||||||
l_description.append ("<h2>Information related to %"" + l_api_resource + "%"</h2><ul>")
|
l_description.append ("<h2>Information related to <code>" + l_api_resource + "</code></h2><ul class=%"mapping%">")
|
||||||
append_documentation_to (l_description, l_api_item.mapping, l_api_item.request_methods)
|
append_documentation_to (l_description, l_api_item.mapping, l_api_item.request_methods)
|
||||||
l_description.append ("</ul>")
|
l_description.append ("</ul>")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
l_description.append ("<h2>Router</h2><ul>")
|
l_description.append ("<h2>Router</h2><ul class=%"mapping%">")
|
||||||
across
|
across
|
||||||
router as c
|
router as c
|
||||||
loop
|
loop
|
||||||
@@ -165,9 +183,10 @@ feature {WSF_RESPONSE} -- Output
|
|||||||
|
|
||||||
l_description.append ("</body></html>")
|
l_description.append ("</body></html>")
|
||||||
|
|
||||||
|
-- Compute and send the response message
|
||||||
h.put_content_length (l_description.count)
|
h.put_content_length (l_description.count)
|
||||||
h.put_current_date
|
h.put_current_date
|
||||||
res.set_status_code ({HTTP_STATUS_CODE}.ok)
|
res.set_status_code (status_code)
|
||||||
res.put_header_text (h.string)
|
res.put_header_text (h.string)
|
||||||
res.put_string (l_description)
|
res.put_string (l_description)
|
||||||
end
|
end
|
||||||
@@ -177,76 +196,78 @@ feature {WSF_RESPONSE} -- Output
|
|||||||
l_url: detachable STRING_8
|
l_url: detachable STRING_8
|
||||||
l_base_url: detachable READABLE_STRING_8
|
l_base_url: detachable READABLE_STRING_8
|
||||||
hdl: WSF_HANDLER
|
hdl: WSF_HANDLER
|
||||||
|
l_doc: detachable WSF_ROUTER_MAPPING_DOCUMENTATION
|
||||||
do
|
do
|
||||||
l_base_url := router.base_url
|
|
||||||
if l_base_url = Void then
|
|
||||||
l_base_url := ""
|
|
||||||
end
|
|
||||||
|
|
||||||
l_url := Void
|
|
||||||
s.append ("<li>")
|
|
||||||
s.append ("<code>")
|
|
||||||
if doc_url_supported then
|
|
||||||
s.append ("<a class=%"mappingresource%" href=%"")
|
|
||||||
s.append (doc_url (m.associated_resource))
|
|
||||||
s.append ("%">")
|
|
||||||
s.append (m.associated_resource)
|
|
||||||
s.append ("</a>")
|
|
||||||
else
|
|
||||||
s.append (m.associated_resource)
|
|
||||||
end
|
|
||||||
s.append ("</code>")
|
|
||||||
|
|
||||||
if attached {WSF_SELF_DOCUMENTED_ROUTER_MAPPING} m as l_doc_mapping then
|
if attached {WSF_SELF_DOCUMENTED_ROUTER_MAPPING} m as l_doc_mapping then
|
||||||
s.append (" <em class=%"mappingdoc%">" + html_encoder.encoded_string (l_doc_mapping.documentation) + "</em> ")
|
l_doc := l_doc_mapping.documentation
|
||||||
else
|
|
||||||
debug
|
|
||||||
s.append (" <em class=%"mappingdoc%">" + m.generating_type.out + "</em> ")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if meths /= Void then
|
|
||||||
s.append (" [")
|
|
||||||
across
|
|
||||||
meths as rq
|
|
||||||
loop
|
|
||||||
s.append (" ")
|
|
||||||
if l_url /= Void and then rq.item.is_case_insensitive_equal ("GET") then
|
|
||||||
s.append ("<a href=%"" + l_base_url + l_url + "%">" + rq.item + "</a>")
|
|
||||||
else
|
|
||||||
s.append (rq.item)
|
|
||||||
end
|
|
||||||
s.append (",")
|
|
||||||
end
|
|
||||||
if s[s.count] = ',' then
|
|
||||||
s.put (' ', s.count) -- Remove last ','
|
|
||||||
else
|
|
||||||
s.append_character (' ')
|
|
||||||
end
|
|
||||||
s.append_character (']')
|
|
||||||
end
|
end
|
||||||
|
if l_doc = Void or else not l_doc.is_hidden then
|
||||||
|
|
||||||
hdl := m.handler
|
l_base_url := router.base_url
|
||||||
if attached {WSF_SELF_DOCUMENTED_HANDLER} hdl as l_doc_handler and then attached l_doc_handler.documentation as l_doc then
|
if l_base_url = Void then
|
||||||
s.append ("%N<ul class=%"handlerdoc%">")
|
l_base_url := ""
|
||||||
s.append (html_encoder.encoded_string (l_doc))
|
end
|
||||||
s.append ("%N</ul>%N")
|
|
||||||
else
|
l_url := Void
|
||||||
debug
|
s.append ("<li>")
|
||||||
|
s.append ("<code>")
|
||||||
|
if doc_url_supported then
|
||||||
|
s.append ("<a class=%"mappingresource%" href=%"")
|
||||||
|
s.append (doc_url (m.associated_resource))
|
||||||
|
s.append ("%">")
|
||||||
|
s.append (m.associated_resource)
|
||||||
|
s.append ("</a>")
|
||||||
|
else
|
||||||
|
s.append (m.associated_resource)
|
||||||
|
end
|
||||||
|
s.append ("</code>")
|
||||||
|
|
||||||
|
if meths /= Void then
|
||||||
|
s.append (" [ ")
|
||||||
|
across
|
||||||
|
meths as rq
|
||||||
|
loop
|
||||||
|
if l_url /= Void and then rq.item.is_case_insensitive_equal ("GET") then
|
||||||
|
s.append ("<a href=%"" + l_base_url + l_url + "%">" + rq.item + "</a>")
|
||||||
|
else
|
||||||
|
s.append (rq.item)
|
||||||
|
end
|
||||||
|
if not rq.is_last then
|
||||||
|
s.append (",")
|
||||||
|
end
|
||||||
|
s.append (" ")
|
||||||
|
end
|
||||||
|
s.append ("]")
|
||||||
|
end
|
||||||
|
|
||||||
|
s.append (" <em class=%"mappingdoc%">" + html_encoder.encoded_string (m.description) + "</em> ")
|
||||||
|
|
||||||
|
if l_doc /= Void and then not l_doc.is_empty then
|
||||||
s.append ("%N<ul class=%"handlerdoc%">")
|
s.append ("%N<ul class=%"handlerdoc%">")
|
||||||
s.append (hdl.generating_type.out)
|
s.append (html_encoder.encoded_string (l_doc.description))
|
||||||
|
s.append ("%N</ul>%N")
|
||||||
|
else
|
||||||
|
debug
|
||||||
|
s.append ("%N<ul class=%"handlerdoc%">")
|
||||||
|
s.append (m.handler.generating_type.out)
|
||||||
|
s.append ("%N</ul>%N")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if attached {WSF_ROUTING_HANDLER} m.handler as l_routing_hdl then
|
||||||
|
s.append ("%N<ul>%N")
|
||||||
|
across
|
||||||
|
l_routing_hdl.router as c
|
||||||
|
loop
|
||||||
|
append_documentation_to (s, c.item.mapping, c.item.request_methods)
|
||||||
|
end
|
||||||
s.append ("%N</ul>%N")
|
s.append ("%N</ul>%N")
|
||||||
end
|
end
|
||||||
end
|
s.append ("</li>%N")
|
||||||
if attached {WSF_ROUTING_HANDLER} hdl as l_routing_hdl then
|
else
|
||||||
s.append ("%N<ul>%N")
|
debug
|
||||||
across
|
s.append ("<li>" + m.associated_resource + " is HIDDEN</li>%N")
|
||||||
l_routing_hdl.router as c
|
|
||||||
loop
|
|
||||||
append_documentation_to (s, c.item.mapping, c.item.request_methods)
|
|
||||||
end
|
end
|
||||||
s.append ("%N</ul>%N")
|
|
||||||
end
|
end
|
||||||
s.append ("</li>%N")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ deferred class
|
|||||||
|
|
||||||
feature -- Documentation
|
feature -- Documentation
|
||||||
|
|
||||||
documentation: detachable READABLE_STRING_32
|
mapping_documentation (m: WSF_ROUTER_MAPPING): WSF_ROUTER_MAPPING_DOCUMENTATION
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,18 @@ note
|
|||||||
deferred class
|
deferred class
|
||||||
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
|
WSF_SELF_DOCUMENTED_ROUTER_MAPPING
|
||||||
|
|
||||||
|
inherit
|
||||||
|
WSF_ROUTER_MAPPING
|
||||||
|
|
||||||
feature -- Documentation
|
feature -- Documentation
|
||||||
|
|
||||||
documentation: READABLE_STRING_32
|
documentation: WSF_ROUTER_MAPPING_DOCUMENTATION
|
||||||
deferred
|
do
|
||||||
|
if attached {WSF_SELF_DOCUMENTED_HANDLER} handler as obj then
|
||||||
|
Result := obj.mapping_documentation (Current)
|
||||||
|
else
|
||||||
|
create Result.make (Current)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Documentation
|
feature -- Documentation
|
||||||
|
|
||||||
documentation: STRING_32 = "Starts-With-URI"
|
description: STRING_32 = "Starts-With-URI"
|
||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Documentation
|
feature -- Documentation
|
||||||
|
|
||||||
documentation: STRING_32 = "Is-URI"
|
description: STRING_32 = "Is-URI"
|
||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Documentation
|
feature -- Documentation
|
||||||
|
|
||||||
documentation: STRING_32 = "Match-URI-Template"
|
description: STRING_32 = "Match-URI-Template"
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Documentation
|
feature -- Documentation
|
||||||
|
|
||||||
documentation: STRING_32 = "Is-URI"
|
description: STRING_32 = "Is-URI"
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ deferred class
|
|||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_resource: READABLE_STRING_8; h: like handler)
|
make (a_resource: READABLE_STRING_8; h: like handler)
|
||||||
|
-- Create mapping based on resource `a_resource' and handler `h'
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -25,6 +26,13 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Documentation
|
||||||
|
|
||||||
|
description: READABLE_STRING_32
|
||||||
|
-- Short description of associated mapping.
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
|
routed_handler (req: WSF_REQUEST; res: WSF_RESPONSE; a_router: WSF_ROUTER): detachable WSF_HANDLER
|
||||||
|
|||||||
Reference in New Issue
Block a user