# platform/document (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/platform/document/

Document. (what the original reads and writes in the browser document: html lang, meta in head)
- The original uses the global document as is. When LanguagePack loads a language it changes document.documentElement.lang,
  and BuildInfo reads the version written by the release build from the content of `meta[name="build-version"]`.
- On web it reads and writes the browser document as in the original.
- Desktop has no HTML document, so the engine holds document values (language, meta list) per thread and does the same work.
  Initial values are document_language and document_meta_list of EngineConfiguration. (where the web version's index.html writes html lang and the meta in head)
  Just as the release build writes the version into the web version's index.html, a desktop game puts values inserted at build time (such as rustc-env of build.rs and env!) into document_meta_list.
- On web too, the engine settings' values are written to the document when the engine is created if they are not empty. (the same game code has the same document on both platforms)
  If empty, on web it stays as the page wrote it.

## Document (struct)

Document. (a set of static functions, lang and meta of the original global document)

Example: Write and read the language and version meta

```rust
use vanilla::Document;

Document::set_language("en");
assert_eq!(Document::get_language(), "en");
Document::set_meta_content("build-version", "1.2.3");
assert_eq!(Document::get_meta_content("build-version"), Some(String::from("1.2.3")));
Document::remove_meta("build-version");
assert_eq!(Document::get_meta_content("build-version"), None);
```

- `pub fn get_language() -> String` (static, since 0.4.0): Document language. (the original document.documentElement.lang, empty text if not written)
  - returns String: Language tag. (such as "ko", "en-US", empty text if not written)
- `pub fn set_language(language: &str)` (static, since 0.4.0): Sets the document language. (the original document.documentElement.lang = language tag)
  - `language` &str: Language tag. (such as "ko", "en-US")
- `pub fn get_meta_content(meta_name: &str) -> Option<String>` (static, since 0.4.0): content of a meta. (the original document.querySelector(`meta[name="name"]`).getAttribute("content"), None if there is no such meta)
  - `meta_name` &str: name of the meta. (such as "build-version")
  - returns Option<String>: content of the first meta with that name. None if there is no such meta.
- `pub fn set_meta_content(meta_name: &str, content: &str)` (static, since 0.4.0): Sets the content of a meta. (creates one at the end of head if there is no meta with that name)
  - `meta_name` &str: name of the meta.
  - `content` &str: content to write.
- `pub fn remove_meta(meta_name: &str)` (static, since 0.4.0): Removes a meta. (the first meta with that name)
  - `meta_name` &str: name of the meta to remove. (does nothing if missing)
