FTD: Programming Language For Prose
FTD is the innovative programming language for writing prose. Say goodbye to the complexities of traditional programming languages and hello to a simplified and intuitive experience.
With FTD, you can express your ideas and bring them to a compilation with ease. Our language is specifically designed for human beings, not just programmers, which is why we have taken precautions like not requiring quotes for strings and avoiding the use of indentation or braces that other languages often rely on.
Take a look at this simple FTD document:
ftd
Hello World!
-- ftd.text: Hello World!
The above code would show Hello World
as output.
With just a few lines of code, you can create a visually appealing and impactful document. It is a language that is easy to read and understand. It is not verbose like HTML, and not simplistic like Markdown.
FTD can be compared with Markdown, but with FTD, you can define variables, perform event handling, abstract out logic into custom components etc.
How to use ftd
?
ftd
can be used using fastn
which provides interface for ftd
.
fastn
[``fastn](https://fastn.dev) is a powerful command line tool written in Rust that offers a seamless experience for ftd package management and static site generation. With
fastn`, you can easily convert your .ftd files into .html files that can be ship on popular platforms such as Github Pages, Vercel etc.
Here are some key features of fastn
that makes it a must-have tool:
How to install fastn
?
So, how do you get started with fastn
?
Installing fastn
is easy and can be done on multiple operating systems. Check out the “How to Install” section for more information. Additionally, an editor is required to use fastn
, and we recommend using Sublime Text.
Declaring Variable
In FTD, you can create variables with specific types. FTD is a strongly-typed language, so the type of each variable must be declared.
Here’s an example of how you can define a boolean type variable:
Defining Variable
-- boolean flag: true
In this code, we’re creating a variable named flag
of boolean
type. The variable is defined as immutable, meaning its value cannot be altered. If you want to define a mutable variable, simply add a $
symbol before the variable name.
Consider this example which has a mutable variable declaration flag
.
Defining Variable
-- boolean $flag: true
To know more about variables checkout variables.
Event handling
ftd
makes it easy to add events to your element. Let’s take a look at the following example:
ftd.text
kernel component
-- boolean $current: true -- ftd.text: Hello World! align-self: center text-align: center padding.px: 20 color if { current }: #D42D42 color: $inherited.colors.cta-primary.text background.solid: $inherited.colors.cta-primary.base $on-click$: $ftd.toggle($a = $current)
Hello World!
Since the target audience for ftd
is human beings, it includes many “default functions” that are commonly used, like the toggle
function which can be used to create simple event handling.
Creating a custom component
In ftd
, you can create custom components to abstract out logic and improve code organization. For example:
Creating a custom component
-- component toggle-text: boolean $current: false caption title: -- ftd.text: $toggle-text.title align-self: center text-align: center color if { toggle-text.current }: #D42D42 color: $inherited.colors.cta-primary.text background.solid: $inherited.colors.cta-primary.base $on-click$: $ftd.toggle($a = $toggle-text.current) -- end: toggle-text -- toggle-text: FTD is cool!
FTD is cool!
Here we have created a new component called toggle-text
, and then instantiated it instead. This way you can create custom component library and use them in our writing without “polluting” the prose with noise.
Import
ftd
allows you to separate component and variable definitions into different modules, and then use them in any module by using the import
keyword. This helps to logically organize your code and avoid complexity, leading to cleaner and easier to understand code.
Consider the below example:
ftd
Hello World!
-- import: lib -- lib.h1: Hello World
The code above shows a FTD document that imports a library named “lib
” and has a level 1 heading of “Hello World”.
Data Modelling
FTD is also a good first class data language. You can define and use records:
Data Modelling in ftd
-- record person: caption name: string location: optional body bio:
Each field has a type. caption
is an alias for string
, and tells ftd that the value can come in the “caption” position, after the :
of the “section line”, eg: lines that start with --
. If a field is optional, it must be marked as such.
Creating a variable
-- person amitu: Amit Upadhyay location: Bangalore, India Amit is the founder and CEO of FifthTry. He loves to code, and is pursuing his childhood goal of becoming a professional starer of the trees.
Here we have defined a variable amitu
. You can also define a list:
Creating a list
-- person list employees: -- person: Sourabh Garg location: Ranchi, India -- person: Arpita Jaiswal location: Lucknow, India Arpita is the primary author of FTD language. -- end: employees
ftd
provides a way to create a component that can render records and loop through lists to display all members of the list:
Looping over a list
-- render-person: person: $p $loop$: $employees as $p
This way we can have clean separation of data from presentation. The data defined in FTD documents can be easily read from say Rust:
Reading Data from ftd
files
#[derive(serde::Deserialize)] struct Employee { name: String, location: String, bio: Option<String> } let doc = ftd::p2::Document::from("some/id", source, lib)?; let amitu: Employee = doc.get("amitu")?; let employees: Vec<Employee> = doc.get("employees")?;
As mentioned earlier, ftd
is a first-class data language that provides a better alternative to sharing data through CSV or JSON files. Unlike CSV/JSON, in ftd
, data is type-checked, and it offers a proper presentation of the data with the option to define components that can render the data, which can be viewed in a browser.
Furthermore, FTD can also serve as a language for configuration purposes.
Getting Involved
We are trying to create the language for human beings and we do not believe it would be possible without your support. We would love to hear from you.
Github: https://github.com/FifthTry/ftd
Discord: Join our ftd
channel.
License: BSD