Permalink
Browse files

First released of a very lame blog

  • Loading branch information...
Nuno Job
Nuno Job committed Apr 14, 2010
1 parent 8d3e5aa commit 748c381e0a2969a77c001b5aef9ac21bb52048c3
Showing with 398 additions and 0 deletions.
  1. +59 −0 css/screen.css
  2. +53 −0 index.xqy
  3. +98 −0 lib/generate-tree.xqy
  4. +81 −0 lib/xqhof.xqy
  5. +59 −0 new.xqy
  6. +48 −0 show.xqy
View
@@ -0,0 +1,59 @@
/* html **********************************************************************/
* { margin: 0; padding: 0; }
body { color: #000; border-top: 4px solid #903; background: #fff;
font: 62.5% Verdana, 'Helvetica Neue', Arial, sans-serif; }
p, form, h1, h2, h3, h4, h5, h6 { font-weight: normal; }
h1, h2, h3, h4, h5, h6 { margin-bottom: .6em; color: #903;
font-family: Verdana, 'Helvetica Neue', Arial, sans-serif;
text-shadow: 4px 4px 10px #fee;}
em { color: #36c; }
p { margin-bottom: 1.5em; }
h1 { font-size: 200%; }
h2 { font-size: 160%; color: #36c; }
h3 { font-size: 150%; }
h4 { font-size: 120%; }
h5 { font-size: 110%; }
h6 { font-size: 105%; }
a { text-decoration: none; text-transform: uppercase; color: #36c; }
a:hover { text-decoration: underline; }
a img { border: none }
input, textarea { font-family: Verdana, 'Helvetica Neue', Arial, sans-serif;
font-size: 100%; }
hr { border: 1px solid #903; margin: 10px 0px 10px 0px; }
dt { margin: 0px; line-height: 1em; font-size: 1.1em;
text-transform: capitalize; font-family: 'HelveticaNeue-Light',
'Helvetica Neue', 'Helvetica Neue Light','Arial', Verdana, sans-serif; }
dd { font-size: .8em; border-style: dotted; border-width: 0px 0px 1px 0px;
border-color: #ddd; text-transform: lowercase; margin-bottom: 5px; }
/* app ***********************************************************************/
#wrapper { font-size: 1.2em; position: relative; margin: auto; width: 750px;
min-height: 100%; margin-bottom: -100px; }
#header { padding: 16px; }
#nav { background: #903; margin-bottom: 1em; border-style: solid;
border-width: 1px 1px 1px 1px; border-color: #903 #903 #903 #903;
height: 30px; text-align: right; -moz-border-radius: 5px;
-webkit-border-radius: 5px; }
#nav ul { margin: 0; padding: 0; padding-left: 20px; }
#nav li { float: left; text-align: center; padding: 8px 10px;
display: inline; border-right: solid 1px #fee; }
#nav li a { color: #fff; text-transform: lowercase; text-decoration: none;}
#nav li a:hover { text-decoration: underline; }
#content { position: relative; background-color: #ccc; clear: both; }
#maincol, #subcol, #help { padding: 20px; overflow: hidden;
margin-bottom: 1em; }
#help { padding: 10px; }
#maincol { float: left; padding: 12px 16px; background: #fee; right: 0;
width: 460px; -moz-border-radius: 5px; -webkit-border-radius: 5px; }
#subcol { background: #fee; float: left; width: 200px; padding: 12px 16px;
margin-right: 20px; border-style: solid; border-width: 1px 1px 1px 4px;
border-color: #903 #903 #903 #903; -moz-border-radius-bottomright: 5px;
-webkit-border-bottom-right-radius: 5px; }
#subcol .subnav li { display: block; text-align: left; padding: 5px 5px; }
#footer { clear: both; background: #903; height: 100px; color: #fff;
text-transform: lowercase; text-decoration: none; text-align: center;
padding: 5px;}
/* tricks ********************************************************************/
#maincol:after, #subcol:after { content: "."; display: block; height: 0;
clear: both; visibility: hidden; }
* html #maincol, * html #subcol { height: 1%; }
#maincol, #subcol { min-height: 1px; }
View
@@ -0,0 +1,53 @@
xquery version "1.0-ml" ;
xdmp:set-response-content-type( "application/xhtml+xml" ),
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title> MarkLogic Blog </title>
<link href="css/screen.css" media="screen" rel="stylesheet" type="text/css"/>
</head>
<body id="home">
<div id="wrapper">
<div id="header">
<h1> MarkLogic Blog </h1>
</div>
<div id="nav">
<ul>
<li><a href="index.xqy">Home</a></li>
</ul>
</div>
<div id="content">
<div id="subcol">
<h2>Facets</h2>
Not yet
</div>
<div id="maincol">
<div id="search">
<form name="form-search" action="search.xqy" id="form-search">
<input type="text" name="q" id="q" size="50"/>
<input type="submit" id="submitbtn" value="search"/>
</form>
</div><br/>
<h2>Listing Posts</h2>
<dl> { for $a in fn:doc() [1 to 10]
let $_ := xdmp:log ( xdmp:quote($a) )
let $permalink := fn:concat('show.xqy?uri=', fn:document-uri($a))
let $snippet := fn:string-join(
fn:tokenize(fn:string($a//*:body), " ")[1 to 20], " ")
return
(<dt><a href="{$permalink}">{fn:string($a//*:title)}</a></dt>,
<dd>{$snippet}</dd>) }
</dl>
<p>[ <a href="new.xqy">Add new</a> ]</p>
</div>
</div>
</div>
<div id="footer">
<p> Copyright © 2010 Mark Logic. All rights Reserved. </p>
</div>
</body>
</html>
View
@@ -0,0 +1,98 @@
xquery version "1.0-ml";
module namespace gen = "http://ns.dscape.org/2010/generate-tree";
import module namespace xqh = "http://ns.dscape.org/2010/xqhof"
at "xqhof.xqy" ;
import module namespace mem = "http://xqdev.com/in-mem-update"
at "/MarkLogic/appservices/utils/in-mem-update.xqy" ;
(:
: XQuery High Order Functions Library for Mark Logic Server
:
: Copyright (c) 2010 Nuno Job [about.nunojob.com]. All Rights Reserved.
:
: Licensed under the Apache License, Version 2.0 (the "License");
: you may not use this file except in compliance with the License.
: You may obtain a copy of the License at
:
: http://www.apache.org/licenses/LICENSE-2.0
:
: Unless required by applicable law or agreed to in writing, software
: distributed under the License is distributed on an "AS IS" BASIS,
: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
: See the License for the specific language governing permissions and
: limitations under the License.
:
: The use of the Apache License does not indicate that this project is
: affiliated with the Apache Software Foundation.
:)
(:
: Generate an XML tree based on a sequence of XPaths
: Original commented work at http://gist.github.com/364356
:)
declare variable $redo as xs:string* := (); (: hack, should be in fold :)
declare function gen:process-fields( $xpaths, $values ) {
let $tree := gen:generate-tree( $xpaths )
return gen:populate-tree( $tree, $xpaths, $values ) } ;
declare function gen:generate-tree( $xpaths ) {
let $f := xdmp:function( xs:QName( 'gen:generate-tree-step' ) )
return xqh:fold( $f, (), $xpaths ) } ;
declare function gen:populate-tree( $tree, $xpaths, $values ) {
let $pairs := for $xpath at $i in $xpaths return ( $xpath, $values[$i] )
let $f := xdmp:function( xs:QName( 'gen:populate-tree-step' ) )
return document { xqh:fold2( $f, $tree, $pairs ) } } ;
declare function gen:generate-tree-step( $current-tree, $xpath ) {
let $_ := xdmp:set( $redo, () )
let $f := xdmp:function( xs:QName( 'gen:create-nodes' ) )
return xqh:fold( $f, $current-tree,
xqh:tail( fn:tokenize( $xpath, "/" ) ) ) } ;
declare function gen:populate-tree-step ( $current-tree, $pair ) {
let $xpath := xqh:fst( $pair )
let $value := xqh:snd( $pair )
let $relative-path := fn:replace($xpath, "^/\w+(/.*)", "$1")
let $selected :=
xdmp:unpath( fn:concat( "$current-tree", $relative-path ) )
return gen:replace-value( $selected, $value ) } ;
declare function gen:replace-value( $node, $value ) {
if( xdmp:node-kind($node) = "attribute" )
then mem:node-replace( $node, attribute {fn:node-name( $node )} {$value} )
else mem:node-replace( $node, element {fn:node-name( $node )} {$value} ) } ;
declare function gen:insert-child( $parent, $child ) {
if( xdmp:node-kind($child) = "attribute" )
then mem:node-insert-before( ($parent/*)[1] , $child )
else mem:node-insert-child( $parent , $child ) } ;
declare function gen:create-nodes( $current-node, $xpath-step ) {
let $current-node-name := $current-node /fn:local-name(.)
let $new-node :=
if ( fn:starts-with( $xpath-step, "@") )
then attribute { fn:substring( $xpath-step, 2 ) } {}
else element { $xpath-step } {}
let $new-node-name := $new-node /fn:local-name(.)
let $steps := fn:string-join( xqh:tail( $redo ), "/" )
let $child := if( $steps )
then xdmp:unpath( fn:concat( "$current-node/", $steps ) )
else xdmp:unpath( fn:concat( "$current-node/", $xpath-step ) )
let $_ := xdmp:set( $redo, ( $redo, $xpath-step ) )
return if( fn:empty( $current-node ) )
then $new-node
else if( $current-node-name = $new-node-name )
then $current-node
else
if ( $steps )
then
if ( $child )
then gen:insert-child( $child , $new-node )
else gen:insert-child( $current-node , $new-node )
else
if( $child )
then $child
else gen:insert-child( $current-node , $new-node ) } ;
View
@@ -0,0 +1,81 @@
xquery version "1.0-ml";
module namespace xqhof = "http://ns.dscape.org/2010/xqhof";
(:
: XQuery High Order Functions Library for Mark Logic Server
:
: Copyright (c) 2010 Nuno Job [about.nunojob.com]. All Rights Reserved.
:
: Licensed under the Apache License, Version 2.0 (the "License");
: you may not use this file except in compliance with the License.
: You may obtain a copy of the License at
:
: http://www.apache.org/licenses/LICENSE-2.0
:
: Unless required by applicable law or agreed to in writing, software
: distributed under the License is distributed on an "AS IS" BASIS,
: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
: See the License for the specific language governing permissions and
: limitations under the License.
:
: The use of the Apache License does not indicate that this project is
: affiliated with the Apache Software Foundation.
:)
declare function xqhof:id($x) { $x } ;
declare function xqhof:fst( $l ) { $l[1] } ;
declare function xqhof:snd( $l ) { $l[2] } ;
declare function xqhof:head($l) { $l[1] } ;
declare function xqhof:tail($l) { fn:subsequence($l, 2) } ;
declare function xqhof:last($l) { $l[fn:last()] } ;
declare function xqhof:take($n, $l) {
fn:subsequence($l, 1, $n) } ;
declare function xqhof:drop($n, $l) {
fn:subsequence($l, $n+1) } ;
declare function xqhof:fold($f, $z, $l) {
if(fn:empty($l)) then $z
else
xqhof:fold($f,
xdmp:apply($f, $z, xqhof:head($l)),
xqhof:tail($l)) } ;
declare function xqhof:reduce($f, $z, $l) { xqhof:fold($f, $z, $l) } ;
declare function xqhof:inject($f, $z, $l) { xqhof:fold($f, $z, $l) } ;
declare function xqhof:accumulate($f, $z, $l) { xqhof:fold($f, $z, $l) } ;
declare function xqhof:compress($f, $z, $l) { xqhof:fold($f, $z, $l) } ;
declare function xqhof:map($f, $l) {
for $e in $l return xdmp:apply($f, $e) } ;
declare function xqhof:collect($f, $l) { xqhof:map($f, $l) } ;
declare function xqhof:tranform($f, $l) { xqhof:map($f, $l) } ;
declare function xqhof:filter($f, $l) {
$l[xdmp:apply($f, .)] } ;
declare function xqhof:select($f, $l) { xqhof:filter($f, $l) } ;
declare function xqhof:grep($f, $l) { xqhof:filter($f, $l) } ;
declare function xqhof:reject($f, $l) {
$l[fn:not(xdmp:apply($f, .))] } ;
declare function xqhof:every($f, $l) {
every $e in $l satisfies xdmp:apply($f, $e) } ;
declare function xqhof:all($f, $l) { xqhof:every($f, $l) } ;
declare function xqhof:some($f, $l) {
some $e in $l satisfies xdmp:apply($f, $e) } ;
declare function xqhof:any($f, $l) { xqhof:some($f, $l) } ;
declare function xqhof:head-two( $l ) { fn:subsequence( $l, 1, 2 ) } ;
declare function xqhof:tail-two( $l ) { fn:subsequence( $l, 3 ) } ;
declare function xqhof:fold2($f, $z, $l) {
if( fn:empty( $l ) ) then $z else
xqhof:fold2( $f,
xdmp:apply( $f, $z, xqhof:head-two( $l ) ),
xqhof:tail-two( $l ) ) } ;
View
59 new.xqy
@@ -0,0 +1,59 @@
xquery version "1.0-ml" ;
import module namespace gen = "http://ns.dscape.org/2010/generate-tree"
at "/lib/generate-tree.xqy" ;
xdmp:set-response-content-type( "application/xhtml+xml" ),
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title> MarkLogic Blog </title>
<link href="css/screen.css" media="screen" rel="stylesheet" type="text/css"/>
</head>
<body id="home">
<div id="wrapper">
<div id="header">
<h1> MarkLogic Blog </h1>
</div>
<div id="nav">
<ul>
<li><a href="index.xqy">Home</a></li>
</ul>
</div>
<div id="content">
<div id="subcol">
<h2>Facets</h2>
Not yet
</div>
<div id="maincol">
<h2>New Post</h2>
<div id="new-article">
{ if (fn:empty(xdmp:get-request-field-names()))
then <form name="form-new-article" method="post"
action="new.xqy" id="form-new-article">
<input type="text" name="/article/title" id="title" size="50"/>
<textarea name="/article/body" id="body" cols="50"/><br/>
<input type="submit" id="submit" value="Publish"/>
</form>
else <p>New Post created</p>,
let $salt := fn:substring(xdmp:md5(fn:string(fn:current-dateTime())), 1, 4)
let $title := xdmp:url-encode(xdmp:get-request-field('/article/title'))
let $dir := fn:replace(fn:tokenize(xs:string(fn:current-dateTime()), "T")[1], "-", "/")
let $path := fn:concat("/", $dir, "/", $title, "-", $salt ,".xml")
let $xpaths := xdmp:get-request-field-names()
let $values := for $field in $xpaths
return xdmp:get-request-field($field)
return xdmp:document-insert( $path,
gen:process-fields( $xpaths, $values ) ) }
</div>
<p>[ <a href="index.xqy">Back to main</a> ]</p>
</div>
</div>
</div>
<div id="footer">
<p> Copyright © 2010 Mark Logic. All rights Reserved. </p>
</div>
</body>
</html>
Oops, something went wrong.

0 comments on commit 748c381

Please sign in to comment.