from trac.core import *
from trac.wiki.macros import WikiMacroBase
from StringIO import StringIO

__all__ = ['ColorMacro']

class ColorMacro(WikiMacroBase):
	"""
	Macro for colorizing short text , usage is
	
	{{{
	[[Color(color, text)]]
	}}}
	
	"""
	def render_macro(self, formatter, name, args):
		buf = StringIO()
		if args:
			args = args.split(', ',1)
			buf.write("<font color='%(color)s'>%(text)s</font>" % dict(color=args[0], text=args[1]))
		else:
			buf.write("<p style='font-weight:bold; color:red;'>[[Color()]] macro requires a color spec and text: [[Color(color, text)]]</p>\n")
	
		return buf.getvalue()

