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

如何扫描所有可用的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!

我有很多SCSS文件,想要制作一个样式指南(一个包含按钮,表格等所有组件的库。 ..)。 此样式指南应自动运行,因此在创建新样式表时,它应自动扫描注释并将数据放入数组中以创建有关新组件的动态信息页面。 p>

例如: p>

  / ** 
 * @title title1 
 * @description description1 
 * @author author1 
 * / 
 
.list {\  n li {
溢出:隐藏;  
 border-bottom:cornflowerblue; 
 margin:0 0 4px 0; 
} 
 
a {
 text-decoration:none; 
} 
} 
  code>  pre> \  n 
 

现在我想解析这个评论,并想在ae之后得到这个词 @title标签。 所以在这种情况下,我想得到“title1”这个词并自动将其保存到数组中。 我试过以下: p>

  $ source = file_get_contents(“mysite /  examplestyles.scss“); 
 
 $的令牌= token_get_all($源); 
 $的注释=阵列(
 T_COMMENT,
 T_DOC_COMMENT 
)的; 
 
foreach($令牌为$令牌)
  {
 if(!in_array($ token [0],$ comment))
 {
 continue; 
} 
 
 $ txt = $ token [1]; 
} 
  code>   pre> 
 
 

我应该如何更改我的代码示例以获取我想要的信息? 如果有人可以帮助我,那会很棒。 我认为如果输出是我想要得到的信息(title1,description1,author1)是可以理解的,那么代码样本会很好。 p>

如果您有任何疑问 你可以问我。 p>

谢谢! p> div>

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