Allow to use WSF_ROUTER_SELF_DOCUMENTATION_MESSAGE without any WSF_ROUTER_SELF_DOCUMENTATION_HANDLER

i.e without any specific URL to this self documentation.
Added custom value such as header, footer, style css url ...
This commit is contained in:
Jocelyn Fiat
2012-11-23 14:12:13 +01:00
parent 5926bbc0c2
commit 9fcb897b0b

View File

@@ -18,26 +18,49 @@ create
feature {NONE} -- Initialization
make (req: WSF_REQUEST; a_router: WSF_ROUTER; a_resource: detachable STRING)
local
do
request := req
router := a_router
if attached a_router.base_url as l_base_url then
resource := l_base_url.twin
else
create resource.make_empty
end
if a_resource /= Void then
resource.append (a_resource)
if a_resource /= Void and then attached a_router.base_url as l_base_url then
resource := l_base_url + a_resource
end
end
feature -- Access
request: WSF_REQUEST
router: WSF_ROUTER
resource: STRING_8
resource: detachable STRING_8
feature -- Properties
header: detachable STRING_8
-- Header's content for the output HTML.
footer: detachable STRING_8
-- Footer's content for the output HTML.
custom_style_url: detachable STRING_8
-- URL for a custom style css document.
feature -- Change
set_header (v: like header)
do
header := v
end
set_footer (v: like footer)
do
footer := v
end
set_custom_style_url (v: like custom_style_url)
do
custom_style_url := v
end
feature {WSF_RESPONSE} -- Output
@@ -58,6 +81,9 @@ feature {WSF_RESPONSE} -- Output
l_description.append ("<html>")
l_description.append ("<head>")
l_description.append ("<title>Documentation</title>")
if attached custom_style_url as l_custom_style_url then
l_description.append ("<link rel=%"stylesheet%" type=%"text/css%" href=%""+ l_custom_style_url +"%"/>%N")
else
l_description.append ("[
<style type="text/css">
.mappingresource { color: #00f; }
@@ -66,8 +92,12 @@ feature {WSF_RESPONSE} -- Output
div#footer { padding: 10px; width: 100%; margin-top: 20px; border-top: 1px dotted #999; color: #999; text-align: center; }
</style>
]")
end
l_description.append ("</head><body>")
if attached header as l_header then
l_description.append (l_header)
end
l_description.append ("<h1>Documentation</h1>%N")
@@ -78,21 +108,20 @@ feature {WSF_RESPONSE} -- Output
end
debug
l_description.append ("<h2>Meta</h2><ul>")
l_description.append ("<h2>Meta Information</h2><ul>")
l_description.append ("<li>PATH_INFO=" + request.path_info + "</li>")
l_description.append ("<li>QUERY_STRING=" + request.query_string + "</li>")
l_description.append ("<li>REQUEST_URI=" + request.request_uri + "</li>")
l_description.append ("<li>SCRIPT_NAME=" + request.script_name + "</li>")
l_description.append ("<li>HOME=" + request.script_url ("/") + "</li>")
if not l_base_url.is_empty then
l_description.append ("<li>Base URL=" + l_base_url + "</li>")
l_description.append ("<li>Router's Base URL=" + l_base_url + "</li>")
end
l_description.append ("</ul>")
end
if attached request.path_info as l_path then
if l_path.starts_with (resource) then
l_api_resource := l_path.substring (resource.count + 1, l_path.count)
if attached resource as l_resource and then attached request.path_info as l_path then
if l_path.starts_with (l_resource) then
l_api_resource := l_path.substring (l_resource.count + 1, l_path.count)
if l_api_resource.is_empty then
l_api_resource := Void
end
@@ -100,7 +129,9 @@ feature {WSF_RESPONSE} -- Output
end
if l_api_resource /= Void then
if doc_url_supported then
l_description.append ("<a href=%""+ doc_url ("") +"%">Index</a><br/>")
end
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>")
append_documentation_to (l_description, l_api_item.mapping, l_api_item.request_methods)
@@ -116,8 +147,14 @@ feature {WSF_RESPONSE} -- Output
l_description.append ("</ul>")
end
l_description.append ("<div id=%"footer%">")
if attached footer as l_footer then
l_description.append (l_footer)
else
l_description.append ("-- Self generated documentation --%N")
end
l_description.append ("</div>%N")
l_description.append ("<div id=%"footer%">-- Self generated documentation --</div>%N")
l_description.append ("</body></html>")
h.put_content_length (l_description.count)
@@ -141,11 +178,16 @@ feature {WSF_RESPONSE} -- Output
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></code>")
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
s.append (" <em class=%"mappingdoc%">" + html_encoder.encoded_string (l_doc_mapping.documentation) + "</em> ")
@@ -198,9 +240,24 @@ feature {WSF_RESPONSE} -- Output
feature {NONE} -- Implementation
doc_url (a_api: STRING_8): STRING_8
doc_url_supported: BOOLEAN
-- Is `doc_url' supported?
do
Result := request.script_url (resource + url_encoder.encoded_string (a_api))
Result := resource /= Void
end
doc_url (a_api: STRING_8): STRING_8
-- URL to show the documentation related to `a_api'.
require
doc_url_supported: doc_url_supported
do
if attached resource as s then
Result := request.script_url (s + url_encoder.encoded_string (a_api))
elseif attached router.base_url as l_base_url then
Result := request.script_url (l_base_url + url_encoder.encoded_string (a_api))
else
Result := request.script_url (a_api)
end
end
html_encoder: HTML_ENCODER