pugjs / pug

Pug – robust, elegant, feature rich template engine for Node.js
https://pugjs.org
21.66k stars 1.96k forks source link

Runtime Filters #1714

Open mathiasschopmans opened 9 years ago

mathiasschopmans commented 9 years ago

I'm using Jade as a static prototype generator and would like to render some html-docs for my custom components, mixins, snippets to support my colleagues, which are integrating my html templates into different CMS.

helpers.jade

mixin code-example(name, options)
  - options = extend({"html":true, "jade":true, "render":true}, options)
  .code-example
    h3.name= name

    if options.html
      pre.code.code-html(data-language="html")
        :examplehtml
          block

    if options.jade
      pre.code.code-jade(data-language="jade")
        :examplejade
          block

  if options.render
    block

usage.jade

+code-example("Tabs")
  +tabs()
    each tab, num in ["One", "Two", "Three"]
      +tab(tab)
        h1 Content Tab #{num}

Do you know how to access the block from filters?

Thank you!

niklashigi commented 7 years ago

@mathiasschopmans Great suggestion, this would simplify the implemenation of code example boxes like the one below (from the Primer CSS documentation) while keeping your code DRY.

Primer CSS documentation code example

brunowego commented 6 years ago

Is there any way around this? Force block work inside a filter...

mixin highlight(lang = 'html')
  pre
    code(class=lang)
      :escape-html:html-beautify:pug
        block
"jstransformer-escape-html": "~1.1.0",
"jstransformer-html-beautify": "0.0.1",
"jstransformer-pug": "~0.3.0",