Jump to content

Tritium (programming language)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ianand (talk | contribs) at 13:52, 11 July 2013 (Removed tag about duplication of "Tritium programming language". I created both pages and requested "Tritium programming language" to be deleted since "Tritium (programming language)" better fits with the usual wikipedia naming conventions.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


Tritium
Designed byHampton Catlin
Filename extensions.ts
Websitetritium.io
Influenced by
XSLT, Sass (stylesheet language)

Tritium is a simple scripting language for efficiently transforming structured data like HTML, XML, and JSON. It is similar in purpose to XSLT but has a syntax intended to be more reminiscent of JQuery than XSLT’s XML based syntax.

History

Tritium was designed by Hampton Catlin, the creator of popular languages Sass (stylesheet language) and Haml (and coincidentally the first mobile version of Wikipedia) and is currently bundled with the Moovweb mobile platform.[1]

As with Sass (created to address deficiencies in CSS) and Haml (created to address deficiencies in coding HTML templates), Catlin designed Tritium to address issues he saw with XSLT while preserving the core benefits of a transformation language. Much of this was based on his prior experience porting Wikipedia’s desktop website to the mobile web.[2]

Concept

Tritium takes as input HTML, XML, or JSON documents and outputs HTML, XML, or JSON data that has been transformed according the rules defined in the Tritium script. Like JQuery, idiomatic Tritium code is structured around selecting a collection of elements via a CSS selector and then chaining a series of operations on them.[3]

For example, the following script will select all the HTML table elements with id of foo and change their width attributes to 100%.

# Select all HTML nodes that are table elements with ID foo.

# The $$() function takes a regular CSS selector
$$(“table#foo”) {
	# change the width attributes to “100%”
	attribute(“width”, “100%”)
}

Tritium supports CSS or XPath selectors via the $() and $$() functions. For example, the above code rewritten to use the equivalent XPath selector would be:

# Select all HTML nodes that are table elements with ID foo.

# The $() uses XPath
$(“//table[@id=’foo’]”) {
	# change the width attributes to “100%”
	attribute(“width”, “100%”)
}

See also

References

  1. ^ C. Coyier, D. Rupert. (2013-05-30). "Episode 070". ShopTalkShow. Retrieved 2013-07-10.
  2. ^ D. Nugent (2013-05-07). "Interview with Hampton Catlin". HTML5 Developer Conference. Retrieved 2013-07-10.
  3. ^ I. Anand (2013-04-30). "From Desktop to Mobile". Future Insights Live - Las Vegas, 2013. Retrieved 2013-07-10.