Skip to content

Commit

Permalink
docs: update format docs
Browse files Browse the repository at this point in the history
Signed-off-by: Gabor Boros <[email protected]>
  • Loading branch information
gabor-boros committed May 15, 2022
1 parent b0a8594 commit a379d4d
Show file tree
Hide file tree
Showing 32 changed files with 354 additions and 205 deletions.
4 changes: 2 additions & 2 deletions _jekyll/_data/api_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@
permalink: upcase
- name: downcase
permalink: downcase
- name: fmt
permalink: fmt
- name: format
permalink: format
- section:
name: Math and logic
commands:
Expand Down
4 changes: 2 additions & 2 deletions _jekyll/_data/api_javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@
permalink: upcase
- name: downcase
permalink: downcase
- name: fmt
permalink: fmt
- name: format
permalink: format
- section:
name: Math and logic
commands:
Expand Down
4 changes: 2 additions & 2 deletions _jekyll/_data/api_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@
permalink: upcase
- name: downcase
permalink: downcase
- name: fmt
permalink: fmt
- name: format
permalink: format
- section:
name: Math and logic
commands:
Expand Down
4 changes: 2 additions & 2 deletions _jekyll/_data/api_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@
permalink: upcase
- name: downcase
permalink: downcase
- name: fmt
permalink: fmt
- name: format
permalink: format
- section:
name: Math and logic
commands:
Expand Down
34 changes: 26 additions & 8 deletions api/java/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1932,27 +1932,45 @@ Result:

[Read more about this command &rarr;](split/)

## [fmt](fmt/) ##
## [format](format/) ##

{% apibody %}
r.fmt(string, object) &rarr; string
r.format(string, object) &rarr; string
{% endapibody %}

Formats a template string based on a string-string key-value object.
Format command takes a string as a template and formatting parameters as an object. The parameters in the template string must exist as keys in the object, otherwise, an error raised. The template must be a string literal and cannot be the result of other commands.

__Example:__
__Example:__ Using simple parameters for formatting.

```js
r.fmt("{name} loves {candy}.", {"name": "Bob", "candy": "candy floss"}).run(conn, callback)
```java
r.format("{name} loves {candy}.",
r.hashMap("name", "Bob").with("candy", "candy floss")
).run(conn, callback)
```

Result:

```js
```java
"Bob loves candy floss."
```

[Read more about this command &rarr;](fmt/)
__Example:__ Using row for formatting.

```java
r.table("movies").map({
id: r.row('id'),
ratings: r.http(r.format('http://example.com/movies/?title={title}&release={year}', r.row))
})
```

Result:

```java
// `ratings` is the result of the HTTP request
[{ id: 1, ratings: { positive: 99, negative: 0 }}]
```

[Read more about this command &rarr;](format/)

## [upcase](upcase/) ##

Expand Down
2 changes: 1 addition & 1 deletion api/java/string-manipulation/downcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ related_commands:
upcase: upcase/
match: match/
split: split/
fmt: fmt/
format: format/
---

# Command syntax #
Expand Down
38 changes: 0 additions & 38 deletions api/java/string-manipulation/fmt.md

This file was deleted.

54 changes: 54 additions & 0 deletions api/java/string-manipulation/format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
layout: api-command
language: Java
permalink: api/java/format/
command: format
io:
- - r
- string
related_commands:
match: match/
split: split/
upcase: upcase/
downcase: downcase/
---

# Command syntax #

{% apibody %}
r.format(string, object) &rarr; string
{% endapibody %}

# Description #

Format command takes a string as a template and formatting parameters as an object. The parameters in the template string must exist as keys in the object, otherwise, an error raised. The template must be a string literal and cannot be the result of other commands.

__Example:__ Using simple parameters for formatting.

```java
r.format("{name} loves {candy}.",
r.hashMap("name", "Bob").with("candy", "candy floss")
).run(conn, callback)
```

Result:

```java
"Bob loves candy floss."
```

__Example:__ Using row for formatting.

```java
r.table("movies").map({
id: r.row('id'),
ratings: r.http(r.format('http://example.com/movies/?title={title}&release={year}', r.row))
})
```

Result:

```java
// `ratings` is the result of the HTTP request
[{ id: 1, ratings: { positive: 99, negative: 0 }}]
```
2 changes: 1 addition & 1 deletion api/java/string-manipulation/match.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ related_commands:
upcase: upcase/
downcase: downcase/
split: split/
fmt: fmt/
format: format/
---

# Command syntax #
Expand Down
2 changes: 1 addition & 1 deletion api/java/string-manipulation/split.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ related_commands:
upcase: upcase/
downcase: downcase/
match: match/
fmt: fmt/
format: format/
---

# Command syntax #
Expand Down
2 changes: 1 addition & 1 deletion api/java/string-manipulation/upcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ related_commands:
downcase: downcase/
match: match/
split: split/
fmt: fmt/
format: format/
---

# Command syntax #
Expand Down
31 changes: 25 additions & 6 deletions api/javascript/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2009,18 +2009,21 @@ Result:

[Read more about this command &rarr;](split/)

## [fmt](fmt/) ##
## [format](format/) ##

{% apibody %}
r.fmt(string, object) &rarr; string
r.format(string, object) &rarr; string
{% endapibody %}

Formats a template string based on a string-string key-value object.
Format command takes a string as a template and formatting parameters as an object. The parameters in the template string must exist as keys in the object, otherwise, an error raised. The template must be a string literal and cannot be the result of other commands.

__Example:__
__Example:__ Using simple parameters for formatting.

```js
r.fmt("{name} loves {candy}.", {"name": "Bob", "candy": "candy floss"}).run(conn, callback)
r.format("{name} loves {candy}.", {
"name": "Bob",
"candy": "candy floss",
}).run(conn, callback)
```

Result:
Expand All @@ -2029,7 +2032,23 @@ Result:
"Bob loves candy floss."
```

[Read more about this command &rarr;](fmt/)
__Example:__ Using row for formatting.

```js
r.table("movies").map({
id: r.row('id'),
ratings: r.http(r.format('http://example.com/movies/?title={title}&release={year}', r.row))
})
```

Result:

```js
// `ratings` is the result of the HTTP request
[{ id: 1, ratings: { positive: 99, negative: 0 }}]
```

[Read more about this command &rarr;](format/)

## [upcase](upcase/) ##

Expand Down
2 changes: 1 addition & 1 deletion api/javascript/string-manipulation/downcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ related_commands:
upcase: upcase/
match: match/
split: split/
fmt: fmt/
format: format/
---

# Command syntax #
Expand Down
39 changes: 0 additions & 39 deletions api/javascript/string-manipulation/fmt.md

This file was deleted.

55 changes: 55 additions & 0 deletions api/javascript/string-manipulation/format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
layout: api-command
language: JavaScript
permalink: api/javascript/format/
command: format
io:
- - r
- string
related_commands:
match: match/
split: split/
upcase: upcase/
downcase: downcase/
---

# Command syntax #

{% apibody %}
r.format(string, object) &rarr; string
{% endapibody %}

# Description #

Format command takes a string as a template and formatting parameters as an object. The parameters in the template string must exist as keys in the object, otherwise, an error raised. The template must be a string literal and cannot be the result of other commands.

__Example:__ Using simple parameters for formatting.

```js
r.format("{name} loves {candy}.", {
"name": "Bob",
"candy": "candy floss",
}).run(conn, callback)
```

Result:

```js
"Bob loves candy floss."
```

__Example:__ Using row for formatting.

```js
r.table("movies").map({
id: r.row('id'),
ratings: r.http(r.format('http://example.com/movies/?title={title}&release={year}', r.row))
})
```

Result:

```js
// `ratings` is the result of the HTTP request
[{ id: 1, ratings: { positive: 99, negative: 0 }}]
```
2 changes: 1 addition & 1 deletion api/javascript/string-manipulation/match.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ related_commands:
upcase: upcase/
downcase: downcase/
split: split/
fmt: fmt/
format: format/
---

# Command syntax #
Expand Down
Loading

0 comments on commit a379d4d

Please sign in to comment.