Giter Site home page Giter Site logo

pug-cache's Introduction

Pug

Full documentation is at pugjs.org

load src of template that included or extended from cache

example

examples/includes.js

examples/includes.pug

/**
 * Module dependencies.
 */

var pug = require('../')
  , path = __dirname + '/includes.pug'
  , str = require('fs').readFileSync(path, 'utf8')

console.time("l")
let options = {
  filename: "includes.pug",
  pretty: true,
  loadFromStrArr:
    [
      { name: "head.pug", content: "head\n  title My Site [[[ LOAD FROM STRING ARRAY ]]] \n  // including other pug works\n  include scripts.pug\n  // including .html, .css, etc works\n  include style.css\n" },
      { name: "includes.pug", content: "\nhtml\n  include includes/head.pug\n  body\n    h1 My Site\n    p Welcome to my super lame site.\n    include includes/foot.pug\n" },
      { name: "foot.pug", content: "#footer\n  p Copyright (c) foobar\n  each product in products\n    div=product" },
      { name: "scripts.pug", content: "script(src=\'/javascripts/jquery.js\')\nscript(src=\'/javascripts/app.js\')\n" },
      { name: "style.css", content: "<style>\n  body {\n    padding: 50px;\n  }\n</style>" }
    ],
  userData: { products: [1, 2, 4] }
}
var fn = pug.compile(str, options);
console.log(fn({ products: [1, 2, 4] }));
console.timeEnd("l")
/* <html>
  <head>
    <title>My Site [[[ LOAD FROM STRING ARRAY ]]] </title>
    <!-- including other pug works-->
    <script src="/javascripts/jquery.js"></script>
    <script src="/javascripts/app.js"></script>
    <!-- including .html, .css, etc works--><style>
  body {
    padding: 50px;
  }
</style>
  </head>
  <body>
    <h1>My Site</h1>
    <p>Welcome to my super lame site.</p>
    <div id="footer">
      <p>Copyright (c) foobar</p>
    </div>
  </body>
</html>
*/

License

MIT

pug-cache's People

Contributors

tseian avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.