oddbird / sassdoc-theme-herman

An Odd SassDoc theme.
http://oddbird.net/herman/
MIT License
117 stars 11 forks source link

Better documentation of template macros, and their relationship to Sass patterns #21

Open mirisuzanne opened 8 years ago

mirisuzanne commented 8 years ago

Problems with the current implementation:

mirisuzanne commented 8 years ago

Based on OddBird discussion:

mirisuzanne commented 8 years ago

After further discussion, sounds like it may be easier to add robust macro documentation as an extension on the @example annotation that already exists. Here's my rough understanding, but maybe @davisagli or @jgerigmeyer wants to expand on it (or take assignment of the issue)?

davisagli commented 8 years ago

I've got an implementation of this started in the rendered-nunjucks-examples branch (https://github.com/oddbird/sassdoc-theme-herman/compare/rendered-nunjucks-examples)

That adds special handling for the normal sassdoc @example annotation so that if the example language is "njk", it will be displayed both as source and as a rendered nunjucks template.

For example this:

// Test Macro
// ----------
// This is a test.
/// @example njk - Basic usage:
///  {% import 'macros.j2' as macros %}
///  {{ macros.mymacro(1, 2) }}
/// @group test
[data-mymacro] {}

shows up like this:

screen shot 2016-04-16 at 5 43 46 pm

Maybe we also want to make it possible to document a macro without attaching that documentation to a particular Sass block, but I think that's outside the scope of this ticket. This should already handle multiple examples attached to the same block and multiple blocks with examples of the same macro.

Does this change what we want to do with the @macro annotation? I think we probably should remove its handling of macroname_data to provide example input, to avoid having two ways to do the same thing. But we probably want to at least keep the handling of macroname_doc so that macros can include some inline documentation.

We might want a way to configure a custom getNunjucksEnv function, so that custom filters can be provided.

carljm commented 8 years ago

(Created a PR from that branch just for code-review purposes, though it turned out then that I didn't have any line-by-line code-review comments :-) Looks great!)

The main improvements that come to mind would be a) allowing passing in a customized nunjucks env, as you mentioned, and b) reducing the duplicated getNunjucksEnv code between the @macro, @icons, and @example annotations.

I agree with you that macroname_data can go away, given this better approach. I wonder whether macroname_doc can go away too: it seems like template-author-oriented inline macro documentation is more readable if done in a nunjucks comment, and designer-oriented documentation can probably be handled entirely via @example?

jgerigmeyer commented 8 years ago

I went ahead and removed macroname_data. I left macroname_doc, but it looks like it's not being called in the templates at all yet. I also cleaned up some of the code duplication. I did not allow passing in a custom nunjucks env, but that can be a new feature if @mirisuzanne wants to get this merged now.

mirisuzanne commented 7 years ago

There is a proposed syntax for template-driven documentation in templates/items/preview.macros.j2 using the same @annotation's available in SassDoc.

{#
  Font Specimen
  -------------
  Display all font-family specimens,
  including multiple variants.

  @group font-specimen

  @prop {String} name -
    Title for the font-family being displayed.
  @prop {Dict} data -
    All the available data on a given font,
    derived from the Sass JSON export.
  @prop {Dict} args -
    Arbitrary arguments passes along
    in the font-specimen call
    (currently only `show` and `key` are supported).
#}