Skip to content

Commit

Permalink
A kind-of almost working beginnings of libsass bindings for PHP. I ca…
Browse files Browse the repository at this point in the history
…n't figure out how to correctly link lib/libsass/libsass.a to the extension...
  • Loading branch information
jamierumbelow committed Apr 29, 2012
1 parent 41eb777 commit 8138755
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 14 deletions.
18 changes: 18 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,23 @@ PHP_ARG_ENABLE(sass, [whether to enable sass extension],
[ --enable-sass Enable sass extension], yes, yes)

if test "$PHP_SASS" != "no"; then

LIBSASS_SEARCH_DIRS="./lib/libsass"

for i in $LIBSASS_SEARCH_DIRS; do
if test -f $i/sass_interface.h; then
LIBSASS_DIR=$i
LIBSASS_INCDIR=$i
fi
done

if test -z "$LIBSASS_DIR"; then
AC_MSG_ERROR(Cannot find libsass)
fi

PHP_ADD_INCLUDE($LIBSASS_INCDIR)
PHP_ADD_LIBRARY_WITH_PATH(libsass, $LIBSASS_DIR, LIBSASS_SHARED_LIBADD)

PHP_SUBST(SASS_SHARED_LIBADD)
PHP_NEW_EXTENSION(sass, "src/sass.c", $ext_shared)
fi
9 changes: 7 additions & 2 deletions src/php_sass.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
#include <ext/standard/info.h>
#include <Zend/zend_extensions.h>

int sass_setup(TSRMLS_D);
#include "lib/libsass/sass_interface.h"

PHP_FUNCTION(sass_test);
zend_class_entry *sass_ce;

PHP_METHOD(Sass, __construct);
PHP_METHOD(Sass, parse);
PHP_METHOD(Sass, parse_file);
PHP_METHOD(Sass, parse_directory);

#endif
70 changes: 58 additions & 12 deletions src/sass.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,63 @@
#include "php_sass.h"

PHP_METHOD(Sass, __construct) { }

PHP_METHOD(Sass, parse)
{
char *source;
int source_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE)
{
return;
}

struct sass_context* context = sass_new_context();

context->options.include_paths = "";
context->options.output_style = SASS_STYLE_NESTED;

context->input_string = source;

sass_compile(context);

if (context->error_status)
{
// throw error
}
else if (context->output_string)
{
RETURN_STRING(context->output_string, 0);
}

sass_free_context(context);
}

PHP_METHOD(Sass, parse_file)
{

}

PHP_METHOD(Sass, parse_directory)
{

}

zend_function_entry sass_methods[] = {
PHP_ME(Sass, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(Sass, parse, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Sass, parse_file, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Sass, parse_directory, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};

static PHP_MINIT_FUNCTION(sass)
{
zend_class_entry ce;

INIT_CLASS_ENTRY(ce, "Sass", sass_methods);
sass_ce = zend_register_internal_class(&ce TSRMLS_CC);

return SUCCESS;
}

Expand All @@ -12,15 +68,10 @@ static PHP_MINFO_FUNCTION(sass)
php_info_print_table_end();
}

static zend_function_entry sass_functions[] = {
PHP_FE(sass_test, NULL)
{ NULL, NULL, NULL }
};

static zend_module_entry sass_module_entry = {
STANDARD_MODULE_HEADER,
"sass",
sass_functions,
NULL,
PHP_MINIT(sass),
NULL,
NULL,
Expand All @@ -32,9 +83,4 @@ static zend_module_entry sass_module_entry = {

#ifdef COMPILE_DL_SASS
ZEND_GET_MODULE(sass)
#endif

PHP_FUNCTION(sass_test)
{
RETURN_STRING("Hello World", 1);
}
#endif

0 comments on commit 8138755

Please sign in to comment.