Commit 6342c982 authored by Oliver Polden's avatar Oliver Polden
Browse files

Added README.txt and template file checking plus fixed problem with new nodes.

parent b0b6b708
Loading
Loading
Loading
Loading

README.txt

0 → 100644
+15 −0
Changes for README.txt: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
// README.txt,v 0.1 2011/05/02 xalen

To get this module working requires two steps, adding the field to the content
type and outputting the field by modifying the CSS template.

 * Set up the fields you want prefixing them with _css_ so that they read:
   field_css_[your_field_name].
 * Copy template/css.tpl.php into a nodecss folder within your files directory
   and edit as necessary.

You may test the module with the Bartik theme by adding the field
"field_css_wrapper_bg_image". There is no need to copy the CSS template for this
fieldname to work.

Please see the comments in css.tpl.php for more examples and instructions.
 No newline at end of file
+36 −1
Changes for nodecss.admin.inc: 36 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ function nodecss_admin_settings() {
    '#title' => t('Generate custom css for these node types'),
    '#options' => $options,
    '#default_value' => variable_get('nodecss_node_types', array()),
    '#description' => t('A CSS file will be generated for these node types.'),
    '#description' => t('CSS will be generated for these node types.'),
  );

  $form['nodecss_settings'] = array(
@@ -52,6 +52,18 @@ function nodecss_admin_settings() {
    '#default_value' => variable_get('nodecss_directory', 'nodecss'),
    '#description' => t("The directory to save CSS files to."),
  );
  $form['nodecss_settings']['nodecss_use_custom'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use a custom CSS template file'),
    '#default_value' => variable_get('nodecss_use_custom', 0),
  );
  $form['nodecss_settings']['nodecss_template_folder'] = array(
    '#type' => 'textfield',
    '#title' => t('Node CSS template folder'),
    '#field_prefix' => t('public://'),
    '#default_value' => variable_get('nodecss_template_folder', 'nodecss'),
    '#description' => t("The location of your custom CSS template file."),
  );
  $form['nodecss_settings']['nodecss_hide_field'] = array(
    '#type' => 'checkbox',
    '#title' => t('Override and remove field from node display'),
@@ -82,6 +94,29 @@ function nodecss_admin_settings() {
    '#default_value' => variable_get('nodecss_display_messages', 0),
    '#description' => t('Display messages when a CSS file is created or updated.'),
  );
  $form['#validate'][] = 'nodecss_admin_settings_validate';
  $form['#submit'][] = 'nodecss_admin_settings_submit';

  return system_settings_form($form);
}

/*
 * Check the CSS template files exist.
 */
function nodecss_admin_settings_validate($form, &$form_state) {
  if ($form_state['values']['nodecss_use_custom'] && !file_exists('public://' . $form_state['values']['nodecss_template_folder'] . '/css.tpl.php')) {
    form_set_error('nodecss_template_folder', t('The template file does not exist. <br />Please copy the file from @d to the relevant location in your files directory.', array('@d' => drupal_get_path('module', 'nodecss') . '/template/css.tpl.php')));
  }
  
  if (!$form_state['values']['nodecss_use_custom'] && !file_exists(drupal_get_path('module', 'nodecss') . '/template/css.tpl.php')) {
    form_set_error('nodecss_use_custom', t('The default module template file does not exist. Please either use a custom template file or restore it from the original module.'));
  }
  
}

/*
 * Flush the theme cache so the correct template file is used.
 */
function nodecss_admin_settings_submit($form, &$form_state) {
  drupal_theme_rebuild();
}
 No newline at end of file
+22 −5
Changes for nodecss.module: 22 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -82,10 +82,12 @@ function nodecss_permission() {
 * Implements hook_theme().
 */
function nodecss_theme() {

  $template_path = variable_get('nodecss_use_custom', 0) ? 'sites/default/files/' . variable_get('nodecss_template_folder', 'nodecss') : drupal_get_path('module', 'nodecss') . '/template';
  return array(
    'nodecss' => array(
      'variables' => array('css_vars' => NULL),
      'path' => drupal_get_path('module', 'nodecss') . '/template',
      'path' => $template_path,
      'template' => 'css',
    ),
  );
@@ -99,10 +101,24 @@ function template_preprocess_nodecss(&$variables) {
*/

/**
 * Save CSS if node type is set to generate CSS and the current node is set to
 * generate CSS.
 * Save CSS on insert if node type is set to generate CSS.
 */
function nodecss_node_insert($node) {
  nodecss_node_save_css($node);
}

/**
 * Save CSS on update if node type is set to generate CSS.
 */
function nodecss_node_presave($node) {
function nodecss_node_update($node) {
  nodecss_node_save_css($node);
}


/**
 * Save CSS if node type is set to generate CSS.
 */
function nodecss_node_save_css($node) {
  if (nodecss_node_enabled($node) && user_access('generate css')) {

    // Save individual CSS files.
@@ -121,6 +137,7 @@ function nodecss_node_presave($node) {
  elseif (nodecss_node_enabled($node) && !user_access('generate css') && variable_get('nodecss_display_messages', 1) == 1) {
    drupal_set_message(t("CSS was not generated because you don't have @link to.", array('@link' => l('permission', 'admin/people/permissions', array('fragment' => 'module-nodecss')))));
  }

}

/**
@@ -249,7 +266,7 @@ function nodecss_save_file($css, $filename) {
    }
  }
  else { // Drupal couldn't create/save to directory.
    drupal_set_message(t("@directory does not exist or is not writeable please check the folder permissions", array('@directory' => $directory), 'error'));
    drupal_set_message(t("@directory does not exist or is not writeable please check the folder permissions", array('@directory' => $directory)), 'error');
  }
}