Describe process.env in jsdoc - jsdoc

I use Dotenv-Webpack. So, in js code I can do something like:
console.log(process.env.DB_HOST);
But I want to have autocomplete for values from my .env file.

Related

How do I load an ejs template file into my HTML?

I am using EJS in the browser (not on the server).
I have some ejs that I would like to use in multiple pages, so I want to put that in its own file, say table.ejs.
Is there a way I can include it in my HTML such that it is immediately accessible to my javascript after onload?
I was thinking something like:
<script id="table-ejs" type="text/ejs" src="ejs/table.ejs"></script>
then in my javascript:
ejs.render(document.querySelector('#table-ejs').???, data)
Is this possible?
I could use the Fetch API to retrieve the ejs file but then I would need to rewrite a lot of code to make it async. I was wondering if I could avoid that.
Well,
place all your ejs-files within a file "views" - within your views you can create another file "partials" - in this file you place your header and footer.ejs.
Within, lets say, your home.ejs you have to include the following code:
<%- include('partials/header'); -%>
// the rest of your code
<%- include('partials/footer'); -%>
You can find more here: https://ejs.co/#docs

How in Sails to access globals in assets?

I am using Sails JS and would like to access globals (sails.config.myGlobals) in my assets, currently in js files.
I would have hoped I there is a similar way like injecting in ejs files. But its not.
Any ideas? Do I have to do a Grunt task for that?
In your config folder create a config file for example MyConfig.js (name doesn't matter). Fill that config with something that you wanted like.
module.exports.myconfig = {
configA: 'this is config A'
}
Use that config in your controller, like.
showconfig: function(req, res){
res.view('viewname', {
config: sails.config.myconfig
});
}
Now in your EJS file that is called, by that example is viewName.ejs at views folder, you can use it like <% config.configA %>, and this is config A would be printed. Also if you want Front End js (in assets folder) able to read that value, just print it in script tag, like this.
<script>
global.configA = '<%= config.configA %>';
</script>
Or if you use front end framework library, it can be placed under some value, service, or factory, not making global variable dirty, so other JS are able to read that value.
I don't think this is possible with Sails.
However, what you can do is setting the variable in a ejs view file to access its value in your js asset file.
// someView.ejs
<script>
myGlobals = '<%= config.myGlobals %>';
</script>

Partial helper doesn't render partials in .hbs file

I feel like I'm missing something obvious. In working with v0.6.0, the Readme indicates you can use:
{%= partial("partial-name") %}
However, these are just getting printed as plain text. Do I need to use a different engine if I want to have those tags parsed?
Assemble allows using different engines and the example that you have is using lodash with custom delimiters.
To use the default partials helper in handlebars do {{partial "partial-name"}}

How do I set a basedir in Jade using command line

Is there a way to set 'basedir' option in jade command line? Or, maybe, another way to use absolute pathing there. Thanks.
Jade has, among other options, the following
-O, --obj <str|path> JavaScript options object or JSON file containing it
So you could write something like this:
jade -O "{basedir:'/home/charlie/Git/ElfSite/Code'}" temp.jade
Or you could create a file called options.json that looked something like this:
{
"basedir": "/home/charlie/Git/ElfSite/Code",
"title": "My Title"
}
And then call jade like this:
jade -O options.json temp.jade
Or like this:
jade --obj options.json temp.jade

jade "include" doesn't work as expected

Referencing another Jade file from within one:
include ../widget
Renders HTML like this:
<include>../widget</include>
Using Scalatra, specifically. What am I doing wrong?
Scalate Jade is different than JavaScript Jade, so the tag isn't the same. You have to reference the filename in full, like so:
- include("../widget.jade")