alanshaw / grunt-include-replace

Grunt task to include files and replace variables. Allows for parameterised includes.
MIT License
200 stars 45 forks source link

Added new option: processIncludeContents #5

Closed monzou closed 11 years ago

monzou commented 11 years ago

Hi, @alanshaw

I added new option processIncludeContents(contents, localVars) to your task. If you don'd mind, can you merge this ?

alanshaw commented 11 years ago

Thanks @monzou! Just wondering specifically what the issue you're addressing is? It looks like it indents included code in CoffeeScript files - I'm guessing because whitespace matters in CoffeeScript and if you indented within the included file it might not be the correct indentation for the file that did the including?

monzou commented 11 years ago

@alanshaw

Sorry my test file was not correct and I fixed it.

BTW, My purpose is to include another CoffeeScript file with correct indent. I want to include CoffeeScript file that is not indented like following:

# module.coffee
class Module

  constructor: (@name) ->

This is a normal valid CoffeScript file that defines single class. But I also want to include this file by another file like following:

define [], ->

  # I want to include Module class here !
  @@include('module.coffe')

But this makes incorrect CoffeeScript file.

# result
define [], ->

  class Module

constructor: (@name) -> # invalid

in the test case, processIncludeContents resolves this problem by following:

define [], ->

@@include('module.coffee', {"indent": "2"})

That makes correct CoffeeScript.

define [], ->

  class Module

    constructor: (@name) -> # valid
alanshaw commented 11 years ago

Ah I see, I was confused by the name I thought it was specifically for indenting coffeescript but I now see you could perform other transformations should you want to.

Do you think there are any other use cases? I'm just curious as to why you've solved the problem this way - I probably would have added an option for the task to auto indent file contents based on how indented the @@include declaration was...

alanshaw commented 11 years ago

Released as 0.2.0 on NPM

monzou commented 11 years ago

Thanks !

Hmm ... I didn't know which is better for adding new option like smart indent or process included contents. Then I selected the latter because It's seems more generic. But I don't know any other use cases for now.