Guest User

Untitled

a guest
Sep 19th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.41 KB | None | 0 0
  1. :- use_module(library(http/http_server)).
  2. :- use_module(library(http/http_files)).
  3. :- use_module(library(http/js_write)).
  4.  
  5. :- http_handler(root(.), homepage, []).
  6. :- http_handler(root(contacts), contacts, [id(contacts_GET)]).
  7. :- http_handler(root(assets/'style.css'), http_reply_file('assets/style.css', []), [id(style_GET)]).
  8.  
  9. user:file_search_path(assets, assets).
  10.  
  11. homepage(_R) :-
  12.     reply_html_page([title("HTMX Test"),
  13.              script([src("https://unpkg.com/htmx.org@1.9.2"),
  14.                  integrity("sha384-L6OqL9pRWyyFU3+/bjdSri+iIphTN/bvYyM37tICVyOJkWZLpP2vGn6VUEXgzg6h"),
  15.                  crossorigin("anonymous")],[]),
  16.              link([rel(stylesheet),href(#(style_GET))])
  17.             ],
  18.             [          
  19.             \js_script("function foo() { return true && !false; }"),
  20.             script(language('JavaScript'),\js_call("function foo() { return true && !false; }")),
  21.             div([id(main)],
  22.                 [          
  23.                 button(['hx-get'(#(contacts_GET)),
  24.                     'hx-target'('#main'),
  25.                     'hx-swap'(outerHTML),
  26.                     'hx-trigger'('click, keyup[ctrlKey && key == \"L\"] from:body'-[])
  27.                        ],
  28.                        "Get the Contacts"),
  29.                 div([id(contacts)],[])
  30.                 ])
  31.             ]).
  32.              
  33. contacts(_R) :-
  34.     reply_htmx(ul([li("Mike"),li("Ren"),li("Tom"),li("Andreas Lindner")])).
  35.  
  36.  
  37. reply_htmx(Elem) :-
  38.     html_write:html_current_option(content_type(Type)),
  39.     phrase(html(Elem), HTML),
  40.     format('Content-type: ~w~n~n', [Type]),
  41.     html_write:print_html(HTML).
  42.  
Advertisement
Add Comment
Please, Sign In to add comment