1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-26 01:50:28 +00:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Bram Chen 2014-07-26 14:28:26 +08:00
commit 6800e1d3e2
11 changed files with 94 additions and 26 deletions

View File

@ -19,6 +19,10 @@ Advanced/Settings/NavigationHistory/Caption: Navigation History
Advanced/Settings/NavigationHistory/Hint: Update browser history when navigating to a tiddler: Advanced/Settings/NavigationHistory/Hint: Update browser history when navigating to a tiddler:
Advanced/Settings/NavigationHistory/No/Description: Do not update history Advanced/Settings/NavigationHistory/No/Description: Do not update history
Advanced/Settings/NavigationHistory/Yes/Description: Update history Advanced/Settings/NavigationHistory/Yes/Description: Update history
Advanced/Settings/ToolbarButtons/Caption: Toolbar Buttons
Advanced/Settings/ToolbarButtons/Hint: Default toolbar button appearance:
Advanced/Settings/ToolbarButtons/Text/Description: Include text
Advanced/Settings/ToolbarButtons/Icons/Description: Include icon
Advanced/TiddlerFields/Caption: Tiddler Fields Advanced/TiddlerFields/Caption: Tiddler Fields
Advanced/TiddlerFields/Hint: This is the full set of TiddlerFields in use in this wiki (including system tiddlers but excluding shadow tiddlers). Advanced/TiddlerFields/Hint: This is the full set of TiddlerFields in use in this wiki (including system tiddlers but excluding shadow tiddlers).
Appearance/Caption: Appearance Appearance/Caption: Appearance

View File

@ -33,7 +33,7 @@ function parseFilterOperation(operators,filterString,p) {
operator.prefix = filterString.charAt(p++); operator.prefix = filterString.charAt(p++);
} }
// Get the operator name // Get the operator name
var nextBracketPos = filterString.substring(p).search(/[\[\{\/]/); var nextBracketPos = filterString.substring(p).search(/[\[\{<\/]/);
if(nextBracketPos === -1) { if(nextBracketPos === -1) {
throw "Missing [ in filter expression"; throw "Missing [ in filter expression";
} }
@ -54,24 +54,28 @@ function parseFilterOperation(operators,filterString,p) {
p = nextBracketPos + 1; p = nextBracketPos + 1;
switch (bracket) { switch (bracket) {
case '{': // Curly brackets case "{": // Curly brackets
operator.indirect = true; operator.indirect = true;
nextBracketPos = filterString.indexOf('}',p); nextBracketPos = filterString.indexOf("}",p);
break; break;
case '[': // Square brackets case "[": // Square brackets
nextBracketPos = filterString.indexOf(']',p); nextBracketPos = filterString.indexOf("]",p);
break; break;
case '/': // regexp brackets case "<": // Angle brackets
var rex = /^((?:[^\\\/]*|\\.)*)\/(?:\(([mygi]+)\))?/g, operator.variable = true;
rexMatch = rex.exec(filterString.substring(p)); nextBracketPos = filterString.indexOf(">",p);
if(rexMatch) { break;
operator.regexp = new RegExp(rexMatch[1], rexMatch[2]); case "/": // regexp brackets
nextBracketPos = p + rex.lastIndex - 1; var rex = /^((?:[^\\\/]*|\\.)*)\/(?:\(([mygi]+)\))?/g,
} rexMatch = rex.exec(filterString.substring(p));
else { if(rexMatch) {
throw "Unterminated regular expression in filter expression"; operator.regexp = new RegExp(rexMatch[1], rexMatch[2]);
} nextBracketPos = p + rex.lastIndex - 1;
break; }
else {
throw "Unterminated regular expression in filter expression";
}
break;
} }
if(nextBracketPos === -1) { if(nextBracketPos === -1) {
@ -193,6 +197,9 @@ exports.compileFilter = function(filterString) {
if(operator.indirect) { if(operator.indirect) {
operand = self.getTextReference(operator.operand,"",currTiddlerTitle); operand = self.getTextReference(operator.operand,"",currTiddlerTitle);
} }
if(operator.variable) {
operand = widget.getVariable(operator.operand,"");
}
results = operatorFunction(accumulator,{ results = operatorFunction(accumulator,{
operator: operator.operator, operator: operator.operator,
operand: operand, operand: operand,

View File

@ -18,11 +18,8 @@ Create a widget object for a parse tree node
options: see below options: see below
Options include: Options include:
wiki: mandatory reference to wiki associated with this render tree wiki: mandatory reference to wiki associated with this render tree
variables: optional hashmap of context variables (see below)
parentWidget: optional reference to a parent renderer node for the context chain parentWidget: optional reference to a parent renderer node for the context chain
document: optional document object to use instead of global document document: optional document object to use instead of global document
Context variables include:
currentTiddler: title of the tiddler providing the context
*/ */
var Widget = function(parseTreeNode,options) { var Widget = function(parseTreeNode,options) {
if(arguments.length > 0) { if(arguments.length > 0) {

View File

@ -0,0 +1,10 @@
title: $:/core/ui/ControlPanel/Advanced/Settings/ToolbarButtons
tags: $:/tags/ControlPanel/Advanced/Settings
caption: {{$:/language/ControlPanel/Advanced/Settings/ToolbarButtons/Caption}}
\define lingo-base() $:/language/ControlPanel/Advanced/Settings/ToolbarButtons/
<<lingo Hint>>
<$checkbox tiddler="$:/config/Toolbar/Icons" field="text" checked="yes" unchecked="no" default="yes"> <$link to="$:/config/Toolbar/Icons"><<lingo Icons/Description>></$link> </$checkbox>
<$checkbox tiddler="$:/config/Toolbar/Text" field="text" checked="yes" unchecked="no" default="no"> <$link to="$:/config/Toolbar/Text"><<lingo Text/Description>></$link> </$checkbox>

View File

@ -6,6 +6,10 @@ tw-page-container tw-page-view-$(themeTitle)$ tw-language-$(languageTitle)$
<$importvariables filter="[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]"> <$importvariables filter="[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]">
<$set name="tw-config-toolbar-icons" value={{$:/config/Toolbar/Icons}}>
<$set name="tw-config-toolbar-text" value={{$:/config/Toolbar/Text}}>
<$set name="themeTitle" value={{$:/view}}> <$set name="themeTitle" value={{$:/view}}>
<$set name="currentTiddler" value={{$:/language}}> <$set name="currentTiddler" value={{$:/language}}>
@ -40,4 +44,8 @@ tw-page-container tw-page-view-$(themeTitle)$ tw-language-$(languageTitle)$
</$set> </$set>
</$set>
</$set>
</$importvariables> </$importvariables>

View File

@ -1,4 +1,11 @@
title: $:/core/ui/ViewToolbar/close title: $:/core/ui/ViewToolbar/close
tags: $:/tags/ViewToolbar tags: $:/tags/ViewToolbar
<$button message="tw-close-tiddler" title={{$:/language/Buttons/Close/Hint}} aria-label={{$:/language/Buttons/Close/Caption}} class="btn-invisible">{{$:/core/images/close-button}}</$button> <$button message="tw-close-tiddler" title={{$:/language/Buttons/Close/Hint}} aria-label={{$:/language/Buttons/Close/Caption}} class="btn-invisible">
<$list filter="[<tw-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/close-button}}
</$list>
<$list filter="[<tw-config-toolbar-text>prefix[yes]]">
<$text text={{$:/language/Buttons/Close/Caption}}/>
</$list>
</$button>

View File

@ -0,0 +1,3 @@
title: $:/config/Toolbar/Icons
yes

View File

@ -0,0 +1,3 @@
title: $:/config/Toolbar/Text
no

View File

@ -270,6 +270,25 @@ describe("Filter tests", function() {
expect(wiki.filterTiddlers("[modifier{!!modifier}] +[sort[title]]",fakeWidget).join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,one,Tiddler Three"); expect(wiki.filterTiddlers("[modifier{!!modifier}] +[sort[title]]",fakeWidget).join(",")).toBe("$:/TiddlerTwo,a fourth tiddler,one,Tiddler Three");
}); });
it("should handle variable operands", function() {
var widget = require("$:/core/modules/widgets/widget.js");
// Create a root widget for attaching event handlers. By using it as the parentWidget for another widget tree, one can reuse the event handlers
var rootWidget = new widget.widget({
type: "widget",
children: [{type: "widget", children: []}]
},{
wiki: $tw.wiki,
document: $tw.document
});
rootWidget.makeChildWidgets();
var anchorWidget = rootWidget.children[0];
rootWidget.setVariable("myVar","Tidd");
rootWidget.setVariable("myVar2","JoeBloggs");
expect(wiki.filterTiddlers("[prefix<myVar>] +[sort[title]]",anchorWidget).join(",")).toBe("Tiddler Three,TiddlerOne");
expect(wiki.filterTiddlers("[modifier<myVar2>] +[sort[title]]",anchorWidget).join(",")).toBe("TiddlerOne");
});
it("should handle the before and after operators", function() { it("should handle the before and after operators", function() {
expect(wiki.filterTiddlers("[list[TiddlerSeventh]after[TiddlerOne]]").join(",")).toBe("Tiddler Three"); expect(wiki.filterTiddlers("[list[TiddlerSeventh]after[TiddlerOne]]").join(",")).toBe("Tiddler Three");
expect(wiki.filterTiddlers("[list[TiddlerSeventh]after[a fourth tiddler]]").join(",")).toBe("MissingTiddler"); expect(wiki.filterTiddlers("[list[TiddlerSeventh]after[a fourth tiddler]]").join(",")).toBe("MissingTiddler");

View File

@ -1,5 +1,5 @@
created: 20140210141217955 created: 20140210141217955
modified: 20140303091312363 modified: 20140725091312363
tags: dev tags: dev
title: TiddlerFilter Formal Grammar title: TiddlerFilter Formal Grammar
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
@ -34,7 +34,7 @@ Whitespace is matched with javascript "\s+", which matches space, tab, carriage
''&lt;opt-operator-suffix&gt;'' ::= ''&lt;string&gt;'' | "" ''&lt;opt-operator-suffix&gt;'' ::= ''&lt;string&gt;'' | ""
''&lt;operand&gt;'' ::= "[" ''&lt;search-string&gt;'' "]" | "{" ''&lt;indirect-search-string&gt;'' "}" | ''&lt;regex&gt;'' ''&lt;operand&gt;'' ::= "[" ''&lt;search-string&gt;'' "]" | "{" ''&lt;indirect-search-string&gt;'' "}" | "<" ''&lt;variable-name-string&gt;'' ">" | ''&lt;regex&gt;''
''&lt;regex&gt;'' ::= "/" ''&lt;string&gt;'' "/" ''&lt;opt-regex-args&gt;'' ''&lt;regex&gt;'' ::= "/" ''&lt;string&gt;'' "/" ''&lt;opt-regex-args&gt;''

View File

@ -1,5 +1,5 @@
created: 20140410101941871 created: 20140410101941871
modified: 20140410103229640 modified: 20140725103229640
tags: introduction tags: introduction
title: Introduction to Filters title: Introduction to Filters
type: text/vnd.tiddlywiki type: text/vnd.tiddlywiki
@ -67,6 +67,16 @@ If a filter operator is written with curly brackets around the operand then it i
[search{$:/temp/search}] [search{$:/temp/search}]
``` ```
! Variable Operands
If a filter operator is written with angle brackets around the operand then it is taken to be the name of a variable containing the actual value. For example, this filter selects all tiddlers containing the title of the current tiddler:
```
[search<currentTiddler>]
```
(Note that the `currentTiddler` variable is used to track the current tiddler).
! Regular Expression Operands ! Regular Expression Operands
The "field" filter also accepts [[regular expressions|http://en.wikipedia.org/wiki/Regular_expression]] with the syntax `/regexp/(modifier)`. For example: The "field" filter also accepts [[regular expressions|http://en.wikipedia.org/wiki/Regular_expression]] with the syntax `/regexp/(modifier)`. For example: