web services - Failure to emit css link html using html_receive and html_post -
trying straightforward.. emit html link stylesheet, explained here, on swi prolog page: repositioning html css , javascript links:
http://www.swi-prolog.org/pldoc/man?section=html-post
the included library is:
:- use_module(library(http/html_write)).
i have generic dcg rule outputting css, per example:
css(url) --> html_post(css, link([ type('text/css'), rel('stylesheet'), href(url) ])).
then example says 'next insert unique css links..', example given doesn't supply parameter unique url inserted. i'm guessing @ this:
reply_html_page([title('mytitle'), \html_receive(css('/my.css'))], [ div([id='mydivid'], 'divstuff..' ) ]).
but running not output css expected.. title gets processed, css link missing.
content-type: text/html; charset=utf-8 <!doctype html> <html> <head> <title>mytitle</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head> <body> <div id="mydivid">divstuff..</div> </body> </html>
looking @ trace, css dcg rule never gets executed(version 6.6.4).
edit: perhaps solution needs include html_receive/2(+id, :handler), rather /1, there no simple copy/paste/run examples explain it's usage. code snippet html_receive/2 contains html_post.
i have used simple/atomic identifier in html_post//1
, html_receive//1
, both make example easier , stay closer swi-prolog documentation. identifier can compound, did not use in example.
the following code opens web browser generated html page. standard html inspection tools show link
element there now.
:- module(css_include, []). :- use_module(library(http/html_write)). :- use_module(library(http/http_dispatch)). :- use_module(library(http/thread_httpd)). :- use_module(library(www_browser)). :- http_server(http_dispatch, [port(5000)]). :- http_handler(root(test), test, []). test(_):- reply_html_page( [title('mytitle'),\html_receive(my_css_link)], \html_body_stuff ), www_open_url('http://localhost:5000/test'). html_body_stuff --> {url = 'http://www.swi-prolog.org'}, html_post( my_css_link, link([type('text/css'),rel('stylesheet'),href(url)]) ).
edit: based on comment @magus have included 'normal' way of generating html page css link in header, i.e. without using html_post//1
, html_receive//1
. may useful comparison other code snippet.
:- module(css_include, []). :- use_module(library(http/html_write)). :- use_module(library(http/http_dispatch)). :- use_module(library(http/thread_httpd)). :- use_module(library(www_browser)). :- http_server(http_dispatch, [port(5000)]). :- http_handler(root(test), test, []). test(_):- reply_html_page( [title('mytitle'),\a_css_link('http://www.swi-prolog.org')], \html_body_stuff ). a_css_link(url) --> html(link([type('text/css'),rel('stylesheet'),href(url)])). html_body_stuff --> html(h1('html body on here.')).
the clause a_css_link//1
can reused other uris requested.
hope helps!
Comments
Post a Comment