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

Adding Functions #17

Closed
raptor235 opened this issue Oct 15, 2012 · 6 comments
Closed

Adding Functions #17

raptor235 opened this issue Oct 15, 2012 · 6 comments

Comments

@raptor235
Copy link

Hi there great work and great to see 1.5 coming along... I have the framework bootstraped within my theme... is there any hooks I can get into to do a proper registrer function call to add my own lessphp functions?

Thanks so much (see lessphp example below)

<?php
include "lessc.inc.php";

function lessphp_double($arg) {
    list($type, $value) = $arg;
    return array($type, $value*2);
}

$less = new lessc;
$less->registerFunction("double", "lessphp_double");

// gives us a width of 800px
echo $less->compile("div { width: double(400px); }");
@thom4parisot
Copy link
Owner

Hi!

Glad you like this update :-)
Can you tell me if the Advanced Usage in the documentation fullfils your request?

@raptor235
Copy link
Author

I'll give this a try, I didn't see this page before but tried something similar already... never got it working but hopefully attempt number 2 will work out :) thanks

@raptor235
Copy link
Author

This doesn't seem to be working... also in the documentation the example seems wrong

if (class_exists(‘WPLessPlugin’){
$less = WPLessPlugin::getInstance();

function less_generate_random($max = 1000){
    return rand(1, $max);
}

$less->registerFunction('random', 'less_generate_random');
// you can now use random() in your *.less files, like
// div.random-size{
//  width: less_generate_random(666);
// }

}

shouldn't

div.random-size{
// width: less_generate_random(666);
// }
}

be

div.random-size{
// width: @random;
// }
}

?

either way I tried didn't work I'm getting nothing rendered out in the css

@raptor235
Copy link
Author

The function is getting registered as per dump of the obj

WPLessPlugin(
is_filters_registered =
is_hooks_registered =
compiler =
WPLessCompiler(

VERSION =
'v0.3.8'
TRUE =
array(

[0] =>
'keyword'
[1] =>
'true'
)
FALSE =
array(

[0] =>
'keyword'
[1] =>
'false'
)
libFunctions =
array(

['random'] =>
'less_generate_random'
)

but when calling

height: @random;
height: less_generate_random();

nothing gets printed from either statement

@raptor235
Copy link
Author

got it working... the function call should be width: random();

I think partially wasn't rendering because an int was returned for width so it was getting stripped

@thom4parisot
Copy link
Owner

Yep, the first argument is the less function name, the second argument is the PHP function name.

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

No branches or pull requests

2 participants