sassdoc icon indicating copy to clipboard operation
sassdoc copied to clipboard

Add ability to document functions, mixins options

Open pascalduez opened this issue 10 years ago • 13 comments

A tweet points out there is no way to document a Map as parameter currently. That might be an interesting new feature to add.

Consider the following:

/// Sowieso
/// @param {Map} $options [()] - some options
@mixn whatever($options: ()) { ... }

There's no way to properly document the options map properties.

Some possible solutions (just to illustrate the matter):

Introduce a new annotation

/// Sowieso
/// @options $options - some options
///    @prop {Number} one [1]- option one
///    @prop {String} two ['two'] - option two
@mixn whatever($options: ()) { ... }

Pro: straightforward Con: How to deal with indentation, nesting

Reference a Map outside the caller

/// Sowieso
/// @type {Option Map}
/// @prop {Number} one [1]- option one
/// @prop {String} two ['two'] - option two
$options: ( one: 1, two: 'two' );

/// Sowieso
/// @options $options - some options
@mixn whatever($options: ()) { ... }

Pro: Con: Weirdo, complex

EDIT: Was already reported in #111

pascalduez avatar Mar 19 '15 16:03 pascalduez

We already have @property! http://sassdoc.com/annotations/#property

valeriangalliat avatar Mar 19 '15 16:03 valeriangalliat

We already have @property!

But no way to apply @property to a Map as a parameter.

pascalduez avatar Mar 19 '15 16:03 pascalduez

Alright. Well if we make it compatible with mixin/function parameters, the syntax should remain the same, or as close as possible.

What I propose:

/// @param {Map} $options
/// @prop {String} $options.foo [default] - Description
/// @prop {Number} $options.bar [42] - Description

valeriangalliat avatar Mar 19 '15 16:03 valeriangalliat

Yeah, much better ! Funny, reminds me the discussions we had when implementing Maps documentation :-)

pascalduez avatar Mar 19 '15 16:03 pascalduez

Great proposal @valeriangalliat. That would fit our needs perfectly and be very flexible for others, too. The display in the default theme could get a little bit tricky, though. As I mentioned in #111 when the default value of a map has more than a couple keys, the current display causes the table to get distorted because the Default Value column is so wide. I really like the way you currently output @prop for maps, so I'm sure you'll find a good way to do so.

ajmueller avatar Mar 19 '15 16:03 ajmueller

Then there is another issue as mentioned in #111

/// Sowieso
/// @param {Map} $options [()] - some options
@mixn whatever($options: ()) { 
  $defaults: (
    one: 1,
    two: 'two'
  );
}

There is no way to document an item inside an item, and I think that would be a bit problematic to implement. That's where the Sass !default is supposed to act.

pascalduez avatar Mar 19 '15 16:03 pascalduez

Have you all had a chance to discuss this further within the team? Let me know if you have any questions about our needs or implementation ideas.

ajmueller avatar Mar 24 '15 23:03 ajmueller

Can I close since we have #111?

KittyGiraudel avatar Apr 05 '15 10:04 KittyGiraudel

I believe @pascalduez opened this issue because #111 was closed.

ajmueller avatar Apr 06 '15 15:04 ajmueller

Yep, #111 is closed, also we are kind of speaking about 2 different features here if I'm not mistaken ?

  • Maps as params
  • Maps inside an item

pascalduez avatar Apr 06 '15 15:04 pascalduez

I think the two are related in this instance, but are definitely separate features. The way we happen to (generally) use maps as params is to define options that are then extended by a "default" map inside a function or mixin.

ajmueller avatar Apr 06 '15 15:04 ajmueller

This would be super helpful! I am using maps in combination with mixins for most things like fonts size, margin, padding, etc. Currently I build in a warning if the value from the mixin parameter is not found, which is super annoying because you have to have it built first before you know what values you can use.

shiftgeist avatar Mar 02 '20 21:03 shiftgeist

Alright. Well if we make it compatible with mixin/function parameters, the syntax should remain the same, or as close as possible.

What I propose:

/// @param {Map} $options
/// @prop {String} $options.foo [default] - Description
/// @prop {Number} $options.bar [42] - Description

That is what i'm really looking for!

We use a theme map and will be cool to allow it to be documented for any mixin using it.

My proposal would be even simpler, by allowing to create custom types!

For instance:

///  @typedef Theme
/// @Theme.color {String} #fff [default] - Description
/// @Theme.size{Number} 14 - Description
/// @Theme.font.family {String} Arial- Description

So you end up with a typedef with props and nested props that you can use as parameter where you need it. For instance:

/// @param {Theme} $theme
@mixin whatever($theme) { }

yuxblank avatar Feb 02 '22 11:02 yuxblank