Tritium (programming Language)
   HOME

TheInfoList



OR:

Tritium is a simple scripting language for efficiently transforming structured data like
HTML The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaSc ...
,
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable ...
, and JSON. It is similar in purpose to XSLT but has a syntax influenced by
jQuery jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax. It is free, open-source software using the permissive MIT License. As of Aug 2022, jQuery is u ...
, Sass, and CSS versus XSLT's XML based syntax.


History

Tritium was designed by Hampton Catlin, the creator of languages Sass and
Haml Haml (HTML Abstraction Markup Language) is a templating system that is designed to avoid writing inline code in a web document and make the HTML cleaner. Haml gives the flexibility to have some dynamic content in HTML. Similar to other template s ...
and is currently bundled with the Moovweb mobile platform. 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. Open Tritium is the open source implementation of the Tritium language. It was presented at
O'Reilly Open Source Convention The O'Reilly Open Source Convention (OSCON) was an American annual convention for the discussion of free and open-source software. It was organized by publisher O'Reilly Media and was held each summer, mostly in Portland, Oregon, from 1999 ...
2014 and the compiler is implemented in Go.


Concept

Tritium takes as input HTML, XML, or JSON documents and outputs HTML, XML, or JSON data that has been transformed according to the rules defined in the Tritium script. Like jQuery, idiomatic Tritium code is structured around selecting a collection of elements via a CSS or
XPath XPath (XML Path Language) is an expression language designed to support the query or transformation of XML documents. It was defined by the World Wide Web Consortium (W3C) and can be used to compute values (e.g., strings, numbers, or Boolean v ...
selector and then chaining a series of operations on them. 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”) While Tritium supports both XPath and CSS selectors via the $() and $$() functions (respectively), the preferred usage is XPath. 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’)


Comparison to XSLT

Both Tritium and XSLT are designed for transforming data. However, Tritium differs in key ways to make it more familiar and easier to use for web developers: * Familiar syntax: Tritium's syntax is similar to CSS and jQuery so that it is more familiar and readable to web developers than the XML based syntax of XSLT. * Imperative style: Tritium uses an imperative programming style instead of the functional and recursive processing model of XSLT. While functional programming has key advantages, it is less familiar to web designers than imperative programming. * Input transparency: In XSLT any input elements that are not specified by a transform rule are removed from the output. Tritium reverses this behavior: any input elements that are not specified by a transform rule are passed to the output unchanged. * HTML-compatible: Tritium was designed to process HTML, XML, and JSON, whereas XSLT only works on XML.


References

{{reflist


External links


Open Tritium website

GitHub page for Open Tritium

Official Tritium website

Applying Transformations to Responsive Web Design

Tritium tagged questions on Stackoverflow
Programming languages