Skip to content

Commit

Permalink
0.5.12 Expand out map root & map path tests
Browse files Browse the repository at this point in the history
  • Loading branch information
absalomedia committed Apr 7, 2017
1 parent 0418cf3 commit 9552f14
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ These extensions also utilise the [Libsass](https://github.com/hcatlin/libsass)

| Release | Description |
| --- | --- |
| 0.5.12 | Cartography - MapRoot functions |
| 0.5.11 | Zoomer (Libsass 3.4.4) stable |
| 0.5.10 | Elwood (Libsass 3.4.3) stable & Travis fix |
| 0.5.9 | Rickshaw (Libsass 3.4.2) stable |
Expand Down
4 changes: 3 additions & 1 deletion src/php_sass.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "config.h"
#endif

#define SASS_VERSION "0.5.11"
#define SASS_VERSION "0.5.12"
#define SASS_FLAVOR "Sassyphpras"

#include <php.h>
Expand Down Expand Up @@ -46,5 +46,7 @@ PHP_METHOD(Sass, getEmbed);
PHP_METHOD(Sass, setEmbed);
PHP_METHOD(Sass, getMapPath);
PHP_METHOD(Sass, setMapPath);
PHP_METHOD(Sass, getMapRoot);
PHP_METHOD(Sass, setMapRoot);

#endif
65 changes: 64 additions & 1 deletion src/sass.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,64 @@ PHP_METHOD(Sass, setMapPath)
}


PHP_METHOD(Sass, getMapRoot)
{
zval *this = getThis();

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "", NULL) == FAILURE) {
RETURN_FALSE;
}

#if ZEND_MODULE_API_NO > 20131226
sass_object *obj = Z_SASS_P(this);
#endif
#if ZEND_MODULE_API_NO <= 20131226
sass_object *obj = (sass_object *)zend_object_store_get_object(this TSRMLS_CC);
#endif

#if ZEND_MODULE_API_NO <= 20131226
if (obj->map_root == NULL) RETURN_STRING("", 1);
RETURN_STRING(obj->map_root, 1);
#endif

#if ZEND_MODULE_API_NO > 20131226
if (obj->map_root == NULL) RETURN_STRING("");
RETURN_STRING(obj->map_root);
#endif
}

PHP_METHOD(Sass, setMapRoot)
{
zval *this = getThis();

char *path;
#if ZEND_MODULE_API_NO <= 20131226
int path_len;
#endif
#if ZEND_MODULE_API_NO > 20131226
size_t path_len;
#endif

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE)
RETURN_FALSE;

#if ZEND_MODULE_API_NO > 20131226
sass_object *obj = Z_SASS_P(this);
#endif
#if ZEND_MODULE_API_NO <= 20131226
sass_object *obj = (sass_object *)zend_object_store_get_object(this TSRMLS_CC);
#endif

if (obj->map_root != NULL)
efree(obj->map_root);
obj->map_path = estrndup(path, path_len);

RETURN_NULL();
}




PHP_METHOD(Sass, getPrecision)
{
zval *this = getThis();
Expand Down Expand Up @@ -700,7 +758,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_sass_setMapPath, 0, 0, 1)
ZEND_ARG_INFO(0, map_path)
ZEND_END_ARG_INFO()


ZEND_BEGIN_ARG_INFO_EX(arginfo_sass_setMapRoot, 0, 0, 1)
ZEND_ARG_INFO(0, map_root)
ZEND_END_ARG_INFO()

zend_function_entry sass_methods[] = {
PHP_ME(Sass, __construct, arginfo_sass_void, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(Sass, compile, arginfo_sass_compile, ZEND_ACC_PUBLIC)
Expand All @@ -719,6 +780,8 @@ zend_function_entry sass_methods[] = {
PHP_ME(Sass, setEmbed, arginfo_sass_setEmbed, ZEND_ACC_PUBLIC)
PHP_ME(Sass, getMapPath, arginfo_sass_void, ZEND_ACC_PUBLIC)
PHP_ME(Sass, setMapPath, arginfo_sass_setMapPath, ZEND_ACC_PUBLIC)
PHP_ME(Sass, getMapRoot, arginfo_sass_void, ZEND_ACC_PUBLIC)
PHP_ME(Sass, setMapRoot, arginfo_sass_setMapRoot, ZEND_ACC_PUBLIC)
PHP_ME(Sass, getLibraryVersion, arginfo_sass_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_MALIAS(Sass, compile_file, compileFile, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
Expand Down
15 changes: 15 additions & 0 deletions tests/get_map_path.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
correctly handles getting source map path
--SKIPIF--
<?php if (!extension_loaded("sass")) print "skip"; ?>
--FILE--
<?php

$sass = new Sass();
// test default from constructor
$sass->setMapPath('map_path.css.map');
echo $sass->getMapPath();

?>
--EXPECT--
map_path.css.map
28 changes: 28 additions & 0 deletions tests/handles_map_root.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-TEST--
correctly handles setting map root
--SKIPIF--
<?php if (!extension_loaded("sass")) print "skip"; ?>
--FILE--
<?php

$sass = new Sass();
// test default from constructor
$sass->setComments(true);
$sass->setMapRoot(__DIR__.'/support/');
$sass->setMapPath('map_root.css.map');
$css = $sass->compileFile(__DIR__.'/support/test.scss');
echo $css[1];
?>
--EXPECT--
{
"version": 3,
"file": "tests/support/test.css",
"sources": [
"tests/support/test.scss"
],
"sourcesContent": [
"@import url(../blahblah/blah.blah);\n\ndiv {\n blah: \"hello #{2+2} world #{unit(23px)} #{'bloo'} blah\";\n}\n\n$foo: iphone;\n\ndiv {\n blah: \"foo #{$foo$
],
"names": [],
"mappings": "AAAA,OAAO,CAAC,0BAAI;;AAEZ,AAAA,GAAG,CAAC;EACF,IAAI,EAAE,4BAAiD,GACxD;;;AAID,AAAA,GAAG,CAAC;EACA,IAAI,EAAE,YAAa,GACtB"
}

0 comments on commit 9552f14

Please sign in to comment.