Project

double_doc

0.01
No release in over 3 years
Low commit activity in last 3 years
Write documentation with your code, to keep them in sync, ideal for public API docs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 1.6

Runtime

 Project Readme

DoubleDoc 2.0

CI Status

Write documentation with your code, to keep them in sync, ideal for public API docs.

This document was generated using DoubleDoc from doc/readme.md, and the source of this project is a great source for how to use DoubleDoc.

Documentation Format

Write documentation in markdown right in source code files by double commenting it:

class User < ActiveRecord::Base
  ## ```js
  ## {
  ##   "id":   1,
  ##   "name": "Mick Staugaard"
  ## }
  ## ```
  def as_json
    # this comment will not be included in the documentation
    # as it only has a single # character
    super(only: [:id, :name])
  end
end

class UsersController < ApplicationController
  ## ### Getting a User
  ## `GET /users/{id}.json`
  ##
  ## #### Format
  ## @import app/models/user.rb
  def show
    render json: User.find(params[:id])
  end
end

Then write a markdown document about User API:

## Users
Access users by using our REST API, blah blah blah...

@import app/controllers/users_controller.rb

And DoubleDoc will generate this markdown document:

## Users
Access users in by using our REST API, blah blah blah...

### Getting a User
`GET /users/{id}.json`

#### Format
```js
{
  "id":   1,
  "name": "Mick Staugaard"
}
```

Rake Task

Generate documentation by telling DoubleDoc what the input files are, and where the output should go. In the example, double_doc is picked to avoid conflicts with the doc rake task in rails.

require 'double_doc'

DoubleDoc::Task.new(
  :double_doc,
  sources:          'doc/source/*.md',
  md_destination:   'doc/generated',
  html_destination: 'site'
)

The available options are:

name Description
sources Required. Documentation source directory (string or array of strings).
md_destination Required. Directory where the generated markdown files should go.
html_destination Where a pretty HTML version of the documentation should go.
html_template Custom ERB template for HTML rendering, see default template for inspiration (templates/default.html.erb).
html_renderer Custom html rendered, defaults to DoubleDoc::HtmlRenderer.
html_css Custom CSS document path.
title Title for generated HTML, defaults to "Documentation".
To generate a README.md for github, write documentation in doc/README.md and put this in the Rakefile:
require 'double_doc'

DoubleDoc::Task.new(:double_doc, sources: 'doc/README.md', md_destination: '.')

Then run rake double_doc, which will generate a readme.md in the root of the project.

If a gh-pages branch exists, run rake doc:publish to generate html documentation and push it to your github pages.

Notes

  • Tested on ruby 3.0+
  • Does not work on jruby because of its dependency on redcarpet.

Release

After merging your changes:

  1. Create a PR with a version bump and updated changelog.
  2. After that PR gets merged, create a new tag (by running gem_push=no rake release or via Github releases).
  3. This will trigger the publishing workflow—approve it in Github Actions).

TODO

  • Support for directory structures
  • Documentation for the Guard
  • Add support for extracting documentation from JavaScript files

License

The MIT License

Copyright © 2012 Mick Staugaard

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS,” WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.