Sébastien Lucas / Dev wiki
  • Blog Wiki
  • Story book
  • Developers comics
  • Angular
    • Angular CLI + Angular.json
    • ngTemplateOutlet
    • Angular Schematic
    • Interceptor
    • Micro frontend + Mono repo
    • Build a library module
    • Error handling
    • Virtual and infinite scroll
    • Angular i18n
    • Debug Angular
    • Angular LifeCycle Hook
    • Nested forms in Angular
    • Angular Recipes
    • Master component in Angular
    • Perfomance optimization
    • Service Workers + PWA
    • Mobile
    • Electron app / Desktop app
    • Unit test & Angular
      • Unit test recipes (Jasmine / Karma / Angular)
      • Testing services with httpMock
    • Communication between components
    • Angular snippet library
    • Release and version management
    • Angular tutorial selection
    • UI components libraries
    • Angular libraries
    • Angular Tutorials
    • NGRX
      • Angular NGRX / Tips and code examples
      • Angular new Redux (alternative to ngrx)
      • NGRX unit test
      • Angular ngrx / Basics
    • Angular 2/Angular 1 differences
  • Graphql
  • Three.js
  • Ag grid
  • Open source BIM and 3D
  • Javascript
    • Null vs undefined
    • Html API
    • Await API
    • Debug memory leaks
    • Offline and PWA
    • Javascript tutorials
    • Javascript recipes
    • Bluebird missing docs
    • Alternative to lodash with ES6
    • ES6 syntax the best parts
    • Vanilla JS
  • RXJS
    • Docs
    • Recipes
    • Mock API and sandbox
    • Observables rxjs recipes
    • Combination operators
  • NODE.js
    • Environment variables
    • Fix CORS
    • Pagination requests in API
    • API tests
    • Node.js security
    • Learn node.js
    • Best libraries for node.js
    • Mongoose recipe
    • Debug node.js
  • Gatsby / React
    • Hooks
    • React concepts
    • Gatsby internationalisation
  • Ghost blog
  • Services for developers
    • SaaS images services
    • Airtable API examples
  • MISC
    • JIRA debugging
    • Wordpress plugins
    • Interview Sébastien Lucas
    • English expression
    • True recipes
    • Science podcast
  • AI
    • Machine learning open source
    • Tensor flow
    • Machine learning
    • Code examples
    • Courses and tutorials
    • Datasets
    • The Future of AI
    • Learn algo and data structures
  • Typescript
    • Generic types
    • Typescript recipes
    • Advanced types
      • Conditional types
      • Type guards
    • d.ts files
  • Docker
    • Starting with docker
    • Dockerise simple node app
    • Docker by aymen el amri
  • Mongodb
    • Pattern and data modeling
  • Devops
    • Heroku
    • Scaleway
    • Github template
    • Gitlab CI
    • http2
    • nginx
    • zsh
    • CI Continuous integration
    • DNS
    • Devops resources
    • Gcloud useful commands
    • Authenticate Gcloud
    • Documentation generators
    • Firebase database
  • Developers ressources
    • Online platform coding
      • Online courses
      • Coding games
      • Coding test platforms
      • Links to check
    • Good developers blogs
    • Nice open source project / github
  • Tooling
    • The chrome urls
    • Linux Mac tips
    • Webstorm configuration
    • Develop in Windows
    • Mac debug hardware
    • Mac Setup for a developer
    • Chrome extension
    • Develop toolbox
  • HTML / CSS
    • Tailwind
    • Css grid
    • ☘️Nice styles & generators
    • Favicon
    • Flexbox grid
    • Flexbox layout
    • PUG templates tips
    • Html and css references
    • Css snippets
    • SASS-CSS libraries
    • New things in scss
    • SASS best practices
    • Style lint
  • Tests
    • Cypress
      • Learn cypress and more tests
      • Cypress commands
      • Cypress plugins
      • Page object && app actions
      • Flaky tests
    • Mobile test
    • BDD + Cucumber
    • Puppeteer
    • Type of tests + Ressources
    • Jasmine test
    • Mock, fake, stub in unit tests
    • E2e tests with protactor
    • Mocha
  • REVIT & AEC tools
  • Git
    • Git commits
    • Git tips
    • Git hooks
    • Set up a mono repo
  • Design Pattern
    • Functional Programming
  • Job board / Remote jobs
  • SVG
  • JSON
  • Github
    • Forking a github repo
  • NPM
    • Private NPM packages
    • Publish to NPM with np
  • Yarn
    • Yarn evolution / 2, 3...
    • Yarn Linking
Powered by GitBook
On this page
  • Recipes
  • Compile pug file locally in command line
  • Mixins with block (to wrap content inside a mixin)
  • How to use a json for data in commande line
  • How to load data in a grunt base environnement
  • Multiline js in jade (work in progress)
  • unescaped html tags inside a variable
  • Conditional attributes
  • Multiline tag content
  • Dynamic Mixin call
  • Dynamic attributes
  • Debug pug or jade
  • unexpected token "indent" :
  • "Unexpected token 'tag' expected 'text', 'code', ':', 'newline' or 'eos'"

Was this helpful?

  1. HTML / CSS

PUG templates tips

PreviousFlexbox layoutNextHtml and css references

Last updated 6 years ago

Was this helpful?

Pug templating recipes and debug tricks.

Recipes

Compile pug file locally in command line

Useful to debug what pug files compile if you do not have access to compiles html (with webpac for example)

pug -O '{"pretty": true}' sr-order.template.pug

Mixins with block (to wrap content inside a mixin)

How to use a json for data in commande line

Option 1

This insane mixin works:

mixin json()
  - var oldbuf = buf; buf = [];
  block
  - var res = JSON.stringify(JSON.parse(buf.join('')));
  - buf = oldbuf;
  != res
You can then call it:

+json().
  [
    {
      "name": "ABC-Logistic",
      "file":  "Abc-logistic",
      "link":  "abc-logistic.co.jp"
    }
  ]
And the resulting file will contain:

[{"name":"ABC-Logistic","file":"Abc-logistic","link":"abc-logistic.co.jp"}]

How to load data in a grunt base environnement

options: {
                pretty: true, // Output HTML in indented style
                doctype: 'html',
                data: {
                    links: grunt.file.readJSON("app/Resources/views/mixins/_vars.json"),
                },
            },

#{link.title} will be available Potentially we can load sevral data objects

Multiline js in jade (work in progress)

unescaped html tags inside a variable

-var title = "blabla bl <br/> szlkjs mlklj ";

h3(class="fs1")
            | !{title}

Conditional attributes

How to print an attributes, only if a js value is available to feed it For example angular directive attributes ng-click... should not be printed if there has no value.

div(#{myAttributes}) just don't work #{t} nterpolation work only in the attribute ""

- var t = "la valeur de t"
- var z ="lkj"
p(class="klj" sdsd="#{t}")(title=s)(blang=z)
<p sdsd="la valeur de t" blang="lkj" class="klj"></p>

Multiline tag content

        .tip.
          Enter a valid
          email address
          such as <em>tj@vision-media.ca</em>.

Dynamic Mixin call

mixin blue
  div(class="blue") Blue
    block

mixin red
  div(class="red") red
    block

mixin para(type)
  - console.log(type);
  +#{type}()
    div Nice dynamic mixin call !


+para('blue')
+para('red')

Result

<div class="blue">Blue
  <div>Nice dynamic mixin call !</div>
</div>
<div class="red">red
  <div>Nice dynamic mixin call !</div>
</div>

Dynamic attributes

- var customAttributes = {'set-nav-pattern': true, 'calamar': "setCalamar()"}
div(class="blue")&attributes(customAttributes)

Result

<div class="blue" set-nav-pattern calamar="setCalamar()"></div>

Debug pug or jade

unexpected token "indent" :

Check if there is no added space at the end of a mixin definition. You can switch on the invisible character display to look up more easily...

"Unexpected token 'tag' expected 'text', 'code', ':', 'newline' or 'eos'"

Wrong because their is no space between "Polaziste" and it's tag

   label(for="polaziste")Polaziste

Fixed

   label(for="polaziste") Polaziste

To check

https://github.com/neuland/jade4j/issues/11
https://github.com/visionmedia/jade/issues/833
https://github.com/gruntjs/grunt-contrib-jade#data
https://github.com/visionmedia/jade/issues/796
http://html2jade.org/
http://html2jade.org/
http://stackoverflow.com/questions/24392055/jade-templates-dynamically-calling-a-mixin?rq=1
http://jade-lang.com/reference/attributes/