 formatDocs = ( docs ) ->
   json =  JSON.stringify docs, null, "  "
   """
-  /* Control member documentation generated from QuickUI control source files. */
+  /* Control documentation generated from QuickUI control source files. */
   var controlDocumentation = #{json};
   """
 

      match = @regexCommentText.exec commentBlock
    text


# Extracts docs from CoffeeScript controls
coffeeDocsExtractor = new DocsExtractor
  className: ///
    \r?\n                     # Start of line (no indentation)
    class                     # "class" keyword
    \s+                       # Whitespace
    (?:window.)?              # optional "window."
    (                         # Group captures class name
      [a-zA-Z0-9\$][\w]+      # JavaScript identifier
    )

class DocsExtractor

  constructor: ( regexes ) ->
    @regexBaseClassName = regexes.baseClassName
    @regexClassName = regexes.className
    @regexComments = regexes.comments
    @regexCommentText = regexes.commentText
    @regexRequiresClasses = regexes.requiresClasses

  extract: ( source ) ->
    baseClassName: @baseClassName source
    className: @controlClassName source
    members: @memberComments source
    requiresClasses: @requiresClasses source

  # Return the name for the control class defined in the source text.
  baseClassName: ( source ) ->
    match = @regexBaseClassName.exec source
    match?[1]

  # Return the name for the control class defined in the source text.
  controlClassName: ( source ) ->
    match = @regexClassName.exec source
    match?[1]

  # Return the comments found for members defined in the source text.
  memberComments: ( source ) ->
    comments = null
    match = @regexComments.exec source
    while match != null
