Skip to content

Commit

Permalink
πŸ› Make sure foundation variables are prepared
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Feb 13, 2024
1 parent 1722a33 commit bfc5eb7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/core/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2860,7 +2860,7 @@ Renderer.setMethod(function evaluate(source, variables, html_only) {
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 1.0.0
* @version 2.3.9
* @version 2.3.16
*
* @param {Pledge} pledge
*/
Expand Down Expand Up @@ -2907,8 +2907,10 @@ function _getFoundationContent(pledge, renderer, hawkejs, options) {
global_protoblast : options.protoblast
};

let variables = renderer.prepareVariables(renderer.variables);

// Add all variables to a single array
packed_variables = [renderer.variables, settings, renderer];
packed_variables = [variables, settings, renderer];

dry = hawkejs.stringifyToExpression(packed_variables);

Expand Down
28 changes: 24 additions & 4 deletions test/30-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ This is the main content
});

CloneTestClass.setMethod(function toHawkejs() {
return new CloneTestClass(this.value + '!!!');
return new CloneTestClass('!!!' + this.value + '!!!');
});

let value = new CloneTestClass('test');
let value = new CloneTestClass('value_to_clone');

let renderer = hawkejs.createRenderer();
renderer.set('test_instance', value);
Expand All @@ -171,14 +171,34 @@ This is the main content
}

try {
assert.strictEqual(block_buffer.toHTML(), 'The value is: "test!!!"');
assert.strictEqual(block_buffer.toHTML(), 'The value is: "!!!value_to_clone!!!"');
} catch (err) {
return done(err);
}

done();
testFoundation();
});

async function testFoundation() {

let foundation = renderer.foundation();

let content = await foundation.getContent();
//console.log('Content:', content)

let has_cloned_value = content.indexOf('"!!!value_to_clone!!!"') > -1;
let has_uncloned_value = content.indexOf('"value_to_clone"') > -1;

try {
assert.strictEqual(has_cloned_value, true, 'The cloned value was not found in the content');
assert.strictEqual(has_uncloned_value, false, 'The uncloned value was found in the content');
} catch (err) {
return done(err);
}

done();
}

});
});

Expand Down

0 comments on commit bfc5eb7

Please sign in to comment.