csml
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:CSML generates HTML from CSS selectors.
h1. CSML 

h2. Generate HTML tags from CSS selectors.

When writting CakePHP views or WordPress templates I *hate* mixing large chunks of PHP with with HTML and  and I loathe echoing HTML tags as concatenated strings. Also I always forget the order of the arguments in frameworks' HTML helpers.

So, this is a very simple way to generate HTML tags without leaving your  blocks using a simple syntax that looks a lot like CSS selectors.

The file csml.php contains the csml class and two helper functions: t() and en() to make lazy people like me, even happier.

h2. t($selector)

This function takes a _CSS…ish_ selector and outputs an HTML tag. 


		echo "lorem ipsum dolor sit amet";
	t('/div') // output: 
?> As you can see in the example above, in order to close a tag, you only have to put a slash (/) before the tag. If you use a selector with id's and/or classes, it will append a helpfull comment to the closing tag. Very useful when you are examining your source.


		echo "lorem ipsum dolor sit amet";
	t('/div#container') // output: 
?> For autoclosing tags just append the slash at the end of the tag name:


?>
You can have only one id per tag, but as any classes as you want, separated by dots. Only remember: id's always has to be declared before classes.


h3. Attributes If you need to pass extra attributes to your tag, you have to options: 1: You can declared them right into your selector using something like CSS PseudoClases. Example:


2: Sometimes you want to generate attributes from some other PHP code, and excessive concatenation looks ugly. So you can pass an associative array of attributes as the second parameter.

'http://google.com','title'=>'google something')); 
?>
h2. en($content,$selector); This function will enclose any string within other tags generated from the passed selector or selectors. Example:

Go to Google
?>
If the second argument is an array of selectors, then the content will be nested into all this selectors, being the last one, the deepest level.

  • Go to Google
  • ?>
    h2. Requirements This class requires PHP 5.2 and a can of Diet Coke. h2. Epilogue Please take into consideration that I'm not a real programmer, so if you find some obvious or clever way to make this little class better, feel free to fork it. Please. Also, if you find it useful and actually use it, let me know. I'm just starting in this OpenSource thing and I may need to get excited :P * Both functions have more arguments, but you have to read the source for those.
    本源码包内暂不包含可直接显示的源代码文件,请下载源码包。