douchun3680 2019-03-14 13:29
浏览 131

如何扫描所有可用的SCSS文件并解析注释以在数组中创建信息?

I have many SCSS files and want to make a style guide (a library with all components like buttons, forms, ...). This style guide should work automatically, so that when you create a new stylesheet it should automatically scan the comments and put the data into an array to create a dynamic information page about the new component.

At example:

/**
* @title title1
* @description description1
* @author author1
*/

.list {
   li {
       overflow: hidden;           
       border-bottom: cornflowerblue;
       margin: 0 0 4px 0;
   }

   a {
       text-decoration: none;
   }       
}

Now I want to parse this comment and want to get the word(s) after a.e. the @title Tag. So in this case I would like to get the word "title1" and automatically save it into an array. My try was following:

$source = file_get_contents("mysite/examplestyles.scss");

$tokens = token_get_all($source);
$comment = array(
    T_COMMENT,
    T_DOC_COMMENT
);

foreach ($tokens as $token)
{
    if (!in_array($token[0], $comment))
    {
        continue;
    }

    $txt = $token[1];
}

How should I change my code sample to get the informations I would like to have? It would be great if somebody can help me. I think it would be understandable if the ouput is the information I would like to get (title1, description1, author1) so a code sample would be nice to have.

If you have any questions you can ask me.

Thank you!

  • 写回答

1条回答 默认 最新

  • dpca31461 2019-03-14 14:07
    关注

    You're basically trying to re-invent SassDoc, but it is much better to use this solution

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值