Templating Engines: Pug/Jade Flashcards

1
Q

Adding attributes and button name to a button tag inside a form

A
form
     button(type='submit') Button Name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

creating a button with the class ‘btn, btn-danger’

A

button.btn.btn-danger

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

installing pug on the server side

A

npm/yarn install/add pug –save

pug has build-in integration with express.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

using a dynamic variable

A

{var} or () inside tag attributes

note: javascript string interpolation uses ${}, while pug uses #{}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

built-in method to iterate through a dynamic var

A

each val in obj

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

built in method to check for a condition

A
if condition
  //do something
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the fundamental tag to create a template .pug file?

A

block (name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to import a file and write over its template?

A

extends (file path)
block (name)
// code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

creating a switch case with a built-in pug expression

A
case expression
    when val
        // do stuff
    when val2
       // do stuff
   when val3
   when val4
      //fall through also works
   default
      // something
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

writing an inline for loop that returns a list of items with the inline javascript capabilities pug offers

A
- for (var i = 0; i < 9; i++)
      li loop number ${i}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

writting block unbuffered code

A
-
   var obj = {var1: 1, var2: 2,
                      var3: 3}
each val in obj
   li #{val}

note: javascript string interpolation uses ${}, while pug uses #{}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

writting inline buffered code

A

h2= ‘buffered supports all’ + ‘javascript expressions’ + var;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

writting buffered unscaped(unsafe) code

A

li!= “dangerous code! <this>"</this>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

why is unscaped code unsafe?

A

because it allows for XSS (cross-site-scripting) in which user can insert client-side javascript code into your site.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

writing a p tag with a text block

A

p.
text
text
text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

pug removes autospace between tags manually, how to manually keep them?

A

a(href=’#’)
| Using
| the ‘|’ operator
a(href=’#’)

17
Q

commenting and block commenting with pug

A

// comment
//
block
commenting

18
Q

include vs extends

A

extends only allows you to write within block statements, while include includes the whole file in the specified section.

extends limit the file as an extension, include doesnt, but your cant write on blocks