webapidoc 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/Rakefile +8 -0
- data/lib/generators/webapidoc/install_generator.rb +25 -0
- data/lib/{webapidoc → generators/webapidoc/templates}/index.md.erb +1 -1
- data/{app/documentation → lib/generators/webapidoc/templates}/sample.md.erb +1 -1
- data/{config → lib/generators/webapidoc/templates}/webapidoc.yml +3 -0
- data/lib/webapidoc/base.rb +98 -0
- data/lib/webapidoc/css/webapidoc.scss +1 -1
- data/lib/webapidoc/template.html.erb +6 -8
- data/lib/webapidoc/version.rb +4 -0
- data/lib/webapidoc.rb +2 -110
- data/webapidoc.gemspec +10 -4
- metadata +25 -7
data/README.md
CHANGED
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#lib/generators/gemname/install_generator.rb
|
2
|
+
require 'rails/generators'
|
3
|
+
require "webapidoc"
|
4
|
+
|
5
|
+
module Webapidoc
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
desc "generate api documentation sample"
|
9
|
+
|
10
|
+
def copy_files
|
11
|
+
source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
12
|
+
|
13
|
+
# create paths
|
14
|
+
FileUtils.mkdir_p "app/documentation"
|
15
|
+
|
16
|
+
# copy files
|
17
|
+
FileUtils.copy(source_root + "/index.md.erb", "app/documentation")
|
18
|
+
FileUtils.copy(source_root + "/sample.md.erb", "app/documentation")
|
19
|
+
FileUtils.copy(source_root + "/webapidoc.yml", "config")
|
20
|
+
|
21
|
+
puts "done"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -39,7 +39,7 @@ Support for ERB
|
|
39
39
|
Table of contents generated via ERB:
|
40
40
|
|
41
41
|
<% @chapters.each_with_index do |chapter, idx| %>
|
42
|
-
<%= idx %>. [<%= chapter[:name] %>](
|
42
|
+
<%= idx %>. [<%= chapter[:name] %>](/documentation/<%= chapter[:out] %>)
|
43
43
|
<% end %>
|
44
44
|
|
45
45
|
Some code
|
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
module Webapidoc
|
3
|
+
|
4
|
+
def self.gem_libdir
|
5
|
+
t = ["#{File.dirname(File.expand_path($0))}/../lib/#{Webapidoc::NAME}",
|
6
|
+
"#{Gem.dir}/gems/#{Webapidoc::NAME}-#{Webapidoc::VERSION}/lib/#{Webapidoc::NAME}"]
|
7
|
+
t.each {|i| return i if File.readable?(i) }
|
8
|
+
raise "both paths are invalid: #{t}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.build(data=nil)
|
12
|
+
|
13
|
+
@data = data
|
14
|
+
|
15
|
+
publicDir = "public/documentation"
|
16
|
+
docDir = "app/documentation"
|
17
|
+
libDir = gem_libdir
|
18
|
+
|
19
|
+
# get config hash
|
20
|
+
configFile = 'config/webapidoc.yml'
|
21
|
+
config = YAML.load_file(configFile).freeze
|
22
|
+
|
23
|
+
puts "building webapidoc for " + config["title"]
|
24
|
+
|
25
|
+
# clean up
|
26
|
+
FileUtils.remove_dir publicDir if File.exists?(publicDir)
|
27
|
+
|
28
|
+
# create paths
|
29
|
+
FileUtils.mkdir_p publicDir
|
30
|
+
FileUtils.mkdir publicDir + "/css"
|
31
|
+
FileUtils.mkdir publicDir + "/js"
|
32
|
+
|
33
|
+
# copy jquery
|
34
|
+
FileUtils.copy(libDir + "/js/jquery.js", publicDir + "/js/jquery.js")
|
35
|
+
|
36
|
+
# copy highlighter
|
37
|
+
FileUtils.copy(libDir + "/js/highlight.js", publicDir + "/js/highlight.js")
|
38
|
+
|
39
|
+
# compile webapidoc style
|
40
|
+
sass_filename = libDir + "/css/webapidoc.scss"
|
41
|
+
css = Sass::Engine.for_file(sass_filename, {:style => :compressed}).render
|
42
|
+
File.open(publicDir + "/css/webapidoc.css", "wb") {|f| f.write(css) }
|
43
|
+
|
44
|
+
# parse chapters and create html from md
|
45
|
+
@chapters = []
|
46
|
+
|
47
|
+
# get chapter info
|
48
|
+
config["chapters"].each_with_index do | chapter, idx|
|
49
|
+
|
50
|
+
inFile = "#{docDir}/#{chapter["file"]}.md"
|
51
|
+
outFile = chapter["file"] + ".html"
|
52
|
+
|
53
|
+
if File.exists?(inFile + ".erb" )
|
54
|
+
inFile = inFile + ".erb"
|
55
|
+
end
|
56
|
+
|
57
|
+
if File.exists?(inFile)
|
58
|
+
contents = File.open(inFile, 'r').read
|
59
|
+
else
|
60
|
+
puts "file not found: #{inFile}"
|
61
|
+
next
|
62
|
+
end
|
63
|
+
|
64
|
+
@chapters << { :name => chapter["name"], :out => outFile, :in => inFile}
|
65
|
+
end
|
66
|
+
|
67
|
+
@chapters.each_with_index do | chapter, idx|
|
68
|
+
|
69
|
+
contents = ERB.new(File.open(chapter[:in], 'r').read).result(binding)
|
70
|
+
maruku = Maruku.new(contents)
|
71
|
+
|
72
|
+
# get content info for subsections ( side pane navigation )
|
73
|
+
sections = []
|
74
|
+
maruku.each_element(:header) do | el |
|
75
|
+
next unless el.meta_priv[:level] == 2
|
76
|
+
sections << el.children[0]
|
77
|
+
end
|
78
|
+
|
79
|
+
chapter[:html] = maruku.to_html
|
80
|
+
chapter[:sections] = sections
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
# open template
|
85
|
+
template = "#{libDir}/template.html.erb"
|
86
|
+
|
87
|
+
# build chapter files
|
88
|
+
@chapters.each do | chapter |
|
89
|
+
|
90
|
+
# bindings
|
91
|
+
@html = chapter[:html]
|
92
|
+
@current = chapter
|
93
|
+
puts "building #{chapter[:name]}"
|
94
|
+
# write it
|
95
|
+
File.open("#{publicDir}/#{chapter[:out]}", 'w') { |file| file.write(ERB.new(File.open(template, 'r').read).result(binding)) }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<html lang="en">
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8">
|
5
|
-
<title>
|
5
|
+
<title>Webapidoc for <%= @data[:title] %></title>
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7
7
|
<meta name="description" content="in-depth WebAPI documentation for <%= @data[:title] %>">
|
8
8
|
<meta name="author" content="the nice guys from <%= @data[:title] %>">
|
@@ -21,16 +21,16 @@
|
|
21
21
|
<link href='http://fonts.googleapis.com/css?family=Lato:300,400,700' rel='stylesheet' type='text/css'>
|
22
22
|
|
23
23
|
<!-- Le styles -->
|
24
|
-
<link href="css/webapidoc.css" rel="stylesheet">
|
24
|
+
<link href="/documentation/css/webapidoc.css" rel="stylesheet">
|
25
25
|
|
26
26
|
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
|
27
27
|
<!--[if lt IE 9]>
|
28
|
-
<script src="js/html5.js"></script>
|
28
|
+
<script src="/documentation/js/html5.js"></script>
|
29
29
|
<![endif]-->
|
30
30
|
|
31
31
|
<!-- Les javascripts -->
|
32
|
-
<script src="js/jquery.js"></script>
|
33
|
-
<script src="js/highlight.js"></script>
|
32
|
+
<script src="/documentation/js/jquery.js"></script>
|
33
|
+
<script src="/documentation/js/highlight.js"></script>
|
34
34
|
|
35
35
|
<!-- enable script highlighting -->
|
36
36
|
<script>
|
@@ -50,12 +50,10 @@
|
|
50
50
|
<div class="four columns offset-by-one" id="nav">
|
51
51
|
<ul class="nav-list">
|
52
52
|
|
53
|
-
<li class="nav-header <%= "active" if !@current[:name] %>"><a href="index.html">Home</a></li>
|
54
|
-
|
55
53
|
<% @chapters.each do |chapter| %>
|
56
54
|
|
57
55
|
<li class="nav-header <%= "active" if chapter[:name] == @current[:name] %>">
|
58
|
-
<a href="
|
56
|
+
<a href="/documentation/<%= chapter[:out] %>"><%= chapter[:name] %></a></li>
|
59
57
|
|
60
58
|
<% chapter[:sections].each do |section| %>
|
61
59
|
<li class="nav-item" >
|
data/lib/webapidoc.rb
CHANGED
@@ -1,117 +1,9 @@
|
|
1
|
-
# WebApiDoc
|
2
|
-
# Static HTML Documentation for JSON APIs
|
3
|
-
|
4
|
-
#
|
5
|
-
# Example:
|
6
|
-
# >> WebApiDoc.build({:title => "WebApiDoc"})
|
7
|
-
#
|
8
|
-
# Arguments:
|
9
|
-
# - data object accessible via @data in templates
|
10
|
-
#
|
11
|
-
# Info
|
12
|
-
# - chapter info is accessible via @chapters in templates
|
13
|
-
#
|
14
|
-
|
15
1
|
require 'maruku'
|
16
2
|
require 'yaml'
|
17
3
|
require 'fileutils'
|
18
4
|
require 'erb'
|
19
5
|
require 'sass'
|
20
6
|
|
21
|
-
|
22
|
-
|
23
|
-
def self.build(data=nil)
|
24
|
-
|
25
|
-
@data = data
|
26
|
-
|
27
|
-
publicDir = "public/documentation"
|
28
|
-
docDir = "app/documentation"
|
29
|
-
libDir = "lib/webapidoc"
|
30
|
-
|
31
|
-
# get config hash
|
32
|
-
config = YAML.load_file('config/webapidoc.yml').freeze
|
33
|
-
|
34
|
-
puts "building webapidoc for " + config["title"]
|
35
|
-
|
36
|
-
# clean up
|
37
|
-
FileUtils.remove_dir publicDir if File.exists?(publicDir)
|
38
|
-
|
39
|
-
# create paths
|
40
|
-
FileUtils.mkdir_p publicDir
|
41
|
-
FileUtils.mkdir publicDir + "/css"
|
42
|
-
FileUtils.mkdir publicDir + "/js"
|
43
|
-
|
44
|
-
# copy jquery
|
45
|
-
FileUtils.copy(libDir + "/js/jquery.js", publicDir + "/js/jquery.js")
|
46
|
-
|
47
|
-
# copy highlighter
|
48
|
-
FileUtils.copy(libDir + "/js/highlight.js", publicDir + "/js/highlight.js")
|
49
|
-
|
50
|
-
# compile webapidoc style
|
51
|
-
sass_filename = libDir + "/css/webapidoc.scss"
|
52
|
-
css = Sass::Engine.for_file(sass_filename, {:style => :compressed}).render
|
53
|
-
File.open(publicDir + "/css/webapidoc.css", "wb") {|f| f.write(css) }
|
54
|
-
|
55
|
-
# parse chapters and create html from md
|
56
|
-
@chapters = []
|
57
|
-
|
58
|
-
# get chapter info
|
59
|
-
config["chapters"].each_with_index do | chapter, idx|
|
60
|
-
|
61
|
-
inFile = "#{docDir}/#{chapter["file"]}.md"
|
62
|
-
outFile = "%02d_%s.html" % [idx.to_s, chapter["file"]]
|
63
|
-
|
64
|
-
if File.exists?(inFile + ".erb" )
|
65
|
-
inFile = inFile + ".erb"
|
66
|
-
end
|
67
|
-
|
68
|
-
if File.exists?(inFile)
|
69
|
-
contents = File.open(inFile, 'r').read
|
70
|
-
else
|
71
|
-
puts "file not found: #{inFile}"
|
72
|
-
next
|
73
|
-
end
|
74
|
-
|
75
|
-
@chapters << { :name => chapter["name"], :out => outFile, :in => inFile}
|
76
|
-
end
|
77
|
-
|
78
|
-
@chapters.each_with_index do | chapter, idx|
|
79
|
-
|
80
|
-
contents = ERB.new(File.open(chapter[:in], 'r').read).result(binding)
|
81
|
-
maruku = Maruku.new(contents)
|
82
|
-
|
83
|
-
# get content info for subsections ( side pane navigation )
|
84
|
-
sections = []
|
85
|
-
maruku.each_element(:header) do | el |
|
86
|
-
next unless el.meta_priv.to_s == "level2"
|
87
|
-
sections << el.children[0]
|
88
|
-
end
|
89
|
-
|
90
|
-
chapter[:html] = maruku.to_html
|
91
|
-
chapter[:sections] = sections
|
92
|
-
end
|
93
|
-
|
94
|
-
# open template
|
95
|
-
template = "#{libDir}/template.html.erb"
|
96
|
-
|
97
|
-
# build chapter files
|
98
|
-
@chapters.each do | chapter |
|
99
|
-
|
100
|
-
# bindings
|
101
|
-
@html = chapter[:html]
|
102
|
-
@current = chapter
|
103
|
-
puts "building #{chapter[:name]}"
|
104
|
-
# write it
|
105
|
-
File.open("#{publicDir}/#{chapter[:out]}", 'w') { |file| file.write(ERB.new(File.open(template, 'r').read).result(binding)) }
|
106
|
-
end
|
107
|
-
|
108
|
-
# build index file, reset bindings
|
109
|
-
contents = ERB.new(File.open("#{libDir}/index.md.erb", 'r').read).result(binding)
|
110
|
-
|
111
|
-
@html = Maruku.new(contents).to_html
|
112
|
-
@current = {}
|
113
|
-
File.open("#{publicDir}/index.html", 'w') { |file| file.write(ERB.new(File.open(template, 'r').read).result(binding)) }
|
114
|
-
|
115
|
-
end
|
7
|
+
require 'webapidoc/version'
|
8
|
+
require 'webapidoc/base'
|
116
9
|
|
117
|
-
end
|
data/webapidoc.gemspec
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "webapidoc/version"
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version =
|
6
|
+
s.name = Webapidoc::NAME
|
7
|
+
s.version = Webapidoc::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
6
9
|
s.date = '2012-12-03'
|
7
10
|
|
8
11
|
s.summary = "Static HTML Documentation for JSON Web APIs."
|
@@ -11,11 +14,14 @@ Gem::Specification.new do |s|
|
|
11
14
|
s.email = 'aliasng@gmail.com'
|
12
15
|
|
13
16
|
s.files = `git ls-files`.split("\n")
|
14
|
-
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
19
|
s.require_paths = ["lib"]
|
16
20
|
|
17
21
|
s.add_dependency('maruku', '>= 0.6.1')
|
18
22
|
s.add_dependency('sass', '>= 3.1.19')
|
19
23
|
|
20
|
-
s.
|
24
|
+
s.add_development_dependency 'rake'
|
25
|
+
|
26
|
+
s.homepage = 'https://github.com/otty/webapidoc'
|
21
27
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webapidoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adrian Fuhrmann
|
@@ -49,6 +49,20 @@ dependencies:
|
|
49
49
|
version: 3.1.19
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: rake
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
52
66
|
description: Create a static HTML Documentation for your JSON Web API.
|
53
67
|
email: aliasng@gmail.com
|
54
68
|
executables: []
|
@@ -60,17 +74,21 @@ extra_rdoc_files: []
|
|
60
74
|
files:
|
61
75
|
- .gitignore
|
62
76
|
- README.md
|
63
|
-
-
|
64
|
-
-
|
77
|
+
- Rakefile
|
78
|
+
- lib/generators/webapidoc/install_generator.rb
|
79
|
+
- lib/generators/webapidoc/templates/index.md.erb
|
80
|
+
- lib/generators/webapidoc/templates/sample.md.erb
|
81
|
+
- lib/generators/webapidoc/templates/webapidoc.yml
|
65
82
|
- lib/webapidoc.rb
|
83
|
+
- lib/webapidoc/base.rb
|
66
84
|
- lib/webapidoc/css/webapidoc.scss
|
67
|
-
- lib/webapidoc/index.md.erb
|
68
85
|
- lib/webapidoc/js/highlight.js
|
69
86
|
- lib/webapidoc/js/html5.js
|
70
87
|
- lib/webapidoc/js/jquery.js
|
71
88
|
- lib/webapidoc/template.html.erb
|
89
|
+
- lib/webapidoc/version.rb
|
72
90
|
- webapidoc.gemspec
|
73
|
-
homepage:
|
91
|
+
homepage: https://github.com/otty/webapidoc
|
74
92
|
licenses: []
|
75
93
|
|
76
94
|
post_install_message:
|