jsduck 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/jsduck/table.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'jsduck/doc_formatter'
2
-
3
1
  module JsDuck
4
2
 
5
3
  # Base class for creating HTML tables of class members.
@@ -12,18 +10,17 @@ module JsDuck
12
10
  #
13
11
  # - cls : the class for which to generate the table.
14
12
  #
13
+ # - formatter : instance of JsDuck::DocFormatter
14
+ #
15
15
  # - cache : shared cache of already generated HTML rows. If Foo
16
16
  # inherits from Bar and we have already generated members table
17
17
  # for Bar, then we don't have to re-render all the HTML the
18
18
  # methods from Bar, but can just look them up from cache.
19
19
  #
20
- def initialize(cls, cache={})
20
+ def initialize(cls, formatter, cache={})
21
21
  @cls = cls
22
+ @formatter = formatter
22
23
  @cache = cache
23
- @formatter = DocFormatter.new
24
- @formatter.context = cls.full_name
25
- @formatter.css_class = 'docClass'
26
- @formatter.url_template = 'output/%cls%.html'
27
24
  end
28
25
 
29
26
  def to_html
@@ -57,8 +54,12 @@ module JsDuck
57
54
  html = @cache[cache_key] = create_row(item)
58
55
  end
59
56
  inherited = inherited?(item) ? 'inherited' : ''
60
- owner = inherited?(item) ? member_link(item) : Class.short_name(item[:member])
61
- html.sub(/!!--inherited--!!/, inherited).sub(/!!--owner-class--!!/, owner)
57
+ owner_link = inherited?(item) ? member_link(item) : Class.short_name(item[:member])
58
+ owner_class = @cls.full_name
59
+ html = html.sub(/!!--inherited--!!/, inherited)
60
+ html = html.sub(/!!--owner-link--!!/, owner_link)
61
+ html = html.sub(/!!--owner-class--!!/, owner_class)
62
+ html
62
63
  end
63
64
 
64
65
  # Generates HTML for the row, leaving in placeholders for owner
@@ -72,7 +73,7 @@ module JsDuck
72
73
  <tr class='#{@row_class} #{expandable} !!--inherited--!!'>
73
74
  <td class='micon'><a href='#expand' class='exi'>&nbsp;</a></td>
74
75
  <td class='sig'>#{signature(item)}<div class='mdesc'>#{description}</div></td>
75
- <td class='msource'>!!--owner-class--!!</td>
76
+ <td class='msource'>!!--owner-link--!!</td>
76
77
  </tr>
77
78
  EOHTML
78
79
  end
@@ -82,7 +83,7 @@ module JsDuck
82
83
  end
83
84
 
84
85
  def signature(item)
85
- id = @cls.full_name+ "-" + item[:name]
86
+ id = "!!--owner-class--!!-" + item[:name]
86
87
  src = "source/#{item[:href]}"
87
88
  return "<a id='#{id}'></a><b><a href='#{src}'>#{item[:name]}</a></b>" + signature_suffix(item)
88
89
  end
@@ -235,10 +235,9 @@ MainPanel = function(){
235
235
  fields: ['cls', 'member', 'type', 'doc']
236
236
  })
237
237
  });
238
- this.searchStore.loadData(Docs.membersData);
239
- this.searchStore.filterBy(function(r) {
240
- return false;
241
- });
238
+ this.searchStore.loadData(Docs.membersData);
239
+ var records = this.searchStore.getRange();
240
+ this.searchStore.removeAll();
242
241
 
243
242
 
244
243
  MainPanel.superclass.constructor.call(this, {
@@ -258,25 +257,14 @@ MainPanel = function(){
258
257
  autoLoad: {url: 'welcome.html', callback: this.initSearch, scope: this, delay: 100},
259
258
  iconCls:'icon-docs',
260
259
  autoScroll: true,
261
- tbar: [
262
- 'Search: ', ' ',
263
- new Ext.ux.SelectBox({
264
- listClass:'x-combo-list-small',
265
- width:90,
266
- value:'Starts with',
267
- id:'search-type',
268
- store: new Ext.data.SimpleStore({
269
- fields: ['text'],
270
- expandData: true,
271
- data : ['Starts with', 'Ends with', 'Any match']
272
- }),
273
- displayField: 'text'
274
- }), ' ',
260
+ tbar: [
261
+ 'Search: ', ' ',
275
262
  new Ext.app.SearchField({
276
- width:240,
277
- store: this.searchStore,
278
- paramName: 'q'
279
- })
263
+ width: 340,
264
+ records: records,
265
+ store: this.searchStore,
266
+ paramName: 'q'
267
+ })
280
268
  ]
281
269
  }
282
270
  });
@@ -341,12 +329,18 @@ Ext.extend(MainPanel, Ext.TabPanel, {
341
329
  var resultTpl = new Ext.XTemplate(
342
330
  '<tpl for=".">',
343
331
  '<div class="search-item">',
344
- '<a class="member docClass" rel="{cls}#{member}" href="output/{cls}.html">',
332
+ '<a class="member docClass" rel="{[this.rel(values)]}" href="output/{cls}.html">',
345
333
  '<img src="resources/images/default/s.gif" class="item-icon icon-{type}"/>{member}',
346
334
  '</a> ',
347
335
  '<a class="cls docClass" rel="{cls}" href="output/{cls}.html">{cls}</a>',
348
336
  '<p>{doc}</p>',
349
- '</div></tpl>'
337
+ '</div></tpl>',
338
+ {
339
+ // Different links to classes and members
340
+ rel: function(values) {
341
+ return (values.type === "cls") ? values.cls : values.cls+"#"+values.member;
342
+ }
343
+ }
350
344
  );
351
345
 
352
346
  var p = new Ext.DataView({
@@ -358,20 +352,6 @@ Ext.extend(MainPanel, Ext.TabPanel, {
358
352
  itemSelector: 'div.search-item',
359
353
  emptyText: '<h3>Use the search field above to search the Ext API for classes, properties, config options, methods and events.</h3>'
360
354
  });
361
- },
362
-
363
- doSearch : function(e){
364
- var k = e.getKey();
365
- if(!e.isSpecialKey()){
366
- var text = e.target.value;
367
- if(!text){
368
- this.searchStore.baseParams.q = '';
369
- this.searchStore.removeAll();
370
- }else{
371
- this.searchStore.baseParams.q = text;
372
- this.searchStore.reload();
373
- }
374
- }
375
355
  }
376
356
  });
377
357
 
@@ -451,9 +431,7 @@ Ext.app.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
451
431
 
452
432
  onTrigger1Click : function(){
453
433
  if(this.hasSearch){
454
- this.store.filterBy(function(r) {
455
- return false;
456
- });
434
+ this.store.removeAll();
457
435
  this.el.dom.value = '';
458
436
  this.triggers[0].hide();
459
437
  this.hasSearch = false;
@@ -472,23 +450,37 @@ Ext.app.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
472
450
  return;
473
451
  }
474
452
 
475
- var type = Ext.getCmp('search-type').getValue();
476
- this.store.filter("member", this.createRegex(type, v));
453
+ this.store.removeAll();
454
+ this.store.add(this.search(v));
477
455
 
478
456
  this.hasSearch = true;
479
457
  this.triggers[0].show();
480
458
  this.focus();
481
459
  },
482
460
 
483
- createRegex: function(type, text) {
461
+ search: function(text) {
462
+ var results = [[], [], []];
484
463
  var safeText = Ext.escapeRe(text);
485
- if (type === 'Starts with') {
486
- return new RegExp("^" + safeText, "i");
487
- } else if (type === 'Ends with') {
488
- return new RegExp(safeText + "$", "i");
489
- } else {
490
- return new RegExp(safeText, "i");
491
- }
464
+ var re0 = new RegExp("^" + safeText + "$", "i");
465
+ var re1 = new RegExp("^" + safeText, "i");
466
+ var re2 = new RegExp(safeText, "i");
467
+ this.records.forEach(function(r) {
468
+ var member = r.get("member");
469
+ if (re0.test(member)) {
470
+ results[0].push(r);
471
+ }
472
+ else if (re1.test(member)) {
473
+ results[1].push(r);
474
+ }
475
+ else if (re2.test(member)) {
476
+ results[2].push(r);
477
+ }
478
+ });
479
+ // flatten results array
480
+ var arr = [];
481
+ results = arr.concat.apply(arr, results);
482
+ // only pick first n results
483
+ return results.slice(0, 50);
492
484
  }
493
485
  });
494
486
 
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsduck
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
9
- version: "0.5"
8
+ - 6
9
+ version: "0.6"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rene Saarsoo
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-29 00:00:00 +03:00
17
+ date: 2011-04-27 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -78,11 +78,13 @@ files:
78
78
  - lib/jsduck/app.rb
79
79
  - lib/jsduck/cfg_table.rb
80
80
  - lib/jsduck/class.rb
81
+ - lib/jsduck/css_parser.rb
81
82
  - lib/jsduck/doc_formatter.rb
82
83
  - lib/jsduck/doc_parser.rb
83
84
  - lib/jsduck/event_table.rb
84
85
  - lib/jsduck/exporter.rb
85
86
  - lib/jsduck/inheritance_tree.rb
87
+ - lib/jsduck/js_parser.rb
86
88
  - lib/jsduck/lexer.rb
87
89
  - lib/jsduck/long_params.rb
88
90
  - lib/jsduck/members.rb
@@ -90,11 +92,11 @@ files:
90
92
  - lib/jsduck/method_table.rb
91
93
  - lib/jsduck/page.rb
92
94
  - lib/jsduck/parallel_wrap.rb
93
- - lib/jsduck/parser.rb
94
95
  - lib/jsduck/property_table.rb
95
96
  - lib/jsduck/relations.rb
96
97
  - lib/jsduck/short_params.rb
97
- - lib/jsduck/source_formatter.rb
98
+ - lib/jsduck/source_file.rb
99
+ - lib/jsduck/source_writer.rb
98
100
  - lib/jsduck/table.rb
99
101
  - lib/jsduck/timer.rb
100
102
  - lib/jsduck/tree.rb