Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-defined value conversion function #2341

Closed
aarontam opened this issue Dec 16, 2014 · 5 comments
Closed

User-defined value conversion function #2341

aarontam opened this issue Dec 16, 2014 · 5 comments

Comments

@aarontam
Copy link

We wanted to create a function to smartly convert measurements in existing LESS files to resolution-independent units. Is there a recommended way of doing this so that we only pass the measurement value, and not the entire property set? We had tried some of the techniques mentioned in #637, but there were issues with complex calculations passed to our function i.e. height: 2*@myVar + 10 and wanting to pass 2*@myVar + 10 to our function. Additionally, we had looked into the technique mentioned in less/old-lesscss.org#54, but need support in node as well as the browser. Are there any recommendations on the best way to implement our conversion function? Thanks!

@bassjobsen
Copy link
Contributor

@aarontam
Copy link
Author

Interesting, thanks for the link. Anyway to do so without creating a custom distribution of LESS? :) We are on LESS 1.7 and looking into creating a plugin - would this be the most flexible approach so that we don't get feature-locked by modifying core LESS files?

@lukeapage
Copy link
Member

Upgrade to 2.0 then use plugins http://lesscss.org/usage/#plugins-for-plugin-authors

Sorry for the slow response.

I've realised there is no function example, but it is along the same lines, you write a short js file and register new functions in the plugin init.

@aarontam
Copy link
Author

aarontam commented Jan 6, 2015

Hi @lukeapage thanks for the response, that should work for us. Is there any documentation on adding rules via plugin?

Edit: I'll open a new issue for this as it is somewhat unrelated, thanks.

@aarontam aarontam closed this as completed Jan 6, 2015
@bassjobsen
Copy link
Contributor

Hi @aarontam,

Please see : http://stackoverflow.com/questions/27809514/how-to-exend-the-less-compiler-with-a-custom-function-leveraging

The list of plugin is growing, see http://lesscss.org/usage/#plugins-list-of-less-plugins. You can use these plugins as an example.
To add rules you can use a visitor plugin (example https://github.com/less/less-plugin-inline-urls) or a postprocess plugin (example: https://github.com/less/less-plugin-autoprefix ).

If you got any not working code already, you could post a question on stack overflow too. Or send me an e-mail.

Notice that you also can use plugins to add custom function to Less easy. Examples can be found at https://github.com/less/less-plugin-advanced-color-functions/ (server side ) and https://github.com/bassjobsen/less-plugin-cubehelix (both server and client side)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants