How to install and use Jade - node.js

Recently I was watching some video tutorials on youtube and came across this JADE thing, how do I install and use it for my web development?
I googled it around but didn't find a proper site that teaches step-by-step to proceed with. And the site jade-lang.com is not available. I did this from websites but node.js is throwing some errors. screenshot below:

first jade is deprecated and new name for jade is pug for more information about this check this link
pug documentation
second to install pug write this command npm install pug -g after you install pug create a new folder to your project and create a file inside your project file.pug and right click on your folder project + shift
and open command window here and write this command pug file.pug after you write this command it will generate a new file file.html
Third write this command pug input.pug input.html --watch --pretty
--watch to compile your code after saving in file.pug
--pretty to write a code with format of html(organized code) not minimized code
to write a tag in pug write the name of tag like
html tag and we will compile to <html></html>
a(href='#' target='_blank') link compile to link
a(href='#' target=''): img(src='' alt='') compile to <img src="" alt=""/>
to write a comment // this is a comment compile to <!-- this is a comment -->
to write class name and content for tag for example p.demo this is a paragraph compile to <p class="demo"> this is a paragraph</p>
to write id and content for tag for example p#demo this is a paragraph compile to <p id="demo"> this is a paragraph</p>
to write a function
mixin list
ul
li foo
li bar
li baz
to use this function write the name of function +list and will compile to
<ul>
<li>foo</li>
<li>bar</li>
<li>baz</li>
</ul>
to include file write include file_name
Finally this is a example for pug code
html
head
title Hello
link(href='' rel='stylesheet' type='text/css')
body
//this is a comment
p.item hello
p#item
br/
a(href='#' target=''): img(src='' alt='')
// to start a new line
|
|
a(href='google.com') Google
// write a function
mixin list
ul
li foo
li bar
li baz
// use function
+list
// include file
include content
For more information about pug check this link pug full documentation

Jade is now called "pug".
npm install pug -g
Here you will find how to use it if you scroll down:
https://www.npmjs.com/package/pug

Related

Load SVG file with ts functions IONIC 3

I converted a dwg file to svg file.
Now this svg file I imported it into a html file.
<ion-scroll scrollX="false" scrollY="true" zoom="true" maxZoom="10">
<object id="svg1" data="assets/svgs/file.svg" type="image/svg+xml" style="width:400%;"></object>
</ion-scroll>
In the svg file on rectangles i put this :
onclick="btnClicked();"
<g id="P2" onclick="btnEvent($event)">
And here the problem, the click works but the function btnClicked() dosen't works.
It gives me this error (in the console)
Uncaught ReferenceError: btnClicked is not defined
at SVGGElement.onclick (file.svg:2946)
It seems like I have to check if this object is loaded and the call the function?
Something like this ?
var elementExists = document.getElementById("svg1");
svg1 is the id of object maybe if i check if it's populate with the svg it ll work?
Anyway this is js I ll do it in ts .
Sorry for my english.
UPDATE
When the page is ready I have to go inside the svg and listen all ids that starts with PI and capture the click. svgDwg is the id of the object. Now I'm not able to go inside, where is the svg.
a.contentDocument dosen't works.
ionViewDidLoad() {
var a = document.getElementById("svgDwg");
console.log(a);
}
I find the answer :
If you want to import in your ionic page a file.svg, without use functions like onclick but use something like listener (.on('click',...) in jquery), you can use a combination of jquery and angular-svg-icon
Install first jquery and import in your .ts ionic page :
$ npm install jquery --save
import * as $ from 'jquery'
Then install the plugin angular-svg-icon :
full description here
Import your file.svg in your html :
<svg-icon src="path/to/file.svg"></svg-icon>
Then write some .ts and jquery for your file.svg in ionViewDidEnter() function of ionic
This works for me (after 2 days of research)

Sails is not injecting the files within the assets folder

I just did a fresh installation of sails (v0.11.0) in my server and after checking this up and working on controllers I found that css, js and templates files included into the assets folders are not being injected to the layout, if there any reason for this to happen? I mean, it is a clean fresh sails installation....
In my quest to get SailsJS to auto-inject stylesheets into the layout file under views/layouts/layout.handlebars in my case, I've found out a couple things...
When you first create your sails app using:
sails new APPNAME --template=handlebars --verbose
note: link below explains above syntax...
Using handlebars templates in Sails.js
Go to config > views.js
It will say:
layout: 'layouts/layout.handlebars'
change to:
layout: 'layouts/layout',
Go to tasks > config > sails-linker.js
Because I'm in development mode right now I will Ctrl + f searching for:
"devStyles"
devStyles: {
options: {
startTag: '<!--STYLES-->',
endTag: '<!--STYLES END-->',
fileTmpl: '<link rel="stylesheet" href="%s">',
appRoot: '.tmp/public'
},
files: {
'.tmp/public/**/*.html': require('../pipeline').cssFilesToInject,
'views/**/*.html': require('../pipeline').cssFilesToInject,
'views/**/*.ejs': require('../pipeline').cssFilesToInject
//ADD HANDLEBARS INJECTION HERE
}
},
Notice it has .html, & .ejs types being injected but not .handlebars
add this line:
'views/**/*.handlebars': require('../pipeline').cssFilesToInject
where I commented:
//ADD HANDLEBARS INJECTION HERE
At this point you should be able to drop a .css file into assets > styles and have it auto-copied to .tmp/public/styles
run:
sails lift
in your command prompt and give it about 20 seconds or so to have the stylesheet manifest its style on whatever page you have in your routes.js
'/': {
view: 'index'
}
As you can see, I made a new .handlebars file index.handlebars and set it as my root level page. You may have to refresh the page a time or two to get the newly auto-injected CSS to show.
P.S. It appears there is no more need to append --linker when first creating a SailsJS project. Also fyi, I'm using sails version 0.11.0
Also if you run sails lift --verbose the line below is how you know the .handlebars injection is working
verbose: Grunt :: File "views/layouts/layout.handlebars" updated.
Hope this helps!
Also, when adding Handlebars Helpers they should go in a file helper.js which should be located in config > helper.js
At the top of the helper.js file I found I had to require handlebars as follows
handlebars = require('sails/node_modules/express-handlebars/node_modules/handlebars');

can't get extremely basic metalsmith installation to build pages

Metalsmith portrays itself as a ridiculously simple static site generator. I'm trying to write the most basic of sites just to get myself familiar with the basics of the software, but I can't seem to get even that to build. Here's my folder structure:
|- build/
|- index.js
|- src/
|-index.html
|- templates
|-index.hbt
My index.js file:
var Metalsmith = require('metalsmith');
Metalsmith(__dirname)
.destination('./build')
.build();
My index.html file:
---
title: Home
template: index.hbt
---
And my index.hbt template:
<!doctype html>
<html>
<head>
<title>FOO</title>
</head>
<body>
something
</body>
</html>
My understanding is that the build command should look through the src directory and parse any file it finds with that YAML stuff at the top. So it should look at index.html, see that it renders using the templates/index.hbt template, and basically just move the file into build/index.html. But when I run node index.js I get absolutely nothing. No progress indicator, no "Done building your stuff!" message, just a blinking command prompt line. My build directory is empty. Obviously something is breaking, but there are no logs to check, and no status messages to google. What am I doing wrong? Shouldn't there be at least one page created in the build directory?
Found the answer, in a comment on a tutorial, of all places: https://blog.robinthrift.com/2014/04/14/metalsmith-part-1-setting-up-the-forge/. It's also on the github examples: https://github.com/segmentio/metalsmith
According to those links, you need to include an error callback on the .build() function:
Metalsmith(__dirname)
.build(function(err) {
if (err) throw err;
});
In addition to the error callback issue, which you've already identified, I think you're missing a few things in your files. True, Metalsmith is very simple, but its simplicity means that a lot of the functionality (like support for templates) is brought by modules that you need to install and include explicitly.
You say the content of your index.js file is:
var Metalsmith = require('metalsmith');
Metalsmith(__dirname)
.destination('./build')
.build();
Is that everything you have in you index.js? If you want to use Handlebars templates, you need to explicitly add the metalsmith plugin that handles templates, and instruct it to use handlebars:
var Metalsmith = require('metalsmith');
var templates = require('metalsmith-templates');
Metalsmith(__dirname)
.destination('./build')
.use(templates('handlebars'))
.build();
And make sure that you install the metalsmith-templates and handlebars modules from npm.
Also, you probably know this, but in your index.hbt, you'll need to change
<title>FOO</title>
to
<title>{{ title }}</title>
in order to load the title metadata from index.html.
Let me know if this gets you going, or if you need more help.

How can Bootstrap glyphicons be marked up using Jade?

I tried to add glyphicons at my HTML, something important to say is that I'm redering from Jade.
For inside buttons glyphicons I tried:
button(ng-click='doLexycalValidation()').btn.btn-default
span.glyphicon.glyphicon-search
| Evalular
For glyphicons at tables I tried:
tr.table.table-hover
td
span.glyphicon.glyphicon-search
| Evalular
But got not result at any of these. I'm importing Bootstrap from CDN this way:
link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css')
link(rel="stylesheet",href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css")
How can I make them work properly?
You can use this module JADE-Bootstrap
http://rajasegar.github.io/JADE-Bootstrap/index.html
install by => npm install --save jade-bootstrap
and use it like this
extends ../node_modules/jade-bootstrap/_bootstrap
block body
button.btn.btn-success(type='submit')
+icon("plus")
| Add
+a-btn-danger("#")
+icon('remove')
| Remove
this module JADE-Bootstrap is very good.It make jade and bootstrap 3 work together more easy.

Meteor, npm, and request

I'm using meteor and I ran npm install request to get access to that library. Everything seems to install correctly but when I run the meteor server, I then get the following error. Is there any word on why this is or how to solve it? Thanks.
While building the application:
node_modules/request/node_modules/node-uuid/test/test.html:1: bad formatting in HTML template
node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js:1:15: Unexpected token ILLEGAL
node_modules/request/node_modules/form-data/node_modules/combined-stream/test/run.js:1:15: Unexpected token ILLEGAL
For reference:
test.html
<html>
<head>
<style>
div {
font-family: monospace;
font-size: 8pt;
}
div.log {color: #444;}
div.warn {color: #550;}
div.error {color: #800; font-weight: bold;}
</style>
<script src="../uuid.js"></script>
</head>
<body>
<script src="./test.js"></script>
</body>
</html>
run.js (same)
#!/usr/bin/env node
var far = require('far').create();
far.add(__dirname);
far.include(/test-.*\.js$/);
far.execute();
Meteor constructs the entire DOM itself so it will typically reject any script tags included in the html (but it will include scripts in the head, thanks Andrew). It also only supports handlebars style templating (right now).
<html>
<head>
<title>Something</title>
</head>
<body>
{{>yourHandlebarsTemplate}}
</body>
</html>
My advice would be to have your js and css located as files inside the client folder under your projects root.
As for NPM request, you will not be able to:
install it normally like you do in most node projects, so node_module is out/npm install require is out
access the functions in it without a Npm.require
At this point you have two options: adding the package NPM from Atmosphere(unofficial package repository) and including request. Or try placing the lib into /packages/ and then using Npm.require('request').
Alternatively you can just use Meteor's built in HTTP package (meteor add http) which functions similar to request.
Remove from your template as it seems Meteor wants to create this tag for you when building the template. This should take care of the "bad formatting in HTML template" error in test.html.

Resources