Same filename in other branches
  1. 8.x-2.x advagg_validator/advagg_validator.module

Advanced aggregation validation module.

File

advagg_validator/advagg_validator.module

View source
<?php


/**
 * @file
 * Advanced aggregation validation module.
 */

/**
 * @addtogroup default_variables
 * @{
 */

/**
 * Default css lint ignore settings.
 */
define('ADVAGG_VALIDATOR_CSSLINT_IGNORE', '');

/**
 * Default js hint ignore settings.
 */
define('ADVAGG_VALIDATOR_JSHINT_IGNORE', '');

/**
 * @} End of "addtogroup default_variables".
 */

/**
 * @addtogroup hooks
 * @{
 */

/**
 * Implements hook_menu().
 */
function advagg_validator_menu() {
    // Make sure the advagg_admin_config_root_path() function is available.
    drupal_load('module', 'advagg');
    $file_path = drupal_get_path('module', 'advagg_validator');
    $config_path = advagg_admin_config_root_path();
    $items = array();
    $items[$config_path . '/advagg/validate_css_w3'] = array(
        'title' => 'Validate CSS via W3',
        'description' => 'Validate CSS syntax using w3.',
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
            'advagg_validator_admin_css_w3_form',
        ),
        'type' => MENU_LOCAL_TASK,
        'access arguments' => array(
            'administer site configuration',
        ),
        'file path' => $file_path,
        'file' => 'advagg_validator.admin.inc',
        'weight' => 10,
    );
    $items[$config_path . '/advagg/validate_css_lint'] = array(
        'title' => 'Validate CSS via Lint',
        'description' => 'Validate CSS syntax using CSS Lint.',
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
            'advagg_validator_admin_css_lint_form',
        ),
        'type' => MENU_LOCAL_TASK,
        'access arguments' => array(
            'administer site configuration',
        ),
        'file path' => $file_path,
        'file' => 'advagg_validator.admin.inc',
        'weight' => 11,
    );
    $items[$config_path . '/advagg/validate_js_hint'] = array(
        'title' => 'Validate JS via Hint',
        'description' => 'Validate JavaScript syntax using JSHint.',
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
            'advagg_validator_admin_js_hint_form',
        ),
        'type' => MENU_LOCAL_TASK,
        'access arguments' => array(
            'administer site configuration',
        ),
        'file path' => $file_path,
        'file' => 'advagg_validator.admin.inc',
        'weight' => 12,
    );
    return $items;
}

/**
 * Implements hook_menu_alter().
 */
function advagg_validator_menu_alter(&$items) {
    // Make sure the advagg_admin_config_root_path() function is available.
    drupal_load('module', 'advagg');
    $config_path = advagg_admin_config_root_path();
    if (!isset($items[$config_path . '/advagg'])) {
        // If the advagg module is not enabled, redirect the /advagg path to
        // /advagg/validate_css_w3.
        $items[$config_path . '/advagg'] = array(
            'title' => 'Advanced CSS/JS Aggregation',
            'type' => MENU_LOCAL_TASK,
            'weight' => 1,
            'description' => $items[$config_path . '/advagg/validate_css_w3']['description'],
            'page callback' => 'drupal_goto',
            'page arguments' => array(
                $config_path . '/advagg/validate_css_w3',
            ),
            'access arguments' => array(
                'administer site configuration',
            ),
        );
    }
    if (!isset($items[$config_path . '/default'])) {
        // Make sure the performance page has a default path.
        $items[$config_path . '/default'] = array(
            'title' => 'Performance',
            'type' => MENU_DEFAULT_LOCAL_TASK,
            'file path' => drupal_get_path('module', 'system'),
            'weight' => -10,
        );
    }
}

/**
 * @} End of "addtogroup hooks".
 */

/**
 * @addtogroup 3rd_party_hooks
 * @{
 */

/**
 * Implements hook_libraries_info().
 */
function advagg_validator_libraries_info() {
    $libraries['csslint'] = array(
        'name' => 'csslint',
        'vendor url' => 'https://github.com/CSSLint/csslint',
        'download url' => 'https://github.com/CSSLint/csslint/archive/master.zip',
        'version arguments' => array(
            'file' => 'package.json',
            'pattern' => '/"version":\\s+"([0-9\\.]+)"/',
            'lines' => 10,
        ),
        'remote' => array(
            'callback' => 'advagg_get_github_version_json',
            'url' => 'https://cdn.jsdelivr.net/gh/CSSLint/csslint@master/package.json',
        ),
        'files' => array(
            'js' => array(
                'dist/csslint.js' => array(
                    'type' => 'file',
                ),
            ),
        ),
        'variants' => array(),
    );
    // Get the latest tagged version for external file loading.
    $version = advagg_get_remote_libraries_version('csslint', $libraries['csslint']);
    $libraries['csslint']['variants'] += array(
        'external' => array(
            'files' => array(
                'js' => array(
                    "https://cdn.jsdelivr.net/gh/CSSLint/csslint@v{$version}/dist/csslint.js" => array(
                        'type' => 'external',
                        'data' => "https://cdn.jsdelivr.net/gh/CSSLint/csslint@v{$version}/dist/csslint.js",
                    ),
                ),
            ),
        ),
    );
    $libraries['jshint'] = array(
        'name' => 'jshint',
        'vendor url' => 'https://github.com/jshint/jshint',
        'download url' => 'https://github.com/jshint/jshint/archive/master.zip',
        'version arguments' => array(
            'file' => 'package.json',
            'pattern' => '/"version":\\s+"([0-9\\.]+)"/',
            'lines' => 10,
        ),
        'remote' => array(
            'callback' => 'advagg_get_github_version_json',
            'url' => 'https://cdn.jsdelivr.net/gh/jshint/jshint@master/package.json',
        ),
        'files' => array(
            'js' => array(
                'dist/jshint.js' => array(
                    'type' => 'file',
                ),
            ),
        ),
        'variants' => array(),
    );
    // Get the latest tagged version for external file loading.
    $version = advagg_get_remote_libraries_version('jshint', $libraries['jshint']);
    $libraries['jshint']['variants'] += array(
        'external' => array(
            'files' => array(
                'js' => array(
                    "https://cdn.jsdelivr.net/gh/jshint/jshint@{$version}/dist/jshint.js" => array(
                        'type' => 'external',
                        'data' => "https://cdn.jsdelivr.net/gh/jshint/jshint@{$version}/dist/jshint.js",
                    ),
                ),
            ),
        ),
    );
    return $libraries;
}

/**
 * @} End of "addtogroup 3rd_party_hooks".
 */

Functions

Title Deprecated Summary
advagg_validator_libraries_info Implements hook_libraries_info().
advagg_validator_menu Implements hook_menu().
advagg_validator_menu_alter Implements hook_menu_alter().

Constants

Title Deprecated Summary
ADVAGG_VALIDATOR_CSSLINT_IGNORE Default css lint ignore settings.
ADVAGG_VALIDATOR_JSHINT_IGNORE Default js hint ignore settings.