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

Add Python code to Connect preview HTML #806

Merged
merged 7 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions R/board_connect_bundle.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ rsc_bundle_preview_index <- function(board, name, x, metadata) {
data_preview_style = if (is.data.frame(x)) "" else "display:none",
urls = paste0("<a href=\"", metadata$urls, "\">", metadata$urls, "</a>", collapse = ", "),
url_preview_style = if (!is.null(metadata$urls)) "" else "display:none",
show_python_style = if (metadata$type != "rds") "" else "display:none",
pin_name = paste0(owner, "/", name$name),
pin_metadata = list(
as_yaml = yaml::as.yaml(metadata),
Expand Down
22 changes: 15 additions & 7 deletions inst/preview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<h3>{{{pin_name}}}</h3>
{{#pin_metadata}}
<p>
{{#date}}<b>Last updated:</b> {{{.}}} &bull;{{/date}}
{{#date}}<b>Last updated from R:</b> {{{.}}} &bull;{{/date}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Python package can say:

Last updated from Python:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this format for a subtle way to be able to tell what language the data is coming from!

<b>Format:</b> {{{format}}} &bull;
<b>API:</b> v{{{api_version}}}
</p>
Expand All @@ -52,14 +52,22 @@ <h3>Learn more about this pin at:</h3>
</section>

<section>
<h3>R Code</h3>
<pre id="pin-r" class="pin-code"><code class="r">library(pins)
<h3>R Code</h3>
<pre id="pin-r" class="pin-code-r"><code class="r">library(pins)
board <- {{{board_deparse}}}
pin_read(board, "{{pin_name}}")</code></pre>
<script type="text/javascript">
hljs.registerLanguage("r", highlight_r);
hljs.initHighlightingOnLoad();
</script>
<script type="text/javascript">
hljs.registerLanguage("r", highlight_r);
hljs.registerLanguage("python", highlight_python);
hljs.initHighlightingOnLoad();
</script>
</section>

<section style="{{show_python_style}}">
<h3>Python Code</h3>
<pre id="pin-python" class="pin-code-python"><code class="python">import pins
board = pins.board_connect()
board.pin_read(board, "{{pin_name}}")</code></pre>
</section>

<section style="{{data_preview_style}}">
Expand Down
22 changes: 15 additions & 7 deletions tests/testthat/_snaps/board_connect_bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<section>
<h3>TEST/test</h3>
<p>
<b>Last updated:</b> 2021-11-11 11:39:56 &bull;
<b>Last updated from R:</b> 2021-11-11 11:39:56 &bull;
<b>Format:</b> rds &bull;
<b>API:</b> v1.0
</p>
Expand Down Expand Up @@ -65,14 +65,22 @@
</section>

<section>
<h3>R Code</h3>
<pre id="pin-r" class="pin-code"><code class="r">library(pins)
<h3>R Code</h3>
<pre id="pin-r" class="pin-code-r"><code class="r">library(pins)
board <- board_connect(auth = "envvar")
pin_read(board, "TEST/test")</code></pre>
<script type="text/javascript">
hljs.registerLanguage("r", highlight_r);
hljs.initHighlightingOnLoad();
</script>
<script type="text/javascript">
hljs.registerLanguage("r", highlight_r);
hljs.registerLanguage("python", highlight_python);
hljs.initHighlightingOnLoad();
</script>
</section>

<section style="display:none">
<h3>Python Code</h3>
<pre id="pin-python" class="pin-code-python"><code class="python">import pins
board = pins.board_connect()
board.pin_read(board, "TEST/test")</code></pre>
</section>

<section style="">
Expand Down
Loading