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

Enabled Compass Extension #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions wp-sass.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,66 @@ public function __parse( $file, $syntax, $style = 'nested' ) {
'warn' => array( $this, 'cb_warn' ),
'debug' => array( $this, 'cb_debug' ),
),
'load_path_functions' => array( array( $this, 'loadCallback' )),
'load_paths' => array(dirname($file)),
'functions' => $this->getFunctions(array('Compass')),
'extensions' => array('Compass'),
);
// Execute the compiler.
$parser = new SassParser( $options );
return $parser->toCss( $file );
}
try{
// Execute the compiler.
$parser = new SassParser( $options );
return $parser->toCss( $file );
} catch (Exception $ex) {
wp_die( $ex->getMessage() );
}
}

public function cb_warn( $message, $context ) {
print "<p class='warn'>WARN : ";
print_r( $message );
print "</p>";
}
}

public function cb_debug( $message ) {
public function cb_debug( $message ) {
print "<p class='debug'>DEBUG : ";
print_r( $message );
print "</p>";
}
}

public function getFunctions($extensions) {
$extensions = array('Compass');
$output = array();
if (!empty($extensions)) {
foreach ($extensions as $extension) {
$name = explode('/', $extension, 2);
$namespace = ucwords(preg_replace('/[^0-9a-z]+/', '_', strtolower(array_shift($name))));
$extensionPath = dirname(__FILE__) . '/phpsass/Extensions/' . $namespace . '/' . $namespace . '.php';
if ( file_exists($extensionPath) ) {
require_once($extensionPath);
$namespace = $namespace . '::';
$function = 'getFunctions';
$output = array_merge($output, call_user_func($namespace . $function, $namespace));
}
}
}
return $output;
}
public function loadCallback($file, $parser) {
$paths = array();
foreach ($parser->extensions as $extensionName) {
$namespace = ucwords(preg_replace('/[^0-9a-z]+/', '_', strtolower($extensionName)));
$extensionPath = dirname(__FILE__) . '/phpsass/Extensions/' . $namespace . '/' . $namespace . '.php';
if (file_exists($extensionPath)) {
require_once($extensionPath);
$hook = $namespace . '::resolveExtensionPath';
$returnPath = call_user_func($hook, $file, $parser);
if (!empty($returnPath)) {
$paths[] = $returnPath;
}
}
}
return $paths;
}


/**
Expand Down