Ejemplo n.º 1
0
/**
 * Recompile all theme scss on plugin form submission.
 * @param $form
 * @param $form_state
 */
function foundation_ui_settings_form_submit($form, $form_state)
{
    // no values submitted for custom scss settings, abort.
    if (empty($form_state['values']['theme_plugin_settings_foundation_ui'])) {
        return;
    }
    $theme = arg(3);
    $themepath = drupal_get_path('theme', $theme);
    // create directories, if they do not exist, to store submitted scss.
    $result = foundation_ui_create_files_directories($theme);
    if (!$result) {
        drupal_set_message('error', 'Directories creation failed. Please check your files directory permissions and retry');
    }
    // Create a valid scss string from submitted values.
    $values = foundation_ui_prepare_values($form_state['values']['theme_plugin_settings_foundation_ui']);
    $new_scss = foundation_ui_create_scss_string_from_array($values);
    // if submitted scss settings are the same than scss settings already stored in file, do nothing more.
    $old_scss = foundation_ui_get_theme_custom_scss($theme);
    if ($new_scss == $old_scss) {
        return;
    }
    // store scss in a file.
    $result = file_put_contents(foundation_ui_get_theme_scss_file_path($theme), $new_scss);
    if (!$result) {
        drupal_set_message('error', 'Fail to write custom scss in a file, please check your files directory permissions and retry.');
    }
    // get app.scss from this theme.
    $app_scss_content = file($themepath . '/scss/app.scss');
    // add @import "user_settings" to app.scss content, just after @import "settings" line.
    $scss_string = foundation_ui_rebuild_scss_import_file($app_scss_content);
    // let phpscss compile this file content to css
    $css = foundation_ui_compile_theme_scss($theme, $scss_string);
    // store compiled css into a files/okcdesign/{theme_name}/app.css file.
    // save compiled css to a file, that will be served by foundation plugin if it can load it.
    $result = file_put_contents(foundation_ui_get_theme_css_file_path($theme), $css);
    if (!$result) {
        drupal_set_message('error', 'Fail to write custom scss in a file, please check your files directory permissions and retry.');
    }
    drupal_set_message("All scss files have been recompiled to css files with new settings.");
}
Ejemplo n.º 2
0
 /**
  * Test function that parse a php array to a valid scss string.
  */
 function test_foundation_ui_creating_scss_string_from_array()
 {
     $values = array('primary-color' => 'blue', 'secondary-color' => '#333', 'row-width' => 'rem-calc(1000)');
     $scss_string = foundation_ui_create_scss_string_from_array($values);
     $this->assertInternalType('string', $scss_string);
     $this->assertContains('$primary-color', $scss_string);
     $this->assertContains('$secondary-color', $scss_string);
     $this->assertContains('$row-width', $scss_string);
 }