Skip to content

Commit

Permalink
Merge branch 'master' into doc-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Apr 23, 2013
2 parents 8cba388 + 0f73195 commit 1d55474
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 81 deletions.
12 changes: 8 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,14 @@ task :touch2 => :sass do
"--output", OUT_DIR,
"--config", "#{SDK_DIR}/touch/docs/config.json",
"--examples-base-url", "touch-build/examples/production/",
# "--import", "Touch 1.1:../docs.sencha.com/exports/touch-1.1",
# "--import", "Touch 2.0:../docs.sencha.com/exports/touch-2.0.1",
# "--import", "Touch 2.1.0:../docs.sencha.com/exports/touch-2.1.0",
# "--import", "Touch 2.1.1",
# "--import", "1.1.0:../docs.sencha.com/exports/touch-1.1.0",
# "--import", "1.1.1:../docs.sencha.com/exports/touch-1.1.1",
# "--import", "2.0.0:../docs.sencha.com/exports/touch-2.0.0",
# "--import", "2.0.1:../docs.sencha.com/exports/touch-2.0.1",
# "--import", "2.1.0:../docs.sencha.com/exports/touch-2.1.0",
# "--import", "2.1.1:../docs.sencha.com/exports/touch-2.1.1",
# "--import", "2.2.0:../docs.sencha.com/exports/touch-2.2.0",
# "--import", "2.2.1",
"--seo"
)

Expand Down
4 changes: 3 additions & 1 deletion bin/jsduck
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ require 'jsduck/options'

opts = JsDuck::Options.new
opts.parse!(ARGV)
JsDuck::App.new(opts).run
exit_code = JsDuck::App.new(opts).run

exit exit_code
8 changes: 8 additions & 0 deletions lib/jsduck/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'jsduck/tag_registry'
require 'jsduck/export_writer'
require 'jsduck/web/writer'
require 'jsduck/logger'

module JsDuck

Expand All @@ -15,6 +16,7 @@ def initialize(opts)
end

# Main App logic.
# Returns application exit code.
def run
parse

Expand All @@ -25,6 +27,12 @@ def run
else
generate_web_page
end

if @opts.warnings_exit_nonzero && Logger.warnings_logged?
return 2
else
return 0
end
end

private
Expand Down
3 changes: 3 additions & 0 deletions lib/jsduck/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'jsduck/examples'
require 'jsduck/categories/factory'
require 'jsduck/format/doc'
require 'jsduck/news'

module JsDuck

Expand All @@ -22,6 +23,7 @@ class Assets
attr_reader :videos
attr_reader :examples
attr_reader :categories
attr_reader :news

def initialize(relations, opts)
@relations = relations
Expand All @@ -35,6 +37,7 @@ def initialize(relations, opts)
@videos = Videos.create(@opts.videos)
@examples = Examples.create(@opts.examples, @opts)
@categories = Categories::Factory.create(@opts.categories_path, doc_formatter, @relations)
@news = News.create(@relations, doc_formatter, @opts)
end

# Writes out the assets that can be written out separately:
Expand Down
48 changes: 5 additions & 43 deletions lib/jsduck/categories/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'jsduck/categories/file'
require 'jsduck/categories/auto'
require 'jsduck/categories/class_name'
require 'jsduck/columns'

module JsDuck
module Categories
Expand All @@ -20,6 +21,7 @@ def self.create(filename, doc_formatter, relations)
def initialize(categories, doc_formatter, relations={})
@categories = categories
@class_name = Categories::ClassName.new(doc_formatter, relations)
@columns = Columns.new("classes")
end

# Returns HTML listing of classes divided into categories
Expand All @@ -41,10 +43,12 @@ def to_html(style="")
EOHTML
end

private

def render_columns(groups)
align = ["left-column", "middle-column", "right-column"]
i = -1
return split(groups, 3).map do |col|
return @columns.split(groups, 3).map do |col|
i += 1
[
"<div class='#{align[i]}'>",
Expand All @@ -65,48 +69,6 @@ def render_groups(groups)
end
end

# Splits the array of items into n chunks so that the sum of
# largest chunk is as small as possible.
#
# This is a brute-force implementation - we just try all the
# combinations and choose the best one.
def split(items, n)
if n == 1
[items]
elsif items.length <= n
Array.new(n) {|i| items[i] ? [items[i]] : [] }
else
min_max = nil
min_arr = nil
i = 0
while i <= items.length-n
i += 1
# Try placing 1, 2, 3, ... items to first chunk.
# Calculate the remaining chunks recursively.
cols = [items[0,i]] + split(items[i, items.length], n-1)
max = max_sum(cols)
# Is this the optimal solution so far? Remember it.
if !min_max || max < min_max
min_max = max
min_arr = cols
end
end
min_arr
end
end

def max_sum(cols)
cols.map {|col| sum(col) }.max
end

# Finds the total size of items in array
#
# The size of one item is it's number of classes + the space for header
def sum(arr)
header_size = 3
arr.reduce(0) {|sum, item| sum + item["classes"].length + header_size }
end

end

end
Expand Down
56 changes: 56 additions & 0 deletions lib/jsduck/columns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module JsDuck

# Splits array of items with subitems into roughly equal size groups.
class Columns
# Initialized with the name of subitems field.
def initialize(subitems_field)
@header_size = 3
@subitems_field = subitems_field
end

# Splits the array of items into n chunks so that the sum of
# largest chunk is as small as possible.
#
# This is a brute-force implementation - we just try all the
# combinations and choose the best one.
def split(items, n)
if n == 1
[items]
elsif items.length <= n
Array.new(n) {|i| items[i] ? [items[i]] : [] }
else
min_max = nil
min_arr = nil
i = 0
while i <= items.length-n
i += 1
# Try placing 1, 2, 3, ... items to first chunk.
# Calculate the remaining chunks recursively.
cols = [items[0,i]] + split(items[i, items.length], n-1)
max = max_sum(cols)
# Is this the optimal solution so far? Remember it.
if !min_max || max < min_max
min_max = max
min_arr = cols
end
end
min_arr
end
end

private

def max_sum(cols)
cols.map {|col| sum(col) }.max
end

# Finds the total size of items in array
#
# The size of one item is it's number of classes + the space for header
def sum(arr)
arr.reduce(0) {|sum, item| sum + item[@subitems_field].length + @header_size }
end

end

end
10 changes: 2 additions & 8 deletions lib/jsduck/inline/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ def initialize(opts={})
@templates = {
"html5" => '<video src="%u">%a</video>',
"vimeo" => [
'<p><object width="640" height="360">',
'<param name="allowfullscreen" value="true" />',
'<param name="allowscriptaccess" value="always" />',
'<param name="flashvars" value="api=1" />',
'<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=%u&amp;server=vimeo.com&amp;color=4CC208&amp;fullscreen=1" />',
'<embed src="http://vimeo.com/moogaloop.swf?clip_id=%u&amp;server=vimeo.com&amp;color=4CC208&amp;fullscreen=1" ',
'type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="360"></embed>',
'</object></p>',
'<p><iframe src="http://player.vimeo.com/video/%u" width="640" height="360" frameborder="0" ',
'webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>'
].join
}

Expand Down
13 changes: 12 additions & 1 deletion lib/jsduck/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ class Logger
# Set to true to enable verbose logging
attr_accessor :verbose

# Set true to force colored output.
# Set false to force no colors.
attr_accessor :colors

def initialize
@verbose = false
@colors = nil

@warning_docs = [
[:global, "Member doesn't belong to any class"],
[:inheritdoc, "@inheritdoc referring to unknown class or member"],
Expand Down Expand Up @@ -173,6 +179,11 @@ def fatal_backtrace(msg, error)
$stderr.puts error.backtrace
end

# True when at least one warning was logged.
def warnings_logged?
@shown_warnings.length > 0
end

private

COLORS = {
Expand All @@ -193,7 +204,7 @@ def fatal_backtrace(msg, error)
# Only does color output when STDERR is attached to TTY
# i.e. is not piped/redirected.
def paint(color_name, msg)
if Util::OS.windows? || !$stderr.tty?
if @colors == false || @colors == nil && (Util::OS.windows? || !$stderr.tty?)
msg
else
COLORS[color_name] + msg + CLEAR
Expand Down
116 changes: 116 additions & 0 deletions lib/jsduck/news.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
require 'jsduck/util/null_object'
require 'jsduck/columns'

module JsDuck

class News
# Creates News object from relations data when --import option
# specified.
def self.create(relations, doc_formatter, opts)
if opts[:imports].length > 0
News.new(relations, doc_formatter)
else
Util::NullObject.new(:to_html => "")
end
end

# Generates list of new classes & members in this version.
def initialize(relations, doc_formatter)
@doc_formatter = doc_formatter
@columns = Columns.new(:members)
@new_items = filter_new_items(relations)
end

# Returns the HTML
def to_html(style="")
return [
"<div id='news-content' style='#{style}'>",
"<div class='section'>",
"<h1>New in this version</h1>",
render_columns(@new_items),
"<div style='clear:both'></div>",
"</div>",
"</div>",
].flatten.join("\n")
end

private

def filter_new_items(relations)
classes = []
new_items = []
relations.each do |cls|
if !cls[:private]
if cls[:new]
classes << cls
else
group = {:name => cls[:name], :members => [], :new => cls[:new]}
cls.all_local_members.each do |m|
group[:members] << m if m[:new] && !m[:private] && !m[:hide]
end
group[:members] = discard_accessors(group[:members])
new_items << group if group[:members].length > 0
end
end
end

new_items.sort! {|a, b| a[:name] <=> b[:name] }

# Place the new classes section at the beginning
if classes.length > 0
new_items.unshift({:name => "New classes", :members => classes})
end

new_items
end

def discard_accessors(members)
accessors = {}
members.find_all {|m| m[:accessor] }.each do |cfg|
accessors["set" + upcase_first(cfg[:name])] = true
accessors["get" + upcase_first(cfg[:name])] = true
accessors[cfg[:name].downcase + "change"] = true if cfg[:evented]
end

members.reject {|m| accessors[m[:name]] }
end

def upcase_first(str)
str[0,1].upcase + str[1..-1]
end

def render_columns(new_items)
align = ["left-column", "middle-column", "right-column"]
i = -1
return @columns.split(new_items, 3).map do |col|
i += 1
[
"<div class='#{align[i]}'>",
render_col(col),
"</div>",
]
end
end

def render_col(col)
return col.map do |item|
[
"<h3>#{item[:name]}</h3>",
"<ul class='links'>",
item[:members].map {|m| "<li>" + link(m) + "</li>" },
"</ul>",
]
end
end

def link(m)
if m[:tagname] == :class
@doc_formatter.link(m[:name], nil, m[:name])
else
@doc_formatter.link(m[:owner], m[:name], m[:name], m[:tagname], m[:static])
end
end

end

end
Loading

0 comments on commit 1d55474

Please sign in to comment.