Comments (13)
Any pull requests are welcome. I can try to play with this as soon as I get some time.
from diff2html.
I can accept uncompiled templates, maybe it helps.
Initially I thought it would not be interesting, since people might want to cache it.
from diff2html.
Currently there is no easy way to make this happen out of the box.
That use case was already mentioned several times and is definitely I want to have.
Just to start the discussion. There are several ways this can be done:
- Allow to inject templates.
This is probably the faster way from the tool side but the user needs to provide full html for a part. If the parts are small enough this might not be that bad.
- Have some kind of subscription that you can hook to. After one html element is generated you receive the element and can apply some changes and return the new element.
This is harder and I am not sure if there is an easy way for you to manipulate the element.
Summing it up, I guess the first one would be better, would you be interested in providing hogan.js templates? Maybe we could even accept compiled and not compiled templates.
Any suggestions?
from diff2html.
Not saying this is the 'right' way but what I've seen elsewhere is a way to override a template like your option 1. So something like this in the config object:
{
templates: {
'file-summary-wrapper': …
}
}
Then any that aren't overridden use the default, library-provided versions.
I've not used Hogan so I'm not familiar with it but I'm guessing the …
above could be like the existing templates, e.g. new Hogan.Template(…)
.
I considered trying to mess about with window.browserTemplates
but there are cases where I want the extra stuff and places where I don't so I think it makes sense for it to be part of the config for a single Diff2HTML instance.
from diff2html.
@jameshoward today I got some time to play around with this.
I made a pretty simple solution in #106 that provides a way to override templates through the initial configuration passed to diff2html.
Let me know if it works for your use case.
from diff2html.
It looks good to me. I'll be working on the same piece again tomorrow so will check it works but looks promising.
from diff2html.
Checked out that branch and got running with it. I suppose the barrier to entry is having to compile the Hogan template and pass it in when the library (quite rightly) doesn't expose Hogan or the JS utils.
It works fine for my case though, where I can pre-compile the template and use Hogan directly so I say merge and release! 🎉
from diff2html.
@jameshoward I exposed one method to help compilation in HoganJsUtils, do you think I should expose it in the main API of the library?
from diff2html.
I'm using the library in a browser so I'm assuming the only globals are Diff2Html
and Diff2HtmlUI
and there's no way to compile a template through either? I wouldn't expect there to be.
I'm not sure about exposing it on the API. There would be pros and cons, I'm sure.
from diff2html.
This was released as version 2.0.8
from diff2html.
That's really cool, thank you. I've used the 2.0.8 version to do exactly what I need.
from diff2html.
I'm going to hang my question here cause it's very related. I've managed to supply the rawTemplates in their uncompiled versions, and that's working well. Now I'm trying to compile them, so I cloned the repo, changed my templates, and ran the 'templates' script which outputs chunks to 'diff2html-templates.js' 'like:
global.browserTemplates["generic-line"] = new Hogan.Template({code: function (c,p,i) { <more js...> ; },partials: {}, subs: { }});
My question is, am I done? i.e., within getPrettyHtml()
just pass this line into "templates" like so:
templates: { 'generic-line': new Hogan.Template({code: function (c,p,i) { etc, etc, }}) }
Or do I have another utility to run?
from diff2html.
@brian-lagerman it should be just like this test
diff2html/test/hogan-cache-tests.js
Line 39 in 1d01d73
from diff2html.
Related Issues (20)
- How to remove the serial number of blank lines HOT 3
- Blank context lines are ignored by diff parser HOT 1
- Vertical align mismatch between inserted/deleted text and matching
- Code breaking when there is no change in a line HOT 3
- Is it possible to generate single html report for multiple git repos? HOT 1
- Unknown argument: diff.txt HOT 1
- 12341
- If the diffString contains special symbols, the page will report an error HOT 1
- Diff2html fails with Error: Cannot find module 'tslib'
- Slim version doesn't fallback to 'plaintext' on unsupported file type HOT 4
- File list links are not working in Angular integration for diff2html-ui HOT 2
- CSS not working inside shadow DOM
- Feature request: option to only show first n files HOT 3
- when execute git diff --word-diff-regex=. ,diff2html is not work HOT 1
- how to make `diff2html` display line breaks for line-by-line view ?? HOT 1
- Backslashes removed in title e.g. C:\dev\alex\test.json -> C:devalex.json HOT 1
- Problems with multiline code blocks highlighted incorrectly HOT 1
- How to hightlight space in new Line? HOT 3
- How to support comments? HOT 1
- How to support code review functionality ? HOT 1
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 diff2html.