Skip to content

Include of external sweet files

joaomdmoura edited this page Jan 12, 2012 · 4 revisions

One of the new features of sweet v0.3.7 is the possibility of including others sweet files inside of another. This is a great feature, and as far as I know everybody use it, so, why not start the wiki with a example of usage right?

The syntax to include a file in sweet is as cool as the .s extension ;), it is:

<~ [PATH/TO/FILE].s

The include feature also support logic, so you can have a sweet file with all your classes and def's, and then, include it on your sweet major file.

In this example we would like to build a simple index page with a menu, and this menu will be used in another files later so we don't want to rewrite code.

First of all we will code our menu sweet file

menu.s

div #menu
	ul
		li
			"home"
		li
			"about us"
		li
			"contact"

After save menu.s we will gonna need to include this file inside our index.s

index.s

html
	head
		title
			"A Sweet language!"

body
	div #container
		<~ menu.s
	div #content
		"This is it folks!"

Both files in this case should be in the same directory. Then, when we compile it:

sweet -c index.s

It will be compiled to:

<html >
	<head >
		<title >
			A Sweet language!
		</title>
	</head>
	<body >
		<div id='container'>
			<div id='menu'>
				<ul >
					<li >
						home
					</li>
					<li >
						about us
					</li>
					<li >
						contact
					</li>
				</ul>
			</div>
		</div>
		<div id='content'>
			This is it folks!
		</div>
	</body>
</html>

And this is it folks, how you guys can see it worked pretty well, and we can include our menu.s file in all pages that we want to, and include it how many time in a file we want too. I hope you liked, in case of doubt just let me know!

Clone this wiki locally