Aptana Studio 3 Snippets For The Singleton Pattern

So it seems my old eclipse templates won’t work anymore in Aptana Studio 3.

Bummer but as it happens we can now do them as snippets with Ruby as the syntax instead of XML.

First of all the tokenization script needs one very minor change, the ${dollar} on line 30 needs to be replaced with \$.

After that’s done, let’s move on to the output script:

echo "with_defaults :scope => 'source.php' do\n";
<?php foreach($to_xml as $el): ?>

	snippet "<?php echo $el['class'].'.'.$el['function'] ?>" do |s|
		s.trigger = "<?php echo $el['class'].'.'.$el['function'] ?>"
		s.expansion = 'singleton("<?php echo $el['class'] ?>")-><?php echo $el['function'] ?>(<?php echo $el['args'] ?>);'
<?php endforeach ?>	

echo "end";
file_put_contents('singleton-methods.rb', ob_get_clean());

Some sample output from singleton-methods.rb:

snippet "Master.push" do |s|
	s.trigger = "Master.push"
	s.expansion = 'singleton("Master")->push(\$func, \$site, \$data, \$files);'

snippet "Master.getDataBySite" do |s|
	s.trigger = "Master.getDataBySite"
	s.expansion = 'singleton("Master")->getDataBySite(\$table, \$field, \$start_time, \$id_name, \$site);'

Having confirmed that it looks good we put singleton-methods.rb in ~/Documents/Aptana Rubles/php.ruble/snippets/.

That’s that, you will now have code completion for your whole singleton based project!

Related Posts

Tags: , , ,