name: portada layout: true class: portada-slide, middle, right --- # YAML ## Markup languages .footnote[Joan Puigcerver Ibáñez ([j.puigcerveribanez@edu.gva.es](mailto:j.puigcerveribanez@edu.gva.es))] --- layout: true class: regular-slide .right[.logo[]] --- # YAML - Yet Another Markup Language - Extensible markup language - Descriptive or semantic language - Uses .b[.yml] or .b[.yaml] file extensions - Uses space identation (usually 2 spaces) to diffirenciate levels. --- # Example YAML files are often used as configuration files. This is an example of a __netplan network interfaces configuration__ in _/etc/netplan/1-network-manager-all.yaml_ ``` network: version: 2 ethernets: eth0: dhcp4: yes eth1: dhcp4: no addresses: [192.168.0.21/24] nameservers: addresses: [192.168.0.1, 8.8.8.8] ``` --- # Values - Text (quotes are optional) ``` Pere Martí ``` - Number (can be integer or float) ``` 29.24 ``` - Boolean ``` true or false (even yes or no) ``` - null values ``` null or ~ ``` --- # Text Values We can use the following syntax to write multiple line text: ``` # This one preserves new lines data: | There once was a tall man from Ealing Who got on a bus to Darjeeling It said on the door "Please don't sit on the floor" So he carefully sat on the ceiling ``` ``` # This one doesn't preserves new lines # New lines are denoted with paragraph breaks data: > Wrapped text will be folded into a single paragraph Blank lines denote paragraph breaks ``` --- # Objects Objects consist in multiple attribute-value pairs. They can be defined in indented block or inline block syntax. Inline block objects are enclosed between .blue[{ }]. ``` # Indented block attribute: value attribute2: value2 # Inline block {attribute: value, attribute2: value2} ``` ``` # Indented block name: Pere Martí age: 29 adult: true # Inline block {name: Pere Martí, age: 29, adult: true} ``` --- # Lists List consist in multiple values. They can be defined in indented block or inline block syntax. Inline block objects are enclosed between .blue[[ ]]. ```python # Indented block list: - value - value2 - value3 # Inline block [value, value2, value3] ``` ```python # Indented block list: - red - green - blue # Inline block [red, green, blue] ``` --- # Exemples Object inside an object: .center[.b[IDENTATION!]] ``` name: Pere surname: Martí address: stret: Av Cardenal Benlloch number: 23 city: València ``` --- # Examples Object array ``` - name: Pere surname: Martí age: 25 - name: Alba surname: Puig age: 66 ``` --- # Examples ``` students: - name: Pere surname: Martí age: 25 - name: Alba surname: Puig age: 66 teachers: - name: Carla surname: Martí age: 39 - name: Ona surname: Roca age: 21 ``` --- # Examples ```python estudiants: - {name: Pere, surname: Martí, age: 25} - {name: Alba, surname: Puig, age: 66} professors: - {name: Carla, surname: Martí, age: 39} - {name: Ona, surname: Roca, age: 21} ``` --- class: background-dark # Exercise 1 Write a YAML that stores the following information (a different JSON for each item) 1. A student named Joan Garcia from València and his birth date is 24th of February. 2. A list of the following restaurants: - Bar Pasqual is a tapes bar in Av. Blsco Ibáñez, 232, València. Its owner is Marc Alcover. - Restaurant Meravelles is a menu restaurant located in Av. Regne de València, 111, València, owned by Maria Pasqual. - Racó de l'Avia is a menu restaurant in Av Roma, 221, Barcelona owned by Alba Puig. 3. A list of art from a museum: - "Der Kuss" its a painting from Gustav Klimt painted in 1907. - "Gernica" its a mural from Pablo Picasso painted in 1937. - "David" its a marble sculpture from Michelangelo created in 1504. --- class: background-dark # Exercise 2 Choose a mobile phone and write down a detailed specification in YAML format. (Battery, CPU, RAM, Storage, Cameras, connectivity, ...) Include the links where you found the information in the document. --- class: background-dark # Exercise 3 Write a YAML document with information about the following operating systems: - Last Windows - Last macOS - Last Ubuntu Desktop - Last Ubuntu Server - Last Fedora Workstation - Last Kali Linux It must include: mantainer, last version, minimum and recommended requieremts and a description about each operating system. --- class: background-dark # Exercise 4 Write a YAML document with information about the following objects: 