jsduck 3.0.pre3 → 3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  JsDuck
2
2
  ======
3
3
 
4
- API documentation generator for Ext JS 4.
4
+ API documentation generator for Sencha JavaScript frameworks.
5
5
 
6
6
  ,~~.
7
7
  ( 6 )-_,
@@ -11,8 +11,9 @@ API documentation generator for Ext JS 4.
11
11
  ~'`~'`~'`~'`~
12
12
 
13
13
  JsDuck aims to be a better documentation generator for [Ext JS][] than
14
- the old [ext-doc][] was. It is used by Sencha to generate the official
15
- [Ext JS 4 documentation][ext4-docs].
14
+ the old [ext-doc][] was. It is used by Sencha to document [Ext JS
15
+ 4][ext4-docs], [Sencha Touch][touch] and [several other][other-docs]
16
+ products.
16
17
 
17
18
  The highlights of JSDuck are [Markdown][] support and keeping you DRY
18
19
  by inferring a lot of information from code. Read the [Guide][] for
@@ -22,17 +23,17 @@ full overview.
22
23
  [ext-doc]: http://ext-doc.org/
23
24
  [Markdown]: http://daringfireball.net/projects/markdown/
24
25
  [ext4-docs]: http://docs.sencha.com/ext-js/4-0/
26
+ [touch2-docs]: http://docs.sencha.com/touch/2-0/
27
+ [other-docs]: http://docs.sencha.com/ext-js/4-0/
25
28
  [Guide]: https://github.com/senchalabs/jsduck/wiki/Guide
26
29
 
27
30
 
28
31
  Getting it
29
32
  ----------
30
33
 
31
- Standard rubygems install should do (use the `--pre` switch to get the
32
- latest 3.0 version which this README documents, otherwise you will get
33
- the stable but quite old [0.6][v0.6] version):
34
+ Standard rubygems install should do:
34
35
 
35
- $ [sudo] gem install --pre jsduck
36
+ $ [sudo] gem install jsduck
36
37
 
37
38
  If you encounter errors during gem installation, you may need to
38
39
  install the header files for compiling extension modules for ruby 1.8.
@@ -43,7 +44,6 @@ For **Windows** users out there, you can download the binary version,
43
44
  which includes Ruby interpreter and all dependencies bundled in a
44
45
  single .exe file. Grab it from the [download page][].
45
46
 
46
- [v0.6]: https://github.com/senchalabs/jsduck/tree/v0.6
47
47
  [download page]: https://github.com/senchalabs/jsduck/downloads
48
48
 
49
49
  Usage
@@ -59,44 +59,34 @@ You can also use `--verbose` option to see what's actually happening.
59
59
 
60
60
  To generate docs for Ext JS 4 add path to the corresponding src/ dir:
61
61
 
62
- $ jsduck --builtin-classes --output your/docs extjs-4.0.2a/src
62
+ $ jsduck ext-4.0.7/src \
63
+ --builtin-classes \
64
+ --images ext-4.0.7/docs/images \
65
+ --output your/docs
63
66
 
64
- Running JSDuck with the current ext-4.0.2a release is expected to
65
- generate a lot of warnings. Because of the bugs in doc-comments a
66
- global class will also get created. You can disable this by adding
67
- `--ignore-global` switch. If you are bothered by the excessive amount
68
- of warnings, use the `--no-warnings` switch. For full list of command
69
- line options type `jsduck --help=full`.
70
-
71
- The latest ext-4.0.6 release will produce only few warnings, so use
72
- that if you can get it.
67
+ The `--images` option specifies a path for images included with
68
+ `{@img}` tags inside the source code.
73
69
 
74
- Finally, to get more similar result to the [official Ext JS 4
75
- documentation][official], copy over the doc-resources directory, which
76
- contains the images referenced by the documentation:
70
+ To generate docs for your own project, simply name additional input
71
+ directories:
77
72
 
78
- $ cp -r ext-4.0.2a/docs/doc-resources your/docs/doc-resources
73
+ $ jsduck ext-4.0.7/src project1/js project2/js ...
79
74
 
80
75
  Note that the resulting documentation will only contain the API
81
76
  documentation. Guides, videos and examples will not be present.
82
- These can be added using more command line options, but for now those
83
- aren't well documented as the ext-4.0.2a release doesn't contain the
84
- source files for these.
85
-
86
- To generate docs for your own project, simply add as many other input
87
- directories as needed:
88
-
89
- $ jsduck --builtin-classes ext-4.0.2a/src project1/js project2/js --output your/docs
90
-
91
- Of course you don't have to include the whole Ext JS into your
92
- documentation, but if your project is built on top of it, it makes
93
- sense to do so - otherwise you won't be able to see which methods your
94
- classes inherit from Ext JS classes.
95
-
96
- To create guides, videos and other sections, read about the
97
- [Advanced Usage][adv] in wiki.
77
+ These can be added using more command line options as explained in the
78
+ [Advanced Usage][adv] section of wiki.
79
+
80
+ Running JSDuck against older Ext JS than 4.0.7 is expected to generate
81
+ a lot of warnings. Similarly your own .js files will probably
82
+ generate warnings too. Sorry for that, JSDuck just wants to be
83
+ helpful. If you are overwhelmed by the warnings, you can disable them
84
+ using `--no-warnings` switch. Another thing that often happens is
85
+ that JSDuck is unable to determine into which class a member belongs
86
+ and will place all such items into a global class - you can disable
87
+ this using the `--ignore-global` switch. For full list of command
88
+ line options type `jsduck --help=full`.
98
89
 
99
- [official]: http://docs.sencha.com/ext-js/4-0/
100
90
  [adv]: https://github.com/senchalabs/jsduck/wiki/Advanced-Usage
101
91
 
102
92
 
@@ -125,7 +115,10 @@ Thanks to [Ondřej Jirman](https://github.com/megous),
125
115
  [Thomas Aylott](https://github.com/subtleGradient),
126
116
  [johnnywengluu](https://github.com/johnnywengluu),
127
117
  [gevik](https://github.com/gevik),
128
- [ligaard](https://github.com/ligaard), and many-many others who
118
+ [ligaard](https://github.com/ligaard),
119
+ [Bill Hubbard](http://www.sencha.com/forum/member.php?272458-BillHubbard),
120
+ [Ed Spencer](https://github.com/edspencer),
121
+ [atian25](https://github.com/atian25) and many-many others who
129
122
  reported bugs, submitted patches, and provided a lot of useful input.
130
123
 
131
124
 
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ def load_sdk_vars
22
22
  puts "For example:"
23
23
  puts
24
24
  puts " # path to Ext JS 4 build"
25
- puts " EXT_DIR='/path/to/ext-4.0.6'"
25
+ puts " EXT_DIR='/path/to/ext-4.0.7'"
26
26
  puts " # where to output the docs"
27
27
  puts " OUT_DIR='/path/to/ouput/dir'"
28
28
  puts " # path to SDK (for developers at Sencha)"
@@ -154,21 +154,47 @@ class JsDuckRunner
154
154
  @options += options
155
155
  end
156
156
 
157
- def add_sdk
157
+ def add_sdk(mode = nil)
158
+
158
159
  head_html = <<-EOHTML
159
160
  <link rel="canonical" href="http://docs.sencha.com/ext-js/4-0/" />
160
161
  <meta name="description" content="Ext JS 4.0 API Documentation from Sencha. Class documentation, Guides and Videos on how to create Javascript applications with Ext JS 4">
161
162
  EOHTML
162
163
 
164
+ if mode == 'export'
165
+
166
+ relative_sdk_path = "../"
167
+
168
+ ["template-min/extIframe.html", "template-min/welcome.html"].each do |file|
169
+ html = IO.read(file);
170
+
171
+ out = []
172
+
173
+ html.each_line do |line|
174
+ out << line.sub(/((src|href)="extjs\/)/, '\2="' + relative_sdk_path)
175
+ end
176
+
177
+ File.open(file, 'w') {|f| f.write(out) }
178
+ end
179
+
180
+ head_html = <<-EOHTML
181
+ <script type="text/javascript">
182
+ Docs.exampleBaseUrl = "#{relative_sdk_path}examples/";
183
+ </script>
184
+ EOHTML
185
+
186
+ end
187
+
163
188
  @options += [
164
189
  "--title", "Sencha Docs - Ext JS 4.0",
165
190
  "--head-html", head_html,
166
- "--footer", "Ext JS 4.0.6 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> rev #{revision}",
191
+ "--footer", "Ext JS 4.0.7 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> rev #{revision}",
167
192
  "--welcome", "template/welcome.html",
168
193
  "--guides", "#{@sdk_dir}/extjs/docs/guides.json",
169
194
  "--videos", "#{@sdk_dir}/extjs/docs/videos.json",
170
195
  "--examples", "#{@sdk_dir}/extjs/examples/examples.json",
171
196
  "--categories", "#{@sdk_dir}/extjs/docs/categories.json",
197
+ "--local-storage-db", "ext-4",
172
198
  "--output", "#{@out_dir}",
173
199
  "--builtin-classes",
174
200
  "--images", "#{@sdk_dir}/extjs/docs/resources",
@@ -185,6 +211,7 @@ class JsDuckRunner
185
211
  "--footer", "Ext JS 3.4 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{revision}",
186
212
  "--categories", "#{@sdk_dir}/../ext-3.4.0/src/categories.json",
187
213
  "--ignore-global",
214
+ "--local-storage-db", "ext-3",
188
215
  "--output", "#{@out_dir}",
189
216
  "#{@sdk_dir}/../ext-3.4.0/src/core",
190
217
  "#{@sdk_dir}/../ext-3.4.0/src/data",
@@ -204,6 +231,7 @@ class JsDuckRunner
204
231
  "--ignore-global",
205
232
  "--no-warnings",
206
233
  "--images", "#{@ext_dir}/docs/doc-resources",
234
+ "--local-storage-db", "ext-4",
207
235
  "--output", "#{@out_dir}",
208
236
  "#{@ext_dir}/src",
209
237
  ]
@@ -221,6 +249,7 @@ class JsDuckRunner
221
249
  "--footer", "Sencha Touch 1.1 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{revision}",
222
250
  "--categories", "#{@sdk_dir}/touch/doc-resources/categories.json",
223
251
  "--videos", "#{@sdk_dir}/touch/doc-resources/videos.json",
252
+ "--local-storage-db", "touch-1",
224
253
  "--output", "#{@out_dir}",
225
254
  "--external=google.maps.Map,google.maps.LatLng",
226
255
  "--images", "#{@sdk_dir}/touch/doc-resources",
@@ -246,10 +275,12 @@ class JsDuckRunner
246
275
  "--guides", "#{@sdk_dir}/touch/docs/guides.json",
247
276
  "--examples", "#{@sdk_dir}/touch/docs/examples.json",
248
277
  "--touch-examples-ui",
278
+ "--local-storage-db", "touch-2",
249
279
  "--output", "#{@out_dir}",
250
280
  "--external=google.maps.Map,google.maps.LatLng",
251
281
  "--builtin-classes",
252
282
  "--img", "<p class='screenshot'><img src='%u' alt='%a'><span>%a</span></p>",
283
+ "--eg-iframe", "template/touch-iframe.html",
253
284
  "#{@sdk_dir}/touch/resources/themes/stylesheets/sencha-touch/default",
254
285
  ]
255
286
 
@@ -320,12 +351,33 @@ class JsDuckRunner
320
351
  "--categories", "#{@sdk_dir}/charts/docs/categories.json",
321
352
  "--guides", "#{@sdk_dir}/charts/docs/guides.json",
322
353
  "--images", "#{@sdk_dir}/charts/docs/resources",
354
+ "--local-storage-db", "touch-charts",
323
355
  "--output", "#{@out_dir}"
324
356
  ]
325
357
 
326
358
  @options += extract_jsb_build_files("#{@sdk_dir}/charts/touch-charts.jsb3")
327
359
  end
328
360
 
361
+ def add_sencha_io
362
+ head_html = <<-EOHTML
363
+ <link rel="canonical" href="http://docs.sencha.com/sencha-io/1-0/" />
364
+ <meta name="description" content="Sencha.io 1.0 API Documentation. Documentation on how to use the Sencha.io SDK" />
365
+ EOHTML
366
+
367
+ @options += [
368
+ "--title", "Sencha Docs - IO 1.0",
369
+ "--head-html", head_html,
370
+ "--footer", "Sencha.io 1.0 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a>",
371
+ "--guides", "#{@sdk_dir}/../sync/docs/guides.json",
372
+ "--images", "#{@sdk_dir}/../sync/docs/resources",
373
+ "--local-storage-db", "sencha-io",
374
+ "--ignore-global",
375
+ "--output", "#{@out_dir}"
376
+ ]
377
+
378
+ @options += extract_jsb_build_files("#{@sdk_dir}/../sync/sencha-io.jsb3")
379
+ end
380
+
329
381
  def add_animator
330
382
  head_html = <<-EOHTML
331
383
  <link rel="canonical" href="http://docs.sencha.com/animator/1-0/" />
@@ -339,6 +391,7 @@ class JsDuckRunner
339
391
  # "--videos", "#{@animator_dir}/docs/videos.json",
340
392
  "--guides", "#{@animator_dir}/docs/guides.json",
341
393
  # "--examples", "#{@animator_dir}/docs/examples/examples.json",
394
+ "--local-storage-db", "animator",
342
395
  "--output", "#{@out_dir}",
343
396
  ]
344
397
  end
@@ -515,7 +568,7 @@ task :sdk, [:mode] => :sass do |t, args|
515
568
  compress if mode == "export" || mode == "live"
516
569
 
517
570
  runner = JsDuckRunner.new
518
- runner.add_sdk
571
+ runner.add_sdk(mode)
519
572
  runner.add_debug if mode == "debug"
520
573
  runner.add_seo if mode == "debug" || mode == "live"
521
574
  runner.add_sdk_export_notice if mode == "export"
@@ -611,6 +664,23 @@ task :charts, [:mode] => :sass do |t, args|
611
664
  runner.run
612
665
  end
613
666
 
667
+ desc "Run JSDuck on Sencha.IO Sync (for internal use at Sencha)\n" +
668
+ "senchaio - creates debug/development version\n" +
669
+ "senchaio[export] - create live version for deployment\n"
670
+ "senchaio[live] - create live version for deployment\n"
671
+ task :senchaio, [:mode] => :sass do |t, args|
672
+ mode = args[:mode] || "debug"
673
+ throw "Unknown mode #{mode}" unless ["debug", "export", "live"].include?(mode)
674
+ compress if mode == "live"
675
+
676
+ runner = JsDuckRunner.new
677
+ runner.add_sencha_io
678
+ runner.add_debug if mode == "debug"
679
+ runner.add_seo if mode == "debug" || mode == "live"
680
+ runner.add_google_analytics if mode == "live"
681
+ runner.run
682
+ end
683
+
614
684
  desc "Run JSDuck JSON Export (for internal use at Sencha)\n" +
615
685
  "export[touch] - creates export for Touch 1\n" +
616
686
  "export[touch2] - creates export for Touch 2"
@@ -2,8 +2,8 @@ Gem::Specification.new do |s|
2
2
  s.required_rubygems_version = ">= 1.3.7"
3
3
 
4
4
  s.name = 'jsduck'
5
- s.version = '3.0.pre3'
6
- s.date = '2011-10-17'
5
+ s.version = '3.0'
6
+ s.date = '2011-10-21'
7
7
  s.summary = "Simple JavaScript Duckumentation generator"
8
8
  s.description = "Documentation generator for Sencha JS frameworks"
9
9
  s.homepage = "https://github.com/senchalabs/jsduck"
@@ -73,7 +73,8 @@ module JsDuck
73
73
  @categories = Categories.new(get_doc_formatter, @relations)
74
74
  if @opts.categories_path
75
75
  @categories.parse(@opts.categories_path)
76
- @categories.validate
76
+ else
77
+ @categories.auto_generate
77
78
  end
78
79
 
79
80
  clear_output_dir unless @opts.export == :stdout
@@ -95,6 +96,9 @@ module JsDuck
95
96
  FileUtils.rm(@opts.output_dir+"/index.php")
96
97
  FileUtils.cp(@opts.output_dir+"/template.html", @opts.output_dir+"/index.html")
97
98
  end
99
+ if @opts.eg_iframe
100
+ FileUtils.cp(@opts.eg_iframe, @opts.output_dir+"/eg-iframe.html")
101
+ end
98
102
  write_src(parsed_files)
99
103
  format_classes
100
104
  write_app_data
@@ -0,0 +1,80 @@
1
+ module JsDuck
2
+
3
+ # Automatically divides all available classes into categories
4
+ class AutoCategories
5
+ def initialize(relations)
6
+ @relations = relations
7
+ end
8
+
9
+ # Performs the generation
10
+ def generate
11
+ # list names of all public classes
12
+ class_names = @relations.to_a.find_all {|cls| !cls[:private] }.map {|cls| cls[:name] }
13
+
14
+ # divide classes into top-level categories by namespace
15
+ categories = categorize(class_names)
16
+
17
+ # in each category, create sub-categories
18
+ categories.each_pair do |ns, classes|
19
+ categories[ns] = categorize(classes, 1)
20
+ end
21
+
22
+ # Turn categories hash into array, sort everything
23
+ categories_array = []
24
+ categories.each_pair do |ns, groups|
25
+ groups_array = []
26
+ groups.each_pair do |gns, classes|
27
+ groups_array << {
28
+ "name" => gns,
29
+ "classes" => classes.sort
30
+ }
31
+ end
32
+ groups_array.sort! {|a, b| cat_compare(a, b) }
33
+ categories_array << {
34
+ "name" => ns,
35
+ "groups" => groups_array
36
+ }
37
+ end
38
+ categories_array.sort! {|a, b| cat_compare(a, b) }
39
+
40
+ return categories_array
41
+ end
42
+
43
+ # Divides classes into categories by namespace. Collapses
44
+ # categories having only one class into a category "Others..."
45
+ def categorize(class_names, level=0)
46
+ categories = {}
47
+ class_names.each do |name|
48
+ ns = name.split(/\./)[level] || name.split(/\./)[0]
49
+ categories[ns] = [] unless categories[ns]
50
+ categories[ns] << name
51
+ end
52
+
53
+ globals = []
54
+ categories.each_pair do |ns, classes|
55
+ if classes.length == 1
56
+ globals << classes[0]
57
+ categories.delete(ns)
58
+ end
59
+ end
60
+ if globals.length > 0
61
+ categories["Others..."] = globals
62
+ end
63
+
64
+ categories
65
+ end
66
+
67
+ # Comparison function for sorting categories that always places
68
+ # "Others..." category at the end.
69
+ def cat_compare(a, b)
70
+ if a["name"] == "Others..."
71
+ 1
72
+ elsif b["name"] == "Others..."
73
+ -1
74
+ else
75
+ a["name"] <=> b["name"]
76
+ end
77
+ end
78
+ end
79
+
80
+ end
@@ -1,5 +1,6 @@
1
1
  require 'jsduck/logger'
2
2
  require 'jsduck/json_duck'
3
+ require 'jsduck/auto_categories'
3
4
 
4
5
  module JsDuck
5
6
 
@@ -11,6 +12,11 @@ module JsDuck
11
12
  @categories = []
12
13
  end
13
14
 
15
+ # Automatically divides all available classes into categories
16
+ def auto_generate
17
+ @categories = AutoCategories.new(@relations).generate
18
+ end
19
+
14
20
  # Parses categories in JSON file
15
21
  def parse(path)
16
22
  @categories = JsonDuck.read(path)
@@ -29,6 +35,8 @@ module JsDuck
29
35
  end.flatten
30
36
  end
31
37
  end
38
+
39
+ validate
32
40
  end
33
41
 
34
42
  # Expands class name like 'Foo.*' into multiple class names.
@@ -127,12 +127,12 @@ module JsDuck
127
127
  elsif @input.check(/'/)
128
128
  return {
129
129
  :type => :string,
130
- :value => @input.scan(/'([^'\\]|\\.)*'/m).sub(/^'(.*)'$/m, "\\1")
130
+ :value => @input.scan(/'([^'\\]|\\.)*('|\Z)/m).gsub(/\A'|'\Z/m, "")
131
131
  }
132
132
  elsif @input.check(/"/)
133
133
  return {
134
134
  :type => :string,
135
- :value => @input.scan(/"([^"\\]|\\.)*"/m).sub(/^"(.*)"$/m, "\\1")
135
+ :value => @input.scan(/"([^"\\]|\\.)*("|\Z)/m).gsub(/\A"|"\Z/m, "")
136
136
  }
137
137
  elsif @input.check(/\//)
138
138
  # Several things begin with dash:
@@ -153,7 +153,7 @@ module JsDuck
153
153
  elsif regex?
154
154
  return {
155
155
  :type => :regex,
156
- :value => @input.scan(/\/([^\/\\]|\\.)*\/[gim]*/)
156
+ :value => @input.scan(META_REGEX)
157
157
  }
158
158
  else
159
159
  return {
@@ -202,6 +202,20 @@ module JsDuck
202
202
  @input.scan(/\s+/)
203
203
  end
204
204
 
205
+ # A regex to match a regex
206
+ META_REGEX = %r{
207
+ / (?# beginning )
208
+ (
209
+ [^/\[\\] (?# any character except \ / [ )
210
+ |
211
+ \\. (?# an escaping \ followed by any character )
212
+ |
213
+ \[ ([^\]\\]|\\.)* \] (?# [...] containing any characters including / )
214
+ (?# except \ ] which have to be escaped )
215
+ )*
216
+ (/[gim]*|\Z) (?# ending + modifiers )
217
+ }x
218
+
205
219
  KEYWORDS = {
206
220
  "break" => true,
207
221
  "case" => true,