Comments (4)
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.
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.
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.
return contents.replace(/^/gm, indent).replace(indent, "");
except the first line
from grunt-include-replace.
Related Issues (20)
- Unexpected token error when trying to replace @@sample with html code HOT 4
- Flatten destination output HOT 2
- Argument of include can't have linebreak HOT 1
- Local variables object refering
- access to local variables
- How to replace a file itself ? HOT 1
- Allow undeclared parameters to be defaulted
- Chokes on })
- Make output less verbose
- options.processIncludeContents called when file is processed
- Renaming Generated files HOT 2
- a space before comma make difference
- the file array format processing is very slow HOT 4
- Encoding change HOT 1
- Request: Support for webpack HOT 1
- Project with committed dependencies has a slightly different v3.2.0 HOT 1
- Directory not being created HOT 1
- Reference in multiple steps
- пиксель защита
- Include file(s) not found error on Windows updated Grunt 1.6.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-include-replace.