Home

Awesome

Alt text

Sweet (current version - 0.6.6)

A Sweet Language, that compiles for HTML.

Description

Sweet is a pre-compiled language based on Ruby and Python. Sweet makes possible to use all the class, defs, conditionals, global and local variables power of server-side languages, defining blocks by indentation like Python in your Sweet HTML markup. It comes with a SIC ( Sweet Interactive Console ) the you can test your code and ideas before really right and compile it.

Features

Installation

Sweet is available through Rubygems and can be installed via:

$ gem install sweet-lang

Usage

For help

sweet -h

For watch a folder

sweet -w ./

For compile a file

sweet -c [FILENAME].s

For SIC ( Sweet Interactive Console )

sweet - o

##Syntax

There is a lot to discuss and show about sweet syntax, I think the best for learn it, is take a look at the examples, but there is details that should be showed.

Including sweet external files

In sweet you can include external files to be compile in anywhere you want to in your code, there is page with an example in wiki:https://github.com/joaomdmoura/sweet/wiki/Include-of-external-sweet-files/

<~ [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.

##Examples

A Basic example

Sweet have to be simple, then we start thinking a new way to write a clean and smart syntax that compiles to HTML So just a few tips:

This is a basic.s ( A Sweet file ) basic.s

html
	head
		title
			"A Sweet basic demostration"
	body
		h1 #title
			"Welcome to Sweet"
		h2 .subtitle
			"Hope you enjoy it"

When we compile it

sweet -c basic.s

It becomes basic.html

<html>
	<head>
		<title>
			A Sweet basic demostration
		</title>
	</head>
	<body>
		<h1 id='title'>
			Welcome to Sweet
		</h1>
		<h2 class='subtitle'>
			Hope you enjoy it
		</h2>
	</body>
</html>

A Medium example

After a Really clean, smart and easy to use precompiled language we should make it INSANE!, then we bring to Sweet a little bit of server-side development to open your mind to impossible:

Remember

This is a medium.s ( A Sweet file ) medium.s

Var1 = "A Sweet medium demostration"
Var2 = "Welcome to Sweet"
Var3 = "Hope you keep enjoing it"

def sweet_content( easy )
	if easy
		"It isn't getting hard, is getting sweet!"

html
	head
		title
			print( Var1 )
	body
		h1 #title
			print( Var2 )
		h2 .subtitle
			print( Var3 )
		div
			content = sweet_content( true )
			print( content )

When we compile it

sweet -c medium.s

It becomes medium.html

<html >
	<head >
		<title >
			A Sweet medium demostration
		</title>
	</head>
	<body >
		<h1 id='title'>
			Welcome to Sweet
		</h1>
		<h2 class='subtitle'>
			Hope you keep enjoing it
		</h2>
		<div >
			It isn't getting hard, is getting sweet!
		</div>
	</body>
</html>

A Sweet ( hard ) example

Let's stop jooking is time to take it to a next level, this isn't a hard example, cuz Sweet isn't hard, it was made to be simple. We will just use all the features together in one .s file.

This is a hard.s ( A Sweet file ) hard.s

class Sweet
	def get_user(admin)
		if admin
			"Jonh Doe"
	
	def get_status(usr)
		if usr
			"Logged"
	
Sweet = Sweet.new

Var1 = "A Sweet hard demostration"
Var2 = "Welcome to Sweet"
Var3 = "Hope you keep enjoing it"

html
	head
		title
			print( Var1 )
	body
		h1 #title
			print( Var2 )
		h2 .subtitle
			print( Var3 )
		div #user
			ul #content
				li .name
					Code_def = Sweet.get_user(true)
					print (Code_def)
				li .status
					code_def = Sweet.get_status(Code_def)
					print (code_def)
		div #logout
			a href=logout
				"Do you wanna logout"
		div #login
			form action=login #form
				input type=text #email

When we compile it

sweet -c hard.s

It becomes hard.html

<html >
	<head >
		<title >
			A Sweet hard demostration
		</title>
	</head>
	<body >
		<h1 id='title'>
			Welcome to Sweet
		</h1>
		<h2 class='subtitle'>
			Hope you keep enjoing it
		</h2>
		<div id='user'>
			<ul id='content'>
				<li class='name'>
					Jonh Doe
				</li>
				<li class='status'>
					Logged
				</li>
			</ul>
		</div>
		<div id='logout'>
			<a href='logout'>
				Do you wanna logout
			</a>
		</div>
		<div id='login'>
			<form action='login' id='form'>
				<input type='text' id='email' />
			</form>
		</div>
	</body>
</html>

This is it!

Well, this is Sweet i really hope you enjoy and use it a lot, I'm still working on it so dont be shy, let me know if something get wrong opening a issue, then i can fix it and we help each other ;) All examples are in examples folder.

Mailing List

A place to talk about it.

http://groups.google.com/group/sweet-lang