jsduck 3.11.2 → 4.0.beta

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.
@@ -12,7 +12,6 @@ module JsDuck
12
12
  attr_accessor :output_dir
13
13
  attr_accessor :ignore_global
14
14
  attr_accessor :external_classes
15
- attr_accessor :ext4_events
16
15
 
17
16
  # Customizing output
18
17
  attr_accessor :title
@@ -74,14 +73,13 @@ module JsDuck
74
73
  # Special anything-goes type
75
74
  "Mixed",
76
75
  ]
77
- @ext4_events = nil
78
76
  @meta_tag_paths = []
79
77
 
80
- @version = "3.11.2"
78
+ @version = "4.0.beta"
81
79
 
82
80
  # Customizing output
83
- @title = "Ext JS - Sencha Docs"
84
- @header = "<strong>Ext JS</strong> Sencha Docs"
81
+ @title = "Sencha Docs - Ext JS"
82
+ @header = "<strong>Sencha Docs</strong> Ext JS"
85
83
  @footer = "Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> #{@version}."
86
84
  @head_html = ""
87
85
  @body_html = ""
@@ -159,14 +157,6 @@ module JsDuck
159
157
  @external_classes += classes
160
158
  end
161
159
 
162
- opts.on('--[no-]ext4-events',
163
- "Appends extra options parameter that all Ext events have.",
164
- "The default is to auto-detect if we're using Ext JS 4",
165
- "based on whether the code uses Ext.define.",
166
- "Use this option to override the auto-detection.", " ") do |e|
167
- @ext4_events = e
168
- end
169
-
170
160
  opts.on('--builtin-classes',
171
161
  "Includes docs for JavaScript builtin classes.", " ") do
172
162
  read_filenames(@root_dir + "/js-classes")
@@ -191,7 +181,7 @@ module JsDuck
191
181
 
192
182
  opts.on('--title=TEXT',
193
183
  "Custom title text for the documentation.",
194
- "Defaults to 'Ext JS - Sencha Docs'", " ") do |text|
184
+ "Defaults to 'Sencha Docs - Ext JS'", " ") do |text|
195
185
  @title = text
196
186
  @header = text.sub(/^(.*?) +- +/, "<strong>\\1 </strong>")
197
187
  end
@@ -0,0 +1,262 @@
1
+ module JsDuck
2
+
3
+ # Transforms Esprima AST into string
4
+ class Serializer
5
+
6
+ # Turns AST node into string
7
+ def to_s(ast)
8
+ case ast["type"]
9
+ when "Program"
10
+ ast["body"].map {|s| to_s(s) }.join
11
+
12
+ # Statements
13
+
14
+ when "BlockStatement"
15
+ "{" + ast["body"].map {|s| to_s(s) }.join + "}"
16
+
17
+ when "BreakStatement"
18
+ "break" + (ast["label"] ? " " + to_s(ast["label"]) : "") + ";"
19
+
20
+ when "ContinueStatement"
21
+ "continue" + (ast["label"] ? " " + to_s(ast["label"]) : "") + ";"
22
+
23
+ when "DoWhileStatement"
24
+ "do " + to_s(ast["body"]) + " while (" + to_s(ast["test"]) + ");"
25
+
26
+ when "DebuggerStatement"
27
+ "debugger;"
28
+
29
+ when "EmptyStatement"
30
+ ";"
31
+
32
+ when "ExpressionStatement"
33
+ to_s(ast["expression"]) + ";"
34
+
35
+ when "ForStatement"
36
+ init = ast["init"] ? to_s(ast["init"]).sub(/;\Z/, "") : ""
37
+ test = ast["test"] ? to_s(ast["test"]) : ""
38
+ update = ast["update"] ? to_s(ast["update"]) : ""
39
+ "for (" + init + "; " + test + "; " + update + ") " + to_s(ast["body"])
40
+
41
+ when "ForInStatement"
42
+ left = to_s(ast["left"]).sub(/;\Z/, "")
43
+ right = to_s(ast["right"])
44
+ "for (" + left + " in " + right + ") " + to_s(ast["body"])
45
+
46
+ when "IfStatement"
47
+ alternate = ast["alternate"] ? " else " + to_s(ast["alternate"]) : ""
48
+ "if (" + to_s(ast["test"]) + ") " + to_s(ast["consequent"]) + alternate
49
+
50
+ when "LabeledStatement"
51
+ to_s(ast["label"]) + ": " + to_s(ast["body"])
52
+
53
+ when "ReturnStatement"
54
+ arg = ast["argument"] ? to_s(ast["argument"]) : ""
55
+ "return " + arg + ";"
56
+
57
+ when "SwitchStatement"
58
+ "switch (" + to_s(ast["discriminant"]) + ") {" + ast["cases"].map {|c| to_s(c) }.join + "}"
59
+
60
+ when "SwitchCase"
61
+ test = ast["test"] ? "case " + to_s(ast["test"]) : "default"
62
+ test + ": " + ast["consequent"].map {|c| to_s(c) }.join
63
+
64
+ when "ThrowStatement"
65
+ "throw " + to_s(ast["argument"]) + ";"
66
+
67
+ when "TryStatement"
68
+ handlers = ast["handlers"].map {|h| to_s(h) }.join
69
+ finalizer = ast["finalizer"] ? " finally " + to_s(ast["finalizer"]) : ""
70
+ "try " + to_s(ast["block"]) + handlers + finalizer
71
+
72
+ when "CatchClause"
73
+ param = ast["param"] ? to_s(ast["param"]) : ""
74
+ " catch (" + param + ") " + to_s(ast["body"])
75
+
76
+ when "WhileStatement"
77
+ "while (" + to_s(ast["test"]) + ") " + to_s(ast["body"])
78
+
79
+ when "WithStatement"
80
+ "with (" + to_s(ast["object"]) + ") " + to_s(ast["body"])
81
+
82
+
83
+ # Declarations
84
+
85
+ when "FunctionDeclaration"
86
+ function(ast)
87
+
88
+ when "VariableDeclaration"
89
+ ast["kind"] + " " + list(ast["declarations"]) + ";"
90
+
91
+ when "VariableDeclarator"
92
+ if ast["init"]
93
+ to_s(ast["id"]) + " = " + to_s(ast["init"])
94
+ else
95
+ to_s(ast["id"])
96
+ end
97
+
98
+ # Expressions
99
+
100
+ when "AssignmentExpression"
101
+ parens(ast, ast["left"]) + " " + ast["operator"] + " " + to_s(ast["right"])
102
+
103
+ when "ArrayExpression"
104
+ "[" + list(ast["elements"]) + "]"
105
+
106
+ when "BinaryExpression"
107
+ binary(ast)
108
+
109
+ when "CallExpression"
110
+ call(ast)
111
+
112
+ when "ConditionalExpression"
113
+ parens(ast, ast["test"]) + " ? " + to_s(ast["consequent"]) + " : " + to_s(ast["alternate"])
114
+
115
+ when "FunctionExpression"
116
+ function(ast)
117
+
118
+ when "LogicalExpression"
119
+ binary(ast)
120
+
121
+ when "MemberExpression"
122
+ if ast["computed"]
123
+ parens(ast, ast["object"]) + "[" + to_s(ast["property"]) + "]"
124
+ else
125
+ parens(ast, ast["object"]) + "." + to_s(ast["property"])
126
+ end
127
+
128
+ when "NewExpression"
129
+ "new " + call(ast)
130
+
131
+ when "ObjectExpression"
132
+ "{" + list(ast["properties"]) + "}"
133
+
134
+ when "Property"
135
+ to_s(ast["key"]) + ": " + to_s(ast["value"])
136
+
137
+ when "SequenceExpression"
138
+ list(ast["expressions"])
139
+
140
+ when "ThisExpression"
141
+ "this"
142
+
143
+ when "UnaryExpression"
144
+ ast["operator"] + parens(ast, ast["argument"])
145
+
146
+ when "UpdateExpression"
147
+ if ast["prefix"]
148
+ ast["operator"] + parens(ast, ast["argument"])
149
+ else
150
+ parens(ast, ast["argument"]) + ast["operator"]
151
+ end
152
+
153
+ # Basics
154
+
155
+ when "Identifier"
156
+ ast["name"]
157
+
158
+ when "Literal"
159
+ ast["raw"]
160
+
161
+ else
162
+ throw "Unknown node type: "+ast["type"]
163
+ end
164
+ end
165
+
166
+ private
167
+
168
+ # serializes function declaration or expression
169
+ def function(ast)
170
+ params = list(ast["params"])
171
+ id = ast["id"] ? to_s(ast["id"]) : ""
172
+ "function " + id + "(" + params + ") " + to_s(ast["body"])
173
+ end
174
+
175
+ # serializes list of comma-separated items
176
+ def list(array)
177
+ array.map {|x| to_s(x) }.join(", ")
178
+ end
179
+
180
+ # serializes call- and new-expression
181
+ def call(ast)
182
+ parens(ast, ast["callee"]) + "(" + list(ast["arguments"]) + ")"
183
+ end
184
+
185
+ # Handles both binary- and logical-expression
186
+ def binary(ast)
187
+ parens(ast, ast["left"]) + " " + ast["operator"] + " " + parens(ast, ast["right"])
188
+ end
189
+
190
+ # serializes child node and wraps it inside parenthesis if the
191
+ # precedence rules compared to parent node would require so.
192
+ def parens(parent, child)
193
+ if precedence(parent) >= precedence(child)
194
+ to_s(child)
195
+ else
196
+ "(" + to_s(child) + ")"
197
+ end
198
+ end
199
+
200
+ # Returns the precedence of operator represented by given AST node
201
+ def precedence(ast)
202
+ p = PRECEDENCE[ast["type"]]
203
+ if p.is_a? Fixnum
204
+ p
205
+ elsif p.is_a? Hash
206
+ p[ast["operator"]]
207
+ else
208
+ 0
209
+ end
210
+ end
211
+
212
+ # Precedence rules of JavaScript operators.
213
+ #
214
+ # Taken from: https://developer.mozilla.org/en/JavaScript/Reference/Operators/Operator_Precedence
215
+ #
216
+ PRECEDENCE = {
217
+ "SequenceExpression" => 17,
218
+ "AssignmentExpression" => 16,
219
+ "ConditionalExpression" => 15,
220
+ "LogicalExpression" => {
221
+ "||" => 14,
222
+ "&&" => 13,
223
+ },
224
+ "BinaryExpression" => {
225
+ "|" => 12,
226
+ "^" => 11,
227
+ "&" => 10,
228
+
229
+ "==" => 9,
230
+ "!=" => 9,
231
+ "===" => 9,
232
+ "!==" => 9,
233
+
234
+ "<" => 8,
235
+ "<=" => 8,
236
+ ">" => 8,
237
+ ">=" => 8,
238
+ "in" => 8,
239
+ "instanceof" => 8,
240
+
241
+ "<<" => 7,
242
+ ">>" => 7,
243
+ ">>>" => 7,
244
+
245
+ "+" => 6,
246
+ "-" => 6,
247
+
248
+ "*" => 5,
249
+ "/" => 5,
250
+ "%" => 5,
251
+ },
252
+ "UnaryExpression" => 4,
253
+ "UpdateExpression" => 3,
254
+ "CallExpression" => 2,
255
+ "MemberExpression" => 1,
256
+ "NewExpression" => 1,
257
+ }
258
+
259
+ end
260
+
261
+ end
262
+
@@ -1,6 +1,4 @@
1
- require 'jsduck/js_parser'
2
- require 'jsduck/css_parser'
3
- require 'jsduck/merger'
1
+ require 'jsduck/source_file_parser'
4
2
  require 'jsduck/html'
5
3
 
6
4
  module JsDuck
@@ -18,15 +16,13 @@ module JsDuck
18
16
  def initialize(contents, filename="", options={})
19
17
  @contents = contents
20
18
  @filename = filename
21
- @options = options
22
19
  @html_filename = ""
23
20
  @links = {}
24
21
 
25
- merger = Merger.new
26
- merger.filename = @filename
27
- @docs = parse.map do |docset|
28
- merger.linenr = docset[:linenr]
29
- link(docset[:linenr], merger.merge(docset[:comment], docset[:code]))
22
+ @docs = SourceFileParser.instance.parse(@contents, @filename, options)
23
+
24
+ @docs.map do |docset|
25
+ link(docset[:linenr], docset)
30
26
  end
31
27
  end
32
28
 
@@ -78,15 +74,6 @@ module JsDuck
78
74
 
79
75
  private
80
76
 
81
- # Parses the file depending on filename as JS or CSS
82
- def parse
83
- if @filename =~ /\.s?css$/
84
- CssParser.new(@contents, @options).parse
85
- else
86
- JsParser.new(@contents, @options).parse
87
- end
88
- end
89
-
90
77
  # Creates two-way link between sourcefile and doc-object.
91
78
  # If doc-object is class, links also the contained cfgs and constructor.
92
79
  # Returns the modified doc-object after done.
@@ -0,0 +1,72 @@
1
+ require 'singleton'
2
+ require 'jsduck/js_parser'
3
+ require 'jsduck/css_parser'
4
+ require 'jsduck/doc_parser'
5
+ require 'jsduck/merger'
6
+ require 'jsduck/ast'
7
+ require 'jsduck/doc_type'
8
+ require 'jsduck/doc_ast'
9
+ require 'jsduck/class_doc_expander'
10
+
11
+ module JsDuck
12
+
13
+ # Performs the actual parsing of CSS or JS source.
14
+ #
15
+ # This is the class that brings together all the different steps of
16
+ # parsing the source.
17
+ class SourceFileParser
18
+ include Singleton
19
+
20
+ def initialize
21
+ @doc_type = DocType.new
22
+ @doc_parser = DocParser.new
23
+ @class_doc_expander = ClassDocExpander.new
24
+ @doc_ast = DocAst.new
25
+ @merger = Merger.new
26
+ end
27
+
28
+ # Parses file into final docset that can be fed into Aggregator
29
+ def parse(contents, filename="", options={})
30
+ @doc_ast.filename = filename
31
+
32
+ parse_js_or_css(contents, filename, options).map do |docset|
33
+ expand(docset)
34
+ end.flatten.map do |docset|
35
+ merge(docset)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # Parses the file depending on filename as JS or CSS
42
+ def parse_js_or_css(contents, filename, options)
43
+ if filename =~ /\.s?css$/
44
+ docs = CssParser.new(contents, options).parse
45
+ else
46
+ docs = JsParser.new(contents, options).parse
47
+ docs = Ast.new(docs, options).detect_all!
48
+ end
49
+ end
50
+
51
+ # Parses the docs, detects tagname and expands class docset
52
+ def expand(docset)
53
+ docset[:comment] = @doc_parser.parse(docset[:comment])
54
+ docset[:tagname] = @doc_type.detect(docset[:comment], docset[:code])
55
+
56
+ if docset[:tagname] == :class
57
+ @class_doc_expander.expand(docset)
58
+ else
59
+ docset
60
+ end
61
+ end
62
+
63
+ # Merges comment and code parts of docset
64
+ def merge(docset)
65
+ @doc_ast.linenr = docset[:linenr]
66
+ docset[:comment] = @doc_ast.detect(docset[:tagname], docset[:comment])
67
+
68
+ @merger.merge(docset)
69
+ end
70
+ end
71
+
72
+ end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsduck
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.11.2
5
- prerelease:
4
+ version: 4.0.beta
5
+ prerelease: 4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rene Saarsoo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-07 00:00:00.000000000 Z
13
+ date: 2012-06-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdiscount
@@ -60,6 +60,22 @@ dependencies:
60
60
  - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: execjs
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
63
79
  - !ruby/object:Gem::Dependency
64
80
  name: rspec
65
81
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +133,8 @@ extra_rdoc_files: []
117
133
  files:
118
134
  - .gitignore
119
135
  - COPYING
136
+ - Gemfile
137
+ - Gemfile.lock
120
138
  - README.md
121
139
  - Rakefile
122
140
  - bin/compare
@@ -137,15 +155,21 @@ files:
137
155
  - lib/jsduck/app_data.rb
138
156
  - lib/jsduck/app_exporter.rb
139
157
  - lib/jsduck/assets.rb
158
+ - lib/jsduck/ast.rb
140
159
  - lib/jsduck/auto_categories.rb
141
160
  - lib/jsduck/categories.rb
142
161
  - lib/jsduck/class.rb
162
+ - lib/jsduck/class_doc_expander.rb
143
163
  - lib/jsduck/class_formatter.rb
144
164
  - lib/jsduck/class_writer.rb
145
165
  - lib/jsduck/css_lexer.rb
146
166
  - lib/jsduck/css_parser.rb
167
+ - lib/jsduck/doc_ast.rb
147
168
  - lib/jsduck/doc_formatter.rb
148
169
  - lib/jsduck/doc_parser.rb
170
+ - lib/jsduck/doc_type.rb
171
+ - lib/jsduck/esprima.rb
172
+ - lib/jsduck/evaluator.rb
149
173
  - lib/jsduck/examples.rb
150
174
  - lib/jsduck/examples_exporter.rb
151
175
  - lib/jsduck/file_categories.rb
@@ -162,8 +186,6 @@ files:
162
186
  - lib/jsduck/inline_img.rb
163
187
  - lib/jsduck/inline_video.rb
164
188
  - lib/jsduck/io.rb
165
- - lib/jsduck/js_literal_builder.rb
166
- - lib/jsduck/js_literal_parser.rb
167
189
  - lib/jsduck/js_parser.rb
168
190
  - lib/jsduck/json_duck.rb
169
191
  - lib/jsduck/lexer.rb
@@ -180,14 +202,15 @@ files:
180
202
  - lib/jsduck/relations.rb
181
203
  - lib/jsduck/renderer.rb
182
204
  - lib/jsduck/search_data.rb
205
+ - lib/jsduck/serializer.rb
183
206
  - lib/jsduck/source_file.rb
207
+ - lib/jsduck/source_file_parser.rb
184
208
  - lib/jsduck/source_writer.rb
185
209
  - lib/jsduck/stats.rb
186
210
  - lib/jsduck/stdout.rb
187
211
  - lib/jsduck/tag/abstract.rb
188
212
  - lib/jsduck/tag/aside.rb
189
213
  - lib/jsduck/tag/author.rb
190
- - lib/jsduck/tag/chainable.rb
191
214
  - lib/jsduck/tag/deprecated.rb
192
215
  - lib/jsduck/tag/docauthor.rb
193
216
  - lib/jsduck/tag/hide.rb
@@ -639,6 +662,7 @@ files:
639
662
  - template-min/extjs/ext-all.js
640
663
  - template-min/build-js.html
641
664
  - template-min/index.php
665
+ - esprima/esprima.js
642
666
  homepage: https://github.com/senchalabs/jsduck
643
667
  licenses: []
644
668
  post_install_message:
@@ -654,12 +678,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
654
678
  required_rubygems_version: !ruby/object:Gem::Requirement
655
679
  none: false
656
680
  requirements:
657
- - - ! '>='
681
+ - - ! '>'
658
682
  - !ruby/object:Gem::Version
659
- version: 1.3.5
683
+ version: 1.3.1
660
684
  requirements: []
661
685
  rubyforge_project: jsduck
662
- rubygems_version: 1.8.24
686
+ rubygems_version: 1.8.23
663
687
  signing_key:
664
688
  specification_version: 3
665
689
  summary: Simple JavaScript Duckumentation generator