Giter Club home page Giter Club logo

Comments (5)

senny avatar senny commented on July 20, 2024

Hi, while this could be applied with simple value insertion fields, how would you assume defaults for loops, conditionals, nested data structures etc.?

I'm not sure I fully understand the use-case where this could come in handy. The way I have used sablon is that the data that was given to the template was fixed but the template itself was dynamic. Meaning application logic would pick a template and then render it with predefined values. Could you maybe expand on the use-case that you are facing?

from sablon.

stadelmanma avatar stadelmanma commented on July 20, 2024

We are migrating an existing excel spreadsheet workflow into a rails app, but the key feature we need is the mail merge functionality for automatic report initialization. Currently we have about 10 templates of varying length (5 - 15 pages) with merge fields sprinkled throughout.

Essentially the main use case would be debugging a template for missing values, i.e. finding un-merged fields due to a field name typo, a table not being joined, model renamed etc. It is a lot easier to spot something that shouldn't be there compared to something that is simply missing.

I agree when the object controlling the evaluation of loops, conditionals and other logic constructs is missing they should just be removed since there isn't any reasonable way to assume a default value.

I assume that standard insertion class is used when evaluating merge fields in the contents of loops and conditional blocks?

Additionally, the default value in my mind would be more of a flag than a "true" drop in replacement, at least for any non-trivial form. Replacement with a default value would just be based on a nil check, since blanks can be valid in some cases, so nested data structures are handled based on the final result.

from sablon.

senny avatar senny commented on July 20, 2024

Thanks for the extended context. I'm not sure this is a common enough use-case for sablon to provide it out of the box. You should be able to put that into your project with a pretty minimal patch though. What if you loaded the following patch before rendering the template:

module DebugInsertions
  def evaluate(context)
    if expr.evaluate(context)
      super
    else
      field.replace(Sablon::Content.wrap('REPLACE ME'))
    end
  end
end

Sablon::Statement::Insertion.prepend(DebugInsertions)

from sablon.

stadelmanma avatar stadelmanma commented on July 20, 2024

Ah understood and just for the sake of saving time I have one additional question I'll ask here instead of making another issue. In regular erb templates you can break things up into partials to make reusable components. Our old templates have a lot of copy and pasted paragraphs that are identical and it would be nice to break those up into components as well.

It would be desirable to have similar functionality in this gem, preferably implemented in a way that lets you edit the partial like a regular docx file instead of just storing XML source code. Since if you can't easily maintain the partial it defeats the whole purpose. The extra baggage that comes with a full docx would have to be dealt with, probably using some form of a <<partial>> merge field tag to isolate the desired paragraphs from everything else.

Any idea on how difficult it would be to extend your experimental WordML injection code to be able to handle partials? This is something I'll be glad to submit a PR for down the road if you are interested.

from sablon.

senny avatar senny commented on July 20, 2024

If you can, I suggest going with HTML or WordML insertion. A partial in a separate docx will be more tricky. You can probably get the majority of cases working by just getting the WordML from the document.xml and then running a WordML insertion on it. As soon as you start to incorporate formatting, images, list definitions etc. in your partial you will need to merge the complete docx file.

I'm hesitant to include something with sablon that only partially works. If you wanted to go with the simple WordML style partials you can prototype your idea and even release a sablon-partials gem. All you would need to do is register a new content object that under the hood reads the document and performs WordML insertion.

from sablon.

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.