ftd Programming Language

ftd is designed for everyone, not just programmers.

Getting Started | Watch Course

Star us on Github

ftd for authoring prose

ftd is a DSL for authoring long for text, and have access to rich collection of ready made components.
writing single or multi line text is easy
-- amitu: Hello World! 😀

-- ds.markdown:

some markdown text!

-- amitu:

you can also write multiline messages easily!

no quotes. and **markdown** is *supported*.
Lang:
ftd
Hello World! 😀
some markdown text!

you can also write multiline messages easily!

no quotes. and markdown is supported.
Note: These are not built in components of ftd, but are using open source component libraries, eg fifthtry.github.io/bling/quote. Learn how to build your own.
using little more complex components
-- import: fifthtry.github.io/bling/quote

-- quote.charcoal: Amit Upadhyay
label: Creator of FTD
avatar: $fastn-assets.files.images.amitu.jpg
logo: $fastn-assets.files.images.logo-fifthtry.svg

The web has lost some of the exuberance from the
early 2000s, and it makes me a little sad.
Lang:
ftd
The web has lost some of the exuberance from the early 2000s, and it makes me a little sad.
Amit Upadhyay
Creator of FTD
There are many components to chose from, and you can create your own with ease.

A language for building UI

ftd comes with basic building blocks like text, images and containers using with other UI can be constructed.
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)
border-radius.px: 5

-- end: toggle-text

-- toggle-text: `ftd` is cool!
Lang:
ftd
Output
click me to toggle colors

With ftd, you can express your ideas and bring them to a compilation with ease.

Take a look at this simple ftd document:
ftd Hello World!
-- ftd.text: Hello World!
Lang:
ftd

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. You need to install fastn to get started.

Here are some of the important fastn related links.

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
Lang:
ftd

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
Lang:
ftd
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)
Lang:
ftd
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!
Lang:
ftd
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
Lang:
ftd
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:
Lang:
ftd
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.
Lang:
ftd
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
Lang:
ftd
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
Lang:
ftd
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")?;
Lang:
rs

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

Support fastn!

Enjoying fastn? Please consider giving us a star ⭐️ on GitHub to show your support!

Getting Help

Have a question or need help?

Visit our GitHub Q&A discussion to get answers and subscribe to it to stay tuned.

Join our Discord channel and share your thoughts, suggestion, question etc.

Connect with our community!

Found an issue?

If you find some issue, please visit our GitHub issues to tell us about it.

Join us

We welcome you to join our Discord community today.

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.
Copyright © 2023 - FifthTry.com