1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
# TOML
A Ruby parser for [TOML](https://github.com/mojombo/toml), built on [parslet](https://github.com/kschiess/parslet).
This is far superior to YAML and JSON because it doesn't suck. Really it doesn't.
[](http://badge.fury.io/rb/toml)
## Usage
Install this library:
```ruby
gem "toml", "~> 0.3.0"
```
```bash
gem install "toml"
```
It's simple, really.
```ruby
content = <<-TOML
# Hello, this is an example.
[things]
other = "things"
what = 900000
TOML
parser = TOML::Parser.new(content).parsed
# => { "things" => { "other" => "things", "what" => 900000 } }
```
You can also use the same API as `YAML` if you'd like:
```ruby
TOML.load("thing = 9")
# => {"thing" => 9}
TOML.load_file("my_file.toml")
# => {"whatever" => "keys"}
```
In case a syntax error occurs, the parser will raise a `Parslet::ParseFailed` exception.
There's also a beta feature for generating a TOML file from a Ruby hash. Please note this will likely not give beautiful output right now.
```ruby
hash = {
"integer" => 1,
"float" => 3.14159,
"true" => true,
"false" => false,
"string" => "hi",
"array" => [[1], [2], [3]],
"key" => {
"group" => {
"value" => "lol"
}
}
}
doc = TOML::Generator.new(hash).body
# doc will be a string containing a proper TOML document.
```
## Contributors
Written by Jeremy McAnally ([@jm](https://github.com/jm)) and Dirk Gadsden ([@dirk](https://github.com/dirk)) based on TOML from Tom Preston-Werner ([@mojombo](https://github.com/mojombo)).
|