From a37c6fe0193209bb50bfcb3e3cba4c80e19330a2 Mon Sep 17 00:00:00 2001 From: "E. Camden Fisher" Date: Wed, 6 May 2015 11:19:08 -0400 Subject: [PATCH] Add support for custom templates --- .gitignore | 3 +++ README.md | 9 +++++++++ lib/calamum.rb | 1 - lib/calamum/config.rb | 9 ++++----- lib/calamum/runner.rb | 16 +++++++++++----- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 68b1752..bfcc99c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,9 @@ tmtags ## VIM *.swp +## Rubymine +.idea + ## PROJECT::GENERAL tmp pkg diff --git a/README.md b/README.md index 215dd2d..036c637 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/lib/calamum.rb b/lib/calamum.rb index 5c7909b..b2cda9b 100644 --- a/lib/calamum.rb +++ b/lib/calamum.rb @@ -10,5 +10,4 @@ module Calamum require 'calamum/doc_parser' require 'calamum/doc_generator' require 'calamum/version' - VALID_TEMPLATES = %{twitter bootstrap} end diff --git a/lib/calamum/config.rb b/lib/calamum/config.rb index e52c664..d4cbe33 100644 --- a/lib/calamum/config.rb +++ b/lib/calamum/config.rb @@ -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 diff --git a/lib/calamum/runner.rb b/lib/calamum/runner.rb index fd4e82c..5425c54 100644 --- a/lib/calamum/runner.rb +++ b/lib/calamum/runner.rb @@ -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', @@ -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 @@ -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)