"Hacking Squiffy Further..." by mrangel

Hi mrangel,

In days of old you made a format for altering Squiffy's defaults from within the Squiffy editor. It was way over my head, but I make habitual use of your nesting function, that you used as an example.

@start nesting 
    window.sq = squiffy;
    var transition = function () {
        var setfunc = setAttribute;
        var processtextoriginal = squiffy.ui.processText;
        squiffy.story.save = function () {
            squiffy.set('_output', squiffy.ui.output.html() || "  ");
            squiffy.set('_transition', squiffy.get('_transitioncode'));
        setAttribute = function (expr) {
            var matches = /^(\w*\s*):=(.*)$/.exec(expr);
            if (matches) {
                expr = matches[1] + '=' + squiffy.ui.processText(matches[2]);
            console.log("Evaluating set: "+expr)
        squiffy.ui.processText = function (text) {
            // insert modified text processor here
            return (processtextoriginal(text));
    squiffy.set('_transitioncode', transition);
    squiffy.set('_transition', transition);
    squiffy.set('_output', ' ');

Is there a way to put this nesting function into "C:\Program Files (x86)\Squiffy\resources\app\node_modules\squiffy\squiffy.template.js"?

Thanks for all you do for us Squiffy users!

A lot of that is a wrapper to actually run the custom code.
I think if you were doing it manually, you could search for the line:

    var setAttribute = function(expr) {

and change it to:

    var setAttribute = function(expr) {
        expr = expr.replace(/^(\w*\s*):=(.*)$/, (match,name,value) => (name + "=" + squiffy.ui.processText(value));

so that the text processing stuff is done at the start of the original function.

The second part, changing the text processor, you can just replace the original definition of squiffy.ui.processText I think.

Thanks, mrangel. There's a fatal bug in it somewhere, but don't understand JavaScript remotely well enough to find it.

I sure with the squiffy editor would identify the line where errors occur. That's the one that keeps me up at night, that I'm going to make a boatload of changes and then break something.

Ugh, careless. The )); at the end of the line should be )));. Sorry about that; it can happen if I'm writing code off the top of my head without checking it.

Actually… it might make more sense to add a little extra:

    var setAttribute = function(expr) {
        expr = expr.replace(/^(\w*\s*):=(.*)$/, (match,name,value) => (name + "=" + squiffy.ui.processText(value.match(/^@[\w\s]+]$) ? squiffy.get(value.substring(1)) : value))));

Then you could use it for something like (for example):

@set expression = some string with {oooh!} text processor stuff in
@set value1 := @expression
@set value2 := @expression

Basically, lets you have the text processor string in another attribute so you can evaluate it later.

(again, not tested)

THIS makes more sense...???

expr.replace(/^(\w*\s*):=(.*)$/, (match,name,value) => (name + "=" + squiffy.ui.processText(value.match(/^@[\w\s]+]$) ? squiffy.get(value.substring(1)) : value))));

Very dry humor, sir!

Thanks mrangel! It works great now, and I've gone ahead and inserted it with your other improvements in another forum post.

Yes, Bluevoss! The Squiffy editor really needs some work. "SyntaxError: Unexpected token" is really not at all a helpful clue.

And I sadly didn't include mrangel's shuffle fuction in unofficial Squiffy 5.1.4 because it breaks the editor, even though it works perfectly fine and dandy in the browser.

Actually, that @ thing looks a little awkward. I should have done something like:

    var setAttribute = function(expr) {
        expr = expr.replace(/^(\w*[\s:]*):=(.*)$/, (match,name,value) => (name + "=" + squiffy.ui.processText(value)));

Off the top of my head, makes the expression stackable.

  • @set var1 = {var2} sets var1 to the string {var2}
  • @set var1 := {var2} sets var1 to the contents of the attribute var2
  • @set var1 ::= {var2} sets var1 to the results of running the text processor on var2's contents, interpolating any mentions of {var3} in it
  • @set var1 :::= {var2} sets var1 to the results of running the text processor on var2, interpolating any mentions of {var3} in it, and then runs the text processor again on the result so that any {} commands in var3 are executed

This topic is now closed. Topics are closed after 60 days of inactivity.