bitcrowd / tickety-tick

A browser extension that helps you name branches and write better commit messages
MIT License
58 stars 11 forks source link

[#233] New helper to limit string length #235

Closed pmeinhardt closed 4 years ago

pmeinhardt commented 4 years ago

I was intrigued @bitboxer and had a moment this morning to throw something together.

It allows for (optionally) parameterized filters in templates, e.g.:

Title is "{value | truncate(50)}"

I've also changed how we handle errors in template expressions, hoping to make it easier to figure out what's going wrong in case of typos and erroneous templates. For instance:

From what I can see, there's at least two more to-dos:

Please take it for a spin when you have time.

Happy about feedback. 🙂

Closes #233.

preview

pmeinhardt commented 4 years ago

Plus, I agree this could use some more help on the preferences page. Even though the error feedback is already an awesome step in the right direction. Do you want to do it in this PR or tackle it as a separate one?

Maybe we can think about what the help should look like here first. At the moment, the options page lists only the helper names. This was sufficient before, when helpers did not take any arguments.

Now, we probably need at least a hint for what arguments a helper accepts. E.g. I could imagine the following for our new helpers:

We could achieve this by assigning an optional description property to the helpers and rendering that on the options page if defined. E.g.

export const substring = (...args) => (s) => s.substring(...args);
substring.description = 'substring(start-index[, end-index])';
klappradla commented 4 years ago

Sorry it took me so long to get back to this @pmeinhardt 🙈 (blog business...)

I think the format you suggested here fits perfect and I would suggest to go that route:

substring(start-index[, end-index])
truncate(max-length)

Should we have this as a separate PR and just merge this as it is?

pmeinhardt commented 4 years ago

I've quickly added it here @klappradla (see the last commit). Looks like this

preview