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

Add support for custom templates #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ tmtags
## VIM
*.swp

## Rubymine
.idea

## PROJECT::GENERAL
tmp
pkg
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Usage: /bin/calamum (options)
-f, --file DEFINITION Path to the file with API definition
-p, --path PATH Path to the directory where docs will be generated
-t, --template TEMPLATE Name of HTML template (twitter or bootstrap , twitter by default)
-l, --tplpath TEMPLATE_PATH Path to look for templates.
-s, --sort Sort the resources alphabetically
-v, --version Show version number
-h, --help Show this help
Expand All @@ -32,9 +33,17 @@ for bootstrap template:

$calamum -f my_api_definition.json -t bootstrap

for your owm template (in some/other/dir/mytemplate):

$calamum -f my_api_definition.json -l some/other/dir -t mytemplate

To preview just generated documentation, navigate to the 'docs' directory (by default in your home path, you can specify the destination path with the option '-p/--path').
Then, find and open the index.html file in your browser and enjoy the result.

## Custom template

Currently, custom templates are based on the `twitter` template format. The simplest way to create your own template is to copy that one and modify it.

## Inspirations
- [Apiary](http://apiary.io/blueprint)
- [IO Docs](https://github.com/mashery/iodocs)
Expand Down
1 change: 0 additions & 1 deletion lib/calamum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ module Calamum
require 'calamum/doc_parser'
require 'calamum/doc_generator'
require 'calamum/version'
VALID_TEMPLATES = %{twitter bootstrap}
end
9 changes: 4 additions & 5 deletions lib/calamum/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ def self.apply(config)
merge!(config)

self.doc_path = File.join(config[:path], 'docs')
self.tpl_path = File.join(File.dirname(__FILE__),
'templates',
config[:template])
unless Calamum::VALID_TEMPLATES.include?(config[:template])
fail "Unknown template #{config[:template]}"
self.tpl_path = File.join(config[:tplpath], config[:template])

unless File.exist?(self.tpl_path)
fail "Cannot find template #{config[:template]}"
end
end
end
16 changes: 11 additions & 5 deletions lib/calamum/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ class Calamum::Runner
option :template,
:short => '-t TEMPLATE',
:long => '--template TEMPLATE',
:description => 'Name of HTML template [twitter, bootstrap](twitter by default)',
:description => 'Name of HTML template [twitter, bootstrap, custom](twitter by default)',
:default => 'twitter'

option :tplpath,
:short => '-l TEMPLATE_PATH',
:long => '--tplpath TEMPLATE_PATH',
:description => 'Path to look for templates.',
:default => File.join(File.dirname(__FILE__), 'templates')

option :path,
:short => '-p PATH',
:long => '--path PATH',
Expand All @@ -51,9 +57,9 @@ class Calamum::Runner
:exit => 0

option :sort,
:short => "-s",
:long => "--sort",
:description => "Sort the resources alphabetically",
:short => '-s',
:long => '--sort',
:description => 'Sort the resources alphabetically',
:boolean => true,
:default => false

Expand All @@ -67,7 +73,7 @@ def run
Calamum::DocGenerator.init_base_dir
process_index

if config[:template] == 'twitter'
unless config[:template] == 'bootstrap'
process_pages
process_section("overview", @definition.get_description)
process_section("authentication", @definition.get_authentication)
Expand Down