Frontend HTML generation with PHP
This plugin requires Grunt ~0.4.1
and php-cgi
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-php2html --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-php2html');
To make this work you need the php-cgi
binaray in your PATH.
The php-cgi
binary can be installed via Homebrew by tapping the
homebrew-php repository:
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install php54
The php-cgi
binary can be installed via XAMPP.
Here is how you can add the binary to your PATH: Link
sudo apt-get install php5-cgi
Use this grunt plugin to compile php files to static html.
In your project's Gruntfile, add a section named php2html
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
php2html: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
// relative links should be renamed from .php to .html
processLinks: true,
// some function to process the output
process: function(response,callback) {
callback(':-)');
},
htmlhint: {},
htmlhintrc: .htmlhintrc,
docroot: <mydocroot relative to Gruntfile.js>
Type: Boolean
Default value: true
Convert links pointing to .php
pages to the .html
equivalent.
Type: Function
Params: String
Response text, Function
Callback function
Default value: undefined
Implement your own response parser and return the processed response back to the task
Type: Object
Pass a list of rules for linting the compiled HTML.
If rules is undefined, it will use default ruleset:
{
'tagname-lowercase': true,
'attr-lowercase': true,
'attr-value-double-quotes': true,
'doctype-first': true,
'tag-pair': true,
'spec-char-escape': true,
'id-unique': true,
'src-not-empty': true
}
Type: String
Default value: null
If this filename is specified, options and globals defined therein will be used. Task and target options override the options within the htmlhintrc
file. The htmlhintrc
file must be valid JSON and looks something like this:
{
"tag-pair": true,
}
Type: String
Default value: process.cwd()
Specify a docroot for the php Server. All php files will be served relative to this directory.
Type: Int
Default value: 8888
Specify a port for the php Server.
grunt.initConfig({
php2html: {
default: {
options: {
// relative links should be renamed from .php to .html
processLinks: false,
process: function(response,callback) {
// do some funy stuff with the reponse text
var parsedResponse = ...
// send it back to the task
callback(parsedResponse);
}
},
files: [
{expand: true, cwd: 'app/', src: ['*.php'], dest: 'build', ext: '.html' }
]
}
},
})
- 2013-11-09 v0.1.7 Added docroot option
- 2013-11-07 v0.1.6 Fixed some path issues on windows
- 2013-11-04 v0.1.5 Added HTMLHint support
- 2013-08-09 v0.1.4 First release