jsduck 4.8.0 → 4.9.0

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.
data/Rakefile CHANGED
@@ -273,10 +273,14 @@ task :touch2 => :sass do
273
273
  "--output", OUT_DIR,
274
274
  "--config", "#{SDK_DIR}/touch/docs/config.json",
275
275
  "--examples-base-url", "touch-build/examples/production/",
276
- # "--import", "Touch 1.1:../docs.sencha.com/exports/touch-1.1",
277
- # "--import", "Touch 2.0:../docs.sencha.com/exports/touch-2.0.1",
278
- # "--import", "Touch 2.1.0:../docs.sencha.com/exports/touch-2.1.0",
279
- # "--import", "Touch 2.1.1",
276
+ # "--import", "1.1.0:../docs.sencha.com/exports/touch-1.1.0",
277
+ # "--import", "1.1.1:../docs.sencha.com/exports/touch-1.1.1",
278
+ # "--import", "2.0.0:../docs.sencha.com/exports/touch-2.0.0",
279
+ # "--import", "2.0.1:../docs.sencha.com/exports/touch-2.0.1",
280
+ # "--import", "2.1.0:../docs.sencha.com/exports/touch-2.1.0",
281
+ # "--import", "2.1.1:../docs.sencha.com/exports/touch-2.1.1",
282
+ # "--import", "2.2.0:../docs.sencha.com/exports/touch-2.2.0",
283
+ # "--import", "2.2.1",
280
284
  "--seo"
281
285
  )
282
286
 
@@ -2,8 +2,8 @@ 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.8.0'
6
- s.date = '2013-04-22'
5
+ s.version = '4.9.0'
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"
9
9
  s.homepage = "https://github.com/senchalabs/jsduck"
@@ -6,6 +6,7 @@ require 'jsduck/videos'
6
6
  require 'jsduck/examples'
7
7
  require 'jsduck/categories'
8
8
  require 'jsduck/doc_formatter'
9
+ require 'jsduck/news'
9
10
 
10
11
  module JsDuck
11
12
 
@@ -22,6 +23,7 @@ module JsDuck
22
23
  attr_reader :videos
23
24
  attr_reader :examples
24
25
  attr_reader :categories
26
+ attr_reader :news
25
27
 
26
28
  def initialize(relations, opts)
27
29
  @relations = relations
@@ -35,6 +37,7 @@ module JsDuck
35
37
  @videos = Videos.create(@opts.videos)
36
38
  @examples = Examples.create(@opts.examples, @opts)
37
39
  @categories = Categories.create(@opts.categories_path, doc_formatter, @relations)
40
+ @news = News.create(@relations, doc_formatter, @opts)
38
41
  end
39
42
 
40
43
  # Writes out the assets that can be written out separately:
@@ -2,6 +2,7 @@ require 'jsduck/logger'
2
2
  require 'jsduck/file_categories'
3
3
  require 'jsduck/auto_categories'
4
4
  require 'jsduck/categories_class_name'
5
+ require 'jsduck/columns'
5
6
 
6
7
  module JsDuck
7
8
 
@@ -19,6 +20,7 @@ module JsDuck
19
20
  def initialize(categories, doc_formatter, relations={})
20
21
  @categories = categories
21
22
  @class_name = CategoriesClassName.new(doc_formatter, relations)
23
+ @columns = Columns.new("classes")
22
24
  end
23
25
 
24
26
  # Returns HTML listing of classes divided into categories
@@ -40,10 +42,12 @@ module JsDuck
40
42
  EOHTML
41
43
  end
42
44
 
45
+ private
46
+
43
47
  def render_columns(groups)
44
48
  align = ["left-column", "middle-column", "right-column"]
45
49
  i = -1
46
- return split(groups, 3).map do |col|
50
+ return @columns.split(groups, 3).map do |col|
47
51
  i += 1
48
52
  [
49
53
  "<div class='#{align[i]}'>",
@@ -64,48 +68,6 @@ module JsDuck
64
68
  end
65
69
  end
66
70
 
67
- # Splits the array of items into n chunks so that the sum of
68
- # largest chunk is as small as possible.
69
- #
70
- # This is a brute-force implementation - we just try all the
71
- # combinations and choose the best one.
72
- def split(items, n)
73
- if n == 1
74
- [items]
75
- elsif items.length <= n
76
- Array.new(n) {|i| items[i] ? [items[i]] : [] }
77
- else
78
- min_max = nil
79
- min_arr = nil
80
- i = 0
81
- while i <= items.length-n
82
- i += 1
83
- # Try placing 1, 2, 3, ... items to first chunk.
84
- # Calculate the remaining chunks recursively.
85
- cols = [items[0,i]] + split(items[i, items.length], n-1)
86
- max = max_sum(cols)
87
- # Is this the optimal solution so far? Remember it.
88
- if !min_max || max < min_max
89
- min_max = max
90
- min_arr = cols
91
- end
92
- end
93
- min_arr
94
- end
95
- end
96
-
97
- def max_sum(cols)
98
- cols.map {|col| sum(col) }.max
99
- end
100
-
101
- # Finds the total size of items in array
102
- #
103
- # The size of one item is it's number of classes + the space for header
104
- def sum(arr)
105
- header_size = 3
106
- arr.reduce(0) {|sum, item| sum + item["classes"].length + header_size }
107
- end
108
-
109
71
  end
110
72
 
111
73
  end
@@ -26,36 +26,12 @@ module JsDuck
26
26
  # Adds small star to new classes in the current version.
27
27
  def render_new_label(cls)
28
28
  if cls[:meta][:new]
29
- "&nbsp;<span class='new-class' title='New class'>#{stars(1)}</span>"
29
+ "&nbsp;<span class='new-class' title='New class'>&#9733;</span>"
30
30
  else
31
- n = new_members_count(cls)
32
- if n > 0
33
- title = "#{n} new member#{(n>1) ? 's' : ''}"
34
- "&nbsp;<span class='new-members' title='#{title}'>#{stars(n)}</span>"
35
- else
36
- ""
37
- end
31
+ ""
38
32
  end
39
33
  end
40
34
 
41
- # Produces string of n stars.
42
- # First 3 stars are rendered as "<unicode-star>", the following as "+".
43
- # At max 15 stars are rendered.
44
- def stars(n)
45
- if n > 15
46
- stars(3) + ("+" * (15-3))
47
- elsif n > 3
48
- stars(3) + ("+" * (n-3))
49
- else
50
- "&#9733;" * n
51
- end
52
- end
53
-
54
- # Returns number of new members the class has in the current version
55
- def new_members_count(cls)
56
- cls.find_members(:local => true).find_all {|m| m[:meta][:new] && !m[:private] }.length
57
- end
58
-
59
35
  end
60
36
 
61
37
  end
@@ -0,0 +1,56 @@
1
+ module JsDuck
2
+
3
+ # Splits array of items with subitems into roughly equal size groups.
4
+ class Columns
5
+ # Initialized with the name of subitems field.
6
+ def initialize(subitems_field)
7
+ @header_size = 3
8
+ @subitems_field = subitems_field
9
+ end
10
+
11
+ # Splits the array of items into n chunks so that the sum of
12
+ # largest chunk is as small as possible.
13
+ #
14
+ # This is a brute-force implementation - we just try all the
15
+ # combinations and choose the best one.
16
+ def split(items, n)
17
+ if n == 1
18
+ [items]
19
+ elsif items.length <= n
20
+ Array.new(n) {|i| items[i] ? [items[i]] : [] }
21
+ else
22
+ min_max = nil
23
+ min_arr = nil
24
+ i = 0
25
+ while i <= items.length-n
26
+ i += 1
27
+ # Try placing 1, 2, 3, ... items to first chunk.
28
+ # Calculate the remaining chunks recursively.
29
+ cols = [items[0,i]] + split(items[i, items.length], n-1)
30
+ max = max_sum(cols)
31
+ # Is this the optimal solution so far? Remember it.
32
+ if !min_max || max < min_max
33
+ min_max = max
34
+ min_arr = cols
35
+ end
36
+ end
37
+ min_arr
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def max_sum(cols)
44
+ cols.map {|col| sum(col) }.max
45
+ end
46
+
47
+ # Finds the total size of items in array
48
+ #
49
+ # The size of one item is it's number of classes + the space for header
50
+ def sum(arr)
51
+ arr.reduce(0) {|sum, item| sum + item[@subitems_field].length + @header_size }
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -37,6 +37,7 @@ module JsDuck
37
37
  "{data_path}" => File.basename(@opts.data_path),
38
38
  "{welcome}" => @assets.welcome.to_html("display:none"),
39
39
  "{categories}" => @assets.categories.to_html("display:none"),
40
+ "{news}" => @assets.news.to_html("display:none"),
40
41
  "{guides}" => @assets.guides.to_html("display:none"),
41
42
  "{head_html}" => @opts.head_html,
42
43
  "{body_html}" => @opts.body_html,
@@ -0,0 +1,128 @@
1
+ require 'jsduck/util/null_object'
2
+ require 'jsduck/columns'
3
+
4
+ module JsDuck
5
+
6
+ class News
7
+ # Creates News object from relations data when --import option
8
+ # specified.
9
+ def self.create(relations, doc_formatter, opts)
10
+ if opts[:imports].length > 0
11
+ News.new(relations, doc_formatter)
12
+ else
13
+ Util::NullObject.new(:to_html => "")
14
+ end
15
+ end
16
+
17
+ # Generates list of new classes & members in this version.
18
+ def initialize(relations, doc_formatter)
19
+ @doc_formatter = doc_formatter
20
+ @columns = Columns.new(:members)
21
+ @new_items = filter_new_items(relations)
22
+ end
23
+
24
+ # Returns the HTML
25
+ def to_html(style="")
26
+ return [
27
+ "<div id='news-content' style='#{style}'>",
28
+ "<div class='section'>",
29
+ "<h1>New in this version</h1>",
30
+ render_columns(@new_items),
31
+ "<div style='clear:both'></div>",
32
+ "</div>",
33
+ "</div>",
34
+ ].flatten.join("\n")
35
+ end
36
+
37
+ private
38
+
39
+ def filter_new_items(relations)
40
+ classes = []
41
+ new_items = []
42
+
43
+ relations.each do |cls|
44
+ if !cls[:meta][:private]
45
+ if cls[:meta][:new]
46
+ classes << cls
47
+ else
48
+ members = filter_new_members(cls)
49
+ if members.length > 0
50
+ new_items << {:name => cls[:name], :members => members}
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ new_items.sort! {|a, b| a[:name] <=> b[:name] }
57
+
58
+ # Place the new classes section at the beginning
59
+ if classes.length > 0
60
+ new_items.unshift({:name => "New classes", :members => classes})
61
+ end
62
+
63
+ new_items
64
+ end
65
+
66
+ def filter_new_members(cls)
67
+ members = []
68
+ cls.all_local_members.each do |m|
69
+ members << m if m[:meta][:new] && visible?(m)
70
+ end
71
+ members = discard_accessors(members)
72
+ members.sort! {|a, b| a[:name] <=> b[:name] }
73
+ end
74
+
75
+ def visible?(member)
76
+ !member[:meta][:private] && !member[:meta][:hide]
77
+ end
78
+
79
+ def discard_accessors(members)
80
+ accessors = {}
81
+ members.find_all {|m| m[:accessor] }.each do |cfg|
82
+ accessors["set" + upcase_first(cfg[:name])] = true
83
+ accessors["get" + upcase_first(cfg[:name])] = true
84
+ accessors[cfg[:name].downcase + "change"] = true if cfg[:evented]
85
+ end
86
+
87
+ members.reject {|m| accessors[m[:name]] }
88
+ end
89
+
90
+ def upcase_first(str)
91
+ str[0,1].upcase + str[1..-1]
92
+ end
93
+
94
+ def render_columns(new_items)
95
+ align = ["left-column", "middle-column", "right-column"]
96
+ i = -1
97
+ return @columns.split(new_items, 3).map do |col|
98
+ i += 1
99
+ [
100
+ "<div class='#{align[i]}'>",
101
+ render_col(col),
102
+ "</div>",
103
+ ]
104
+ end
105
+ end
106
+
107
+ def render_col(col)
108
+ return col.map do |item|
109
+ [
110
+ "<h3>#{item[:name]}</h3>",
111
+ "<ul class='links'>",
112
+ item[:members].map {|m| "<li>" + link(m) + "</li>" },
113
+ "</ul>",
114
+ ]
115
+ end
116
+ end
117
+
118
+ def link(m)
119
+ if m[:tagname] == :class
120
+ @doc_formatter.link(m[:name], nil, m[:name])
121
+ else
122
+ @doc_formatter.link(m[:owner], m[:name], m[:name], m[:tagname], m[:meta][:static])
123
+ end
124
+ end
125
+
126
+ end
127
+
128
+ end
@@ -93,7 +93,7 @@ module JsDuck
93
93
  @ext4_events = nil
94
94
  @meta_tag_paths = []
95
95
 
96
- @version = "4.8.0"
96
+ @version = "4.9.0"
97
97
 
98
98
  # Customizing output
99
99
  @title = "Documentation - JSDuck"
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.8.0
4
+ version: 4.9.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-04-22 00:00:00.000000000 Z
13
+ date: 2013-05-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdiscount
@@ -203,6 +203,7 @@ files:
203
203
  - lib/jsduck/class_formatter.rb
204
204
  - lib/jsduck/class_name.rb
205
205
  - lib/jsduck/class_writer.rb
206
+ - lib/jsduck/columns.rb
206
207
  - lib/jsduck/css_lexer.rb
207
208
  - lib/jsduck/css_parser.rb
208
209
  - lib/jsduck/doc_ast.rb
@@ -249,6 +250,7 @@ files:
249
250
  - lib/jsduck/meta_tag_loader.rb
250
251
  - lib/jsduck/meta_tag_registry.rb
251
252
  - lib/jsduck/meta_tag_renderer.rb
253
+ - lib/jsduck/news.rb
252
254
  - lib/jsduck/option_parser.rb
253
255
  - lib/jsduck/options.rb
254
256
  - lib/jsduck/override.rb
@@ -671,10 +673,10 @@ files:
671
673
  - template-min/extjs/resources/themes/images/default/btn-group/btn-group-default-framed-sides.gif
672
674
  - template-min/index-template.html
673
675
  - template-min/README.md
674
- - template-min/app-9096a86b4ef476d85905927d55b2fdef.js
675
676
  - template-min/eg-iframe.html
677
+ - template-min/app-baf1b533a51447e178d66adecf5e85d4.js
676
678
  - template-min/index.php
677
- - template-min/resources/css/app-d837b293d081641aaa2111b87080b6d6.css
679
+ - template-min/resources/css/app-44f34022ca84128086b28c375ab02185.css
678
680
  - template-min/resources/images/link-green-standard.png
679
681
  - template-min/resources/images/class-m.png
680
682
  - template-min/resources/images/singleton-m.png