Coder Social home page Coder Social logo

Comments (2)

gparlakov avatar gparlakov commented on June 22, 2024

@danjor thanks for your support and active participation!

This sounds like an annoying problem.

Sorry,

Handling it on SCuri's side would be much more difficult (update templates are executed in isolation from each other and the main template).

from scuri.

danjor avatar danjor commented on June 22, 2024

Hello,
Thanks for your reply.

I'm giving you another example with more details to try to be more precise :

I have the following in my custom template

let <%= camelize(className) %>: <%= className %>;
<%params.sort((a,b) => a.type > b.type ? 1 : -1).forEach(p => {%>let <%= camelize(p.type.replace(new RegExp('\\[\\]', 'g'), 'List')) %>Spy: Spy<<%= p.type %>>;<% }) %>   // this is for create
// scuri:lets    // this is for update

// Below the template definition for lets update
/** scuri:template:lets:<%params.sort((a,b) => a.type > b.type ? 1 : -1).forEach(p => {%>let <%= camelize(p.type.replace(new RegExp('\\[\\]', 'g'), 'List')) %>Spy: Spy<<%= p.type %>>;
<% }) %>*/

and I also have custom helper function defined in the custom template :

<%
sortAsc = function(params) {
   return params.sort((a,b) => a.type > b.type ? 1 : -1)
}

getLetVarname = (pType) {
   return camelize(replaceArrayWithList(pType))
}

replaceArrayWithList = function(pType) {
  return pType.replace(new RegExp('\\[\\]', 'g'), 'List')
}
%>

So I now want to use these functions in both directly from the custom template for the create (which already work), but also from all the scuri:template:* (does not work) :

let <%= camelize(className) %>: <%= className %>;
<%sortAsc(params).forEach(p => {%>let <%= getLetVarname(p.type) %>Spy: Spy<<%= p.type %>>;<% }) %>   // this is for create
// scuri:lets    // this is for update

// Below the template definition for lets update
/** scuri:template:lets:<%sortAsc(params).forEach(p => {%>let <%= getLetVarname(p.type) %>Spy: Spy<<%= p.type %>>;
<% }) %>*/

One way to acheive this could be to give the schematic the ability for user to provide not only the custom template, but also another custom template dedicated to helpers functions. This one could be provided in both from a new argument of the schematic or in the config file.

For this to work, you would need to provide all ejs with the template helper that contains custom functions, if that is possible ?
This way, all these function would be accessible from anywhere.

from scuri.

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.