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

feature: Render mixed-in methods and constants with --embed-mixins #842

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flavorjones
Copy link
Contributor

When --embed-mixins option is set:

  • methods from an extended module are documented as singleton methods
  • attrs from an extended module are documented as class attributes
  • methods from an includeed module are documented as instance methods
  • attrs from an includeed module are documented as instance attributes
  • constants from an includeed module are documented

Sections are created when needed, and Darkfish's template annotates
each of these mixed-in CodeObjects.

This feature is inspired by Yard's option of the same name.


Example class:

module IncMod
  # :section: Things That Were Included

  # incmod attribute
  attr :incmod_attr

  # constant via mixin
  INCMOD_CONST = "incmod_const"

  # instance method via mixin
  def incmod_method
    "incmod_method"
  end
end

module ExtMod
  # :section: Things That Were Extended

  # extmod attribute
  attr :extmod_attr

  # class method via mixin
  def extmod_method
    "extmod_method"
  end
end

class Foo
  include IncMod
  extend ExtMod
end

Currently this renders like:

Screenshot from 2021-09-23 02-01-18

With --embed-mixins it renders like:

Screenshot from 2021-09-23 02-01-38

@flavorjones flavorjones changed the title Embed mixed-in methods and constants with --embed-mixins feature: Render mixed-in methods and constants with --embed-mixins Oct 11, 2021
@flavorjones
Copy link
Contributor Author

I've pushed an update to this PR to ensure that code object visibility is respected (which was a bug in the original patch).

@flavorjones
Copy link
Contributor Author

@aycabta I'm curious if you have feedback on this feature? It's off by default but I think would be a real improvement to standard-library classes like Array that inherit significant functionality from Enumerable.

@flavorjones
Copy link
Contributor Author

@aycabta This feature is live at https://nokogiri.org/rdoc/Nokogiri/XML/Node.html#method-i-at_css if you'd like to see what it looks like. Is this something you would consider merging?

@flavorjones
Copy link
Contributor Author

flavorjones commented Dec 8, 2022

Rebased off v6.5.0.

I still think this is a valuable feature to consider. It's been in use at https://nokogiri.org/rdoc/ for the past year, see https://nokogiri.org/rdoc/Nokogiri/XML/Node.html#method-i-css for example.

@flavorjones
Copy link
Contributor Author

Rebased again off master. @aycabta @nobu would you consider merging this feature?

@flavorjones
Copy link
Contributor Author

I've rebased again onto master. I still think this would be a valuable feature to merge. @hsbt @drbrain I would appreciate any feedback you have for me.

When `--embed-mixins` option is set:

- methods from an `extend`ed module are documented as singleton methods
- attrs from an `extend`ed module are documented as class attributes
- methods from an `include`ed module are documented as instance methods
- attrs from an `include`ed module are documented as instance attributes
- constants from an `include`ed module are documented

Sections are created when needed, and Darkfish's template annotates
each of these mixed-in CodeObjects. We also respect the mixin methods'
visibility.

This feature is inspired by Yard's option of the same name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants