import Immutable from "immutable" ; import Promise from "../utils/promise" ; class Parser extends Immutable . Record ( { name : String ( ) , extensions : Immutable . List ( ) , readme : Function ( ) , langs : Function ( ) , summary : Function ( ) , glossary : Function ( ) , page : Function ( ) , inline : Function ( ) , } ) { getName ( ) { return this . get ( "name" ) ; } getExtensions ( ) { return this . get ( "extensions" ) ; } parseReadme ( content ) { const readme = this . get ( "readme" ) ; return Promise ( readme ( content ) ) ; } parseSummary ( content ) { const summary = this . get ( "summary" ) ; return Promise ( summary ( content ) ) ; } parseGlossary ( content ) { const glossary = this . get ( "glossary" ) ; return Promise ( glossary ( content ) ) ; } preparePage ( content ) { const page = this . get ( "page" ) ; if ( ! page . prepare ) { return Promise ( content ) ; } return Promise ( page . prepare ( content ) ) ; } parsePage ( content ) { const page = this . get ( "page" ) ; return Promise ( page ( content ) ) ; } parseInline ( content ) { const inline = this . get ( "inline" ) ; return Promise ( inline ( content ) ) ; } parseLanguages ( content ) { const langs = this . get ( "langs" ) ; return Promise ( langs ( content ) ) ; } renderLanguages ( content ) { const langs = this . get ( "langs" ) ; return Promise ( langs . toText ( content ) ) ; } renderSummary ( content ) { const summary = this . get ( "summary" ) ; return Promise ( summary . toText ( content ) ) ; } renderGlossary ( content ) { const glossary = this . get ( "glossary" ) ; return Promise ( glossary . toText ( content ) ) ; } param { string } ext return { boolean } matchExtension ( ext ) { const exts = this . getExtensions ( ) ; return exts . includes ( ext . toLowerCase ( ) ) ; } param { string } name param { Array < String > } extensions param { Object } module return { Parser } static create ( name , extensions , module ) { return new Parser ( { name : name , extensions : Immutable . List ( extensions ) , readme : module . readme , langs : module . langs , summary : module . summary , glossary : module . glossary , page : module . page , inline : module . inline , } ) ; } } export default Parser ;