rstudio / sass

Sass compiler package for R
https://rstudio.github.io/sass/
Other
102 stars 17 forks source link

Tweaks to `as_sass` semantics #8

Open jcheng5 opened 5 years ago

jcheng5 commented 5 years ago

It's really cool that sass() allows nested unnamed lists! I would like to make this work:

sass(
  list(
    if (use_theme) theme_options, # A named list
    bootstrap_dependencies, # A list of sass_files
    custom_sass # A string
  )
)

This almost works now, but not if use_theme is FALSE. This is because anywhere a NULL is found, it turns into "null":

> as_sass(list(
+   NULL,
+   list(foo = NULL),
+   list(bar = list(NULL))
+ ))
/* Sass */
null
$foo: null;
$bar: null;

My position is that the first NULL should render as empty string, and the list(foo=NULL) should render as $foo: null;. The third entry should render as either $bar: (null); or $bar: [null];.

Once you encounter a named list, the recursion shouldn't be via as_sass, but something else--as_sass_value perhaps?

object as_sass as_sass_value
NULL "" "null"
Unnamed list Recurse with as_sass, collapse with "\n" Recurse with as_sass_value, then create (bracketed?) Sass list
Named list Recurse with as_sass_value, turn into name/value pairs Recurse with as_sass_value, turn into Sass map
Numeric, logical Throw error Convert to string
String Identity Identity
schloerke commented 5 years ago

Looks good to me!

Link for understanding sass list spec (unnamed list): https://www.sitepoint.com/sass-reference/lists/

$list: ('foo', 'bar', 'baz');

Link for understanding sass map spec (named list): https://webdesign.tutsplus.com/tutorials/an-introduction-to-sass-maps-usage-and-examples--cms-22184

$map: (
    key: value,
    nextkey: nextvalue
);
schloerke commented 5 years ago

... double check for brackets on grid

rich-iannone commented 5 years ago

@jcheng5 should this change be done for the CRAN release?