mirror of
https://github.com/flynx/pWiki.git
synced 2026-01-05 17:41:14 +00:00
added @(..) as alias to @arg(..) + minor tweaks and fixes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
819b665a87
commit
323eb39c1b
@ -618,10 +618,16 @@ object.Constructor('Page', BasePage, {
|
|||||||
//
|
//
|
||||||
// XXX ASYNC make these support async page getters...
|
// XXX ASYNC make these support async page getters...
|
||||||
macros: {
|
macros: {
|
||||||
|
//
|
||||||
|
// @(<name>[ <default>][ local])
|
||||||
|
// @(name=<name>[ default=<default>][ local])
|
||||||
//
|
//
|
||||||
// @arg(<name>[ <default>][ local])
|
// @arg(<name>[ <default>][ local])
|
||||||
// @arg(name=<name>[ default=<value>][ local])
|
// @arg(name=<name>[ default=<value>][ local])
|
||||||
//
|
//
|
||||||
|
// <arg <name>[ <default>][ local]/>
|
||||||
|
// <arg name=<name>[ default=<value>][ local]/>
|
||||||
|
//
|
||||||
arg: Macro(
|
arg: Macro(
|
||||||
['name', 'default', ['local']],
|
['name', 'default', ['local']],
|
||||||
function(args){
|
function(args){
|
||||||
@ -630,6 +636,11 @@ object.Constructor('Page', BasePage, {
|
|||||||
&& this.root
|
&& this.root
|
||||||
&& this.root.args[args.name])
|
&& this.root.args[args.name])
|
||||||
|| args.default }),
|
|| args.default }),
|
||||||
|
// alias to @arg(..)...
|
||||||
|
'': Macro(
|
||||||
|
['name', 'default', ['local']],
|
||||||
|
function(args){
|
||||||
|
return this.macros.arg.call(this, args) }),
|
||||||
//
|
//
|
||||||
// @filter(<filter-spec>)
|
// @filter(<filter-spec>)
|
||||||
// <filter <filter-spec>/>
|
// <filter <filter-spec>/>
|
||||||
|
|||||||
@ -33,24 +33,20 @@ module.BaseParser = {
|
|||||||
// STOP -- '\\>' or ')'
|
// STOP -- '\\>' or ')'
|
||||||
// PREFIX -- 'inline' or 'elem'
|
// PREFIX -- 'inline' or 'elem'
|
||||||
//
|
//
|
||||||
// XXX quote escaping???
|
|
||||||
// /(?<quote>['"])(\\\k<quote>|[^\1])*\k<quote>/
|
|
||||||
// ...this will work but we'll also need to remove the \ in the
|
|
||||||
// final string...
|
|
||||||
MACRO_ARGS: ['(\\s*(',[
|
MACRO_ARGS: ['(\\s*(',[
|
||||||
// arg='val' | arg="val" | arg=val
|
// arg='val' | arg="val" | arg=val
|
||||||
'(?<PREFIXArgName>[a-z-]+)\\s*=\\s*(?<PREFIXArgValue>'+([
|
'(?<PREFIXArgName>[a-z-]+)\\s*=\\s*(?<PREFIXArgValue>'+([
|
||||||
// XXX CHROME/NODE BUG: this does not work yet...
|
// XXX CHROME/NODE BUG: this does not work yet...
|
||||||
//'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>',
|
//'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>',
|
||||||
"'(?<PREFIXSingleQuotedValue>[^']*)'",
|
'"(?<PREFIXDoubleQuotedValue>(\\"|[^"])*?)"',
|
||||||
'"(?<PREFIXDoubleQuotedValue>[^"]*)"',
|
"'(?<PREFIXSingleQuotedValue>(\\'|[^'])*?)'",
|
||||||
'(?<PREFIXValue>[^\\sSTOP\'"]+)',
|
'(?<PREFIXValue>[^\\sSTOP\'"]+)',
|
||||||
].join('|'))+')',
|
].join('|'))+')',
|
||||||
// "arg" | 'arg'
|
// "arg" | 'arg'
|
||||||
// XXX CHROME/NODE BUG: this does not work yet...
|
// XXX CHROME/NODE BUG: this does not work yet...
|
||||||
//'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>',
|
//'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>',
|
||||||
'"(?<PREFIXDoubleQuotedArg>[^"]*)"',
|
'"(?<PREFIXDoubleQuotedArg>(\\"|[^"])*?)"',
|
||||||
"'(?<PREFIXSingleQuotedArg>[^']*)'",
|
"'(?<PREFIXSingleQuotedArg>(\\'|[^'])*?)'",
|
||||||
// arg
|
// arg
|
||||||
// NOTE: this is last because it could eat up parts of
|
// NOTE: this is last because it could eat up parts of
|
||||||
// the above alternatives...
|
// the above alternatives...
|
||||||
@ -77,15 +73,15 @@ module.BaseParser = {
|
|||||||
//
|
//
|
||||||
// needs:
|
// needs:
|
||||||
// MACROS
|
// MACROS
|
||||||
// INLINE_ARGS -- MACRO_ARGS.replace(/STOP/, ')')
|
// INLINE_ARGS
|
||||||
// ARGS -- MACRO_ARGS.replace(/STOP/, '\\/>')
|
// UNNAMED_ARGS
|
||||||
|
// ARGS
|
||||||
//
|
//
|
||||||
// XXX BUG: this fails to match inline macros with non-empty args @moo(a)
|
|
||||||
// ...the problem seems to be with the lack of whitespace
|
|
||||||
// between ( and the first arg -- @moo( a) is matched fine...
|
|
||||||
MACRO: '('+([
|
MACRO: '('+([
|
||||||
// @macro(arg ..)
|
// @macro(arg ..)
|
||||||
'\\\\?@(?<nameInline>MACROS)\\((?<argsInline>INLINE_ARGS)\\)',
|
'\\\\?@(?<nameInline>MACROS)\\((?<argsInline>INLINE_ARGS)\\)',
|
||||||
|
// @(arg ..)
|
||||||
|
'\\\\?@\\((?<argsUnnamed>UNNAMED_ARGS)\\)',
|
||||||
// <macro ..> | <macro ../>
|
// <macro ..> | <macro ../>
|
||||||
'<\\s*(?<nameOpen>MACROS)(?<argsOpen>ARGS)?\\s*/?>',
|
'<\\s*(?<nameOpen>MACROS)(?<argsOpen>ARGS)?\\s*/?>',
|
||||||
// </macro>
|
// </macro>
|
||||||
@ -102,9 +98,15 @@ module.BaseParser = {
|
|||||||
//
|
//
|
||||||
buildMacroPattern: function(macros=['MACROS'], regexp='smig'){
|
buildMacroPattern: function(macros=['MACROS'], regexp='smig'){
|
||||||
var pattern = this.MACRO
|
var pattern = this.MACRO
|
||||||
.replace(/MACROS/g, macros.join('|'))
|
.replace(/MACROS/g,
|
||||||
|
macros
|
||||||
|
.filter(function(m){
|
||||||
|
return m.length > 0 })
|
||||||
|
.join('|'))
|
||||||
.replace(/INLINE_ARGS/g,
|
.replace(/INLINE_ARGS/g,
|
||||||
this.buildArgsPattern('inline', ')', false) +'*')
|
this.buildArgsPattern('inline', ')', false) +'*')
|
||||||
|
.replace(/UNNAMED_ARGS/g,
|
||||||
|
this.buildArgsPattern('unnamed', ')', false) +'*')
|
||||||
.replace(/ARGS/g,
|
.replace(/ARGS/g,
|
||||||
this.buildArgsPattern('elem', '\\/>', false) +'*')
|
this.buildArgsPattern('elem', '\\/>', false) +'*')
|
||||||
return regexp ?
|
return regexp ?
|
||||||
@ -264,30 +266,42 @@ module.BaseParser = {
|
|||||||
var args = {}
|
var args = {}
|
||||||
var i = -1
|
var i = -1
|
||||||
for(var {groups}
|
for(var {groups}
|
||||||
of (cur.argsInline ?? cur.argsOpen ?? '')
|
of (cur.argsInline
|
||||||
|
?? cur.argsUnnamed
|
||||||
|
?? cur.argsOpen
|
||||||
|
?? '')
|
||||||
.matchAll(macro_args_pattern)){
|
.matchAll(macro_args_pattern)){
|
||||||
i++
|
i++
|
||||||
args[groups.elemArgName
|
args[groups.elemArgName
|
||||||
?? groups.inlineArgName
|
?? groups.inlineArgName
|
||||||
|
?? groups.unnamedArgName
|
||||||
?? i] =
|
?? i] =
|
||||||
groups.elemSingleQuotedValue
|
(groups.elemSingleQuotedValue
|
||||||
?? groups.inlineSingleQuotedValue
|
?? groups.inlineSingleQuotedValue
|
||||||
?? groups.elemDoubleQuotedValue
|
?? groups.unnamedSingleQuotedValue
|
||||||
?? groups.inlineDoubleQuotedValue
|
?? groups.elemDoubleQuotedValue
|
||||||
?? groups.elemValue
|
?? groups.inlineDoubleQuotedValue
|
||||||
?? groups.inlineValue
|
?? groups.unnamedDoubleQuotedValue
|
||||||
?? groups.elemSingleQuotedArg
|
?? groups.elemValue
|
||||||
?? groups.inlineSingleQuotedArg
|
?? groups.inlineValue
|
||||||
?? groups.elemDoubleQuotedArg
|
?? groups.unnamedValue
|
||||||
?? groups.inlineDoubleQuotedArg
|
?? groups.elemSingleQuotedArg
|
||||||
?? groups.elemArg
|
?? groups.inlineSingleQuotedArg
|
||||||
?? groups.inlineArg }
|
?? groups.unnamedSingleQuotedArg
|
||||||
|
?? groups.elemDoubleQuotedArg
|
||||||
|
?? groups.inlineDoubleQuotedArg
|
||||||
|
?? groups.unnamedDoubleQuotedArg
|
||||||
|
?? groups.elemArg
|
||||||
|
?? groups.inlineArg
|
||||||
|
?? groups.unnamedArg)
|
||||||
|
.replace(/\\(["'])/g, '$1') }
|
||||||
|
|
||||||
// macro-spec...
|
// macro-spec...
|
||||||
yield {
|
yield {
|
||||||
name: (cur.nameInline
|
name: (cur.nameInline
|
||||||
?? cur.nameOpen
|
?? cur.nameOpen
|
||||||
?? cur.nameClose)
|
?? cur.nameClose
|
||||||
|
?? '')
|
||||||
.toLowerCase(),
|
.toLowerCase(),
|
||||||
type: match[0] == '@' ?
|
type: match[0] == '@' ?
|
||||||
'inline'
|
'inline'
|
||||||
|
|||||||
@ -106,7 +106,7 @@ require(['./browser'], function(browser){
|
|||||||
// handle location.hash/history (both directions)
|
// handle location.hash/history (both directions)
|
||||||
window.addEventListener('hashchange', function(evt){
|
window.addEventListener('hashchange', function(evt){
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
var [path, hash] = location.hash.slice(1).split('#')
|
var [path, hash] = decodeURI(location.hash).slice(1).split('#')
|
||||||
path = path.trim() == '' ?
|
path = path.trim() == '' ?
|
||||||
pwiki.location
|
pwiki.location
|
||||||
//'/'
|
//'/'
|
||||||
@ -142,7 +142,7 @@ require(['./browser'], function(browser){
|
|||||||
// handle refresh...
|
// handle refresh...
|
||||||
// NOTE: we need to do this as hashchange is only triggered
|
// NOTE: we need to do this as hashchange is only triggered
|
||||||
// when the hash is actually changed...
|
// when the hash is actually changed...
|
||||||
for(var lnk of this.dom.querySelectorAll(`a[href="${window.location.hash}"]`)){
|
for(var lnk of this.dom.querySelectorAll(`a[href="${location.hash}"]`)){
|
||||||
lnk.addEventListener('click', function(evt){
|
lnk.addEventListener('click', function(evt){
|
||||||
that.refresh() }) } })
|
that.refresh() }) } })
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ require(['./browser'], function(browser){
|
|||||||
browser.setup.then(function(){
|
browser.setup.then(function(){
|
||||||
|
|
||||||
// show current page...
|
// show current page...
|
||||||
pwiki.location = location.hash.slice(1)
|
pwiki.location = decodeURI(location.hash).slice(1)
|
||||||
|
|
||||||
}) })
|
}) })
|
||||||
|
|
||||||
|
|||||||
45
pwiki2.js
45
pwiki2.js
@ -1,40 +1,17 @@
|
|||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* XXX FEATURE add a uniform way to track some state in links in pwiki
|
* XXX FEATURE list macro paging...
|
||||||
* for things like paging and the like with simple user/macro
|
* ...should this be macro level or handled in .each()
|
||||||
* access (???)...
|
* what mode?
|
||||||
* ...the simplest that comes to mind is to store in in path
|
* - count + block-offset (preferred)
|
||||||
* somehow:
|
* - count + elem-offset
|
||||||
* - <path>?<arg>=<value>&...
|
* - from + to
|
||||||
* traditional "query string"...
|
* XXX what should page caching use?
|
||||||
* - <path>/<arg>:<valu>/<arg>:<value>/.../<action>
|
* - .path (current)
|
||||||
* stack-style arguments...
|
* - .location
|
||||||
* + simple to implement
|
* - .path + normalized .args
|
||||||
* - goes through page search???
|
* ...should this be configurable???
|
||||||
* - <path>:<value>:<name>=<value>:...
|
|
||||||
* - ...
|
|
||||||
* the general idea is to be:
|
|
||||||
* - flexible enough to allow the basics done
|
|
||||||
* - restrictive enough to prevent misuse
|
|
||||||
* ...the rest of the state can simply be stored in the root pwiki
|
|
||||||
* object in one of the following ways:
|
|
||||||
* - directly (attrs/dict)
|
|
||||||
* - a special page
|
|
||||||
* - virtual (path-specific)
|
|
||||||
* e.g.
|
|
||||||
* /some/path/@state/page -> 4
|
|
||||||
* ...might be fun to implement a basic json editor
|
|
||||||
* and viewer with this api...
|
|
||||||
* ...controlled via js
|
|
||||||
* ...or special actions:
|
|
||||||
* /some/path/@state/page/next (increment)
|
|
||||||
* /some/path/@state/page/prev (decrement)
|
|
||||||
* /some/path/@state/page=10 (assign)
|
|
||||||
* ...
|
|
||||||
* - session
|
|
||||||
* - stored (config)
|
|
||||||
* ...css selector as path....
|
|
||||||
* XXX FEATURE tags and accompanying API...
|
* XXX FEATURE tags and accompanying API...
|
||||||
* - add tags to page -- macro/filter
|
* - add tags to page -- macro/filter
|
||||||
* <page>.text -> <page>.tags (cached on .update(..))
|
* <page>.text -> <page>.tags (cached on .update(..))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user