erlapi 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +15 -0
  5. data/Rakefile +56 -0
  6. data/VERSION +1 -0
  7. data/bin/erlapi +26 -0
  8. data/erlapi.gemspec +140 -0
  9. data/lib/erlapi.rb +38 -0
  10. data/lib/erlapi/generator.rb +194 -0
  11. data/lib/erlapi/generator/shtml.rb +353 -0
  12. data/lib/erlapi/generator/template/direct/_context.rhtml +172 -0
  13. data/lib/erlapi/generator/template/direct/class.rhtml +40 -0
  14. data/lib/erlapi/generator/template/direct/file.rhtml +30 -0
  15. data/lib/erlapi/generator/template/direct/index.rhtml +14 -0
  16. data/lib/erlapi/generator/template/direct/resources/apple-touch-icon.png +0 -0
  17. data/lib/erlapi/generator/template/direct/resources/css/main.css +263 -0
  18. data/lib/erlapi/generator/template/direct/resources/css/panel.css +383 -0
  19. data/lib/erlapi/generator/template/direct/resources/css/reset.css +53 -0
  20. data/lib/erlapi/generator/template/direct/resources/favicon.ico +0 -0
  21. data/lib/erlapi/generator/template/direct/resources/i/arrows.png +0 -0
  22. data/lib/erlapi/generator/template/direct/resources/i/results_bg.png +0 -0
  23. data/lib/erlapi/generator/template/direct/resources/i/tree_bg.png +0 -0
  24. data/lib/erlapi/generator/template/direct/resources/js/jquery-1.3.2.min.js +19 -0
  25. data/lib/erlapi/generator/template/direct/resources/js/jquery-effect.js +593 -0
  26. data/lib/erlapi/generator/template/direct/resources/js/main.js +22 -0
  27. data/lib/erlapi/generator/template/direct/resources/js/searchdoc.js +628 -0
  28. data/lib/erlapi/generator/template/direct/resources/panel/index.html +71 -0
  29. data/lib/erlapi/generator/template/merge/index.rhtml +14 -0
  30. data/lib/erlapi/generator/template/shtml/_context.rhtml +164 -0
  31. data/lib/erlapi/generator/template/shtml/class.rhtml +46 -0
  32. data/lib/erlapi/generator/template/shtml/file.rhtml +37 -0
  33. data/lib/erlapi/generator/template/shtml/index.rhtml +14 -0
  34. data/lib/erlapi/generator/template/shtml/resources/apple-touch-icon.png +0 -0
  35. data/lib/erlapi/generator/template/shtml/resources/css/main.css +191 -0
  36. data/lib/erlapi/generator/template/shtml/resources/css/panel.css +383 -0
  37. data/lib/erlapi/generator/template/shtml/resources/css/reset.css +53 -0
  38. data/lib/erlapi/generator/template/shtml/resources/favicon.ico +0 -0
  39. data/lib/erlapi/generator/template/shtml/resources/i/arrows.png +0 -0
  40. data/lib/erlapi/generator/template/shtml/resources/i/results_bg.png +0 -0
  41. data/lib/erlapi/generator/template/shtml/resources/i/tree_bg.png +0 -0
  42. data/lib/erlapi/generator/template/shtml/resources/js/jquery-1.3.2.min.js +19 -0
  43. data/lib/erlapi/generator/template/shtml/resources/js/main.js +34 -0
  44. data/lib/erlapi/generator/template/shtml/resources/js/searchdoc.js +628 -0
  45. data/lib/erlapi/generator/template/shtml/resources/panel/index.html +71 -0
  46. data/lib/erlapi/helpers.rb +26 -0
  47. data/lib/erlapi/merge.rb +217 -0
  48. data/lib/erlapi/parser.rb +134 -0
  49. data/lib/erlapi/shtml.rb +351 -0
  50. data/lib/erlapi/templatable.rb +51 -0
  51. data/lib/erlapi/templates/html/direct/_context.rhtml +172 -0
  52. data/lib/erlapi/templates/html/direct/class.rhtml +40 -0
  53. data/lib/erlapi/templates/html/direct/file.rhtml +30 -0
  54. data/lib/erlapi/templates/html/direct/index.rhtml +14 -0
  55. data/lib/erlapi/templates/html/direct/resources/apple-touch-icon.png +0 -0
  56. data/lib/erlapi/templates/html/direct/resources/css/main.css +263 -0
  57. data/lib/erlapi/templates/html/direct/resources/css/panel.css +383 -0
  58. data/lib/erlapi/templates/html/direct/resources/css/reset.css +53 -0
  59. data/lib/erlapi/templates/html/direct/resources/favicon.ico +0 -0
  60. data/lib/erlapi/templates/html/direct/resources/i/arrows.png +0 -0
  61. data/lib/erlapi/templates/html/direct/resources/i/results_bg.png +0 -0
  62. data/lib/erlapi/templates/html/direct/resources/i/tree_bg.png +0 -0
  63. data/lib/erlapi/templates/html/direct/resources/js/jquery-1.3.2.min.js +19 -0
  64. data/lib/erlapi/templates/html/direct/resources/js/jquery-effect.js +593 -0
  65. data/lib/erlapi/templates/html/direct/resources/js/main.js +22 -0
  66. data/lib/erlapi/templates/html/direct/resources/js/searchdoc.js +628 -0
  67. data/lib/erlapi/templates/html/direct/resources/panel/index.html +71 -0
  68. data/lib/erlapi/templates/html/merge/index.rhtml +14 -0
  69. data/lib/erlapi/templates/html/shtml/_context.rhtml +68 -0
  70. data/lib/erlapi/templates/html/shtml/class.rhtml +25 -0
  71. data/lib/erlapi/templates/html/shtml/file.rhtml +37 -0
  72. data/lib/erlapi/templates/html/shtml/index.rhtml +14 -0
  73. data/lib/erlapi/templates/html/shtml/resources copy/apple-touch-icon.png +0 -0
  74. data/lib/erlapi/templates/html/shtml/resources copy/css/main.css +195 -0
  75. data/lib/erlapi/templates/html/shtml/resources copy/css/panel.css +383 -0
  76. data/lib/erlapi/templates/html/shtml/resources copy/css/reset.css +53 -0
  77. data/lib/erlapi/templates/html/shtml/resources copy/favicon.ico +0 -0
  78. data/lib/erlapi/templates/html/shtml/resources copy/i/arrows.png +0 -0
  79. data/lib/erlapi/templates/html/shtml/resources copy/i/results_bg.png +0 -0
  80. data/lib/erlapi/templates/html/shtml/resources copy/i/tree_bg.png +0 -0
  81. data/lib/erlapi/templates/html/shtml/resources copy/js/jquery-1.3.2.min.js +19 -0
  82. data/lib/erlapi/templates/html/shtml/resources copy/js/main.js +34 -0
  83. data/lib/erlapi/templates/html/shtml/resources copy/js/searchdoc.js +628 -0
  84. data/lib/erlapi/templates/html/shtml/resources copy/panel/index.html +71 -0
  85. data/lib/erlapi/templates/html/shtml/resources/apple-touch-icon.png +0 -0
  86. data/lib/erlapi/templates/html/shtml/resources/css/main.css +263 -0
  87. data/lib/erlapi/templates/html/shtml/resources/css/panel.css +383 -0
  88. data/lib/erlapi/templates/html/shtml/resources/css/reset.css +53 -0
  89. data/lib/erlapi/templates/html/shtml/resources/favicon.ico +0 -0
  90. data/lib/erlapi/templates/html/shtml/resources/i/arrows.png +0 -0
  91. data/lib/erlapi/templates/html/shtml/resources/i/results_bg.png +0 -0
  92. data/lib/erlapi/templates/html/shtml/resources/i/tree_bg.png +0 -0
  93. data/lib/erlapi/templates/html/shtml/resources/js/jquery-1.3.2.min.js +19 -0
  94. data/lib/erlapi/templates/html/shtml/resources/js/jquery-effect.js +593 -0
  95. data/lib/erlapi/templates/html/shtml/resources/js/main.js +22 -0
  96. data/lib/erlapi/templates/html/shtml/resources/js/searchdoc.js +620 -0
  97. data/lib/erlapi/templates/html/shtml/resources/panel/index.html +71 -0
  98. data/test/erlapi_test.rb +7 -0
  99. data/test/test_helper.rb +10 -0
  100. metadata +155 -0
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Andrew Rudenko
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ = erlapi
2
+
3
+ Generate searchable api docs for elang libs.
4
+
5
+ Based on http://railsapi.com/.
6
+
7
+ Result for all Erlang OTP sources – http://erlapi.prepor.ru/docs/
8
+
9
+ == Usage
10
+
11
+ erlapi -o ~/Docs/erlang -s dir/to/erlang/sources
12
+
13
+ == Copyright
14
+
15
+ Copyright (c) 2009 Andrew Rudenko. See LICENSE for details.
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "erlapi"
8
+ gem.summary = %Q{Searchable erlang api generator}
9
+ gem.email = "ceo@prepor.ru"
10
+ gem.homepage = "http://github.com/prepor/erlapi"
11
+ gem.authors = ["Andrew Rudenko"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "erlapi #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.9
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/erlapi'
4
+
5
+ require 'optparse'
6
+
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: erlapi -o [output_dir] -s [source_dir]"
10
+
11
+ opts.on("-o", "--output OUTPUT_DIR", "Output dir") do |o|
12
+ options[:output_dir] = o
13
+ end
14
+
15
+ opts.on("-s", "--source SOURCE_DIR", "Source dir with erlang docs") do |s|
16
+ options[:source_dir] = s
17
+ end
18
+
19
+ opts.on_tail("-h", "--help", "Show this message") do
20
+ puts opts
21
+ exit
22
+ end
23
+
24
+ end.parse!
25
+
26
+ Erlapi::Cmd.start!(options)
@@ -0,0 +1,140 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{erlapi}
8
+ s.version = "0.1.9"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andrew Rudenko"]
12
+ s.date = %q{2009-12-13}
13
+ s.default_executable = %q{erlapi}
14
+ s.email = %q{ceo@prepor.ru}
15
+ s.executables = ["erlapi"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bin/erlapi",
28
+ "erlapi.gemspec",
29
+ "lib/erlapi.rb",
30
+ "lib/erlapi/generator.rb",
31
+ "lib/erlapi/generator/shtml.rb",
32
+ "lib/erlapi/generator/template/direct/_context.rhtml",
33
+ "lib/erlapi/generator/template/direct/class.rhtml",
34
+ "lib/erlapi/generator/template/direct/file.rhtml",
35
+ "lib/erlapi/generator/template/direct/index.rhtml",
36
+ "lib/erlapi/generator/template/direct/resources/apple-touch-icon.png",
37
+ "lib/erlapi/generator/template/direct/resources/css/main.css",
38
+ "lib/erlapi/generator/template/direct/resources/css/panel.css",
39
+ "lib/erlapi/generator/template/direct/resources/css/reset.css",
40
+ "lib/erlapi/generator/template/direct/resources/favicon.ico",
41
+ "lib/erlapi/generator/template/direct/resources/i/arrows.png",
42
+ "lib/erlapi/generator/template/direct/resources/i/results_bg.png",
43
+ "lib/erlapi/generator/template/direct/resources/i/tree_bg.png",
44
+ "lib/erlapi/generator/template/direct/resources/js/jquery-1.3.2.min.js",
45
+ "lib/erlapi/generator/template/direct/resources/js/jquery-effect.js",
46
+ "lib/erlapi/generator/template/direct/resources/js/main.js",
47
+ "lib/erlapi/generator/template/direct/resources/js/searchdoc.js",
48
+ "lib/erlapi/generator/template/direct/resources/panel/index.html",
49
+ "lib/erlapi/generator/template/merge/index.rhtml",
50
+ "lib/erlapi/generator/template/shtml/_context.rhtml",
51
+ "lib/erlapi/generator/template/shtml/class.rhtml",
52
+ "lib/erlapi/generator/template/shtml/file.rhtml",
53
+ "lib/erlapi/generator/template/shtml/index.rhtml",
54
+ "lib/erlapi/generator/template/shtml/resources/apple-touch-icon.png",
55
+ "lib/erlapi/generator/template/shtml/resources/css/main.css",
56
+ "lib/erlapi/generator/template/shtml/resources/css/panel.css",
57
+ "lib/erlapi/generator/template/shtml/resources/css/reset.css",
58
+ "lib/erlapi/generator/template/shtml/resources/favicon.ico",
59
+ "lib/erlapi/generator/template/shtml/resources/i/arrows.png",
60
+ "lib/erlapi/generator/template/shtml/resources/i/results_bg.png",
61
+ "lib/erlapi/generator/template/shtml/resources/i/tree_bg.png",
62
+ "lib/erlapi/generator/template/shtml/resources/js/jquery-1.3.2.min.js",
63
+ "lib/erlapi/generator/template/shtml/resources/js/main.js",
64
+ "lib/erlapi/generator/template/shtml/resources/js/searchdoc.js",
65
+ "lib/erlapi/generator/template/shtml/resources/panel/index.html",
66
+ "lib/erlapi/helpers.rb",
67
+ "lib/erlapi/merge.rb",
68
+ "lib/erlapi/parser.rb",
69
+ "lib/erlapi/shtml.rb",
70
+ "lib/erlapi/templatable.rb",
71
+ "lib/erlapi/templates/html/direct/_context.rhtml",
72
+ "lib/erlapi/templates/html/direct/class.rhtml",
73
+ "lib/erlapi/templates/html/direct/file.rhtml",
74
+ "lib/erlapi/templates/html/direct/index.rhtml",
75
+ "lib/erlapi/templates/html/direct/resources/apple-touch-icon.png",
76
+ "lib/erlapi/templates/html/direct/resources/css/main.css",
77
+ "lib/erlapi/templates/html/direct/resources/css/panel.css",
78
+ "lib/erlapi/templates/html/direct/resources/css/reset.css",
79
+ "lib/erlapi/templates/html/direct/resources/favicon.ico",
80
+ "lib/erlapi/templates/html/direct/resources/i/arrows.png",
81
+ "lib/erlapi/templates/html/direct/resources/i/results_bg.png",
82
+ "lib/erlapi/templates/html/direct/resources/i/tree_bg.png",
83
+ "lib/erlapi/templates/html/direct/resources/js/jquery-1.3.2.min.js",
84
+ "lib/erlapi/templates/html/direct/resources/js/jquery-effect.js",
85
+ "lib/erlapi/templates/html/direct/resources/js/main.js",
86
+ "lib/erlapi/templates/html/direct/resources/js/searchdoc.js",
87
+ "lib/erlapi/templates/html/direct/resources/panel/index.html",
88
+ "lib/erlapi/templates/html/merge/index.rhtml",
89
+ "lib/erlapi/templates/html/shtml/_context.rhtml",
90
+ "lib/erlapi/templates/html/shtml/class.rhtml",
91
+ "lib/erlapi/templates/html/shtml/file.rhtml",
92
+ "lib/erlapi/templates/html/shtml/index.rhtml",
93
+ "lib/erlapi/templates/html/shtml/resources copy/apple-touch-icon.png",
94
+ "lib/erlapi/templates/html/shtml/resources copy/css/main.css",
95
+ "lib/erlapi/templates/html/shtml/resources copy/css/panel.css",
96
+ "lib/erlapi/templates/html/shtml/resources copy/css/reset.css",
97
+ "lib/erlapi/templates/html/shtml/resources copy/favicon.ico",
98
+ "lib/erlapi/templates/html/shtml/resources copy/i/arrows.png",
99
+ "lib/erlapi/templates/html/shtml/resources copy/i/results_bg.png",
100
+ "lib/erlapi/templates/html/shtml/resources copy/i/tree_bg.png",
101
+ "lib/erlapi/templates/html/shtml/resources copy/js/jquery-1.3.2.min.js",
102
+ "lib/erlapi/templates/html/shtml/resources copy/js/main.js",
103
+ "lib/erlapi/templates/html/shtml/resources copy/js/searchdoc.js",
104
+ "lib/erlapi/templates/html/shtml/resources copy/panel/index.html",
105
+ "lib/erlapi/templates/html/shtml/resources/apple-touch-icon.png",
106
+ "lib/erlapi/templates/html/shtml/resources/css/main.css",
107
+ "lib/erlapi/templates/html/shtml/resources/css/panel.css",
108
+ "lib/erlapi/templates/html/shtml/resources/css/reset.css",
109
+ "lib/erlapi/templates/html/shtml/resources/favicon.ico",
110
+ "lib/erlapi/templates/html/shtml/resources/i/arrows.png",
111
+ "lib/erlapi/templates/html/shtml/resources/i/results_bg.png",
112
+ "lib/erlapi/templates/html/shtml/resources/i/tree_bg.png",
113
+ "lib/erlapi/templates/html/shtml/resources/js/jquery-1.3.2.min.js",
114
+ "lib/erlapi/templates/html/shtml/resources/js/jquery-effect.js",
115
+ "lib/erlapi/templates/html/shtml/resources/js/main.js",
116
+ "lib/erlapi/templates/html/shtml/resources/js/searchdoc.js",
117
+ "lib/erlapi/templates/html/shtml/resources/panel/index.html",
118
+ "test/erlapi_test.rb",
119
+ "test/test_helper.rb"
120
+ ]
121
+ s.homepage = %q{http://github.com/prepor/erlapi}
122
+ s.rdoc_options = ["--charset=UTF-8"]
123
+ s.require_paths = ["lib"]
124
+ s.rubygems_version = %q{1.3.5}
125
+ s.summary = %q{Searchable erlang api generator}
126
+ s.test_files = [
127
+ "test/erlapi_test.rb",
128
+ "test/test_helper.rb"
129
+ ]
130
+
131
+ if s.respond_to? :specification_version then
132
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
133
+ s.specification_version = 3
134
+
135
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
136
+ else
137
+ end
138
+ else
139
+ end
140
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'erb'
4
+ require 'ostruct'
5
+ if Gem.available? "json"
6
+ gem "json", ">= 1.1.3"
7
+ else
8
+ gem "json_pure", ">= 1.1.3"
9
+ end
10
+ module Erlapi
11
+ require 'erlapi/helpers'
12
+ require 'erlapi/templatable'
13
+
14
+ require 'erlapi/parser'
15
+ require 'erlapi/generator'
16
+
17
+ class Cmd
18
+ class << self
19
+ def start!(options)
20
+ if !options[:source_dir] || !options[:output_dir]
21
+ raise "You must define source and output dirs"
22
+ end
23
+
24
+ pa = Erlapi::Parser::Base.new(options[:source_dir])
25
+
26
+ pa.parse
27
+
28
+ ge = Erlapi::Generator.new(:data => pa.modules, :output_dir => options[:output_dir])
29
+
30
+ options = OpenStruct.new( {:charset => 'utf-8', :title => 'Erlang API'})
31
+ ge.generate(options)
32
+
33
+ puts 'Generating completed'
34
+ end
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,194 @@
1
+ require 'pathname'
2
+ class Erlapi::Generator
3
+ attr_accessor :data, :output_dir, :source_dir
4
+
5
+ GENERATOR_DIRS = [File.join('sdoc', 'generator'), File.join('rdoc', 'generator')]
6
+
7
+ # Used in js to reduce index sizes
8
+ TYPE_CLASS = 1
9
+ TYPE_METHOD = 2
10
+ TYPE_FILE = 3
11
+
12
+
13
+ TEMPLATE_DIR = Pathname.new(File.dirname(__FILE__)) + 'templates' + 'html' + 'shtml'
14
+
15
+
16
+ FILE_DIR = 'files'
17
+ CLASS_DIR = 'classes'
18
+
19
+ RESOURCES_DIR = 'resources'
20
+
21
+
22
+ include ERB::Util
23
+ include Erlapi::Templatable
24
+ include Erlapi::Helpers
25
+
26
+ def initialize(options = {})
27
+ self.output_dir = Pathname.new(options[:output_dir])
28
+
29
+ self.output_dir.mkdir if !self.output_dir.directory?
30
+
31
+ self.data = options[:data]
32
+ define_paths
33
+ end
34
+
35
+ def define_paths
36
+ @tree_file = output_dir + 'panel' + 'tree.js'
37
+ @search_index_file = output_dir + 'panel' + 'search_index.js'
38
+ end
39
+
40
+ def generate(options = {})
41
+ @options = options
42
+ copy_resources
43
+ generate_search_index
44
+ generate_class_tree
45
+ generate_class_files
46
+ generate_index_file
47
+ end
48
+
49
+ ### Copy all the resource files to output dir
50
+ def copy_resources
51
+ resources_path = File.join(TEMPLATE_DIR, RESOURCES_DIR) + '/.'
52
+ debug_msg "Copying #{resources_path}/** to #{output_dir}/**"
53
+ FileUtils.cp_r resources_path.to_s, output_dir.to_s, :preserve => true
54
+ end
55
+
56
+ ### Generate a documentation file for each class
57
+ def generate_class_files
58
+ debug_msg "Generating class documentation in #{output_dir}"
59
+ templatefile = TEMPLATE_DIR + 'class.rhtml'
60
+
61
+ self.data.each do |mod_name, mod|
62
+ if mod_name
63
+ debug_msg " working on %s" % [ mod.title]
64
+ outfile = output_dir + (mod.title + '.html')
65
+ # rel_prefix = OUTPUT_DIR.relative_path_from( outfile.dirname )
66
+
67
+ debug_msg " rendering #{outfile}"
68
+ self.render_template( templatefile, binding(), outfile )
69
+ end
70
+ end
71
+ end
72
+
73
+ ### Create index.html with frameset
74
+ def generate_index_file
75
+ debug_msg "Generating index file in #{output_dir}"
76
+ templatefile = TEMPLATE_DIR + 'index.rhtml'
77
+ outfile = output_dir + 'index.html'
78
+ index_path = self.data.to_a.first[1].title + '.html'
79
+ self.render_template( templatefile, binding(), outfile )
80
+ end
81
+
82
+ ### Create class tree structure and write it as json
83
+ def generate_class_tree
84
+ debug_msg "Generating class tree"
85
+ tree = self.data.map { |mod_name, mod| [mod_name, mod_name + '.html', '', []] }.sort{ |a, b| a[0] <=> b[0] }
86
+ debug_msg " writing class tree to %s" % @tree_file
87
+ File.open(@tree_file, "w", 0644) do |f|
88
+ f.write('var tree = '); f.write(tree.to_json)
89
+ end
90
+ end
91
+
92
+ def generate_search_index
93
+ debug_msg "Generating search index"
94
+
95
+ index = {
96
+ :searchIndex => [],
97
+ :longSearchIndex => [],
98
+ :info => []
99
+ }
100
+
101
+ add_class_search_index(index)
102
+ add_method_search_index(index)
103
+
104
+ debug_msg " writing search index to %s" % @search_index_file
105
+ data = {
106
+ :index => index
107
+ }
108
+ File.open(@search_index_file, "w", 0644) do |f|
109
+ f.write('var search_data = '); f.write(data.to_json)
110
+ end
111
+ end
112
+
113
+
114
+ ### Add classes to search +index+ array
115
+ def add_class_search_index(index)
116
+ debug_msg " generating class search index"
117
+
118
+ self.data.each do |mod_name, mod|
119
+ index[:searchIndex].push( search_string(mod.title) )
120
+ index[:longSearchIndex].push( search_string(mod.title) )
121
+ index[:info].push([
122
+ mod.title,
123
+ '',
124
+ mod.title + '.html',
125
+ '',
126
+ snippet(mod.summary),
127
+ TYPE_CLASS
128
+ ])
129
+ end
130
+ end
131
+
132
+ ### Add methods to search +index+ array
133
+ def add_method_search_index(index)
134
+ debug_msg " generating method search index"
135
+
136
+ list = self.data.map { |mod_name, mod|
137
+ mod.funcs
138
+ }.flatten
139
+
140
+ list.each do |func|
141
+ func.short_names.each do |func_name|
142
+ index[:searchIndex].push( search_string(func.p_module.title + ':' + func_name) + '()' )
143
+ index[:longSearchIndex].push(search_string(func_name))
144
+ index[:info].push([
145
+ func_name,
146
+ func.p_module.title + ':' + func_name,
147
+ func.p_module.title + '.html#' + func.ref,
148
+ '',
149
+ snippet(func.summary),
150
+ TYPE_METHOD
151
+ ])
152
+ end
153
+ end
154
+ end
155
+
156
+
157
+
158
+ ### Build search index key
159
+ def search_string(string)
160
+ string ||= ''
161
+ string.downcase.gsub(/\s/,'')
162
+ end
163
+
164
+ def snippet(str)
165
+ str ||= ''
166
+ if str =~ /^(?>\s*)[^\#]/
167
+ content = str
168
+ else
169
+ content = str.gsub(/^\s*(#+)\s*/, '')
170
+ end
171
+
172
+ content = content.sub(/^(.{100,}?)\s.*/m, "\\1").gsub(/\r?\n/m, ' ')
173
+
174
+ begin
175
+ content.to_json
176
+ rescue # might fail on non-unicode string
177
+ begin
178
+ content = Iconv.conv('latin1//ignore', "UTF8", content) # remove all non-unicode chars
179
+ content.to_json
180
+ rescue
181
+ content = '' # something hugely wrong happend
182
+ end
183
+ end
184
+ content
185
+ end
186
+
187
+ ### Output progress information if debugging is enabled
188
+ def debug_msg( *msg )
189
+ return unless $DEBUG_DOC
190
+ $stderr.puts( *msg )
191
+ end
192
+
193
+
194
+ end