jsduck 4.0.1 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. data/Rakefile +14 -0
  2. data/esprima/esprima.js +210 -85
  3. data/jsduck.gemspec +3 -3
  4. data/lib/jsduck/accessors.rb +10 -8
  5. data/lib/jsduck/aggregator.rb +7 -7
  6. data/lib/jsduck/app.rb +24 -164
  7. data/lib/jsduck/app_data.rb +2 -4
  8. data/lib/jsduck/assets.rb +5 -2
  9. data/lib/jsduck/ast.rb +9 -4
  10. data/lib/jsduck/batch_formatter.rb +54 -0
  11. data/lib/jsduck/batch_parser.rb +106 -0
  12. data/lib/jsduck/categories.rb +5 -6
  13. data/lib/jsduck/class.rb +77 -239
  14. data/lib/jsduck/class_doc_expander.rb +0 -5
  15. data/lib/jsduck/class_formatter.rb +14 -10
  16. data/lib/jsduck/class_name.rb +23 -0
  17. data/lib/jsduck/class_writer.rb +9 -8
  18. data/lib/jsduck/doc_ast.rb +5 -6
  19. data/lib/jsduck/doc_formatter.rb +61 -272
  20. data/lib/jsduck/enum.rb +4 -4
  21. data/lib/jsduck/esprima.rb +10 -4
  22. data/lib/jsduck/examples.rb +5 -5
  23. data/lib/jsduck/export_writer.rb +62 -0
  24. data/lib/jsduck/exporter/app.rb +62 -0
  25. data/lib/jsduck/exporter/examples.rb +58 -0
  26. data/lib/jsduck/exporter/full.rb +60 -0
  27. data/lib/jsduck/file_categories.rb +7 -4
  28. data/lib/jsduck/function_ast.rb +99 -0
  29. data/lib/jsduck/grouped_asset.rb +27 -16
  30. data/lib/jsduck/guide_writer.rb +8 -7
  31. data/lib/jsduck/guides.rb +31 -29
  32. data/lib/jsduck/icons.rb +12 -1
  33. data/lib/jsduck/images.rb +3 -3
  34. data/lib/jsduck/importer.rb +7 -7
  35. data/lib/jsduck/index_html.rb +20 -6
  36. data/lib/jsduck/inherit_doc.rb +9 -12
  37. data/lib/jsduck/inline/example.rb +42 -0
  38. data/lib/jsduck/inline/img.rb +55 -0
  39. data/lib/jsduck/inline/link.rb +227 -0
  40. data/lib/jsduck/inline/video.rb +67 -0
  41. data/lib/jsduck/inline_examples.rb +7 -7
  42. data/lib/jsduck/js_parser.rb +5 -4
  43. data/lib/jsduck/lint.rb +14 -2
  44. data/lib/jsduck/logger.rb +5 -6
  45. data/lib/jsduck/members_index.rb +132 -0
  46. data/lib/jsduck/merger.rb +3 -9
  47. data/lib/jsduck/options.rb +39 -41
  48. data/lib/jsduck/override.rb +3 -7
  49. data/lib/jsduck/relations.rb +9 -9
  50. data/lib/jsduck/renderer.rb +3 -3
  51. data/lib/jsduck/return_values.rb +72 -0
  52. data/lib/jsduck/search_data.rb +16 -20
  53. data/lib/jsduck/shortener.rb +58 -0
  54. data/lib/jsduck/signature_renderer.rb +1 -2
  55. data/lib/jsduck/source/file.rb +98 -0
  56. data/lib/jsduck/source/file_parser.rb +72 -0
  57. data/lib/jsduck/source/writer.rb +89 -0
  58. data/lib/jsduck/tag/aside.rb +1 -1
  59. data/lib/jsduck/tag/since.rb +1 -1
  60. data/lib/jsduck/template_dir.rb +2 -2
  61. data/lib/jsduck/util/html.rb +27 -0
  62. data/lib/jsduck/util/io.rb +32 -0
  63. data/lib/jsduck/util/json.rb +60 -0
  64. data/lib/jsduck/util/null_object.rb +23 -0
  65. data/lib/jsduck/util/os.rb +14 -0
  66. data/lib/jsduck/util/parallel.rb +34 -0
  67. data/lib/jsduck/util/singleton.rb +35 -0
  68. data/lib/jsduck/util/stdout.rb +33 -0
  69. data/lib/jsduck/videos.rb +5 -5
  70. data/lib/jsduck/web_writer.rb +79 -0
  71. data/lib/jsduck/welcome.rb +6 -6
  72. data/spec/class_factory.rb +20 -0
  73. metadata +32 -20
  74. data/lib/jsduck/api_exporter.rb +0 -48
  75. data/lib/jsduck/app_exporter.rb +0 -60
  76. data/lib/jsduck/examples_exporter.rb +0 -56
  77. data/lib/jsduck/full_exporter.rb +0 -35
  78. data/lib/jsduck/html.rb +0 -25
  79. data/lib/jsduck/inline_img.rb +0 -53
  80. data/lib/jsduck/inline_video.rb +0 -58
  81. data/lib/jsduck/io.rb +0 -30
  82. data/lib/jsduck/json_duck.rb +0 -52
  83. data/lib/jsduck/lexer.rb +0 -251
  84. data/lib/jsduck/null_object.rb +0 -19
  85. data/lib/jsduck/os.rb +0 -11
  86. data/lib/jsduck/parallel_wrap.rb +0 -32
  87. data/lib/jsduck/source_file.rb +0 -97
  88. data/lib/jsduck/source_file_parser.rb +0 -70
  89. data/lib/jsduck/source_writer.rb +0 -87
  90. data/lib/jsduck/stats.rb +0 -103
  91. data/lib/jsduck/stdout.rb +0 -31
@@ -1,97 +0,0 @@
1
- require 'jsduck/source_file_parser'
2
- require 'jsduck/html'
3
-
4
- module JsDuck
5
-
6
- # Represents one JavaScript or CSS source file.
7
- #
8
- # The filename parameter determines whether it's parsed as
9
- # JavaScript (the default) or CSS.
10
- class SourceFile
11
- attr_reader :filename
12
- attr_reader :contents
13
- attr_reader :docs
14
- attr_reader :html_filename
15
-
16
- def initialize(contents, filename="", options={})
17
- @contents = contents
18
- @filename = filename
19
- @html_filename = ""
20
- @links = {}
21
-
22
- @docs = SourceFileParser.new.parse(@contents, @filename, options)
23
-
24
- @docs.map do |docset|
25
- link(docset[:linenr], docset)
26
- end
27
- end
28
-
29
- # loops through each doc-object in file
30
- def each(&block)
31
- @docs.each(&block)
32
- end
33
-
34
- # Sets the html filename of this file,
35
- # updating also all doc-objects linking this file
36
- def html_filename=(html_filename)
37
- @html_filename = html_filename
38
- @links.each_value do |line|
39
- line.each do |link|
40
- link[:file][:html_filename] = @html_filename
41
- link[:file][:href] = @html_filename + "#" + id(link[:doc])
42
- end
43
- end
44
- end
45
-
46
- # Returns source code as HTML with lines starting doc-comments specially marked.
47
- def to_html
48
- linenr = 0
49
- lines = []
50
- # Use #each_line instead of #lines to support Ruby 1.6
51
- @contents.each_line do |line|
52
- linenr += 1;
53
- line = HTML.escape(line)
54
- # wrap the line in as many spans as there are links to this line number.
55
- if @links[linenr]
56
- @links[linenr].each do |link|
57
- line = "<span id='#{id(link[:doc])}'>#{line}</span>"
58
- end
59
- end
60
- lines << line
61
- end
62
- lines.join()
63
- end
64
-
65
- def id(doc)
66
- if doc[:tagname] == :class
67
- doc[:name].gsub(/\./, '-')
68
- else
69
- # when creation of global class is skipped,
70
- # this owner property can be nil.
71
- (doc[:owner] || "global").gsub(/\./, '-') + "-" + doc[:id]
72
- end
73
- end
74
-
75
- private
76
-
77
- # Creates two-way link between sourcefile and doc-object.
78
- # If doc-object is class, links also the contained cfgs and constructor.
79
- # Returns the modified doc-object after done.
80
- def link(linenr, doc)
81
- @links[linenr] = [] unless @links[linenr]
82
- file = {
83
- :filename => @filename,
84
- :linenr => linenr,
85
- }
86
- @links[linenr] << {:doc => doc, :file => file}
87
- doc[:files] = [file]
88
- if doc[:tagname] == :class
89
- doc[:members][:cfg].each {|cfg| link(linenr, cfg) }
90
- doc[:members][:method].each {|method| link(linenr, method) }
91
- end
92
- doc
93
- end
94
-
95
- end
96
-
97
- end
@@ -1,70 +0,0 @@
1
- require 'jsduck/js_parser'
2
- require 'jsduck/css_parser'
3
- require 'jsduck/doc_parser'
4
- require 'jsduck/merger'
5
- require 'jsduck/ast'
6
- require 'jsduck/doc_type'
7
- require 'jsduck/doc_ast'
8
- require 'jsduck/class_doc_expander'
9
-
10
- module JsDuck
11
-
12
- # Performs the actual parsing of CSS or JS source.
13
- #
14
- # This is the class that brings together all the different steps of
15
- # parsing the source.
16
- class SourceFileParser
17
-
18
- def initialize
19
- @doc_type = DocType.new
20
- @doc_parser = DocParser.new
21
- @class_doc_expander = ClassDocExpander.new
22
- @doc_ast = DocAst.new
23
- @merger = Merger.new
24
- end
25
-
26
- # Parses file into final docset that can be fed into Aggregator
27
- def parse(contents, filename="", options={})
28
- @doc_ast.filename = filename
29
-
30
- parse_js_or_css(contents, filename, options).map do |docset|
31
- expand(docset)
32
- end.flatten.map do |docset|
33
- merge(docset)
34
- end
35
- end
36
-
37
- private
38
-
39
- # Parses the file depending on filename as JS or CSS
40
- def parse_js_or_css(contents, filename, options)
41
- if filename =~ /\.s?css$/
42
- docs = CssParser.new(contents, options).parse
43
- else
44
- docs = JsParser.new(contents, options).parse
45
- docs = Ast.new(docs, options).detect_all!
46
- end
47
- end
48
-
49
- # Parses the docs, detects tagname and expands class docset
50
- def expand(docset)
51
- docset[:comment] = @doc_parser.parse(docset[:comment])
52
- docset[:tagname] = @doc_type.detect(docset[:comment], docset[:code])
53
-
54
- if docset[:tagname] == :class
55
- @class_doc_expander.expand(docset)
56
- else
57
- docset
58
- end
59
- end
60
-
61
- # Merges comment and code parts of docset
62
- def merge(docset)
63
- @doc_ast.linenr = docset[:linenr]
64
- docset[:comment] = @doc_ast.detect(docset[:tagname], docset[:comment])
65
-
66
- @merger.merge(docset)
67
- end
68
- end
69
-
70
- end
@@ -1,87 +0,0 @@
1
- require 'jsduck/logger'
2
- require 'jsduck/parallel_wrap'
3
- require 'fileutils'
4
-
5
- module JsDuck
6
-
7
- # Writes HTML JavaScript/CSS source into HTML files.
8
- class SourceWriter
9
- def initialize(source_files)
10
- @source_files = source_files
11
- end
12
-
13
- # Writes all source files as HTML files into destination dir.
14
- def write(destination)
15
- generate_html_filenames
16
-
17
- FileUtils.mkdir(destination)
18
- ParallelWrap.each(@source_files) do |file|
19
- Logger.instance.log("Writing source", file.html_filename)
20
- write_single(destination + "/" + file.html_filename, file.to_html)
21
- end
22
- end
23
-
24
- private
25
-
26
- # Generates unique HTML filenames for each file.
27
- #
28
- # Can't be done in parallel for obvious reasons, but also
29
- # because file.html_filename= method updates all the doc-objects
30
- # related to the file.
31
- def generate_html_filenames
32
- filenames = {}
33
- @source_files.each do |file|
34
- i = 0
35
- begin
36
- name = html_filename(file.filename, i)
37
- ci_name = name.downcase # case insensitive name
38
- i += 1
39
- end while filenames.has_key?(ci_name)
40
- filenames[ci_name] = true
41
- file.html_filename = name
42
- end
43
- end
44
-
45
- # Returns HTML filename for n'th file with given name.
46
- #
47
- # html_filename("Foo.js", 0) => "Foo.html"
48
- # html_filename("Foo.js", 1) => "Foo2.html"
49
- # html_filename("Foo.js", 2) => "Foo3.html"
50
- #
51
- def html_filename(filename, nr=0)
52
- File.basename(filename, ".js") + (nr > 0 ? (nr+1).to_s : "") + ".html"
53
- end
54
-
55
- def write_single(filename, source)
56
- File.open(filename, 'w') {|f| f.write(wrap_page(source)) }
57
- end
58
-
59
- # Returns source wrapped inside HTML page
60
- def wrap_page(source)
61
- return <<-EOHTML
62
- <!DOCTYPE html>
63
- <html>
64
- <head>
65
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
66
- <title>The source code</title>
67
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
68
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
69
- <style type="text/css">
70
- .highlight { display: block; background-color: #ddd; }
71
- </style>
72
- <script type="text/javascript">
73
- function highlight() {
74
- document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
75
- }
76
- </script>
77
- </head>
78
- <body onload="prettyPrint(); highlight();">
79
- <pre class="prettyprint lang-js">#{source}</pre>
80
- </body>
81
- </html>
82
- EOHTML
83
- end
84
-
85
- end
86
-
87
- end
@@ -1,103 +0,0 @@
1
-
2
- module JsDuck
3
-
4
- # Calculates all kinds of statistics for classes
5
- class Stats
6
- # Maps array of classes into array of stats per class
7
- def create(classes)
8
- @classes = classes
9
-
10
- classes.map do |cls|
11
- local_members = cls.all_local_members
12
- total_members = cls.all_members
13
- class_wc = wc(cls[:doc])
14
- members_wc = members_wc(cls)
15
-
16
- {
17
- :name => cls[:name],
18
-
19
- :local_cfgs => member_count(local_members, :cfg),
20
- :local_properties => member_count(local_members, :property),
21
- :local_methods => member_count(local_members, :method),
22
- :local_events => member_count(local_members, :event),
23
- :local_members => local_members.length,
24
-
25
- :total_cfgs => member_count(total_members, :cfg),
26
- :total_properties => member_count(total_members, :property),
27
- :total_methods => member_count(total_members, :method),
28
- :total_events => member_count(total_members, :event),
29
- :total_members => total_members.length,
30
-
31
- :fanIn => fan_in(cls),
32
- :fanOut => fan_out(cls),
33
-
34
- :class_wc => class_wc,
35
- :members_wc => members_wc,
36
- :wc_per_member => local_members.length > 0 ? (members_wc / local_members.length) : 0,
37
- }
38
- end
39
- end
40
-
41
- def member_count(members, type)
42
- members.find_all {|m| m[:tagname] == type }.length
43
- end
44
-
45
- # How many classes depend on this class
46
- def fan_in(cls)
47
- fan_in_table[cls[:name]] || 0
48
- end
49
-
50
- # On how many classes this class depends on
51
- def fan_out(cls)
52
- dependencies(cls).length
53
- end
54
-
55
- # list of class names the class depends on
56
- def dependencies(cls)
57
- [
58
- cls[:extends],
59
- cls[:mixins],
60
- cls[:requires],
61
- cls[:uses],
62
- ].compact.flatten.sort.uniq
63
- end
64
-
65
- # Returns map of class names to its fan-in number.
66
- def fan_in_table
67
- return @fi_table if @fi_table
68
-
69
- @fi_table = {}
70
- @classes.each do |cls|
71
- dependencies(cls).each do |d|
72
- @fi_table[d] = (@fi_table[d] || 0) + 1
73
- end
74
- end
75
- @fi_table
76
- end
77
-
78
- # Counts nr of words in documentation of all members of class
79
- def members_wc(cls)
80
- cnt = 0
81
- cls.all_local_members.each do |m|
82
- cnt += wc(m[:doc])
83
- (m[:params] || []).each {|p| cnt += property_wc(p) }
84
- (m[:properties] || []).each {|p| cnt += property_wc(p) }
85
- cnt += wc(m[:return][:doc]) if m[:return]
86
- end
87
- cnt
88
- end
89
-
90
- def property_wc(property)
91
- cnt = wc(property[:doc] || "")
92
- (property[:properties] || []).each {|p| cnt += property_wc(p) }
93
- cnt
94
- end
95
-
96
- # Strips HTML and counts words in text
97
- def wc(str)
98
- str.gsub(/<\/?[^>]*>/, "").scan(/\w+/).length
99
- end
100
-
101
- end
102
-
103
- end
@@ -1,31 +0,0 @@
1
- require 'jsduck/json_duck'
2
- require 'singleton'
3
-
4
- module JsDuck
5
-
6
- # Central place for buffering JSON data that's meant to be written to STDOUT
7
- class Stdout
8
- include Singleton
9
-
10
- def initialize
11
- @data = nil
12
- end
13
-
14
- # Adds array of new data
15
- def add(data)
16
- if @data
17
- @data += data
18
- else
19
- @data = data
20
- end
21
- end
22
-
23
- # Writes data to STDOUT in JSON format,
24
- # but only if some data was added.
25
- def flush
26
- puts JsonDuck.generate(@data) if @data
27
- end
28
-
29
- end
30
-
31
- end