Skip to content

Instantly share code, notes, and snippets.

@ssire
ssire / gist:5195019
Created March 19, 2013 10:14
Utility XQuery date manipulation functions
(: ======================================================================
Returns a label (in French or English) to print $date as a month-day
("on March 15") or as a short label ("today", "yesterday",
"the day before yesterday") depending on current dateTime
======================================================================
:)
declare function local:gen-display-date( $date as xs:string, $lang as xs:string ) as xs:string
{
let $today := current-dateTime()
let $dur := $today - xs:dateTime($date)
@ssire
ssire / language selection menu
Created May 24, 2013 18:57
Arguable solution to generate language switch links using lang (2 letters code) injection in post-epilogue typeswitch function site:localize: the purpose of the site:lang function is to generate a relative URL when an absolute URL (starting with '/') would be rewritten in site:localize.
declare function site:lang( $cmd as element(), $view as element() ) as element()*
{
let $lang := $cmd/@lang
let $qs := request:get-query-string()
let $action := if ($cmd/@action = ('GET', 'POST')) then () else concat('/', $cmd/@action)
let $slash := if ($cmd/@type = 'item') then () else '/'
return
(
if ($lang = 'en') then
<span id="curLg">EN</span>
@ssire
ssire / localize.xql
Last active December 17, 2015 19:49
language pre-processing sample before invoking Oppidum
declare function local:localize( $path as xs:string, $languages as xs:string, $deflang as xs:string ) as xs:string {
let $options := tokenize($languages," ")
let $code := if (matches($path,"^/\w\w/?$|^/\w\w/")) then substring($path, 2, 2) else ()
return
if ($code = $options) then
(: valid 2-letters language code in URL path, return it :)
$code
else
if ($code) then
(: wrong code in URL path, pickup default language and most probably will trigger a 404 error :)
/**
* AXEL Plugin
*
* Sample input element transformed into an AXEL plugin (called "date" in this example) but this is a plain vanilla plugin
*
* The purpose is to have an example to brainstorm on AXEL plugin API and keyboard manager API
*
* Synopsis :
* - <xt:use types="date">default value</xt:use>
*