GithubHelp home page GithubHelp logo

stefankuijers / live-templates Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 179 KB

This is a way to make live.js work with templates. Tested with Ionic and Angular. Should work with pretty much any framework as long as you specify the routerURL in the script.

JavaScript 100.00%

live-templates's People

Contributors

stefankuijers avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

live-templates's Issues

Detection of URL Routers

As mentioned in issue #1 the routerURL detection is not very strong.
issue #1 suggests to make the regex stronger which is a good goal but a maybe that should only be used as fallback of a better way to get the templateURLs which I will suggest in this issue.

Currently after getting all the JS and CSS the live-template.js code set's out another AJAX call to fetch the apps router a second time. The question is; why fetch a second time? It's already there.

After all is done loading we can simply detect which MV* framework is used and based on that retrieve the templateURLs through the app.router object. No fragile algorithm.

I'm not sure how easy this is as everybody can build their app the way they want... I could be this is a solution that is way more robust than a regex.

templateURL detection algorithm

Currently the templateURL detection regex is not very strong. It has the following weaknesses:

  • urls that are commented out will still be recognized
  • not only template urls but orther links or urls will match aswell

It will not match on the following cases:

  • any url with an : so http(s)
  • if the file-extension is not .html or .jade

Current regex:
/[a-zA-Z0-9-./][a-zA-Z0-9-.]+.(html|jade)(/\S)?/g;
https://github.com/stefanKuijers/live-templates/blob/master/live-templates.js#L30

To make this algorithm stronger it could:

  • ignore commented lines
  • look for string in single or double qoutes
  • url should be preceded by templateURL|url|template and :

Can as well be extended to support more template extensions

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.