Coder Social home page Coder Social logo

Comments (3)

leopiccionia avatar leopiccionia commented on June 17, 2024 1

I've made some investigations about templates and I think I've made some progress in 0ab0138.

I've decided to use lodash.template due to the following reasons:

  • It's reasonably small, fast and well-maintained;
  • Its syntax is similar to PHP templates and very expressive;
  • It runs in the browser without headaches; other contenders were originally built for Node and required workarounds.

I'm passing the templates' contents to front-end, instead of their URLs, to make the script synchronous and more reliable. We can discuss alternatives to wp_localize_script, like using <template/> or <script type="x-template/> tags as templates.

There are still many room for improvements:

  • It's currently compiling the template for each iteration of the loop. It can be optimized for caching templates;
  • It's not yet extendable, i.e. a plugin user can't yet override default templates or create their own templates (e.g. for layers tooltips). I'm open to suggestions about how to do it;
  • We can discuss naming conventions, file extensions and how to document it.

If it's green-lighted, I'll adopt the same strategies for "More info" in maps, layers tooltips, etc.

from jeo-plugin.

leogermani avatar leogermani commented on June 17, 2024

Nice! Perfect.

As for the improvements, the most important thing is to allow templates to be overwritten by a plugin or theme author. This can be easily done here:

https://github.com/EarthJournalismNetwork/jeo-plugin/blob/0ab0138ece52d27d13bb557375d83b3c7ec0a8b5/src/includes/class-jeo.php#L153

Instead of calling the file directly, we could use a method, something like get_template($template_name). In this method we could do one of the following, or both:

  • Pass the response through a filter, so themes and plugins can modify the result and return other templates
  • First check if the template exists in a jeo folder inside the current theme folder (using get_template_part.

I think it's worth to do both.

And yes, documentation is needed. What the templates are, what variables are available inside it.

from jeo-plugin.

brunosmartin avatar brunosmartin commented on June 17, 2024

@leopiccionia keeping this open until documentation is done

from jeo-plugin.

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.