Git Product home page Git Product logo

Comments (13)

rtfpessoa avatar rtfpessoa commented on May 25, 2024 1

Any pull requests are welcome. I can try to play with this as soon as I get some time.

from diff2html.

rtfpessoa avatar rtfpessoa commented on May 25, 2024 1

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.

rtfpessoa avatar rtfpessoa commented on May 25, 2024

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.

jameshoward avatar jameshoward commented on May 25, 2024

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.

rtfpessoa avatar rtfpessoa commented on May 25, 2024

@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.

jameshoward avatar jameshoward commented on May 25, 2024

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.

jameshoward avatar jameshoward commented on May 25, 2024

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.

rtfpessoa avatar rtfpessoa commented on May 25, 2024

@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.

jameshoward avatar jameshoward commented on May 25, 2024

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.

rtfpessoa avatar rtfpessoa commented on May 25, 2024

This was released as version 2.0.8

from diff2html.

jameshoward avatar jameshoward commented on May 25, 2024

That's really cool, thank you. I've used the 2.0.8 version to do exactly what I need.

from diff2html.

brian-lagerman avatar brian-lagerman commented on May 25, 2024

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.

rtfpessoa avatar rtfpessoa commented on May 25, 2024

@brian-lagerman it should be just like this test

it('should allow templates to be overridden with compiled templates', function() {

from diff2html.

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.