Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add format ReQL command #1332

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _jekyll/_data/api_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
permalink: upcase
- name: downcase
permalink: downcase
- name: format
permalink: format
- section:
name: Math and logic
commands:
Expand Down
2 changes: 2 additions & 0 deletions _jekyll/_data/api_javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
permalink: upcase
- name: downcase
permalink: downcase
- name: format
permalink: format
- section:
name: Math and logic
commands:
Expand Down
2 changes: 2 additions & 0 deletions _jekyll/_data/api_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@
permalink: upcase
- name: downcase
permalink: downcase
- name: format
permalink: format
- section:
name: Math and logic
commands:
Expand Down
2 changes: 2 additions & 0 deletions _jekyll/_data/api_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
permalink: upcase
- name: downcase
permalink: downcase
- name: format
permalink: format
- section:
name: Math and logic
commands:
Expand Down
11 changes: 5 additions & 6 deletions _scripts/dataexplorer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import codecs
import json
import os
import re
import markdown
import os
import sys
import yaml
import json
import codecs

IGNORED_FILES = ["index.md", "accessing-rql/event_emitter.md"]

Expand Down Expand Up @@ -118,7 +117,7 @@ def add_io_field(file_name, result):
if is_yaml == True:
yaml_raw += line

yaml_data = yaml.load(yaml_raw)
yaml_data = yaml.load(yaml_raw, Loader=yaml.Loader)
if "io" in yaml_data:
result[yaml_data["permalink"]]["io"] = yaml_data["io"]
else:
Expand All @@ -131,7 +130,7 @@ def browse_files(base, result):
for path, dirs, files in os.walk(base):
rel = path[len(base)+1:]
for item in files:
print os.path.join(rel, item)
print(os.path.join(rel, item))
if os.path.join(rel, item) not in IGNORED_FILES:
add_io_field(os.path.join(path, item), result)

Expand Down
40 changes: 40 additions & 0 deletions api/java/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,46 @@ Result:

[Read more about this command →](split/)

## [format](format/) ##

{% apibody %}
r.format(string, object) → string
{% endapibody %}

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 }}]
```

[Read more about this command →](format/)

## [upcase](upcase/) ##

{% apibody %}
Expand Down
1 change: 1 addition & 0 deletions api/java/string-manipulation/downcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ related_commands:
upcase: upcase/
match: match/
split: split/
format: format/
---

# Command syntax #
Expand Down
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) → 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 }}]
```
1 change: 1 addition & 0 deletions api/java/string-manipulation/match.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ related_commands:
upcase: upcase/
downcase: downcase/
split: split/
format: format/
---

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

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

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

[Read more about this command →](split/)

## [format](format/) ##

{% apibody %}
r.format(string, object) → string
{% endapibody %}

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 }}]
```

[Read more about this command →](format/)

## [upcase](upcase/) ##

{% apibody %}
Expand Down
1 change: 1 addition & 0 deletions api/javascript/string-manipulation/downcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ related_commands:
upcase: upcase/
match: match/
split: split/
format: format/
---

# Command syntax #
Expand Down
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) → 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 }}]
```
1 change: 1 addition & 0 deletions api/javascript/string-manipulation/match.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ related_commands:
upcase: upcase/
downcase: downcase/
split: split/
format: format/
---

# Command syntax #
Expand Down
1 change: 1 addition & 0 deletions api/javascript/string-manipulation/split.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ related_commands:
upcase: upcase/
downcase: downcase/
match: match/
format: format/
---

# Command syntax #
Expand Down
1 change: 1 addition & 0 deletions api/javascript/string-manipulation/upcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ related_commands:
downcase: downcase/
match: match/
split: split/
format: format/
---

# Command syntax #
Expand Down
43 changes: 43 additions & 0 deletions api/python/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,49 @@ __Example:__ Split on whitespace.

[Read more about this command →](split/)

## [format](format/) ##

{% apibody %}
r.format(string, object) → string
{% endapibody %}

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.

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

Result:

```py
"Bob loves candy floss."
```

__Example:__ Using row for formatting.

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

Result:

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

[Read more about this command →](format/)

## [upcase](upcase/) ##

## [upcase](upcase/) ##

{% apibody %}
Expand Down
1 change: 1 addition & 0 deletions api/python/string-manipulation/downcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ related_commands:
upcase: upcase/
match: match/
split: split/
format: format/
---

# Command syntax #
Expand Down
Loading