Skip to content

Adding Grunt, Error Admin & Nav

Darryl Hein edited this page Jan 17, 2014 · 11 revisions

We've recently added 3 new pieces to the xm module:

  • Grunt – for SASS, compass and minification
  • Error Admin – for tracking and viewing errors
  • Nav – for creating navigation/menus

We also remove jQuery UI from the public pages.

Grunt

To add grunt, you need to do the following.

Copy these files from the XM Template into your project:

  • package.json
  • Gruntfile.js
  • .gitignore (either copy or just add npm_modules to the list)

Remove the //@codekit-prepend's from the JS files.

The run npm install. This will download and install all the modules listed in package.json.

The run grunt to compile all the files. Watch for errors.

To automatically compile CSS & JS files while working on the site, just run grunt watch from the root of the site.

Delete the compass scripts: compass_compile.sh, compass_watch.sh, compass_create.sh. Copy in link_icons.sh from the template. (Delete the update.sh script as well.)

Error Admin

To setup the error admin, first create the 2 tables and add the permission:

CREATE TABLE `error_group` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `file` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `line` int(10) unsigned NOT NULL,
  `data` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `error_log` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `error_group_id` int(10) unsigned NOT NULL,
  `datetime` datetime NOT NULL,
  `message` varchar(1024) COLLATE utf8_unicode_ci NOT NULL,
  `file` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `line` int(10) unsigned NOT NULL,
  `code` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `trace` longtext COLLATE utf8_unicode_ci NOT NULL,
  `url` varchar(1024) COLLATE utf8_unicode_ci NOT NULL,
  `remote_address` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
  `server` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `post` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `get` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `files` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `cookie` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `session` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `html` longtext COLLATE utf8_unicode_ci NOT NULL,
  `resolved` tinyint(1) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `datetime` (`error_group_id`,`datetime`,`resolved`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- you may need to adjust the permission ID
INSERT INTO `permission` VALUES (30, 'error_admin', 'Error Admin', 'Gives full access to the Error Admin.');
INSERT INTO `group_permission` VALUES (NULL, 1, 30);

Copy in the minion and miniond scripts from the root of the template.

Add a cron job for every 2 hours to parse the errors:

0 */2 * * * cd /path/to/site && ./minion error:log:parse:all

Add error_admin admin to the list of nav items in _private_nav.scss.

Nav

A new system has been added to the xm module to generate the navigation within the private pages. It uses config files instead of putting HTML and if statements directly in a view. It has been implement in views/base/header.php.

Basically all additions to the navigation in the sites header.php need to be moved to applocation/config/nav.php and then delete header.php. See the documentation in the config file here: https://github.com/xmmedia/kohana_module/blob/kohana_v3.3/master/config/nav.php

jQuery UI

jQuery UI has been removed from the public JS & CSS. Instead, it has only been included in the private CSS & JS. Only make this change if jQuery UI is not used on the public pages of the site. Changes:

  • The @import has been moved from base.scss to private.scss
  • The jQuery UI script "include" is unset within Controller_Public with the following:
<?php
	public function before() {
		parent::before();

		// remove jQuery UI if it exists since we typically don't need it for public sites
		if ($this->auto_render && isset($this->scripts['jquery_ui'])) {
			unset($this->scripts['jquery_ui']);
		}
	}