1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-12 13:34:29 +01:00

Nuweb drop

Signed-off-by: root <root@tdm-cloud.(none)>
This commit is contained in:
root 2019-03-09 12:32:11 +01:00
parent ee9a720f67
commit a7b55553ad
62 changed files with 1772 additions and 608 deletions

0
inc/nuweb/html.inc.sh Normal file → Executable file
View file

View file

@ -0,0 +1,5 @@
@namespace block.rewrite {
:call nuweb.html.html '+e html' '-e html'
:call nuweb.html.head '+e html' '-e html'
}

69
inc/nuweb/html.syntax.nuxsh.sh Executable file
View file

@ -0,0 +1,69 @@
@prefix statement nux.nuxsh.statement
@prefix block nux.nuxsh.block
@namespace nuweb.html.syntax {
function :statement {
:start "$@"
:end "$@"
}
function :start tag indent args {
echo -n "${indent}echo '<$tag'";
nux.log debug "Args are '$args'";
set -- $args
local attr="";
local classes="";
for arg; do
if [ -n "$attr" ] ; then
echo -n $arg"'\"'"
attr="";
else
case "$arg" in
@*)
attr="${arg#@}";
echo -n " '${attr}=\"'"
;;
.*) classes="${classes}${arg//./ }";;
*)
nux.dsl.process.fail "unknown argument '$arg' '$line' "
return 1;
;;
esac
fi
done
if [ -n "$classes" ] {
echo -n " 'class=\"'$classes'\"'"
}
echo " '>'";
}
function :end tag indent {
echo "${indent}echo '</$tag>'";
}
function :element {
for tag in "$@" ; do
block:rewrite.call nuweb.html.dynamic.$tag "nuweb.html.element $tag" "nuweb.html.element.end $tag"
block:rewrite.func nuweb.html.$tag "nuweb.html.syntax.start $tag" "nuweb.html.syntax.end $tag"
statement:rewrite.func nuweb.html.$tag "nuweb.html.syntax.statement $tag"
statement:rewrite.call nuweb.dynamic.$tag "nuweb.html.element --close $tag"
done
}
:element html body head title
:element style link meta script
:element header main nav
:element span div p pre
:element a img
:element b i strong small
:element h1 h2 h3 h4 h5 h6
:element form input submit button textarea select label
}

View file

@ -1,268 +0,0 @@
nux.use nuweb/mdl.io
nux.use nuweb/router
nux.use nux.mime
mdlio.app() {
mdlio.app.html "$@"
}
app.header() {
:
}
mdlio.app.custom() {
local func=$1; shift;
nux.exec.or $func app.$func "$@";
}
mdlio.app.html() {
nuweb.content_type text/html
echo
local spec="$1"; shift;
$spec "$@";
local appName=$(nux.exec.optional app.name);
local title="$(nux.exec.optional title)";
echo "<!doctype html>"
+e html
+e head
e meta @charset utf-8
e meta @http-equiv x-ua-compatible @content ie=edge
e meta @name "viewport" @content "width=device-width, initial-scale=1.0, minimum-scale=1.0"
mdlio.css $(mdlio.app.custom color.primary) $(mdlio.app.custom color.accent)
e link @rel stylesheet @href "$NUWEB_SCRIPT_URI/action:asset/mdlio-app.css"
e link @rel stylesheet @href "https://unpkg.com/simplelightbox@1.11.0/dist/simplelightbox.css"
nux.exec.optional app.custom.head
e title "$title - $appName"
-e head
+e body .mdl-base
+mdlio.layout .mdl-layout--fixed-header
e.mdlio.header++ "$appName"
mdlio.app.custom header
-e div
-e header
if nux.check.function app.drawer ; then
+e div .mdl-layout__drawer
app.drawer
nux.exec.optional drawer
-e div
fi
+mdlio.main
nux.exec.optional app.main.start
main "$@"
+e div @id scooter
+e div .mdl-grid @id sizer
e div @id gutter .gutter .mdl-cell .mdl-cell--1-col .mdl-cell--1-col-phone .mdl_cell--1-col-tablet
-e div
-e div
nux.exec.optional app.main.end
-e main
-e div
mdlio.app.photoswipe.html
e script @src https://code.jquery.com/jquery-3.2.1.min.js
e script @src https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.js
#e script @src https://unpkg.com/simplelightbox@1.11.0/dist/simple-lightbox.js
e script @src https://unpkg.com/photoswipe@4.1.2/dist/photoswipe.js
e script @src https://unpkg.com/photoswipe@4.1.2/dist/photoswipe-ui-default.js
e link @rel stylesheet @href https://unpkg.com/photoswipe@4.1.2/dist/photoswipe.css
e link @rel stylesheet @href https://unpkg.com/photoswipe@4.1.2/dist/default-skin/default-skin.css
e script @src https://unpkg.com/infinite-scroll@3/dist/infinite-scroll.pkgd.js
e script @src "$NUWEB_SCRIPT_URI/action:asset/mdlio-app.js"
e script @src "https://code.getmdl.io/1.3.0/material.min.js"
nux.exec.optional scripts
-e body
-e html
}
app.color.primary() {
echo teal
}
app.color.accent() {
echo cyan
}
mdlio.app.infinity() {
# outlayer: msnry,
local container=$1;
local item=$2;
local nextPage=$3;
local outlayer="";
e script """
var grid = document.querySelector('$container');
var infScroll = new InfiniteScroll( grid, {
path: '$nextPage',
append: '$item',
$outlayer
status: '.page-load-status',
elementScroll: '.mdl-layout__content',
});
"""
}
function mdlio.app.masonry() {
local grid="$1"
local gridItem="$2"
local lightBoxItem="$3"
local gutter="$4"
local nextPage="$5";
e script """
var gallery = new mdlio.cardsGallery(document.querySelector('$grid'), '$gridItem', '$lightBoxItem');
"""
}
function mdlio.app.thumb.uri() {
local filename="$1";
local mimetype="$2";
#if [ -d "$filename" ] ; then
# nux.log info "File $filename is folder."
# filename=$(find "$1" -maxdepth 1 -iname "*.jpg" -or -iname "*.png" | head -n1)
# nux.log info "Using $filename for thumbnail."
#fi
local thumb_name="$(thumby.name.shared "$filename")"
local dirname=$(dirname "$filename")
local thumb_path="$dirname/.sh_thumbnails/large/$thumb_name"
if [ -e "$thumb_path" ] ; then
nux.dirty.urlencode $thumb_path
elif thumby.thumb.can.generate "$filename" "$mimetype"; then
echo "$NUWEB_SCRIPT_URI/action:thumb/$NUWEB_REQUEST_PATH/$filename"
fi
}
function mdlio.app.thumb.get() {
img_path="${@##/}"
nux.log info "Generating thumb for" $(pwd) "$img_path"
thumb_path=$(thumby.thumb.get "${DOCUMENT_ROOT}/$img_path");
if [ -n "$thumb_path" ]; then
nux.dirty.urlencode ${thumb_path#$DOCUMENT_ROOT};
fi
}
mdlio.app.run() {
nuweb.router.exec mdlio.app.routes
}
mdlio.app.routes() {
get() {
local uri_spec="$1"; shift;
nuweb.get "$uri_spec" mdlio.app "$@"
}
get.paginate() {
main() {
#nux.exec.optional before "$@";
before=before after=after nuweb.paginate div .gallery .mdl-grid items per-item next-page 20;
#nux.exec.optional after "$@";
}
next-page() {
+e div .mdl-grid
e div .mdl-cell .mdl-cell--11-col .mdl-cell--col-3-phone .mdl-cell--col-7-tablet
+e div .mdl-cell .mdl-cell--1-col
e a .next-page .mdl-button.mdl-button--colored @href "${REQUEST_URI%%?*}?page=$1&per_page=$2" Next
-e div
-e div
}
get "$@"
}
#nuweb.get "/action:zip:serve/@+" mdlio.action.zip.serve
nuweb.get "/action:thumb/@+" nuweb.redirect.exec mdlio.app.thumb.get
nuweb.get "/action:asset/@" mdlio.app.asset
nux.exec.optional app.routes;
}
mdlio.app.asset() {
file="$NUX_ENV_DIR/assets/nuweb/$1";
if [ -e "$file" ]; then
mime=$(nux.mime "$file");
echo Content-Type: $mime
echo
cat "$file"
fi
}
mdlio.app.photoswipe.html() {
cat <<EOF
<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<!-- Background of PhotoSwipe.
It's a separate element as animating opacity is faster than rgba(). -->
<div class="pswp__bg"></div>
<!-- Slides wrapper with overflow:hidden. -->
<div class="pswp__scroll-wrap">
<!-- Container that holds slides.
PhotoSwipe keeps only 3 of them in the DOM to save memory.
Don't modify these 3 pswp__item elements, data is added later on. -->
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<!-- Controls are self-explanatory. Order can be changed. -->
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
<!-- element will get class pswp__preloader--active when preloader is running -->
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
</button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
</button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
EOF
}

View file

@ -1,25 +0,0 @@
nux.use nuweb/html
mdlio.css() {
e.link stylesheet "https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en"
e.link stylesheet "https://fonts.googleapis.com/icon?family=Material+Icons"
e.link stylesheet "https://code.getmdl.io/1.3.0/material.${1}-${2}.min.css"
}
e.mdlio.header++() {
+e header .mdl-layout__header .mdl-color--primary
+e div .mdl-layout__header-row
e span .mdl-layout-title $1
e div .mdl-layout-spacer
}
e.alias mdlio.layout "div" ".mdl-layout .mdl-js-layout"
e.alias mdlio.main "main" ".mdl-layout__content"
e.alias mdlio.card "div" ".mdl-card.mdl-shadow--2dp"
.mdl_cell() {
echo .mdl-cell.mdl-cell--"$1"-col.mdl-cell--"$2"-col-tablet.mdl-cell--"$2"-col-phone
}

View file

@ -0,0 +1,16 @@
@namespace app {
function :color.primary {
echo teal
}
function :color.accent {
echo cyan
}
function :header {
:
}
}

228
inc/nuweb/mdlio.app.nuxsh.sh Executable file
View file

@ -0,0 +1,228 @@
@syntax nuweb/html
nux.use nuweb/mdlio
nux.use nuweb/mdlio.app.defaults
nux.use nuweb/router
nux.use nux/mime
nux.use thumby
nux.use thumby/builtin
@prefix h nuweb.html
@prefix router nuweb.router
@block:rewrite:call2 e +e -e ;
@namespace mdlio.app {
function mdlio.app spec {
#nux.exec.optional app.init
$spec "$@";
mdlio.app.html
}
function :custom func {
nux.exec.or $func app.$func "$@";
}
function :additional-css css {
mdlio_app_additional_css="$mdlio_app_additional_css $css"
}
function :additional-script script {
mdlio_app_additional_script="$mdlio_app_additional_script $script"
}
function :html {
nuweb.content_type text/html
echo
local app_uri="${NUWEB_SCRIPT_URI}";
local appName=$(nux.exec.optional app.name);
echo "<!doctype html>"
h:html {
h:head {
h:meta @charset utf-8
h:meta @http-equiv x-ua-compatible @content ie=edge
h:meta @name "viewport" @content "width=device-width, initial-scale=1.0, minimum-scale=1.0"
mdlio.css $(mdlio.app.custom color.primary) $(mdlio.app.custom color.accent)
h:link @rel stylesheet @href "$NUWEB_SCRIPT_URI/action/mdlio:asset/mdlio-app.css"
h:link @rel stylesheet @href "https://unpkg.com/simplelightbox@1.11.0/dist/simplelightbox.css"
for css in $mdlio_app_additional_css; do
h:link @rel stylesheet @href "$NUWEB_SCRIPT_DIR_URI/$css"
done
nux.exec.optional app.custom.head
h:title {
nux.exec.optional title
echo -
nux.exec.optional app.name
}
}
h:body .mdl-base {
+mdlio.layout .mdl-layout--fixed-header
e.mdlio.header++ "$appName"
mdlio.app.custom header
-e div
-e header
if nux.check.function app.drawer ; then
h:div .mdl-layout__drawer {
app.drawer
nux.exec.optional drawer
}
fi
+mdlio.main
nux.exec.optional app.main.start
nux.exec.or app.template-main app.content "$@"
-e main
-e div
mdlio.app.photoswipe.html
h:div .scripts {
h:script @src "https://code.jquery.com/jquery-3.2.1.min.js"
h:script @src "https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.js"
h:script @src "https://unpkg.com/photoswipe@4.1.2/dist/photoswipe.js"
h:script @src "https://unpkg.com/photoswipe@4.1.2/dist/photoswipe-ui-default.js"
h:link @rel stylesheet @href https://unpkg.com/photoswipe@4.1.2/dist/photoswipe.css
h:link @rel stylesheet @href https://unpkg.com/photoswipe@4.1.2/dist/default-skin/default-skin.css
h:script @src "https://unpkg.com/infinite-scroll@3/dist/infinite-scroll.pkgd.js"
h:script @src "$(mdlio.app.action.uri mdlio:asset /mdlio-app.js)"
h:script @src "https://code.getmdl.io/1.3.0/material.min.js"
for script in $mdlio_app_additional_script; do
h:script @src "$NUWEB_SCRIPT_DIR_URI/$script"
done
nux.exec.optional scripts
}
}
}
}
function :grid-sizer {
h:div @id scooter {
h:div .mdl-grid @id sizer {
h:div @id gutter .gutter .mdl-cell .mdl-cell--1-col .mdl-cell--1-col-phone .mdl_cell--1-col-tablet
h:div @id gutter .gutter .mdl-cell .mdl-cell--1-col .mdl-cell--1-col-phone .mdl_cell--1-col-tablet
h:div @id gutter .gutter .mdl-cell .mdl-cell--1-col .mdl-cell--1-col-phone .mdl_cell--1-col-tablet
h:div @id gutter .gutter .mdl-cell .mdl-cell--1-col .mdl-cell--1-col-phone .mdl_cell--1-col-tablet
h:div @id gutter .gutter .mdl-cell .mdl-cell--1-col .mdl-cell--1-col-phone .mdl_cell--1-col-tablet
h:div @id gutter .gutter .mdl-cell .mdl-cell--1-col .mdl-cell--1-col-phone .mdl_cell--1-col-tablet
h:div @id gutter .gutter .mdl-cell .mdl-cell--1-col .mdl-cell--1-col-phone .mdl_cell--1-col-tablet
h:div @id gutter .gutter .mdl-cell .mdl-cell--1-col .mdl-cell--1-col-phone .mdl_cell--1-col-tablet
}
}
}
function :infinity container item nextPage {
local outlayer="";
e script """
var infScroll = new InfiniteScrolldocument.querySelector('$container'); grid, {
path: '$nextPage',
append: '$item',
$outlayer
status: '.page-load-status',
elementScroll: '.mdl-layout__content'
});
"""
}
function :masonry grid gridItem lightBoxItem gutter nextPage {
e script """
var gallery = new mdlio.cardsGallery(document.querySelector('$grid'), '$gridItem', '$lightBoxItem');
"""
}
function :action.uri action path args {
echo "$NUWEB_SCRIPT_URI/action/${action}${path}${args}"
}
function :thumb.uri filename mimetype {
local thumb_name="$(thumby.name.shared "$filename")"
local dirname=$(dirname "$filename")
local thumb_path="$dirname/.sh_thumbnails/large/$thumb_name"
if thumby.thumb.can.generate "$filename" "$mimetype"; then
if thumby.thumb.should.generate "$filename" "$mimetype"; then
:action.uri mdlio:thumb "$NUWEB_REQUEST_PATH/$filename"
return 0;
fi
fi
if [ -e "$thumb_path" ] ; then
nux.dirty.urlencode "$thumb_path"
fi
}
function :thumb.get {
img_path="${@##/}"
nux.log info "Generating thumb for" $(pwd) "$img_path"
thumb_path="$(thumby.thumb.get "${DOCUMENT_ROOT}/$img_path")";
if [ -n "$thumb_path" ]; then
nux.dirty.urlencode "${thumb_path#$DOCUMENT_ROOT}";
fi
}
function :run {
nuweb.router.exec mdlio.app.routes
}
function :routes {
function :post uri_spec {
router:post "$uri_spec" mdlio.app "$@"
}
function :get uri_spec {
router:get "$uri_spec" mdlio.app "$@"
}
function :get.paginate {
function app.content {
#nux.exec.optional before "$@";
before=before after=after nuweb.paginate div .gallery .mdl-grid items per-item next-page 20;
#nux.exec.optional after "$@";
}
function next-page {
h:div .mdl-grid {
h:div .mdl-cell .mdl-cell--11-col .mdl-cell--col-3-phone .mdl-cell--col-7-tablet
h:div .mdl-cell .mdl-cell--1-col {
h:a .next-page .mdl-button.mdl-button--colored @href "${REQUEST_URI%%?*}?page=$1&per_page=$2" Next
}
}
}
:get "$@"
}
#nuweb.get "/action:zip:serve/@+" mdlio.action.zip.serve
router:get "/action/mdlio:thumb/@+" nuweb.redirect.exec mdlio.app.thumb.get
router:get "/action/mdlio:asset/@" mdlio.app.asset
nux.exec.optional app.routes;
:get "/" app.main;
}
function :asset name {
local file="$NUX_ENV_DIR/assets/nuweb/$name";
if [ -e "$file" ]; then
mime=$(nux.mime "$file");
echo Content-Type: $mime
echo
cat "$file"
fi
}
function :photoswipe.html {
echo "<div></div>"
}
}

View file

@ -0,0 +1,50 @@
@syntax nuweb/html
@prefix statement nux.nuxsh.statement
@prefix block nux.nuxsh.block
@prefix hs nuweb.html.syntax
nux.use nuweb/html.syntax
@namespace nuweb.mdlio.syntax {
function :element name tag {
block:rewrite.call nuweb.mdlio.tag.$name "nuweb.html.element $tag $@" "nuweb.html.element.end $tag"
statement:rewrite.call nuweb.mdlio.tag.$name "nuweb.html.element --close $tag $@"
}
function :block-as-function fqn {
block:rewrite.call $fqn "function $fqn {" "}"
}
function :statement-as-echo-function fqn {
statement:rewrite.call $fqn "function $fqn() { echo " ";}"
}
:element card div .mdl-card.mdl-shadow--2dp
:element card-media div .mdl-card_media
:element card-title div .mdl-card_title
:element nav nav .mdl-navigation
:block-as-function app.name
:block-as-function app.main
:block-as-function app.content
:block-as-function app.drawer
:block-as-function app.page-title
:block-as-function app.title
:block-as-function app.scripts
:block-as-function app.template-main
:block-as-function app.routes
#:statement-as-echo-function app.page-title
#:statement-as-echo-function app.content
}
function .block.app.start.plan {
identifier=app .match.namespace_block_start.plan
}
function .block.app.end.plan {
.block.rule.namespace.end.plan
}

49
inc/nuweb/mdlio.nuxsh.sh Executable file
View file

@ -0,0 +1,49 @@
@syntax nuweb/html
@prefix h nuweb.html
@prefix hd nuweb.html.dynamic
nux.use nuweb/html
function mdlio.css() {
e.link stylesheet "https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en"
e.link stylesheet "https://fonts.googleapis.com/icon?family=Material+Icons"
e.link stylesheet "https://code.getmdl.io/1.3.0/material.${1}-${2}.min.css"
}
function e.mdlio.header++() {
+e header .mdl-layout__header .mdl-color--primary
+e div .mdl-layout__header-row
e span .mdl-layout-title $1
e div .mdl-layout-spacer
}
@namespace nuweb.mdlio.tag {
function :textfield id type label {
h:div .mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label {
hd:input .mdl-textfield__input @type "$type" @id "$id" "$@"
h:label .mdl-textfield__label @for $id {
echo $label
}
}
}
function :submit name {
hd:input @type submit .mdl-button.mdl-js-button.mdl-button--raised.mdl-button--accent @value "$name" "$@"
}
function :nav-link href {
h:a .mdl-navigation__link @href "$href" {
echo "$@"
}
}
}
e.alias mdlio.layout "div" ".mdl-layout .mdl-js-layout"
e.alias mdlio.main "main" ".mdl-layout__content"
e.alias mdlio.card "div" ".mdl-card.mdl-shadow--2dp"
function .mdl_cell() {
echo mdl-cell mdl-cell--"$1"-col mdl-cell--"$2"-col-tablet mdl-cell--"$2"-col-phone
}

30
inc/nuweb/router.inc.sh Normal file → Executable file
View file

@ -20,13 +20,18 @@
##
##
nuweb.router.tryexec.concrete() {
full_spec=$1;
method="$1";
full_spec="$2";
func="$3";
shift; shift; shift;
if [ "$REQUEST_METHOD" != "$method" ]; then
return 1;
fi
path_spec=${full_spec%%\?*}
query_spec=${full_spec#$path_spec}
query_spec=${query_spec#\?}
func=$2;
shift; shift;
nux.log trace "Checking Path Spec: '$path_spec', Query Spec: '$query_spec' Function:$func Additional Args:$@" >&2
IFS='/' read -ra spec_components <<< "$path_spec"
@ -41,12 +46,12 @@ nuweb.router.tryexec.concrete() {
elif [ "$spec" == "@" ]; then
path_args="$path_args $path";
elif [ "$spec" != "$path" ] ; then
return -1
return 1
fi
let i=$i+1
done
if [ $i -lt "${#spec_components[@]}" ] ; then
return -1;
return 1;
fi
if [ -n "$query_spec" ]; then
IFS='&' read -ra query_components <<< "$query_spec"
@ -59,27 +64,29 @@ nuweb.router.tryexec.concrete() {
else
if [ -z "$value" ]; then
#echo "$def $value is empty." >&2;
return -1;
return 1;
elif [ "$valueDef" == "@" ]; then
query_args="$query_args $value"
elif [ "$value" != "$valueDef" ]; then
#echo "$def $value != $valueDef" >&2;
return -1;
return 1;
fi
fi
done
fi
path_c=$(dirty.url.decode "$path_c")
$func "$@" $path_args "$path_c" $query_args
nuweb.http.query.with_env nuweb.http.post.with_env $func "$@" $path_args "$path_c" $query_args
exit 0
}
nuweb.get() {
nuweb.router.tryexec.concrete $@;
nuweb.router.get() {
nuweb.router.tryexec.concrete GET "$@";
}
nuweb.router.post() {
nuweb.router.tryexec.concrete POST "$@";
}
##
## nuweb.router.exec:: <definition> [path]
@ -99,6 +106,7 @@ nuweb.router.exec() {
path="/"
fi
nux.log debug "Method: '$REQUEST_METHOD' Path: '$path'"
IFS='/' read -ra PATH_COMPONENTS <<< "$path"
$definition

0
inc/nuweb/utils.inc.sh Normal file → Executable file
View file