简体   繁体   English

漂亮地打印嵌套 SASS 地图的结构?

[英]Pretty Printing the structure of nested SASS Maps?

If we have nested maps in SASS (an Angular Theme for example) we can log the contents of it with @debug however it outputs everything in one line.如果我们在 SASS 中嵌套了映射(例如 Angular 主题),我们可以使用@debug记录它的内容,但它会在一行中输出所有内容。

Anyone know if SASS has something that will pretty print the structure of nested maps?任何人都知道 SASS 是否有可以漂亮地打印嵌套地图结构的东西?

So for example if we had:例如,如果我们有:

$colors: (
  "primary": (
    "milk":       #fff,
    "cola":       #000,
    "mine-shaft": #232323,
  ),
  "secondary": (
    "pampas":      #f4f1ef,
    "pearl-brush": #e9e2dd,
    "alto":        #ddd,
  ),
);

We could do something like我们可以做类似的事情

@recursive-debug $colors

To log the structure of it.记录它的结构。

I created a NPM package for this that is a SASS installable file.我为此创建了一个 NPM 包,它是一个 SASS 可安装文件。

npm i @fireflysemantics/sass-logger

https://www.npmjs.com/package/@fireflysemantics/sass-logger https://www.npmjs.com/package/@fireflysemantics/sass-logger

This is from the usage section of the README.这来自自述文件的使用部分。

This demo will create a Angular Material Palette $theme-primary and log the contents by first using the logger to structure the map data containing the result and then outputting that result with @debug.

@use '@angular/material' as mat;
@use '@fireflysemantics/sass-logger' as logger;

// ============================================
// Palettes: https://material.io/design/color/
// ============================================
$theme-primary: mat.define-palette(mat.$indigo-palette);
$result: logger.pretty-map($theme-primary);
@debug ($result);

$theme: mat.define-light-theme($theme-primary, $theme-primary, $theme-primary);
//$result: logger.pretty-map($theme);

This is a stackblitz demo of the package.这是该软件包的 stackblitz 演示。

https://stackblitz.com/edit/angular-r9tzuk-ov8kx4 https://stackblitz.com/edit/angular-r9tzuk-ov8kx4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM