Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- use_module(library(http/http_server)).
- :- use_module(library(http/http_files)).
- :- use_module(library(http/js_write)).
- :- http_handler(root(.), homepage, []).
- :- http_handler(root(contacts), contacts, [id(contacts_GET)]).
- :- http_handler(root(assets/'style.css'), http_reply_file('assets/style.css', []), [id(style_GET)]).
- user:file_search_path(assets, assets).
- homepage(_R) :-
- reply_html_page([title("HTMX Test"),
- script([src("https://unpkg.com/htmx.org@1.9.2"),
- integrity("sha384-L6OqL9pRWyyFU3+/bjdSri+iIphTN/bvYyM37tICVyOJkWZLpP2vGn6VUEXgzg6h"),
- crossorigin("anonymous")],[]),
- link([rel(stylesheet),href(#(style_GET))])
- ],
- [
- \js_script("function foo() { return true && !false; }"),
- script(language('JavaScript'),\js_call("function foo() { return true && !false; }")),
- div([id(main)],
- [
- button(['hx-get'(#(contacts_GET)),
- 'hx-target'('#main'),
- 'hx-swap'(outerHTML),
- 'hx-trigger'('click, keyup[ctrlKey && key == \"L\"] from:body'-[])
- ],
- "Get the Contacts"),
- div([id(contacts)],[])
- ])
- ]).
- contacts(_R) :-
- reply_htmx(ul([li("Mike"),li("Ren"),li("Tom"),li("Andreas Lindner")])).
- reply_htmx(Elem) :-
- html_write:html_current_option(content_type(Type)),
- phrase(html(Elem), HTML),
- format('Content-type: ~w~n~n', [Type]),
- html_write:print_html(HTML).
Advertisement
Add Comment
Please, Sign In to add comment