Skip to content

Add Puppet Data Type documentation #199

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

Merged
merged 4 commits into from
Jul 17, 2019

Conversation

glennsarti
Copy link
Contributor

@glennsarti glennsarti commented Jun 17, 2019

Builds on #205

WIP do not merge

Addresses PDOC-226.
Also fixes PDOC- 215, 73

Punting

@glennsarti glennsarti force-pushed the add-datatype-support branch 7 times, most recently from f4b9868 to 048551f Compare June 21, 2019 06:36
@glennsarti
Copy link
Contributor Author

glennsarti commented Jun 21, 2019

Markdown rendering is basically done.

For both full ruby data types and puppet type aliases

EDIT: removed picture as it's no longer relevant

@glennsarti glennsarti force-pushed the add-datatype-support branch 7 times, most recently from 4430a59 to 11e048f Compare June 24, 2019 06:08
Copy link
Contributor

@scotje scotje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed a couple minor things.

I don't really feel qualified to review all the parser machinations though, maybe @kris-bosland could weigh in on some of that?

@scotje scotje requested a review from kris-bosland June 25, 2019 00:55
@glennsarti glennsarti force-pushed the add-datatype-support branch 2 times, most recently from 33f6c31 to 2b61666 Compare July 1, 2019 06:40
@glennsarti
Copy link
Contributor Author

glennsarti commented Jul 1, 2019

Example Output

Given the following files

# An example Puppet Data Type in Ruby.
#
# @param arg1 [String[1]] A message parameter.
# @param arg2 Optional String parameter. Defaults to 'param'.
# @param badarg3 Optional String parameter. Defaults to 'param'.
Puppet::DataTypes.create_type('RubyDataType') do
  interface <<-PUPPET
    attributes => {
      arg1   => Numeric,
      missingarg1   => { type => OString[1], value => "missing" },
      arg2  => { type => Optional[String[1]], value => "param" }
    }
    PUPPET
end

and

# Documentation for Defaultmodule Modultetypealias
type Defaultmodule::Modultetypealias = Pattern[/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/]

Outputs

JSON

...
  "data_types": [
    {
      "name": "RubyDataType",
      "file": "C:/Source/puppet-editor-services/spec/languageserver-sidecar/fixtures/real_agent/cache/lib/puppet/datatypes/cachedatatype.rb",
      "line": 6,
      "docstring": {
        "text": "An example Puppet Data Type in Ruby.",
        "tags": [
          {
            "tag_name": "param",
            "text": "A message parameter.",
            "types": [
              "Numeric"
            ],
            "name": "arg1"
          },
          {
            "tag_name": "param",
            "text": "Optional String parameter. Defaults to 'param'.",
            "types": [
              "Optional[String[1]]"
            ],
            "name": "arg2"
          },
          {
            "tag_name": "param",
            "text": "",
            "types": [
              "OString[1]"
            ],
            "name": "missingarg1"
          }
        ]
      },
      "defaults": {
        "missingarg1": "missing",
        "arg2": "param"
      },
      "source": null
    }
  ],
  "data_type_aliases": [
    {
      "name": "Defaultmodule::Modultetypealias",
      "file": "C:/Source/puppet-editor-services/spec/languageserver-sidecar/fixtures/real_agent/environments/testfixtures/modules/defaultmodule/types/moduletypealias.pp",
      "line": 2,
      "docstring": {
        "text": "Documentation for Defaultmodule Modultetypealias"
      },
      "alias_of": "Pattern[/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$/]"
    }
  ],
...

Markdown


Reference

Table of Contents

...

Data types


Data types

Defaultmodule::Modultetypealias

Documentation for Defaultmodule Modultetypealias

Alias of Pattern[/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/]

RubyDataType

An example Puppet Data Type in Ruby.

Parameters

The following parameters are available in the RubyDataType data type.

arg1

Data type: Numeric

A message parameter.

arg2

Data type: Optional[String[1]]

Optional String parameter. Defaults to 'param'.

Default value: param

missingarg1

Data type: OString[1]

Default value: missing


HTML

Index

image

Type Alias

image

Type Alias

image

@glennsarti
Copy link
Contributor Author

@jbondpdx Updated with images of outputs.

@jbondpdx
Copy link
Contributor

jbondpdx commented Jul 1, 2019

@glennsarti the regex pattern looks a little overwhelming and a bit incomprehensible to me. The caveat is that I don't know regex (I know, it's on the list of "things to learn"), so maybe most people will see that and easily read/understand it? I'll defer to you and the other devs on that one.

@glennsarti
Copy link
Contributor Author

@jbondpdx The regex was just an example of what the documentation will look like for a given source file. Also it's quite long so seeing how things wrap text or would using ellipsis (...) be appropriate etc.

This example is from stdlib - https://github.com/puppetlabs/puppetlabs-stdlib/blob/822c4d2c85a838c8bcfea48efcf399fbeb719a59/types/fqdn.pp#L1

@jbondpdx
Copy link
Contributor

jbondpdx commented Jul 2, 2019 via email

@scotje
Copy link
Contributor

scotje commented Jul 9, 2019

This PR looks good but it looks like you wanted to add some acceptance tests once #204 was merged which I just did. :)

@glennsarti
Copy link
Contributor Author

glennsarti commented Jul 10, 2019

@scotje Correct! and now that 204 is merged I can move forward with that

@trevor-vaughan
Copy link
Contributor

Just tried this for generating my REFERENCE.md and it appears to work great.

Previously the markdown unit testing used an a simple if statement to switch
between common and Puppet Plans.  However with the introduction of Puppet Types
we need another combination.  This commit refactors the Markdown testing use an
additive style to figure out test fixtures which makes adding conditional tests
easier in the future.
Previously Puppet-Strings could not document Ruby Data Types. This commit:

* Updates the ruby handler to receive `Puppet::DataTypes.create_type` method
  invocations and document the call site.  The documention is similar to that
  of a puppet custom type.
* Adds tests for ruby parsing to ensure the Yard Code Object is populated
  correctly
* Adds support for JSON, Markdown and HTML rendering.
* Adds tests for JSON and Markdown rendering
Previously Puppet-Strings could not document Data Type Aliases. This commit:

* Updates the puppet parser to interpret TypeAlias statements.
* Adds a DataTypeAlias code object and handler to document the Type Alias
  statement correctly.
* Adds tests for puppet parsing to ensure the Yard Code Object is populated
  correctly
* Adds support for JSON, Markdown and HTML rendering. Note that JSON separates
  Data Types from Data Type Aliases whereas Markdown and HTML rendering lump
  them together.  This is because from a human documentation point of view (i.e
  Mardown or HTML) they are very similar things. Much like Puppet V3 vs V4
  functions.  However the JSON output can be used by other systems so it is
  important to diffentiate them as they are different from a code inspection
  point of view.
* Adds tests for JSON and Markdown rendering
@glennsarti glennsarti force-pushed the add-datatype-support branch from 2b61666 to 8a802f2 Compare July 17, 2019 05:59
This commit updates the acceptance tests for the new Data Types and Data Type
Aliases.
@glennsarti
Copy link
Contributor Author

Acceptance tests added and green.

@glennsarti glennsarti changed the title (WIP) Add Puppet Data Type documentation Add Puppet Data Type documentation Jul 17, 2019
@scotje
Copy link
Contributor

scotje commented Jul 17, 2019

🎉

@scotje scotje merged commit ede2b0e into puppetlabs:master Jul 17, 2019
@scotje scotje added the feature label Jul 17, 2019
@alexjfisher
Copy link

I've left feedback on the puppet-strings styleguide page, as it explicitly states type aliases are not supported.

@alexjfisher
Copy link

Works great BTW! Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants