Coder Social home page Coder Social logo

Comments (4)

alanshaw avatar alanshaw commented on September 25, 2024

I'm sorry but I won't be adding this feature request to grunt-include-replace. PHP for one exhibits exactly the same behaviour. If you want pretty HTML you could run the output through something like https://github.com/jonschlinkert/grunt-prettify

from grunt-include-replace.

bradcavanagh avatar bradcavanagh commented on September 25, 2024

I'd like to throw my support behind this request, because there are some file formats that require consistent indenting of code. The case I've run into are Amazon's Elastic Beanstalk configuration files, which can be either YAML or JSON. In YAML, indentation is required to separate different levels of "stuff", and if I'm trying to include a multi-line file in an EB config file, it all needs to be indented at the same level.

While I could hard-wire this indentation into the included file, a better way would be to have an "indent depth" option for grunt-include-replace that indents the entire block of text by a certain number of spaces.

from grunt-include-replace.

alanshaw avatar alanshaw commented on September 25, 2024

There's an undocumented option processIncludeContents which should be a function that is passed the include file contents and local variables as parameters. You could use that to indent each line by however many spaces you like.

You could customise the number of spaces processIncludeContents inserts by passing in a parameter to the include directive:

@@include('/path/to/include/file.html', {"spaces": 2})

With your grunt options looking like:

options: {
  processIncludeContents: function (contents, locals) {
    var indent = new Array((locals.spaces || 0) + 1).join(" ")
    return contents.replace(/^/gm, indent)
  }
}

Pull requests accepted if you want to add in a specific option for doing this, I imagine it'd just hook into processIncludeContents.

from grunt-include-replace.

monkeytwins avatar monkeytwins commented on September 25, 2024

@alanshaw

return contents.replace(/^/gm, indent).replace(indent, "");

except the first line

from grunt-include-replace.

Related Issues (20)

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.