Closed esc-mhild closed 8 years ago
thanks for the pr. no need to implement a clone function, grunt uses lodash as a util library which comes with one already.
grunt.util._.extend
i don't quite get the use case could you expand on that?
the file will only be processed if process: true
in the options. with the object passed as data. and there are no way of dynamically updating that data object in the processor chain. (i think, there is no transform function).
Denis,
Many thanks for your reply. The pull request is, of course, a little heavy-handed but I thought this would quickly give you a sense of what I'm asking for.
You asked about the use-case. We have a template that includes various libraries (jquery, d3, leaflet etc.) depending on defaults set in Gruntfile.js. To illustrate:
processhtml : {
build : { files : [ { expand : true, flatten : false, cwd : 'src/main/html', src : '*/.html', dest : 'target/html' } ], options : { process : true, includeBase : 'target/templates/processhtml', recursive : false, data : {
theme : 'portal',
libs : {
jquery : true, d3 : true, leaflet : true
}
} } }
},
In an individual HTML page, we start with a preamble like the following to override the defaults above:
<%
theme = 'plain'; libs.leaflet = false;
%><!DOCTYPE html>
... This manipulates the config object. Without cloning, these changes persist to other pages. We can use the console to verify this: <% console.log('theme', theme); console.log('libs', libs); %> ... We like that we can manage overrides in the individual page and not in some external, probably centralized file. For completeness, I paste the libs.htmlf file below. Does this explain the situation? M. <% if(libs.kendo || (contextMenu != null && contextMenu.length > 0)){ %> <% } if(theme === 'plain'){ %> <% } else if(theme === 'fancy'){ %> <% } else if(theme === 'portal'){ %> <% } else if(theme === 'system'){ %> <% } %> <% if(libs.jquery || libs.kendo || (contextMenu != null && contextMenu.length > 0) || libs.standard || libs.matrix){ %> <% } if(libs.kendo || (contextMenu != null && contextMenu.length > 0)){ %> <% } if(libs.mathjax){ %> <% } if(libs.querybuilder){ %> <% } if(libs.d3 || libs.matrix){ %> <% } if(libs.leaflet){ %> <% } if(libs.swfobject){ %> <% } if(libs.standard){ %> <% } if(libs.matrix){ %> <% } %> --- From: Denis Ciccale notifications@github.com Sent: Thursday, October 29, 2015 5:56 AM To: dciccale/grunt-processhtml Cc: Matthias Hild Subject: Re: [grunt-processhtml] Update processhtml.js (#85) thanks for the pr. no need to implement a clone function, grunt uses lodash as a util library which comes with one already. grunt.util._.extend i don't quite get the use case could you expand on that? the file will only be processed if process: true in the options. with the object passed as data. and there are no way of dynamically updating that data object in the processor chain. (i think, there is no transform function). ## Reply to this email directly or view it on GitHubhttps://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152132017. [https://avatars1.githubusercontent.com/u/1745754?v=3&s=400]https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152132017 Update processhtml.js by MatthiasHild · Pull Request #85 · dciccale/grunt-processhtml Please consider adding the following feature that is illustrated in the fork. The feature clones the data object passed into the template for each page processed. This allows individual pages to o... Read more...https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152132017great! thanks a lot for your time on explaining. now i get it.
cloning the object on each iteration may harm performance. so a flag to clone or not could be a solution.
just to know, how many html files are you processing? more or less.. doesn't need to be exact.
On Thu, Oct 29, 2015 at 9:28 PM, Matthias Hild notifications@github.com wrote:
Denis,
Many thanks for your reply. The pull request is, of course, a little heavy-handed but I thought this would quickly give you a sense of what I'm asking for.
You asked about the use-case. We have a template that includes various libraries (jquery, d3, leaflet etc.) depending on defaults set in Gruntfile.js. To illustrate:
processhtml : {
build : { files : [ { expand : true, flatten : false, cwd : 'src/main/html', src : '*/.html', dest : 'target/html' } ], options : { process : true, includeBase : 'target/templates/processhtml', recursive : false, data : {
theme : 'portal',
libs : {
jquery : true, d3 : true, leaflet : true
}
} } }
},
In an individual HTML page, we start with a preamble like the following to override the defaults above:
<%
theme = 'plain'; libs.leaflet = false;
%><!DOCTYPE html>
... This manipulates the config object. Without cloning, these changes persist to other pages. We can use the console to verify this: <% console.log('theme', theme); console.log('libs', libs); %> ... We like that we can manage overrides in the individual page and not in some external, probably centralized file. For completeness, I paste the libs.htmlf file below. Does this explain the situation? M. <% if(libs.kendo || (contextMenu != null && contextMenu.length > 0)){ %> <% } if(theme === 'plain'){ %> <% } else if(theme === 'fancy'){ %> <% } else if(theme === 'portal'){ %> <% } else if(theme === 'system'){ %> <% } %> <% if(libs.jquery || libs.kendo || (contextMenu != null && contextMenu.length > 0) || libs.standard || libs.matrix){ %> <% } if(libs.kendo || (contextMenu != null && contextMenu.length > 0)){ %> <% } if(libs.mathjax){ %> <% } if(libs.querybuilder){ %> <% } if(libs.d3 || libs.matrix){ %> <% } if(libs.leaflet){ %> <% } if(libs.swfobject){ %> <% } if(libs.standard){ %> <% } if(libs.matrix){ %> <% } %> --- From: Denis Ciccale notifications@github.com Sent: Thursday, October 29, 2015 5:56 AM To: dciccale/grunt-processhtml Cc: Matthias Hild Subject: Re: [grunt-processhtml] Update processhtml.js (#85) thanks for the pr. no need to implement a clone function, grunt uses lodash as a util library which comes with one already. grunt.util._.extend i don't quite get the use case could you expand on that? the file will only be processed if process: true in the options. with the object passed as data. and there are no way of dynamically updating that data object in the processor chain. (i think, there is no transform function). ## Reply to this email directly or view it on GitHub< https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152132017 > . [https://avatars1.githubusercontent.com/u/1745754?v=3&s=400]< https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152132017 Update processhtml.js by MatthiasHild · Pull Request #85 · dciccale/grunt-processhtml Please consider adding the following feature that is illustrated in the fork. The feature clones the data object passed into the template for each page processed. This allows individual pages to o... Read more...< https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152132017 — Reply to this email directly or view it on GitHub https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152308800 .
In a single project, we are processing around 70 files. A grunt-watch refresh times at .8 seconds and we are doing some crazy things inside of the templates that I haven't mentioned yet. I don't think the cloning is the expensive part in this. A flag would give us the best of both worlds.
Best wishes,
M.
From: Denis Ciccale notifications@github.com Sent: Thursday, October 29, 2015 4:35 PM To: dciccale/grunt-processhtml Cc: Matthias Hild Subject: Re: [grunt-processhtml] Update processhtml.js (#85)
great! thanks a lot for your time on explaining. now i get it.
cloning the object on each iteration may harm performance. so a flag to clone or not could be a solution.
however i don't know how many files users normally process. if it is <50 i guess you wouldn't notice a difference. but >100 you may.
just to know, how many html files are you processing? more or less.. doesn't need to be exact.
On Thu, Oct 29, 2015 at 9:28 PM, Matthias Hild notifications@github.com wrote:
Denis,
Many thanks for your reply. The pull request is, of course, a little heavy-handed but I thought this would quickly give you a sense of what I'm asking for.
You asked about the use-case. We have a template that includes various libraries (jquery, d3, leaflet etc.) depending on defaults set in Gruntfile.js. To illustrate:
processhtml : {
build : { files : [ { expand : true, flatten : false, cwd : 'src/main/html', src : '*/.html', dest : 'target/html' } ], options : { process : true, includeBase : 'target/templates/processhtml', recursive : false, data : {
theme : 'portal',
libs : {
jquery : true, d3 : true, leaflet : true
}
} } }
},
In an individual HTML page, we start with a preamble like the following to override the defaults above:
<%
theme = 'plain'; libs.leaflet = false;
%><!DOCTYPE html>
... This manipulates the config object. Without cloning, these changes persist to other pages. We can use the console to verify this: <% console.log('theme', theme); console.log('libs', libs); %> ... We like that we can manage overrides in the individual page and not in some external, probably centralized file. For completeness, I paste the libs.htmlf file below. Does this explain the situation? M. <% if(libs.kendo || (contextMenu != null && contextMenu.length > 0)){ %> <% } if(theme === 'plain'){ %> <% } else if(theme === 'fancy'){ %> <% } else if(theme === 'portal'){ %> <% } else if(theme === 'system'){ %> <% } %> <% if(libs.jquery || libs.kendo || (contextMenu != null && contextMenu.length > 0) || libs.standard || libs.matrix){ %> <% } if(libs.kendo || (contextMenu != null && contextMenu.length > 0)){ %> <% } if(libs.mathjax){ %> <% } if(libs.querybuilder){ %> <% } if(libs.d3 || libs.matrix){ %> <% } if(libs.leaflet){ %> <% } if(libs.swfobject){ %> <% } if(libs.standard){ %> <% } if(libs.matrix){ %> <% } %> --- From: Denis Ciccale notifications@github.com Sent: Thursday, October 29, 2015 5:56 AM To: dciccale/grunt-processhtml Cc: Matthias Hild Subject: Re: [grunt-processhtml] Update processhtml.js (#85) thanks for the pr. no need to implement a clone function, grunt uses lodash as a util library which comes with one already. grunt.util._.extend i don't quite get the use case could you expand on that? the file will only be processed if process: true in the options. with the object passed as data. and there are no way of dynamically updating that data object in the processor chain. (i think, there is no transform function). ## Reply to this email directly or view it on GitHub< https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152132017 > . [https://avatars1.githubusercontent.com/u/1745754?v=3&s=400]< https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152132017 Update processhtml.js by MatthiasHild · Pull Request #85 · dciccale/grunt-processhtml Please consider adding the following feature that is illustrated in the fork. The feature clones the data object passed into the template for each page processed. This allows individual pages to o... Read more...< https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152132017 ## Reply to this email directly or view it on GitHub https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152308800 .
Reply to this email directly or view it on GitHubhttps://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152310497.
Update processhtml.js by MatthiasHild · Pull Request #85 · dciccale/grunt-processhtml Please consider adding the following feature that is illustrated in the fork. The feature clones the data object passed into the template for each page processed. This allows individual pages to o... Read more...https://github.com/dciccale/grunt-processhtml/pull/85#issuecomment-152310497
I will release this in a new version, thanks, I will let you know
Please consider adding the following feature that is illustrated in the fork.
The feature clones the data object passed into the template for each page processed. This allows individual pages to override defaults set in Gruntfile.js.
A use case is a standard configuration that holds for most processed pages (e.g., standard version numbers of CSS/JS imports in the page head) but which needs modification for a small number of pages.
The fork contains working code. A polished version should likely add a clone option in the configuration. A further addition could be a check within the clone function if the data object itself has a clone method that could be used instead.
Many thanks for your work on this plugin!
M.
Matthias Hild