(index ("add-widget" 0) ("load-widget" 282) ("load-widgets-from-directory" 1388) ("waffle-sxml->html" 1931) ("widget-rules" 2281))
(def (sig (procedure "(add-widget widget-name definition)" (id add-widget))) (p "Makes the widget described by " (tt "definition") " available as " (tt "widget-name") ".") (highlight scheme "(add-widget 'say-hello `((markup . (div \"Hello \" ,user)) (attributes . ((user #f)))))"))
(def (sig (procedure "(load-widget widget-name filename)" (id load-widget))) (p "Loads a widget from the specified " (tt "filename") " and makes it available as " (tt "widget-name") ".") (p "The files are similar to scheme source files and have " (tt "markup") " and " (tt "attribute") " sections thus:") (highlight scheme "(markup . `(*TOP*\n  ,@(if user\n    `(div (img (@ (class user-avatar) (src \"/face.svg\")))\n          (span ,user)\n          (a (@ (href \"/logout\")) \"Log out\"))\n    `(a (@ (href \"/login\")) \"Log in\"))\n))\n(attributes . (\n  (user #f)\n))") (p "The " (tt "cdr") " of " (tt "markup") " should evaluate to some sxml. You can use R5RS scheme and the variables listed in " (tt "attributes") " to generate it. When the widget is called, if an attribute is specified then it is bound to that value otherwise it is bound to the default value specified in the " (tt "attributes") " list.") (p "If the above code was placed in the " (tt "user-menu.widget.scm") " file you could load it thus:") (highlight scheme "(use waffle)\n(load-widget 'user-menu \"user-menu.widget.scm\")"))
(def (sig (procedure "(load-widgets-from-directory dir extension #!optional prefix)" (id load-widgets-from-directory))) (p "Loads a bunch of widgets from the specified " (tt "dir") ".") (p "For example,") (highlight scheme "(use waffle)\n(load-widgets-from-directory \"./widgets\" \".widget.scm\")") (p "...will load the files " (tt "*.widget.scm") ". They will be automatically assigned widget names based on their filename. " (tt "x.widget.scm") " will be named as if it has been loaded thus " (tt "(load-widget 'x \"x.widget.scm\")") "."))
(def (sig (procedure "(waffle-sxml->html sxml)" (id waffle-sxml->html))) (p "Render the widget tree in " (tt "sxml") " down to HTML on " (tt "(current-output-port)") ".") (highlight scheme "(use waffle)\n(load-widgets-from-directory \"./widgets\" \".widget.scm\")\n\n(waffle-sxml->html\n  `(html (body (user-menu \"Andy\") (say-hello \"Andy\"))))"))
(def (sig (parameter "widget-rules" (id widget-rules))) (p "This is where the widgets end up after they've been added or loaded. If you want to use two or more distinct widget sets in the same process, you should " (tt "parameterize") " this around your render pipeline."))
