mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
added sort attr to macro.... not fully done yet...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
24bb047564
commit
19c910f0ac
2
bootstrap.js
vendored
2
bootstrap.js
vendored
File diff suppressed because one or more lines are too long
@ -164,7 +164,7 @@ Each new occurrence of a name will change slot content.
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### macro (name src text) / else ()
|
### macro (name src sort) / else ()
|
||||||
|
|
||||||
Apply macro to source page and include the result.
|
Apply macro to source page and include the result.
|
||||||
|
|
||||||
@ -184,6 +184,7 @@ a named macro or in the current macro.
|
|||||||
Arguments:
|
Arguments:
|
||||||
- `name` -- macro name (optional).
|
- `name` -- macro name (optional).
|
||||||
- `src` -- path to source page (optional).
|
- `src` -- path to source page (optional).
|
||||||
|
- `sort` -- space separated list of methods to use for item sorting
|
||||||
|
|
||||||
|
|
||||||
`else` macro is applicable inside `macro`. it is used when the `src` path
|
`else` macro is applicable inside `macro`. it is used when the `src` path
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="sortable">
|
<div class="sortable">
|
||||||
<macro src="../*">
|
<macro src="../*" sort="checked">
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<div>
|
<div>
|
||||||
<span class="sort-handle">☰</span>
|
<span class="sort-handle">☰</span>
|
||||||
|
|||||||
38
wiki.js
38
wiki.js
@ -120,6 +120,8 @@ var macro = {
|
|||||||
|
|
||||||
// Macros...
|
// Macros...
|
||||||
//
|
//
|
||||||
|
// XXX add support for sort and reverse attrs in all relavant macros
|
||||||
|
// (see: macro for details)
|
||||||
macro: {
|
macro: {
|
||||||
now: Macro('Create a now id',
|
now: Macro('Create a now id',
|
||||||
[],
|
[],
|
||||||
@ -235,15 +237,17 @@ var macro = {
|
|||||||
// XXX revise macro definition rules -- see inside...
|
// XXX revise macro definition rules -- see inside...
|
||||||
// XXX do we need macro namespaces or context isolation (for inculdes)???
|
// XXX do we need macro namespaces or context isolation (for inculdes)???
|
||||||
macro: Macro('Define/fill macro',
|
macro: Macro('Define/fill macro',
|
||||||
['name', 'src'],
|
['name', 'src', 'sort', 'reverse'],
|
||||||
function(context, elem, state, parse){
|
function(context, elem, state, parse){
|
||||||
elem = $(elem)
|
elem = $(elem)
|
||||||
var name = elem.attr('name')
|
var name = elem.attr('name')
|
||||||
var path = elem.attr('src')
|
var path = elem.attr('src')
|
||||||
|
var sort = elem.attr('sort')
|
||||||
|
var reverse = elem.attr('reverse')
|
||||||
|
|
||||||
state.templates = state.templates || {}
|
state.templates = state.templates || {}
|
||||||
|
|
||||||
|
// get named macro...
|
||||||
if(name){
|
if(name){
|
||||||
// XXX not sure which definition rules to use for macros...
|
// XXX not sure which definition rules to use for macros...
|
||||||
// - first define -- implemented now
|
// - first define -- implemented now
|
||||||
@ -264,16 +268,26 @@ var macro = {
|
|||||||
if(path){
|
if(path){
|
||||||
var pages = context.get(path)
|
var pages = context.get(path)
|
||||||
|
|
||||||
// no matching pages...
|
// no matching pages -- show the else block or nothing...
|
||||||
if(pages.length == 0){
|
if(pages.length == 0){
|
||||||
var e = elem
|
var e = elem
|
||||||
.find('else').first().clone()
|
.find('else').first().clone()
|
||||||
.attr('src', path)
|
.attr('src', path)
|
||||||
parse(e, context)
|
parse(e, context)
|
||||||
return e
|
return e
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// see if we need to overload attrs...
|
||||||
|
sort = sort == null ? (elem.attr('sort') || '') : sort
|
||||||
|
sort = sort
|
||||||
|
.split(/\s+/g)
|
||||||
|
.filter(function(e){ return e && e != '' })
|
||||||
|
reverse = reverse == null ? elem.attr('reverse') == 'true' : false
|
||||||
|
|
||||||
|
// do the sorting...
|
||||||
|
pages = sort.length > 0 ? pages.sort(sort) : pages
|
||||||
|
pages = reverse ? pages.reverse() : pages
|
||||||
|
|
||||||
// fill with pages...
|
// fill with pages...
|
||||||
elem = elem.clone()
|
elem = elem.clone()
|
||||||
.find('else')
|
.find('else')
|
||||||
@ -1330,6 +1344,9 @@ var Wiki = {
|
|||||||
return this.text.text() },
|
return this.text.text() },
|
||||||
|
|
||||||
|
|
||||||
|
get checked(){ return this.data.checked },
|
||||||
|
set checked(value){ this.data.checked = value },
|
||||||
|
|
||||||
// NOTE: this is set by setting .text
|
// NOTE: this is set by setting .text
|
||||||
get links(){
|
get links(){
|
||||||
var data = this.data || {}
|
var data = this.data || {}
|
||||||
@ -1490,6 +1507,8 @@ var Wiki = {
|
|||||||
|
|
||||||
|
|
||||||
// sorting...
|
// sorting...
|
||||||
|
// XXX make these not affect the general order unless they have to...
|
||||||
|
// XXX add a reverse method...
|
||||||
__default_sort_methods__: ['path'],
|
__default_sort_methods__: ['path'],
|
||||||
__sort_methods__: {
|
__sort_methods__: {
|
||||||
title: function(a, b){
|
title: function(a, b){
|
||||||
@ -1502,6 +1521,13 @@ var Wiki = {
|
|||||||
: a.path > b.path ? 1
|
: a.path > b.path ? 1
|
||||||
: 0
|
: 0
|
||||||
},
|
},
|
||||||
|
// XXX
|
||||||
|
checked: function(a, b){
|
||||||
|
// XXX chech if with similar states the order is kept....
|
||||||
|
return a.checked == b.checked ? 0
|
||||||
|
: a.checked ? 1
|
||||||
|
: -1
|
||||||
|
},
|
||||||
// XXX date, ...
|
// XXX date, ...
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1530,7 +1556,9 @@ var Wiki = {
|
|||||||
var res = this.clone()
|
var res = this.clone()
|
||||||
var path = res.path
|
var path = res.path
|
||||||
|
|
||||||
var methods = [].slice.call(arguments)
|
var methods = arguments[0] instanceof Array ?
|
||||||
|
arguments[0]
|
||||||
|
: [].slice.call(arguments)
|
||||||
|
|
||||||
res.__order_by = methods = methods.length == 0 ?
|
res.__order_by = methods = methods.length == 0 ?
|
||||||
this.__default_sort_methods__
|
this.__default_sort_methods__
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user