Sha256: 233c5c55be81f10653b4d796e18d4d61d42a6379f91835fbec67fbb36bb5a2ce

Contents?: true

Size: 885 Bytes

Versions: 12

Compression:

Stored size: 885 Bytes

Contents

const { concat, group, indent, line } = require("../../prettier");

// The `BEGIN` and `END` keywords are used to hook into the Ruby process. Any
// `BEGIN` blocks are executed right when the process starts up, and the `END`
// blocks are executed right before exiting.
//
//     BEGIN {
//       # content goes here
//     }
//
//     END {
//       # content goes here
//     }
//
// Interesting side note, you don't use `do...end` blocks with these hooks. Both
// nodes contain one child which is a `stmts` node.
function printHook(name) {
  return function printHookWithName(path, opts, print) {
    return group(
      concat([
        name,
        " ",
        path.call(print, "body", 0),
        indent(concat([line, path.call(print, "body", 1)])),
        concat([line, "}"])
      ])
    );
  };
}

module.exports = {
  BEGIN: printHook("BEGIN"),
  END: printHook("END")
};

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
prettier-1.6.1 src/ruby/nodes/hooks.js
prettier-1.6.0 src/ruby/nodes/hooks.js
prettier-1.5.5 src/ruby/nodes/hooks.js
prettier-1.5.4 src/ruby/nodes/hooks.js
prettier-1.5.3 src/ruby/nodes/hooks.js
prettier-1.5.2 src/ruby/nodes/hooks.js
prettier-1.5.1 src/ruby/nodes/hooks.js
prettier-1.5.0 src/ruby/nodes/hooks.js
prettier-1.4.0 src/ruby/nodes/hooks.js
prettier-1.3.0 src/ruby/nodes/hooks.js
prettier-1.2.5 src/ruby/nodes/hooks.js
prettier-1.2.4 src/ruby/nodes/hooks.js