Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use table for parameter #83

Open
A-312 opened this issue May 3, 2020 · 0 comments
Open

Don't use table for parameter #83

A-312 opened this issue May 3, 2020 · 0 comments

Comments

@A-312
Copy link
Contributor

A-312 commented May 3, 2020

This should be good to have the choice between a table or new lines for parameters

In my project I did this:

Before:

image

After:

image

Script

<?js
  var isChild = false
  var origin = ''

  if (typeof obj === 'object' && obj !== null && obj.subparams) {
    origin = obj.path + '.'
    obj = obj.subparams
    isChild = true
  }

  var params = obj

  function escapeRegExp(string) {
    return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  }

  /* sort subparams under their parent params (like opts.classname) */
  var parentParam = null
  params.forEach(function(param, i) {
    var paramRegExp

    if (!param) {
      return
    }

    param.fullname = origin + param.name
    if (parentParam && parentParam.name && param.name) {
      try {
        paramRegExp = new RegExp('^(?:' + escapeRegExp(parentParam.name) + '(?:\\[\\])*)\\.(.+)$')
      }   
      catch (e) {   
        console.error('Problem parsing comment', e)
        // there's probably a typo in the JSDoc comment that resulted in a weird  
        // parameter name   
        return   
      }

      if ( paramRegExp.test(param.name) ) {
        param.name = RegExp.$1
        parentParam.subparams = parentParam.subparams || []
        parentParam.subparams.push(param)
        params[i] = null
      }
      else {
        parentParam = param
      }
    }
    else {
      parentParam = param
    }
  })
?>

<dl>
  <?js if (isChild) { ?>
    <h6>Sub properties</h6>
  <?js } ?>
  <?js
    var self = this
    params.forEach(function(param) {
      if (!param) { return }
  ?>
    <dt>
      <code class="parameter"><?js= param.fullname ?></code>
      <?js if (param.type && param.type.names) {?>
        <?js= self.partial('type.tmpl', param.type.names) ?>
      <?js } ?>
    </dt>
    <dd class="para">
      <?js if (params.hasAttributes) {?>
        <?js if (param.optional) { ?>
          &ltoptional><br>
        <?js } ?>

        <?js if (param.nullable) { ?>
          &ltnullable><br>
        <?js } ?>

        <?js if (param.variable) { ?>
          &ltrepeatable><br>
        <?js } ?>
      <?js } ?>

      <?js if (params.hasDefault) {?>
        <?js if (typeof param.defaultvalue !== 'undefined') { ?>
          <code><?js= self.htmlsafe(param.defaultvalue) ?></code>
        <?js } ?>
      <?js } ?>

      <?js= param.description ?></p>

      <?js if (param.subparams) { ?>
        <?js= self.partial('params.tmpl', { 'subparams': param.subparams, 'path': param.fullname }) ?>
      <?js } ?>
    </dd>
  <?js }) ?> 
</dl>

config (with jsdoc/jsdoc#1771 ):

{
  "opts": {
    "destination": "./gh-pages/",
    "tutorials": "./docs/",
    "template": "node_modules/docdash"
  },
  // ...
  "templates": {
    "default": {
      "staticFiles": {
        "include": [
          "./docs/home/custom.css"
        ]
      }
    },
    "overwrite": {
      "node_modules/docdash/tmpl/params.tmpl": "docs/home/tmpl/params.tmpl"
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant