Giter VIP home page Giter VIP logo

chef_attrdoc's Introduction

chef_attrdoc

Gem Version Build Status Code Climate

The problem: README documentation gets outdated because it's not close to the code. A lot of cookbook documentation describes the configuration options that the cookbook provides; so it naturally lies in attributes files.

The solution: Extract documentation from chef cookbooks' attributes files and format and output it to the cookbook's README.md file.

chef_attrdoc groups attribute initialization lines together with the comments immediately above them. Any lines containing an attribute initialization which are not separated by an empty line are considered a group. The comment immediately above them is assumed to describe the group of attributes below. Groups of attribute initialization lines which are not immediately preceded by a comment line are ignored and will not show up in the output.

chef_attrdoc currently ignores TODO, XXX, NOTE and foodcritic comments.

Usage:

$ gem install chef_attrdoc
$ chef_attrdoc ~/cookbooks/mycookbook

It's that simple. Only one command to run and chef_attrdoc will know how to do the rest.

chef_attrdoc will try to find an Attributes heading in the README.md file in that directory and replace its contents with the generated attributes documentation. The attributes documentation is compiled from all the files in the cookbook's attributes/ directory. All the files ending in .rb in that directory are considered to be attributes files.

chef_attrdoc uses ruby's stdlib ripper module and so does not have any dependencies.

chef_attrdoc currently requires ruby >= 1.9.

Examples

These are the two input files from a chef cookbook:

$ cat cookbook-example/attributes/default.rb
# Copyright 1970, nobody

# this is the attribute
default['some']['attribute'] = 'foo'

default['this']['will']['be'] = 'ignored'

# NOTE code blocks without a comment are ignored as are those beginning
# NOTE with 'NOTE', 'XXX', 'TODO' or foodcritic comments

# a longer block of code
case something
when 'foo'
  default['some']['foo'] = 'baz'
else
  default['some']['foo'] = 'qux'
end
$ cat cookbook-example/README.md
chef_attrdoc example README
===========================

This is just an example

Attributes
==========
nothing here now


License
=======
This is usually important.

This is the output README file after running:

$ chef_attrdoc cookbook-example
$ cat cookbook-example/README.md
```
chef_attrdoc example README
===========================

This is just an example

Attributes
==========

## default.rb

this is the attribute

```ruby
default['some']['attribute'] = 'foo'
```

a longer block of code

```ruby
case something
when 'foo'
  default['some']['foo'] = 'baz'
else
  default['some']['foo'] = 'qux'
end
```


License
=======
This is usually important.
```

Here are some longer examples from openstack chef cookbooks:

openstack-identity attributes file - output

openstack-common attributes file - output

chef_attrdoc's People

Contributors

iartarisi avatar retr0h avatar

Stargazers

Angus H. avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.