https://github.com/gocom/rah_minify
Tells Textpattern to minify flat CSS and JavaScript files
https://github.com/gocom/rah_minify
Last synced: 2 months ago
JSON representation
Tells Textpattern to minify flat CSS and JavaScript files
- Host: GitHub
- URL: https://github.com/gocom/rah_minify
- Owner: gocom
- License: gpl-2.0
- Created: 2012-02-09T14:24:28.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2013-08-01T09:33:45.000Z (almost 13 years ago)
- Last Synced: 2025-03-21T15:43:00.880Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 426 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: LICENSE
Awesome Lists containing this project
README
h1. rah_minify
p. "Packagist":https://packagist.org/packages/rah/rah_minify | "GitHub":https://github.com/gocom/rah_minify | "Twitter":http://twitter.com/gocom | "Donate":http://rahforum.biz/donate/rah_minify
p. Rah_minify is an asset compressor plugin for "Textpattern CMS":http://textpattern.com. It minifies and preprocesses flat JavaScript and CSS files. Rah_minify removes comments, unneeded white-space and compressed property values and variables to its shortest format, while keeping the code's behavior intact.
h2. Installing
p. Using "Composer":http://getcomposer.org. The plugin uses relies to some development packages, so you will have to add some repository link rules to your composer.json file:
bc. {
"repositories": [
{
"type": "vcs",
"url": "https://github.com/gocom/YUI-CSS-compressor-PHP-port.git"
}
],
"minimum-stability": "dev"
}
p. The above lower your minimum-stability to development versions and adds link to our fork of "YUI CSS compressor":https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port PHP port by "Túbal Martín":https://github.com/tubalmartin. After done, you can run the installation:
bc. $ composer.phar require rah/rah_minify
h2. Requirements
p. Rah_minify's minimum requirements:
* Textpattern 4.5 or newer.
h2. Preferences
p. Rah_minify offers few preferences that can be used to do all the needed configuration. All settings can be found from "Advanced Preferences":http://textpattern.net/wiki/index.php?title=Advanced_Preferences, organized under a *Minify* section. The following settings will be present.
h3. Security key for the public callback
p. A key that is used to restrict unwanted access to the callback URL. This should be set as a long, strong value, containing combination of numbers, characters and symbols.
p. If set, assets can be processed and minified with a public callback URL. This removes any need to have the site to set to debugging mode or having to login to Textpattern. Each time the callback URL is accessed, processed files are created from your assets.
p. This callback URL can be used with a "cron job":http://en.wikipedia.org/wiki/Cron to do scheduled processing job, or added into automated "deployment task":http://www.deployhq.com/. The callback could be executed on "post-hook":http://git-scm.com/book/en/Customizing-Git-Git-Hooks after each commit, or code change. This way you never have to worry about compressing and compiling your JavaScript or CSS code manually, or polluting your repository with unneeded files.
p. A callback URL would look like this:
bc. http://example.com/?rah_minify=key
p. Where @key@ is the value set in _Security key for the public callback_ field, and @http://example.com/@ is path to your Textpattern site.
h3. List of compressed files
p. This setting sets the JavaScript and CSS files that are being compressed by rah_minify. The setting takes an list of absolute file system paths, formatted in source and target pairs, pairs separated by line breaks.
bc. source target
source target [\n...]
p. Where the source is the file that is being compressed and the target is the location where the compressed file is written to. The target and the source paths are separated by a space (U+0020). Compressed files are separated by line breaks (a single UNIX style linefeed). All paths will be relative to the Textpattern's installation directory (e.g. @./textpattern@).
p. The following would compress files named @main.js@, @extra.js@ and @default.css@, located in @assets/src/@, and write the results to the parent @assets@ directory. The files would be located in a @assets@ directory placed to the site's root, the same directory containing the @textpattern@ directory and your site's @index.php@ file.
bc. ../assets/src/main.js ../assets/main.js
../assets/src/extra.js ../assets/extra.js
../assets/src/default.css ../assets/default.css
h3. Create snapshots?
p. If set to Yes, additional timestamped files are created each time an asset file is compressed. These files act as versions of the created files. These files offer an way to "optimize caching of static resources":https://developers.google.com/speed/docs/best-practices/caching.
p. These timestamped versions are written to the same target directory as the compressed file. Versioned files follow the naming pattern:
bc. {targetName}.{timestamp}.{targetExtension}
p. Where in the @{targetName}@ is the name of the target file (e.g. main.min), the @{timestamp}@ is a Unix timestamp (e.g. 1345269546) and the @{targetExtension}@ is the target files extension (e.g. css or js). The timestamp included in the filename is same as the target file's modification date.
p. Consider the following file pair:
bc. ../assets/src/main.js ../assets/main.js
p. The created versioned file would be named as @main.1345269546.js@, written to the same parent @assets@ directory as the minified @main.js@ file.
h2. Setting processed files
p. Todo.
h3. Optionally from PHP
p. Todo.
h2. Extension decides
p. Processing action is decided from the source asset file's extension. Files that end with a @.css@ are processed as a CSS and @.js@ as a JavaScript. If the optional "LESS PHP compiler":https://github.com/leafo/lessphp is installed, rah_minify can also process LESS code used in @.less@ files. Files with an unrecognized extension fill be ignored.
h2. Joining files
p. Rah_minify also supports file joining. All the source assets files are and can be processed as stacks, where contents are written to a single compressed target file. How this works is very simple. Any file pair that has the same target path will be joined and compressed output written to the same target file.
p. With the following file configuration setting only two compressed files are written while there are total of five source files:
bc. ../js/jquery.plugin.js ../js/main.min.js
../js/main.js ../js/main.min.js
../css/bootstrap.css ../css/main.min.css
../css/jquery.plugin.css ../css/main.min.css
../css/main.css ../css/main.min.css
p. The above will compress two files named as @main.min.css@ and @main.min.js@. The files are joined and written to the target files in the order they are listed. The sources of @bootstrap.css@ will be at the top of the @main.min.css@ while the styles from @main.css@ are at the end of the file.
h2. LESS support
p. To enable "LESS":http://lesscss.org/ syntax support in your stylesheets, you would first need to install and import LESS PHP class to Textpattern. First download "LESSPHP":http://leafo.net/lessphp/ and upload "lessc.inc.php":https://raw.github.com/leafo/lessphp to your website's server. After you have uploaded the file open up your Textpattern's configuration file, @config.php@ and add the following line to it:
bc. include "/absolute/path/to/lessc.inc.php";
p. Where the @/absolute/path/to/less.inc.php@ is an absolute path to the LESS PHP's class file you uploaded.
h2. Debugging and the activity log
p. Rah_minify writes a log and a debugging lines to Textpattern's "tag trace":http://textpattern.net/wiki/index.php?title=Tag_trace when the site is in a debugging mode. Looking at the trace can give an idea why a file isn't processed correctly. Lines added by rah_minify look something like the following:
bc. [rah_minify: main.min.css is up to date]
p. Every line added by rah_minify is prefixed appropriately with @rah_minify:@.
h2. Thanks to
* "Douglas Crockford":https://github.com/douglascrockford for "JSMin":https://github.com/douglascrockford/JSMin, and "Ryan Grove":https://github.com/rgrove for a "PHP port":https://github.com/rgrove/jsmin-php.
* "YUI CSS compressor":https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port PHP port by "Túbal Martín":https://github.com/tubalmartin
h2. Changelog
h3. Version 0.1 - upcoming
* Initial release.