pugjs / pug

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

Support for pure plain text block. #2080

Closed pjincz closed 9 years ago

pjincz commented 9 years ago

Hi friend,

Can you support pure plain text block, such as follow

script
  |.
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  if ab
    |.
      ga('set', 'expId', '#{ab.id}');
      ga('set', 'expVar', '#{ab.varid}');
  |.
    ga('send', 'pageview');

I known I can write tag. begin a text block. But I cannot do more control in the text block. And some times, we have to generate codes by some condition.

Thank you for your awesome project. Best regards

alubbe commented 9 years ago

You could try writing

script.
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    #[= ab ? "ga('set', 'expId', '" + ab.id + "');" : ""]
    #[= ab ? "ga('set', 'expVar', '" + ab.varid + "');" : ""]
    ga('send', 'pageview');
TimothyGu commented 9 years ago

Tagless dot has been implemented so you can do this in jade 2.0.0:

script
  .
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  if ab
    .
      ga('set', 'expId', '#{ab.id}');
      ga('set', 'expVar', '#{ab.varid}');
  .
    ga('send', 'pageview');

You can also use piped text:

script
  | (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  | m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  | })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  if ab
    | ga('set', 'expId', '#{ab.id}');
    | ga('set', 'expVar', '#{ab.varid}');
  | ga('send', 'pageview');