How to load a lottie-web animation directly with the JSON content without providing a path - lottie

I would like to create a single animated web-component without any external dependency.
Until now, when I use lottie, I provide a path to the lottie JSON
lottie.loadAnimation({
[...]
path: 'data.json' // the path to the animation json
});
But I need to package my web-component without external reference to a JSON.
My first idea is to put the JSON content into a blob and then use URL.createObjectURL() to create a local URL.
Is there more direct way to create an animation already having loaded the JSON ?

Bodymovin has an option to export a Standalone animation file.
This will bundle your json and the player itself into one js file you can use.
See: https://github.com/airbnb/lottie-web/wiki/Composition-Settings

Related

Embed file content in ARM template

I have an ARM template, which I use to deploy a resource which has a property that contains a Python script as a string. Instead of having the script in the template file, I would prefer to have it in a .py file, and embed that in the template on deployment.
Is there a way to achieve this?
The simplest way to do this is using loadTextContent() in bicep: https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions-files#loadtextcontent
If you're not using bicep (and can't) there's no good substitution for it in JSON, you'd have to fashion something to parse the json, figure out where that goes and stringify yourself.
That help?

How to load CSS file in qooxdoo dynamically

Is there a special qooxdoo class to load CSS files dynamically like qx.util.DynamicScriptLoader does for JavaScript files?
For example, depends on user choice what geo maps he wants to use an application loads specific JavaScript and CSS files. I can get .js file via qx.util.DynamicScriptLoader class but for css I use externalResources section in Manifest.json file which always loads a style file (am I right?).
A dynamic possibility to include css files, e.g. in the constructor of a class, is using qx.bom.Stylesheet.includeFile like this:
qx.bom.Stylesheet.includeFile("https://myserver.com/my.css");
This way I've successfully built completely dynamic wrappers for packages/frameworks where all external resources are loaded only on wrapper class instantiation in conjunction with qx.util.DynamicScriptLoader.
If the css files are within your projects resources, you have to call qx.util.ResourceManager.getInstance().toUri() on the resource name and feed it then into qx.bom.Stylesheet.includeFile.
Lets say you have a css file in your project in resource/myframework/my.css you have to first create an #asset hint like this in your wrapper class:
/*
* #asset(myframework/my.css)
*/
and afterwards, e.g. in the constructor you call:
qx.bom.Stylesheet.includeFile(qx.util.ResourceManager.getInstance().toUri(
"resource/myframework/my.css"
));
In order to avoid multiple loading of the css file, I've added a static class member CSS_INCLUDED to the wrapper class, initialized to false and then set to true after calling qx.bom.Stylesheet.includeFile which results in the this code:
if(my.wrapper.CSS_INCLUDED === false) {
qx.bom.Stylesheet.includeFile(qx.util.ResourceManager.getInstance().toUri(
"resource/myframework/my.css"
));
my.wrapper.CSS_INCLUDED = true;
}
This way subsequent instantiations do not load the css file again.

Access the content of css files with Webpacker

Using Webpacker I can load css files and they get output in the stylesheet pack files, but sometimes I'd like to access the CSS in these files from within javascript for use say in a WYSIWYG editor's config (specifying some extra styles for the IFRAME). The other option is to be able to access the public path of a css file loaded in like so:
import froala_style from '../../../css/froala.css'
My suspicion is that it's to do with the css loader that comes with Webpacker. Its job is to load the css and compile it out to a seperate file. I think that one can't have two css loaders at the same time? Could the answer be to apply filters to a custom loader so that it takes effect on only the file I'm wanting to load in as text or the path?
One can override the existing loaders for a particular import like so:
import froala_style from '!css-loader!../../../css/froala.css'
Prepending the ! overrides existing loaders allowing us to specify our own. In this example one can call froala_style.toString() to receive the contents of the CSS file.
For reference: https://webpack.js.org/concepts/loaders/#inline

File extension validation in Symfony3

Is there any already implemented way to validate file extension in Symfony? File and Image validators can only validate mime type. Is there any way to do it or do I have to use a custom validator / callback?
You could use a RegexValidator if all you want to validate about is the file extension. Do keep in mind that a file extension in no way guarantees the contents of the file. Someone could upload an executable as a .png for instance.
Example
new RegexValidator('/(.+)(\.jpg|\.png|\.gif)$/')
Will match any filename ending in .jpg, .png or .gif
If you want more control over it (for example, passing an array of allowed extensions) I would recommend using a CallbackValidator or making your own. Good luck!

Jade - calling page specific css pages

I have page specific css files I would like to call automatically. Does anyone have a nice way of doing this elegantly?
This should do it
link(rel="stylesheet", href="#{req.path + '.css'}", type="text/css")
Where you pass either req (the request object) as a local variable when rendering the jade template (or even just pass in req.path as path). This could just be handled in your layout.jade and it will work for each of your route paths.
If you want to get fancy, you could establish a consistent pattern where a page's route maps 1 to 1 to a filesystem path for a .css file in your public directory. In that case you could easily but the stylesheet link tag inside a conditional and only link to the .css file if you find a matching one on disk.

Resources