diff --git a/_jekyll/_data/api_java.yml b/_jekyll/_data/api_java.yml index 9c23dba89..9af2a7df6 100644 --- a/_jekyll/_data/api_java.yml +++ b/_jekyll/_data/api_java.yml @@ -219,6 +219,8 @@ permalink: upcase - name: downcase permalink: downcase + - name: format + permalink: format - section: name: Math and logic commands: diff --git a/_jekyll/_data/api_javascript.yml b/_jekyll/_data/api_javascript.yml index 20765c0cd..c3f78b5b8 100644 --- a/_jekyll/_data/api_javascript.yml +++ b/_jekyll/_data/api_javascript.yml @@ -219,6 +219,8 @@ permalink: upcase - name: downcase permalink: downcase + - name: format + permalink: format - section: name: Math and logic commands: diff --git a/_jekyll/_data/api_python.yml b/_jekyll/_data/api_python.yml index 1c97924ac..c806405c8 100644 --- a/_jekyll/_data/api_python.yml +++ b/_jekyll/_data/api_python.yml @@ -217,6 +217,8 @@ permalink: upcase - name: downcase permalink: downcase + - name: format + permalink: format - section: name: Math and logic commands: diff --git a/_jekyll/_data/api_ruby.yml b/_jekyll/_data/api_ruby.yml index cc95c6480..0456ac412 100644 --- a/_jekyll/_data/api_ruby.yml +++ b/_jekyll/_data/api_ruby.yml @@ -215,6 +215,8 @@ permalink: upcase - name: downcase permalink: downcase + - name: format + permalink: format - section: name: Math and logic commands: diff --git a/_scripts/dataexplorer.py b/_scripts/dataexplorer.py index 03942fdce..933eef3f8 100644 --- a/_scripts/dataexplorer.py +++ b/_scripts/dataexplorer.py @@ -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"] @@ -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: @@ -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) diff --git a/api/java/index.md b/api/java/index.md index ed5089274..a6716d89c 100644 --- a/api/java/index.md +++ b/api/java/index.md @@ -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 %} diff --git a/api/java/string-manipulation/downcase.md b/api/java/string-manipulation/downcase.md index 94f535720..b26eedddb 100644 --- a/api/java/string-manipulation/downcase.md +++ b/api/java/string-manipulation/downcase.md @@ -7,6 +7,7 @@ related_commands: upcase: upcase/ match: match/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/java/string-manipulation/format.md b/api/java/string-manipulation/format.md new file mode 100644 index 000000000..655c23585 --- /dev/null +++ b/api/java/string-manipulation/format.md @@ -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 }}] +``` diff --git a/api/java/string-manipulation/match.md b/api/java/string-manipulation/match.md index 19f0bc1dd..5123e2a2e 100644 --- a/api/java/string-manipulation/match.md +++ b/api/java/string-manipulation/match.md @@ -10,6 +10,7 @@ related_commands: upcase: upcase/ downcase: downcase/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/java/string-manipulation/split.md b/api/java/string-manipulation/split.md index eeedc6146..ed2f194a9 100644 --- a/api/java/string-manipulation/split.md +++ b/api/java/string-manipulation/split.md @@ -7,6 +7,7 @@ related_commands: upcase: upcase/ downcase: downcase/ match: match/ + format: format/ --- # Command syntax # diff --git a/api/java/string-manipulation/upcase.md b/api/java/string-manipulation/upcase.md index 51ad851e9..a751a15d8 100644 --- a/api/java/string-manipulation/upcase.md +++ b/api/java/string-manipulation/upcase.md @@ -7,6 +7,7 @@ related_commands: downcase: downcase/ match: match/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/javascript/index.md b/api/javascript/index.md index 3dc424e59..6de5289ad 100644 --- a/api/javascript/index.md +++ b/api/javascript/index.md @@ -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 %} diff --git a/api/javascript/string-manipulation/downcase.md b/api/javascript/string-manipulation/downcase.md index 89296144e..21305d983 100644 --- a/api/javascript/string-manipulation/downcase.md +++ b/api/javascript/string-manipulation/downcase.md @@ -10,6 +10,7 @@ related_commands: upcase: upcase/ match: match/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/javascript/string-manipulation/format.md b/api/javascript/string-manipulation/format.md new file mode 100644 index 000000000..31fafd5f1 --- /dev/null +++ b/api/javascript/string-manipulation/format.md @@ -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 }}] +``` diff --git a/api/javascript/string-manipulation/match.md b/api/javascript/string-manipulation/match.md index b9e141cb4..702fb4d1c 100644 --- a/api/javascript/string-manipulation/match.md +++ b/api/javascript/string-manipulation/match.md @@ -10,6 +10,7 @@ related_commands: upcase: upcase/ downcase: downcase/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/javascript/string-manipulation/split.md b/api/javascript/string-manipulation/split.md index c70be4828..07fbe50bd 100644 --- a/api/javascript/string-manipulation/split.md +++ b/api/javascript/string-manipulation/split.md @@ -10,6 +10,7 @@ related_commands: upcase: upcase/ downcase: downcase/ match: match/ + format: format/ --- # Command syntax # diff --git a/api/javascript/string-manipulation/upcase.md b/api/javascript/string-manipulation/upcase.md index 789fcc5d4..e65c5544f 100644 --- a/api/javascript/string-manipulation/upcase.md +++ b/api/javascript/string-manipulation/upcase.md @@ -10,6 +10,7 @@ related_commands: downcase: downcase/ match: match/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/python/index.md b/api/python/index.md index 034b25c04..5762bab54 100644 --- a/api/python/index.md +++ b/api/python/index.md @@ -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 %} diff --git a/api/python/string-manipulation/downcase.md b/api/python/string-manipulation/downcase.md index c05e7df3c..00e9dec5a 100644 --- a/api/python/string-manipulation/downcase.md +++ b/api/python/string-manipulation/downcase.md @@ -7,6 +7,7 @@ related_commands: upcase: upcase/ match: match/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/python/string-manipulation/format.md b/api/python/string-manipulation/format.md new file mode 100644 index 000000000..b30db0fd8 --- /dev/null +++ b/api/python/string-manipulation/format.md @@ -0,0 +1,55 @@ +--- +layout: api-command +language: Python +permalink: api/python/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. + +```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 }}] +``` diff --git a/api/python/string-manipulation/match.md b/api/python/string-manipulation/match.md index 0daed787b..955aa43d1 100644 --- a/api/python/string-manipulation/match.md +++ b/api/python/string-manipulation/match.md @@ -7,6 +7,7 @@ related_commands: upcase: upcase/ downcase: downcase/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/python/string-manipulation/split.md b/api/python/string-manipulation/split.md index dff7849b7..42926c183 100644 --- a/api/python/string-manipulation/split.md +++ b/api/python/string-manipulation/split.md @@ -7,6 +7,7 @@ related_commands: upcase: upcase/ downcase: downcase/ match: match/ + format: format/ --- # Command syntax # diff --git a/api/python/string-manipulation/upcase.md b/api/python/string-manipulation/upcase.md index bea86c6cf..867450d12 100644 --- a/api/python/string-manipulation/upcase.md +++ b/api/python/string-manipulation/upcase.md @@ -7,6 +7,7 @@ related_commands: downcase: downcase/ match: match/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/ruby/index.md b/api/ruby/index.md index 9db3c53ab..47b5b9838 100644 --- a/api/ruby/index.md +++ b/api/ruby/index.md @@ -1877,6 +1877,47 @@ __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. + +```rb +r.format("{name} loves {candy}.", { + "name" => "Bob", + "candy" => "candy floss", +}).run(conn) +``` + +Result: + +```rb +"Bob loves candy floss." +``` + +__Example:__ Using row for formatting. + +```rb +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: + +```rb +# `ratings` is the result of the HTTP request +[{ id: 1, ratings: { positive: 99, negative: 0 }}] +``` + +[Read more about this command →](format/) + ## [upcase](upcase/) ## {% apibody %} diff --git a/api/ruby/string-manipulation/downcase.md b/api/ruby/string-manipulation/downcase.md index 015228f12..7f531629a 100644 --- a/api/ruby/string-manipulation/downcase.md +++ b/api/ruby/string-manipulation/downcase.md @@ -7,6 +7,7 @@ related_commands: upcase: upcase/ match: match/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/ruby/string-manipulation/format.md b/api/ruby/string-manipulation/format.md new file mode 100644 index 000000000..719107709 --- /dev/null +++ b/api/ruby/string-manipulation/format.md @@ -0,0 +1,55 @@ +--- +layout: api-command +language: Ruby +permalink: api/ruby/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. + +```rb +r.format("{name} loves {candy}.", { + "name" => "Bob", + "candy" => "candy floss", +}).run(conn) +``` + +Result: + +```rb +"Bob loves candy floss." +``` + +__Example:__ Using row for formatting. + +```rb +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: + +```rb +# `ratings` is the result of the HTTP request +[{ id: 1, ratings: { positive: 99, negative: 0 }}] +``` diff --git a/api/ruby/string-manipulation/match.md b/api/ruby/string-manipulation/match.md index d2a8d18a1..e219b1bfe 100644 --- a/api/ruby/string-manipulation/match.md +++ b/api/ruby/string-manipulation/match.md @@ -7,6 +7,7 @@ related_commands: upcase: upcase/ downcase: downcase/ split: split/ + format: format/ --- # Command syntax # diff --git a/api/ruby/string-manipulation/split.md b/api/ruby/string-manipulation/split.md index da2ac201e..5ad8d0eba 100644 --- a/api/ruby/string-manipulation/split.md +++ b/api/ruby/string-manipulation/split.md @@ -7,6 +7,7 @@ related_commands: upcase: upcase/ downcase: downcase/ match: match/ + format: format/ --- # Command syntax # diff --git a/api/ruby/string-manipulation/upcase.md b/api/ruby/string-manipulation/upcase.md index dc3b83e6f..939b8cd15 100644 --- a/api/ruby/string-manipulation/upcase.md +++ b/api/ruby/string-manipulation/upcase.md @@ -7,6 +7,7 @@ related_commands: downcase: downcase/ match: match/ split: split/ + format: format/ --- # Command syntax #