Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[feature] Resource: added a new function in Resource named fullpage_w…

…ith_doctype allowing to use a certain doctype {xhtml1_1} or {html5} for the moment
  • Loading branch information...
commit cc38ad05ee8eeed4c7d9a39898e42daf6c5060ff 1 parent 030de7e
@Aqua-Ye Aqua-Ye authored
View
16 stdlib/core/web/resource/resource.opa
@@ -156,9 +156,9 @@ base_url =
* to simplify page & full_page
*/
@private
-html_constructor(title,headers,html,status,customizers,rc_lastm) =
+html_constructor(title, doctype, headers, html, status, customizers, rc_lastm) =
{ rc_content =
- {~html ~customizers
+ {~html ~customizers ~doctype
headers = match title
| "" -> headers
| _ -> headers <+> <title>{title}</title>}
@@ -186,7 +186,7 @@ page(title:string, body: xhtml): resource = styled_page(title, [], body)
* @param styles A list of addresses for CSS pages.
* @param body The contents of the page.
*/
-styled_page(title:string, styles:list(string), body: xhtml): resource = html_constructor(title,
+styled_page(title:string, styles:list(string), body: xhtml): resource = html_constructor(title, {none},
<>
{List.map(url -> <link rel="stylesheet" type="text/css" href="{url}" />, styles)}
</>
@@ -211,9 +211,12 @@ html = page
* to cellphones or broken browsers. The empty list is a safe default until you start testing your application on exotic platforms.
*/
full_page(title: string, body:xhtml, headers:xhtml, status: web_response, customizers: list(platform_customization)):resource =
- html_constructor(title,headers,body,status,List.append(Resource_private.default_customizers, customizers), {volatile})
+ html_constructor(title, {none}, headers, body, status, List.append(Resource_private.default_customizers, customizers), {volatile})
// Do not cache pages, we always generate a fresh number
+full_page_with_doctype(title: string, doctype, body:xhtml, headers:xhtml, status: web_response, customizers: list(platform_customization)):resource =
+ html_constructor(title, {some=doctype}, headers, body, status, List.append(Resource_private.default_customizers, customizers), {volatile})
+
/**
* Create a resource which is recomputed at each time it is served.
* @param compute The function was recompute the resource with the
@@ -540,10 +543,11 @@ later(maker : ((resource -> void) -> void)) =
export_data({~rc_content rc_lastm=_ rc_status=_}: resource)=
rec aux(rc_content : resource_private_content) =
match rc_content with
- | {~html ~headers customizers=_} ->
+ | {~html ~doctype ~headers customizers=_} ->
body= <body id="Body">{html}</body>
head = <head>{headers}</head>
- page= Xhtml.of_string_unsafe(Resource_private.shared_html_header) <+>
+ doctype = match doctype with {some=d} -> Resource_private.html_doctype_to_string(d) {none} -> Resource_private.shared_xhtml1_1_header
+ page= Xhtml.of_string_unsafe(doctype) <+>
<html xmlns="http://www.w3.org/1999/xhtml">{head}{body}</html>
data=Xhtml.serialize_as_standalone_html(page)
some({~data mimetype="text/html"})
View
33 stdlib/core/web/resource/resource_private.opa
@@ -42,11 +42,18 @@ import stdlib.core.compare
*/
/**
+ * The doctype of an html resource
+ */
+type html_resource_doctype =
+ {html5} /
+ {xhtml1_1}
+
+/**
* The actual contents of a resource.
*/
type resource_private_content =
//User-definable resources
- {html:xhtml; headers: xhtml; customizers: list(platform_customization)}
+ {html:xhtml; doctype:option(html_resource_doctype); headers: xhtml; customizers: list(platform_customization)}
/* / {soap:xmlns}*/
/ {xml:xmlns}
/ {png:binary}
@@ -121,7 +128,10 @@ Resource_private =
@private
xhtml_equality(a,b) = xhtml_compare(a,b) == {eq}
-
+ html_doctype_to_string(doctype:html_resource_doctype) =
+ match doctype with
+ {xhtml1_1} -> shared_xhtml1_1_header
+ {html5} -> shared_html5_header
/**
* Construct the inclusion of an external resource that can possibly be modified dynamically for debugging purposes
@@ -498,12 +508,11 @@ Resource_private =
* {2 Delivery mechanism}
*/
-/**
- * The html header shared by all web pages
- */
-shared_html_header =
- "<?xml version=\"1.0\" encoding=\"utf-8\"?>
- <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"
+shared_xhtml1_1_header =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"
+
+shared_html5_header =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html>"
shared_xml_header =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
@@ -638,7 +647,7 @@ default_customizers = [customizer_for_icon,customizer_for_google_frame,required_
}
]
})
-
+
/**
* A cache for generation of xhtml resources
*/
@@ -827,7 +836,7 @@ export_resource(external_css_files: list(string),
| {~later} ->
(r -> later(( (resource : resource) -> response(force_mimetype)(winfo, resource)(r))))
- | { html=body ~headers ~customizers } ->
+ | { html=body ~doctype ~headers ~customizers } ->
(
(req:WebInfo.private.native_request) ->
//Prepare customizations
@@ -862,7 +871,9 @@ export_resource(external_css_files: list(string),
<></>, base_url)
ready_head = <head>{base}{head_without_id}{global_variable}</head>
- page= Xhtml.of_string_unsafe(shared_html_header) <+>
+ doctype = match doctype with {some=d} -> html_doctype_to_string(d) {none} -> shared_xhtml1_1_header
+
+ page= Xhtml.of_string_unsafe(doctype) <+>
<html xmlns="http://www.w3.org/1999/xhtml">{ready_head}{ready_body}</html>
//Serialize and send
Please sign in to comment.
Something went wrong with that request. Please try again.