켈 경고 : 이 프로젝트는npmjs.com에서"dss"에서"@documented-style-sheets/parser"로 이동했습니다.
DSS , 문서화 된 스타일 시트는 일반 목적 코멘트 가이드 및 파서입니다 (예 : CSS, Less, Stylus, Sass, SCSS & JS 의견). 이 프로젝트는 정적 파일 분석 및 구문 분석을 수행하여 스타일 가이드를 생성하는 데 사용할 객체를 생성합니다.
dss.detectordss.parsernpm i @documented-style-sheets/parser 대부분의 경우, DSS 파서를 구축 단계에 포함시켜 문서 파일을 자동으로 생성하는 빌드 단계에 포함하려고합니다 (또는 다른 수단에 대해이 반환 된 Object 와 함께 플레이하고 싶다). 어느 쪽이든, 우리는 공식적으로 Grunt 플러그인과 Gulp 플러그인을 지원합니다.
//
// @name Button
// @description Your standard form button.
//
// @state :hover - Highlights when hovering.
// @state :disabled - Dims the button when disabled.
// @state .primary - Indicates button is the primary action.
// @state .smaller - A smaller button
//
// @markup
// <button>This is a button</button>
// // Requirements
const fs = require ( 'fs' )
const { parse } = require ( '@documented-style-sheets/parser' )
// Get file contents
const fileContents = fs . readFileSync ( 'styles.css' )
// Run the DSS Parser on the file contents
parse ( fileContents , { } , function ( parsedObject ) {
// Output the parsed document
console . log ( parsedObject )
} ) {
"name" : " Button " ,
"description" : " Your standard form button. " ,
"state" : [
{
"name" : " :hover " ,
"escaped" : " pseudo-class-hover " ,
"description" : " Highlights when hovering. "
},
{
"name" : " :disabled " ,
"escaped" : " pseudo-class-disabled " ,
"description" : " Dims the button when disabled. "
},
{
"name" : " .primary " ,
"escaped" : " primary " ,
"description" : " Indicates button is the primary action. "
},
{
"name" : " .smaller " ,
"escaped" : " smaller " ,
"description" : " A smaller button "
}
],
"markup" : {
"example" : " <button>This is a button</button> " ,
"escaped" : " <button>This is a button</button> "
}
}이 방법은 관심 지점 (예 : 변수)이 텍스트 줄에서 발견 된 다음 나중에 구문 분석하는 방식을 정의합니다. DSS Dogfoods이 API 및 기본 구현은 다음과 같습니다.
// Describe default detection pattern
// Note: the current line, as a string, is passed to this function
const dss = require ( '@documented-style-sheets/parser' )
dss . detector ( function ( line ) {
if ( typeof line !== 'string' ) {
return false
}
var reference = line . split ( "nn" ) . pop ( )
return ! ! reference . match ( / .*@ / )
} )
dss . parse ( ... ) DSS 는 기본적으로 주석 블록의 name , description , state 및 markup 위한 4 개의 구문 분석기를 포함합니다. 새 파서를 등록하여 이러한 기본값을 추가하거나 재정의 할 수 있습니다. 이 기본값은 또한 @ 데코레이터를 사용하여 식별하는 패턴을 따릅니다. dss.detector() 에 다른 콜백 함수를 제공하는이 behaivour를 수정할 수 있습니다.
dss.parser 원하는 변수의 이름과 내용을 조작하기위한 콜백 함수를 기대합니다. 해당 콜백 기능에 의해 반환되는 것은 JSON 생성에 사용되는 것입니다.
this :this.file : 현재 파일this.name : 파서의 이름this.options : 처음에 dss.parse() 로 전달 된 옵션this.line :this.line.contents :이 변수와 관련된 내용this.line.from :이 변수가 발견 된 줄 번호this.line.to :이 변수의 내용이 끝나는 줄 번호this.block :this.block.contents :이 변수의 주석 블록과 관련된 내용this.block.from :이 변수의 주석 블록이 시작되는 줄 번호this.block.to :이 변수의 주석 블록이 끝나는 줄 번호 // Matches @version
dss . parser ( 'version' , function ( ) {
// Just returns the lines contents
return this . line . contents
} ) dss . parser ( 'link' , function ( ) {
// Replace link with HTML wrapped version
const exp = / (b(https?|ftp|file): / / [ - A - Z0 - 9 + & @# / % ? = ~ _ | ! : , . ; ] * [ - A - Z0 - 9 + & @# / %= ~ _ | ] ) / ig
this . line . contents . replace ( exp , "<a href='$1'>$1</a>" )
return line
} )