sails.js : using dust in sails 0.10.5 - sails.js

I am trying to migrate a project from 0.9.9 to 0.10.5
We were using dust templating engine in our porject instead of the default ejs engine.
Contents of config/views.js file
module.exports.views = {
engine: 'dust',
layout: 'layout'
};
In my controller, I was able to render this view like this
res.view('layout', obj);
However, in sails 0.10.5, when I lift sails, first of all I get this warning
warn: Sails' built-in layout support only works with the `ejs` view engine.
warn: You're using `dust`.
warn: Ignoring `sails.config.views.layout`...
And then when I try to render the view as I was doing earlier, I get following error:
error: Sending 500 ("Server Error") response:
Error: ENOENT, open '/.dust'
{ [Error: ENOENT, open '/.dust'] errno: 34, code: 'ENOENT', path: '/.dust' }
Any idea what is the correct way of doing this in 0.10.5 ?

The layout property does not apply to dust (just ejs). Set layout to false to get the warning to go away. You want to use Dust's built-in support for partials and blocks anyways.
Using res.view('layout', obj); means that you expect a file called views/layout.dust to exist. Prior to 0.10, sails was including the layout property from config/views.js as part of the path.
So my best guess is that your res.view() call is actually being invoked with an empty string as the first parameter, and it wasn't breaking because you were trying to render something called layout. I'd check your invocation to make sure that you're calling res.view() with an instantiated variable.

Related

Ag Grid Properties do not exist while using TypeScript

I'm trying to use TypeScript and AgGrid and using an example similar to https://www.ag-grid.com/react-data-grid/column-sizing/#resizing-example
The issue is that when using TypeScript I get different values than when I'm trying to use regular JavaScript.The main property I'm trying to get back is api
https://gitpodio-templatetypescr-ze7tjimg9lm.ws-us43.gitpod.io/ - here is a gitpod that I created. If you look at the console.log I get most of the same properties, but I'm not getting the api property to make changes.
*** Edit ***
Actually one thing I just noticed is that if I use
import { AgGridReact } from 'ag-grid-react'; it works properly
but if I use
import { AgGridReact } from '#ag-grid-community/react'; it doesn't work. Why would there be a difference and what am I missing?
*** Edit 2 ***
Why do I need to at least put in one module to get the api? Is there a core module that I can put in, instead of something like the ClientSideRowModelModule to trigger the api?

How to replace deprecated SOBE Code in TYPO3 10.4

I inherited an old TYPO3 Extension using SOBE. As far as I unterstand it's deprecated, but it seems there is no documentation on how to replace it.
The Extension is using Backend Forms and the following line is throwing an error:
if (is_array($GLOBALS['SOBE']->editconf['tt_content']) && reset($GLOBALS['SOBE']->editconf['tt_content']) === 'new') {
The error is:
Cannot access protected property TYPO3\CMS\Backend\Controller\EditDocumentController::$editconf
The Var $GLOBALS['SOBE'] is still there, and there is also editconf, but it's not working.
How can I replace this code or rewrite it?
The SOBE object is part by part removed since years. As there are multiple ways for using it - see https://docs.typo3.org/c/typo3/cms-core/main/en-us/search.html?q=sobe&check_keywords=yes&area=default - you may need to take a closer look what is the exact part of replacing this code.
I would guess you can see more at https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/9.2/Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.html?highlight=editconf.

Stop huge error output from testing-library

I love testing-library, have used it a lot in a React project, and I'm trying to use it in an Angular project now - but I've always struggled with the enormous error output, including the HTML text of the render. Not only is this not usually helpful (I couldn't find an element, here's the HTML where it isn't); but it gets truncated, often before the interesting line if you're running in debug mode.
I simply added it as a library alongside the standard Angular Karma+Jasmine setup.
I'm sure you could say the components I'm testing are too large if the HTML output causes my console window to spool for ages, but I have a lot of integration tests in Protractor, and they are SO SLOW :(.
I would say the best solution would be to use the configure method and pass a custom function for getElementError which does what you want.
You can read about configuration here: https://testing-library.com/docs/dom-testing-library/api-configuration
An example of this might look like:
configure({
getElementError: (message: string, container) => {
const error = new Error(message);
error.name = 'TestingLibraryElementError';
error.stack = null;
return error;
},
});
You can then put this in any single test file or use Jest's setupFiles or setupFilesAfterEnv config options to have it run globally.
I am assuming you running jest with rtl in your project.
I personally wouldn't turn it off as it's there to help us, but everyone has a way so if you have your reasons, then fair enough.
1. If you want to disable errors for a specific test, you can mock the console.error.
it('disable error example', () => {
const errorObject = console.error; //store the state of the object
console.error = jest.fn(); // mock the object
// code
//assertion (expect)
console.error = errorObject; // assign it back so you can use it in the next test
});
2. If you want to silence it for all the test, you could use the jest --silent CLI option. Check the docs
The above might even disable the DOM printing that is done by rtl, I am not sure as I haven't tried this, but if you look at the docs I linked, it says
"Prevent tests from printing messages through the console."
Now you almost certainly have everything disabled except the DOM recommendations if the above doesn't work. On that case you might look into react-testing-library's source code and find out what is used for those print statements. Is it a console.log? is it a console.warn? When you got that, just mock it out like option 1 above.
UPDATE
After some digging, I found out that all testing-library DOM printing is built on prettyDOM();
While prettyDOM() can't be disabled you can limit the number of lines to 0, and that would just give you the error message and three dots ... below the message.
Here is an example printout, I messed around with:
TestingLibraryElementError: Unable to find an element with the text: Hello ther. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
...
All you need to do is to pass in an environment variable before executing your test suite, so for example with an npm script it would look like:
DEBUG_PRINT_LIMIT=0 npm run test
Here is the doc
UPDATE 2:
As per the OP's FR on github this can also be achieved without injecting in a global variable to limit the PrettyDOM line output (in case if it's used elsewhere). The getElementError config option need to be changed:
dom-testing-library/src/config.js
// called when getBy* queries fail. (message, container) => Error
getElementError(message, container) {
const error = new Error(
[message, prettyDOM(container)].filter(Boolean).join('\n\n'),
)
error.name = 'TestingLibraryElementError'
return error
},
The callstack can also be removed
You can change how the message is built by setting the DOM testing library message building function with config. In my Angular project I added this to test.js:
configure({
getElementError: (message: string, container) => {
const error = new Error(message);
error.name = 'TestingLibraryElementError';
error.stack = null;
return error;
},
});
This was answered here: https://github.com/testing-library/dom-testing-library/issues/773 by https://github.com/wyze.

Call to a member function get_cart_subtotal() on a non-object in config-woocommerce/config.php on line 790

I'm trying to login into my WordPress Admin panel, and am getting the following error:
Call to a member function get_cart_subtotal() on a non-object in /home/spicom/public_html/adwinang.com/wp-content/themes/enfold/config-woocommerce/config.php on line 790
This is my code at line 790:
$cart_subtotal = $woocommerce->cart->get_cart_subtotal();
It sounds like you haven't called global $woocommerce;, before trying to access the $woocommerce object.
A better way would be to use WC():
$cart_subtotal = WC()->cart->get_cart_subtotal();
Alternatively, it's possible the WooCommerce hasn't even been installed and activated...make sure to do that, if it's a theme dependency.
I had a very similar message.
[25-Sep-2018 10:24:08 UTC] PHP Fatal error: Uncaught Error:
Call to a member function get_cart_subtotal() on null in
themes\storefront\inc\woocommerce\storefront-woocommerce-template-functions.php:80
It was due to me having the following in my wp-config.php file.
define( 'DOING_CRON', false );
I'd added this line while attempting to run something from the command line with W3 Total Cache activated. I didn't realise that it would completely ruin WooCommerce and didn't notice the side effect until attempting to view the site in my browser.

neo4jphp: Cannot instantiate abstract class Everyman\Neo4j\Transport

maybe a simple question but for me as starter with Neo4j a hurdle. I installed the neo4jphp with composer in the same directory as my application. Vendor-Subfolder has been created and the everyman/neo4j folder below is available. For a first test I used this code snippet from the examples:
spl_autoload_register(function ($className) {
$libPath = 'vendor\\';
$classFile = $className.'.php';
$classPath = $libPath.$classFile;
if (file_exists($classPath)) {
require($classPath);
}
});
require('vendor/autoload.php');
use everyman\Neo4j\Client,
everyman\Neo4j\Transport;
$client = new Client(new Transport('localhost', 7474));
print_r($client->getServerInfo());
I always stumple upon the error
Fatal error: Cannot instantiate abstract class Everyman\Neo4j\Transport
Googling brought me to a comment from Josh Adell stating
You can't instantiate Everyman\Neo4j\Transport, since it is an abstract class. You must instantiate Everyman\Neo4j\Transport\Curl or Everyman\Neo4j\Transport\Stream depending on your needs
So I thought I just need to alter the use-statements to
use everyman\Neo4j\Client,
everyman\Neo4j\Transport\Curl;
but this doesnt work, debugging shows, that the autoloader only get "Transport.php" instead of "everyman\Neo4j\Transport\Curl.php". For "Client.php" its still working ("vendor\everyman\Neo4j\Client.php") so I am guessing that the use-statement is wrong or the code is not able to handle an additional subfolder-structure.
Using
require('phar://neo4jphp.phar');
works fine but I read that this is deprecated and should be replaced by composer / autoload.
Anyone has a hint what to change or had the same problem?
Thanks for your time,
Balael
Curl is the default transport. You only need to instantiate your own Transport object if you want to use Stream instead of Curl. If you really want to instantiate your own Curl Transport, the easiest change to your existing code is to modify the use statement to be:
use everyman\Neo4j\Client,
everyman\Neo4j\Transport\Curl as Transport;
Also, you don't need to register your own autoload function if you are using the Composer package. vendor/autoload.php does that for you.
Thanks Josh, I was trying but it seems I still stuck somewhere. I am fine with using the default CURL - so I shrinked the code down to
require('vendor/autoload.php');
use everyman\Neo4j\Client;
$client = new Everyman\Neo4j\Client('localhost', 7474);
print_r($client->getServerInfo());`
The folder structure is main (here are the files and the composer.json with the content
{
"require": {
"everyman/Neo4j": "dev-master"
}
}
and in the subfolder "vendor" we have the "autoload.php" and the subfolder everyman with the related content. When I run the file I come out with
Fatal error: Class 'Everyman\Neo4j\Client' not found
which does not happen when I have the autoloadfunction. I guess I made a mistake somewehere - can you give me a hint?
Thanks a lot, B
Hmmm... I was just trying around and it seems the Transport CLASS is not needed in the use-statement and the class instantiation. This seems to work:
require('vendor/autoload.php');
use everyman\Neo4j\Client;
$client = new Client();
print_r($client->getServerInfo());
also valid for having a dedicated server/port:
$client = new Everyman\Neo4j\Client('localhost', 7474);
If you have more input I would be happy to learn more - thanks, all input & thoughts are very appreciated.
Balael