Title: | Interact with 'carbon.js' |
---|---|
Description: | Create beautiful images of source code using 'carbon.js'<https://carbon.now.sh/about>. |
Authors: | Jonathan Sidi [aut, cre] |
Maintainer: | Jonathan Sidi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.4 |
Built: | 2024-11-20 04:05:42 UTC |
Source: | https://github.com/yonicd/carbonate |
opens the uri address in $uri in the browser window.
.browse(self, private)
.browse(self, private)
self |
carbon self object |
private |
carbon private object |
x <- carbon$new('x <- 1') if(interactive()) x$browse()
x <- carbon$new('x <- 1') if(interactive()) x$browse()
Main function of the package that invokes RSelenium to open a browser to the carbon.js uri, create an image and download the file.
.carbonate(self, private, file, path, code, rD, driver)
.carbonate(self, private, file, path, code, rD, driver)
self |
carbon self object |
private |
carbon private object |
file |
character, name of file to save image as |
path |
character, path to save the image |
code |
character, lines of script to make carbon image from |
rD |
RSelenium driver |
driver |
character, select either 'firefox' or 'chrome' driver |
Script is passed to https://carbon.now.sh/ is downloaded to the tempdir()
and appended to the list $carbons using RSelenium and Chrome.
image object
if(interactive()){ x <- carbon$new('x <- 1') x$carbonate() }
if(interactive()){ x <- carbon$new('x <- 1') x$carbonate() }
Functions to open,close,set chrome webdriver
.chromeOptions(self, private)
.chromeOptions(self, private)
self |
carbon self object |
private |
carbon private object |
encode uri string for carbon.js. Augmented version of than URLencode
.encode(self, private, URL, reserved, repeated)
.encode(self, private, URL, reserved, repeated)
self |
carbon self object |
private |
carbon private object |
URL |
character, uri string to url encode |
reserved |
boolean, should ‘reserved’ characters be encoded? |
repeated |
boolean, should apparently already-encoded URLs be encoded again? |
character
Functions to open,close,set gecko webdriver
.firefoxOptions(self, private)
.firefoxOptions(self, private)
self |
carbon self object |
private |
carbon private object |
function that gets the available list of aesthetic values of fields
.get_windows_control_themes(self, private) .get_font_families(self, private) .get_templates(self, private)
.get_windows_control_themes(self, private) .get_font_families(self, private) .get_templates(self, private)
self |
carbon self object |
private |
carbon private object |
combine all the carbon options into a carbon.js valid string
.options(self, private, code)
.options(self, private, code)
self |
carbon self object |
private |
carbon private object |
code |
character, script to embbed into the uri |
OUTPUT_DESCRIPTION
wrapper for post_tweet to send tweets with media created using carbonate.
.rtweet(self, private, media, status = self$tweet_status, media_format = c("png", "gif"), ...)
.rtweet(self, private, media, status = self$tweet_status, media_format = c("png", "gif"), ...)
self |
carbon self object |
private |
carbon private object |
media |
magick-image object or path to image |
status |
character, status to attach to post, Default: self$tweet_status |
media_format |
character, type of media to tweet, Default: c('png','gif') |
... |
arguments to pass to post_tweet |
If multiple images are passed they can be either converted to a gif by setting media_format to 'gif' or attached each one to the post.
outcome from rtweet
## Not run: x <- carbonate::carbon$new() x$carbonate(code = readLines(system.file('DESCRIPTION',package='carbonate'))) x$carbonate(code = 'x+2') # using default status value (x$tweet_status) x$rtweet(system.file('figures/hex_black_small.png',package='carbonate')) x$rtweet(status = 'these are two pngs',media = x$carbons,media_format='png') x$rtweet(status = 'this is a gif', media = x$carbons,media_format='gif') ## End(Not run)
## Not run: x <- carbonate::carbon$new() x$carbonate(code = readLines(system.file('DESCRIPTION',package='carbonate'))) x$carbonate(code = 'x+2') # using default status value (x$tweet_status) x$rtweet(system.file('figures/hex_black_small.png',package='carbonate')) x$rtweet(status = 'these are two pngs',media = x$carbons,media_format='png') x$rtweet(status = 'this is a gif', media = x$carbons,media_format='gif') ## End(Not run)
function that set the aesthetics of the carbon image output
.set_template(self, private, template) .set_window_control_theme(self, private, theme) .set_font_family(self, private, family)
.set_template(self, private, template) .set_window_control_theme(self, private, theme) .set_font_family(self, private, family)
self |
carbon self object |
private |
carbon private object |
template |
character, name of template to set $template to |
theme |
character, theme to set $theme to |
family |
character, font family to set $font_family to |
Functions to open,stop, stop_all RSelenium sessions
.start(self, private, eCap, driver = c("firefox", "chrome")) .driver_start(self, private, driver = c("chrome", "firefox")) .driver_stop(self, private) .stop(self, private) .stop_all(self, private) .set_port(self, private, port = NULL) .get_port(self, private)
.start(self, private, eCap, driver = c("firefox", "chrome")) .driver_start(self, private, driver = c("chrome", "firefox")) .driver_stop(self, private) .stop(self, private) .stop_all(self, private) .set_port(self, private, port = NULL) .get_port(self, private)
self |
carbon self object |
private |
carbon private object |
eCap |
chromeOptions passed into rsDriver |
driver |
character, select either 'firefox' or 'chrome' driver |
port |
integer, port for the rsDriver to use, if NULL then a random port is selected |
convert carbon uri to tinyurl with option to attach to clipboard.
.tiny(self, private, clip = FALSE)
.tiny(self, private, clip = FALSE)
self |
carbon self object |
private |
carbon private object |
clip |
boolean, write tinyurl to clipboard, Default: FALSE |
If clip is set to TRUE write_clip will put the tinyurl on the clipboard.
character
Function that is called in a carbon object to construct valid uri to send to browser
.uri(self, private, code)
.uri(self, private, code)
self |
carbon self object |
private |
carbon private object |
code |
character, script to embbed into the uri |
if(interactive()){ x <- carbon$new('x <- 1') # populate from self$code x$uri() # enter manually x$uri(code = 'x <- y + 3') }
if(interactive()){ x <- carbon$new('x <- 1') # populate from self$code x$uri() # enter manually x$uri(code = 'x <- y + 3') }
The Carbon generator creates a new Carbon
-object, which is the class containing
all the app logic. The class is based on the R6 OO-system and
is thus reference-based with methods and data attached to each object, in
contrast to the more well known S3 and S4 systems.
A new 'Carbon'-object is initialized using the new()
method on the generator:
x <- carbon$new(code = clipr::read_clip())
|
Description of fields of the R6 object that can be set by the user can be found in the following page.
$carbonate | Using RSelenium fetch the carbon image output |
$browse | open $uri in the browser |
$set_template | set $template |
$get_templates | get a list of possible templates |
$set_window_control_theme | set $windows_control_theme |
$get_windows_control_themes | get a list of possible window control themes |
$set_font_family | set $font_family |
$get_font_families | get a list of possible fonts |
$uri | construct valid carbon.js uri |
$options | return all current carbon options |
$encode | URL encode a string for the $uri |
$tiny | Create tinyurl from $uri |
$rtweet | Send tweets containing media generated from carbon |
$chromeOptions | construct a chromeOptions object |
$chrome_start | start a chrome session |
$chrome_stop | stop a chrome session |
$start | start a RSelenium session |
$stop | stop a RSelenium session |
$stop_all | stop all active RSelenium sessions |
$get_port | Get active port |
$set_port | Set new port |
Fields that can be changed in the Carbon object
code |
character, script to embbed, Default: NULL |
palette |
numeric, layout pallete, Default: c(r=171,g=184,b=195,a=1) |
template |
character, layout template, Default: 'seti' |
add_window_control |
boolean, add/remove window controls (circles on top left corner), Default: TRUE |
window_control_theme |
character, change window control themes, Default: 'none' |
language |
character, language, Default: 'r' |
add_drop_shadow |
boolean, add/remove dropshadow, Default: TRUE |
drop_shadow_offset_y |
numeric, shadow vertical offset (px), Default: 20 |
drop_shadow_blur_radius |
numeric, shadow blur radius (px), Default: 68 |
auto_adjust_width |
boolean, auto-audjust output width, Default: TRUE |
padding_vertical |
numeric, vertical padding (px), Default: 48 |
padding_horizontal |
numeric, horizontal padding (px), Default: 32 |
add_line_number |
boolean, add/remove line numbers, Default: FALSE |
font_family |
character, layout font family, Default: 'Hack' |
font_size |
numeric, font size (px), Default: 14 |
line_height_percent |
numeric, relative space between lines (percent), Default: 133 |
square_image |
boolean, output image is square, Default: FALSE |
relative_export_size |
numeric, image size in export relative to what is in the preview (1,2 or 4), Default: 1 |
add_watermark |
boolean, add official carbon.js watermark, Default: FALSE |
add_tinyurl |
boolean, add tinyurl link to image directing to the carbon page that created the image, Default: FALSE |
tinyurl_location |
character, string with gravity value to place the annotate tinyurl address on image, Default: 'southeast' |
tweet |
boolean, tweet out the image using post_tweet |
tweet_status |
character, status to add to the tweet. If add_tinyurl is TRUE then a link to the url will be appended to the status automatically, Default: 'Created in R using the Carbonate (Package Icon)' |
add_timestamp |
boolean, add timestamp to output filename, Default: FALSE |
carbons |
list, storage of rendered carbon images, Default: NULL |
download_path |
character, path to download the images, Default: tempdir() |
chrome_args |
character, arguments passed to chrome browser, Default: c('–disable-gpu', '–window-size=1280,800') |
chrome_pref |
list, preferences passed to chrome browser, Default: list("profile.default_content_settings.popups" = 0L,"download.prompt_for_download" = FALSE,"download.default_directory" = tempdir()) |
rD |
RSelenium Driver object |
cDrv |
Chrome Driver object from wdman |
convert uri to tinyurl.
tinyurl(uri)
tinyurl(uri)
uri |
character, the uri to convert |
character