To use Watcher download source code open config.rb
- Change properties to match your machine
- Open your command line and navigate to the folder where you downloaded the source and run
rake watch
- Open the haml-sass directory (or in the codeigniter example the haml folder) and edit index.haml or index.phaml make a change save it
- phaml files will be saved as .php files, haml files will be saved as .html files
- Open the php directory or your codeigniter views directory folder and open index.html or index.php in your editor to view your changes.
<?php $heading = "Haml & Sass Watcher for PHP develope"; ?>
!!! Strict
%html
%head
%title
Haml & Sass Watcher for PHP developers
%body
%h1
<?php echo $heading; ?>
In some cases we would like to add our php code to be in a html attribute
%content
%p{ :id => "<?php echo 'paragraph'; ?>" }
but the Haml parser by default escapes PHP opening and closing brackets. Work around is to hack the Haml code to do this find the haml folder inside your gems folder open haml-3.0.11\lib\haml\helpers.rb find
NOTE: If you have HAML 3.1.4 you can set in config file @hamloptions = {:attr_wrapper => '"', :escape_attrs => false } to stop HAML from escaping charactersif you have a previouse version you canfollow the instructions bellow.
HTML_ESCAPE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
Comment out the existing code and add the code below
#HTML_ESCAPE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
HTML_ESCAPE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
Just add :plain
tag and Haml will render the code below this tag as you write see example below
#content
%p
PHP block code example
:plain
<?php function helloworld()
{
$haml = "Hellow world";
return $haml;
}
?>
#wrapper
<?php helloworld(); ?>