# Code coverage report for lib/register.js

## Statements: 26.32% (5 / 19) Branches: 0% (0 / 4) Functions: 0% (0 / 5) Lines: 29.41% (5 / 17) Ignored: none

All files » lib/ » register.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    301

    1

    1

    1

    1

     var parser = require("./parser"),
    fs         = require("fs");

    require.extensions[".pc"] = function (module, filename) {

      var paper, watching, compiled;

      function compileOnce () {
        if (compiled) return;
        compiled = true;
        compile();
      }

      function compile () {
        paper = parser.compile(fs.readFileSync(filename, "utf8"));
      }

      function watch () {
        if (watching) return;
        watching = true;
        fs.watchFile(filename, { persistent: true, interval: 500 }, compile)
      }

      module.exports = function () {
        compileOnce();
        watch();
        return paper.apply(this, arguments);
      }
    };