动态变化的不带点参数带点、参数、动态

2023-09-05 00:20:51 作者:内裤再酷也是装逼的

我想存储在数据库.LESS参数,一个例子用例可能是基于他或她的preference为每个用户的颜色变化。

I would like to store .less parameters in a DB, an example use case might be that colour changes for each user based on his or her preference.

我图做到这将是解析所有.LESS文件以获取这些参数,用户可以再设置这将在DB保存对用户的参数的最佳方式。当请求较少文件的处理程序的过载可以查询DB中的参数。该处理器可以再输出的参数设置CSS

I figure the best way to do this would be to parse all the .less files to get the parameters, the user can then set the parameters which would save in a DB against the user. When the less file is requested a handler overload can query the DB for the parameters. The handler can then output the css with the parameters set.

问题: - 我如何可以采取.LESS文件,获取一个参数列表? - 我如何可以采取.LESS文件的参数数组(键值对)和输出的CSS

Questions: - How can I take a .less file and get a list of parameters? - How can I take a .less file an array of parameters (key value pairs) and output css?

所有使用无点框架。

推荐答案

可能是一个迟到的答复,但我们做了类似的要求,我们已经基于存储在数据库中的用户自定义颜色的东西。

Might be a late reply but we did something similar to your requirement, where we had custom colors based on users stored in the database.

我们的解决方案中添加自定义code到带点的来源,可在这里,我相信 https://开头github.com/dotless/dotless

Our solution was adding custom code to the source of dotless which is available here I believe https://github.com/dotless/dotless

于是在分析它甫一字符串替换期间,我们要更换的部件。唯一的缺点的方法是获得更新的构建,我们需要每次都重新emerge我们的源代码的新的无点的dll。

So then during the parsing it justs string replaced the parts we wanted to replace. Only drawback to this approach is to get updated builds of the new dotless dll we need to remerge our source each time.

修改 下面是一个例子code片断:

EDIT Here is an example code snippet:

dotless.Core.Utils.HslColor hslcolor = dotless.Core.Utils.HslColor.FromRgbColor( new dotless.Core.Parser.Tree.Color( "187AAB" );
                hslcolor.Lightness = 0.93;
                var hexString = '#' + ( hslcolor.ToRgbColor().RGB.Select( i => ( ( int )i ).ToString( "X2" ) ).Aggregate( ( a, b ) => a + b ) ).ToLowerInvariant();
                var resultColor = hexString;