jsduck 4.9.0 → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -159,6 +159,11 @@ class JsDuckRunner
159
159
  add_options("--comments-domain", db_name+"/"+version)
160
160
  end
161
161
 
162
+ def add_search(product, version)
163
+ add_options("--search-url", "http://support-test.sencha.com:8080/docsearch/search")
164
+ add_options("--search-domain", product+"/"+version)
165
+ end
166
+
162
167
  def add_ext4
163
168
  @options += [
164
169
  "--title", "Sencha Docs - Ext JS 4.0",
@@ -261,6 +266,7 @@ task :sdk => :sass do
261
266
  )
262
267
  runner.add_debug
263
268
  runner.add_comments('ext-js', '4')
269
+ runner.add_search('Ext JS', '4.2.0')
264
270
  runner.run
265
271
 
266
272
  system("ln -s #{EXT_BUILD} #{OUT_DIR}/extjs-build")
data/jsduck.gemspec CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
2
2
  s.required_rubygems_version = ">= 1.3.5"
3
3
 
4
4
  s.name = 'jsduck'
5
- s.version = '4.9.0'
5
+ s.version = '4.10.0'
6
6
  s.date = Time.new.strftime('%Y-%m-%d')
7
7
  s.summary = "Simple JavaScript Duckumentation generator"
8
8
  s.description = "Documentation generator for Sencha JS frameworks"
@@ -21,7 +21,8 @@ module JsDuck
21
21
  :guides => @assets.guides.to_array,
22
22
  :videos => @assets.videos.to_array,
23
23
  :examples => @assets.examples.to_array,
24
- :search => SearchData.new.create(@relations.classes, @assets),
24
+ :search => SearchData.new.create(@relations.classes, @assets, @opts),
25
+ :guideSearch => @opts.search,
25
26
  :tests => @opts.tests,
26
27
  :signatures => MetaTagRegistry.instance.signatures,
27
28
  :localStorageDb => @opts.local_storage_db,
@@ -0,0 +1,32 @@
1
+ module JsDuck
2
+
3
+ # Transforms in-page links so they won't break docs app #!-navigation.
4
+ #
5
+ # For example a link to "#automation" in testing guide will be
6
+ # replaced with "#!/guide/testing-section-automation" and the link
7
+ # target ID will be transformed into "testing-section-automation".
8
+ class GuideAnchors
9
+
10
+ def self.transform(html, guide_name)
11
+ html.gsub(/(<a\s+(?:[^<>]*\s+)?href=['"]#)([^!].*?)(['"])/i) do |m|
12
+ "#{$1}!/guide/#{guide_name}-section-#{$2}#{$3}"
13
+
14
+ end.gsub(/(<a\s+(?:[^<>]*\s+)?name=['"])(.*?)(['"])/i) do |m|
15
+ $1 + transform_id($2, guide_name) + $3
16
+
17
+ end.gsub(/(<\w+\s+(?:[^<>]*\s+)?id=['"])(.*?)(['"])/i) do |m|
18
+ $1 + transform_id($2, guide_name) + $3
19
+ end
20
+ end
21
+
22
+ def self.transform_id(id, guide_name)
23
+ if id =~ /^#{guide_name}-section-/
24
+ id
25
+ else
26
+ "#{guide_name}-section-#{id}"
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,49 @@
1
+ require 'jsduck/util/html'
2
+
3
+ module JsDuck
4
+
5
+ # Adds Table of Contents section to guide HTML.
6
+ class GuideToc
7
+
8
+ # Inserts table of contents at the top of guide HTML by looking
9
+ # for <h2> elements.
10
+ def self.inject(html, guide_name)
11
+ toc = []
12
+ new_html = []
13
+
14
+ html.each_line do |line|
15
+ if line =~ /^\s*<(h[1-6])>(.*?)<\/h[1-6]>$/
16
+ tag = $1
17
+ text = Util::HTML.strip_tags($2)
18
+ id = guide_name + "-section-" + title_to_id(text)
19
+ if tag == "h2"
20
+ toc << "<li><a href='#!/guide/#{id}'>#{text}</a></li>\n"
21
+ end
22
+ new_html << "<#{tag} id='#{id}'>#{text}</#{tag}>\n"
23
+ else
24
+ new_html << line
25
+ end
26
+ end
27
+
28
+ # Inject TOC below first heading if at least 2 items in TOC
29
+ if toc.length >= 2
30
+ new_html.insert(1, [
31
+ "<div class='toc'>\n",
32
+ "<p><strong>Contents</strong></p>\n",
33
+ "<ol>\n",
34
+ toc,
35
+ "</ol>\n",
36
+ "</div>\n",
37
+ ])
38
+ end
39
+
40
+ new_html.flatten.join
41
+ end
42
+
43
+ def self.title_to_id(title)
44
+ title.downcase.gsub(/[^\w]+/, "-")
45
+ end
46
+
47
+ end
48
+
49
+ end
data/lib/jsduck/guides.rb CHANGED
@@ -4,7 +4,8 @@ require 'jsduck/util/io'
4
4
  require 'jsduck/util/null_object'
5
5
  require 'jsduck/logger'
6
6
  require 'jsduck/grouped_asset'
7
- require 'jsduck/util/html'
7
+ require 'jsduck/guide_toc'
8
+ require 'jsduck/guide_anchors'
8
9
  require 'jsduck/img/dir'
9
10
  require 'fileutils'
10
11
 
@@ -67,7 +68,9 @@ module JsDuck
67
68
  def format_guide(guide)
68
69
  @formatter.doc_context = {:filename => guide[:filename], :linenr => 0}
69
70
  @formatter.images = Img::Dir.new(guide["url"], "guides/#{guide["name"]}")
70
- html = add_toc(guide, @formatter.format(Util::IO.read(guide[:filename])))
71
+ html = @formatter.format(Util::IO.read(guide[:filename]))
72
+ html = GuideToc.inject(html, guide['name'])
73
+ html = GuideAnchors.transform(html, guide['name'])
71
74
 
72
75
  # Report unused images (but ignore the icon files)
73
76
  @formatter.images.get("icon.png")
@@ -115,36 +118,6 @@ module JsDuck
115
118
  end
116
119
  end
117
120
 
118
- # Creates table of contents at the top of guide by looking for <h2> elements in HTML.
119
- def add_toc(guide, html)
120
- toc = [
121
- "<div class='toc'>\n",
122
- "<p><strong>Contents</strong></p>\n",
123
- "<ol>\n",
124
- ]
125
- new_html = []
126
- i = 0
127
- html.each_line do |line|
128
- if line =~ /^<h2>(.*)<\/h2>$/
129
- i += 1
130
- text = Util::HTML.strip_tags($1)
131
- toc << "<li><a href='#!/guide/#{guide['name']}-section-#{i}'>#{text}</a></li>\n"
132
- new_html << "<h2 id='#{guide['name']}-section-#{i}'>#{text}</h2>\n"
133
- else
134
- new_html << line
135
- end
136
- end
137
- toc << "</ol>\n"
138
- toc << "</div>\n"
139
- # Inject TOC at below first heading if at least 2 items in TOC
140
- if i >= 2
141
- new_html.insert(1, toc)
142
- new_html.flatten.join
143
- else
144
- html
145
- end
146
- end
147
-
148
121
  # Returns HTML listing of guides
149
122
  def to_html(style="")
150
123
  html = @groups.map do |group|
@@ -40,6 +40,7 @@ module JsDuck
40
40
  attr_accessor :tests
41
41
  attr_accessor :comments_url
42
42
  attr_accessor :comments_domain
43
+ attr_accessor :search
43
44
  attr_accessor :ignore_html
44
45
 
45
46
  # Debugging
@@ -93,7 +94,7 @@ module JsDuck
93
94
  @ext4_events = nil
94
95
  @meta_tag_paths = []
95
96
 
96
- @version = "4.9.0"
97
+ @version = "4.10.0"
97
98
 
98
99
  # Customizing output
99
100
  @title = "Documentation - JSDuck"
@@ -120,6 +121,7 @@ module JsDuck
120
121
  @tests = false
121
122
  @comments_url = nil
122
123
  @comments_domain = nil
124
+ @search = {}
123
125
  @ignore_html = {}
124
126
 
125
127
  # Debugging
@@ -426,6 +428,8 @@ module JsDuck
426
428
  end
427
429
 
428
430
  opts.on('--comments-domain=STRING',
431
+ "A name identifying the subset of comments.",
432
+ "",
429
433
  "A string consisting of <name>/<version>.",
430
434
  "",
431
435
  "For example: ext-js/4",
@@ -434,6 +438,37 @@ module JsDuck
434
438
  @comments_domain = domain
435
439
  end
436
440
 
441
+ opts.on('--search-url=URL',
442
+ "Address of guides search server.",
443
+ "",
444
+ "When supplied, the search for guides is performed through this",
445
+ "external service and the results merged together with API search.",
446
+ "The search server must respond to JSONP requests.",
447
+ "",
448
+ "For example: http://sencha.com/docsearch",
449
+ "",
450
+ "Must be used together with --search-domain option.",
451
+ "",
452
+ "This option is EXPERIMENTAL.") do |url|
453
+ @search[:url] = url
454
+ end
455
+
456
+ opts.on('--search-domain=STRING',
457
+ "A name identifying the subset to search from.",
458
+ "",
459
+ "A string consisting of <name>/<version>.",
460
+ "",
461
+ "Tells the search engine which product and version",
462
+ "to include into search.",
463
+ "",
464
+ "For example: Ext JS/4.2.0",
465
+ "",
466
+ "Must be used together with --search-url option.",
467
+ "",
468
+ "This option is EXPERIMENTAL.") do |domain|
469
+ @search[:product], @search[:version] = domain.split(/\//)
470
+ end
471
+
437
472
  opts.separator ""
438
473
  opts.separator "Tweaking:"
439
474
  opts.separator ""
@@ -8,7 +8,7 @@ module JsDuck
8
8
  class SearchData
9
9
  # Given list of classes and other assets, returns an array of
10
10
  # hashes describing the search data.
11
- def create(classes, assets)
11
+ def create(classes, assets, opts)
12
12
  list = []
13
13
 
14
14
  classes.each do |cls|
@@ -30,7 +30,8 @@ module JsDuck
30
30
  end
31
31
  end
32
32
 
33
- assets.guides.each_item {|g| list << guide_node(g) }
33
+ # Don't include guides data when separate guides search engine is provided
34
+ assets.guides.each_item {|g| list << guide_node(g) } unless opts.search[:url]
34
35
 
35
36
  assets.videos.each_item {|v| list << video_node(v) }
36
37
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsduck
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.9.0
4
+ version: 4.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-03 00:00:00.000000000 Z
13
+ date: 2013-05-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdiscount
@@ -224,6 +224,8 @@ files:
224
224
  - lib/jsduck/file_categories.rb
225
225
  - lib/jsduck/function_ast.rb
226
226
  - lib/jsduck/grouped_asset.rb
227
+ - lib/jsduck/guide_anchors.rb
228
+ - lib/jsduck/guide_toc.rb
227
229
  - lib/jsduck/guide_writer.rb
228
230
  - lib/jsduck/guides.rb
229
231
  - lib/jsduck/html_stack.rb
@@ -673,10 +675,10 @@ files:
673
675
  - template-min/extjs/resources/themes/images/default/btn-group/btn-group-default-framed-sides.gif
674
676
  - template-min/index-template.html
675
677
  - template-min/README.md
678
+ - template-min/app-0b00cb36fe5624b12d5a495c4289e5d9.js
676
679
  - template-min/eg-iframe.html
677
- - template-min/app-baf1b533a51447e178d66adecf5e85d4.js
678
680
  - template-min/index.php
679
- - template-min/resources/css/app-44f34022ca84128086b28c375ab02185.css
681
+ - template-min/resources/css/app-c8e1f59f40e720cb5379f7041379119a.css
680
682
  - template-min/resources/images/link-green-standard.png
681
683
  - template-min/resources/images/class-m.png
682
684
  - template-min/resources/images/singleton-m.png