1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-20 00:34:50 +00:00

Add support for StyleSheet tiddler

Note how you can update BaseColour and watch the stylesheet get
automatically refreshed
This commit is contained in:
Jeremy Ruston 2012-04-19 10:15:55 +02:00
parent 441479f1b4
commit de979a3af2

View File

@ -16,10 +16,12 @@ var WikiStore = require("./WikiStore.js").WikiStore,
tiddlerOutput = require("./TiddlerOutput.js"), tiddlerOutput = require("./TiddlerOutput.js"),
Renderer = require("./Renderer.js").Renderer, Renderer = require("./Renderer.js").Renderer,
WikiTextParser = require("./WikiTextParser.js").WikiTextParser, WikiTextParser = require("./WikiTextParser.js").WikiTextParser,
TiddlyTextParser = require("./TiddlyTextParser.js").TiddlyTextParser,
PlainTextParser = require("./PlainTextParser.js").PlainTextParser, PlainTextParser = require("./PlainTextParser.js").PlainTextParser,
JavaScriptParser = require("./JavaScriptParser.js").JavaScriptParser, JavaScriptParser = require("./JavaScriptParser.js").JavaScriptParser,
JSONParser = require("./JSONParser.js").JSONParser, JSONParser = require("./JSONParser.js").JSONParser,
ImageParser = require("./ImageParser.js").ImageParser; ImageParser = require("./ImageParser.js").ImageParser,
utils = require("./Utils.js");
var App = function() { var App = function() {
var t; var t;
@ -29,6 +31,7 @@ var App = function() {
this.store = new WikiStore(); this.store = new WikiStore();
// Register the parsers // Register the parsers
this.store.registerParser("text/x-tiddlywiki",new WikiTextParser({store: this.store})); this.store.registerParser("text/x-tiddlywiki",new WikiTextParser({store: this.store}));
this.store.registerParser("text/x-tiddlywiki-css",new TiddlyTextParser({store: this.store}));
this.store.registerParser("text/plain",new PlainTextParser({store: this.store})); this.store.registerParser("text/plain",new PlainTextParser({store: this.store}));
this.store.registerParser(["image/svg+xml",".svg","image/jpg",".jpg","image/jpeg",".jpeg","image/png",".png","image/gif",".gif"],new ImageParser({store: this.store})); this.store.registerParser(["image/svg+xml",".svg","image/jpg",".jpg","image/jpeg",".jpeg","image/png",".png","image/gif",".gif"],new ImageParser({store: this.store}));
this.store.registerParser(["application/javascript",".js"],new JavaScriptParser({store: this.store})); this.store.registerParser(["application/javascript",".js"],new JavaScriptParser({store: this.store}));
@ -109,6 +112,13 @@ var App = function() {
if(this.isBrowser) { if(this.isBrowser) {
// Set up HttpSync // Set up HttpSync
this.httpSync = new HttpSync(this.store); this.httpSync = new HttpSync(this.store);
// Apply the dynamic stylesheet
var styleRenderer = this.store.renderMacro("tiddler",{target: "StyleSheet"});
utils.applyStyleSheet("StyleSheet",styleRenderer.render("text/plain"));
this.store.addEventListener("",function(changes) {
styleRenderer.refresh(changes);
utils.applyStyleSheet("StyleSheet",styleRenderer.render("text/plain"));
});
// Open the PageTemplate // Open the PageTemplate
var renderer = this.store.renderMacro("tiddler",{target: "PageTemplate"}); var renderer = this.store.renderMacro("tiddler",{target: "PageTemplate"});
renderer.renderInDom(document.body); renderer.renderInDom(document.body);