diff --git a/.gitignore b/.gitignore index 794d745a..c3ffa34e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ npm-debug.log docs-ghpages bower_components +.vscode/ diff --git a/lib/builder.js b/lib/builder.js index 2f5b42c3..7d169b48 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -292,6 +292,7 @@ var BuilderContext = { debug('skipping class ' + clazz.name); return; } + clazz.members.sort(compareEntries); if (clazz.isEnum) { clazz.type = 'enums'; enums.push(clazz); @@ -300,6 +301,8 @@ var BuilderContext = { classes.push(clazz); } }); + classes.sort(compareEntries); + enums.sort(compareEntries); opts.meta.classes = classes; opts.meta.enums = enums; return opts; @@ -325,6 +328,28 @@ var BuilderContext = { mod.type = 'modules'; mod.submodules = _.sortBy(submodules, 'name'); } + if (mod.classes.length > 0) { + mod.hasClasses = true; + var classes = []; + var enums = []; + _.each(mod.classes, function (obj) { + if (obj.isEnum) { + enums.push(obj); + } + else { + classes.push(obj); + } + }); + classes.sort(compareEntries); + enums.sort(compareEntries); + mod.classes = classes; + mod.enums = enums; + } else { + mod.hasClasses = false; + } + if (mod.members) { + mod.members.sort(compareEntries); + } }); opts.meta.modules = _.sortBy(modules, 'name'); return opts; @@ -634,7 +659,7 @@ var BuilderContext = { var view = new DocView(locals.meta); view.base = '.'; var html = this.render('index', view, locals); - var filename = this.options.markdown ? '/readme.md' : '/index.html'; + var filename = this.options.markdown ? '/index.md' : '/index.html'; var dest = this.options.dest + filename; debug('Start writing index.html'); @@ -710,6 +735,7 @@ var BuilderContext = { locals.meta.modules, function (mod) { mod.globals = locals.meta; + mod.enums = locals.meta.enums; var view = new DocView(mod, null, '../'); var dest = path.join(self.options.dest, 'modules', mod.name + self.extname); view.base = '..'; @@ -729,6 +755,19 @@ var BuilderContext = { var emitter = new EventEmitter(); BuilderContext = _.extend(BuilderContext, emitter); +// sorting entries +function compareEntries (a, b) { + var nameA = a.name.toLowerCase(); + var nameB = b.name.toLowerCase(); + if (nameA < nameB) { + return -1; + } + if (nameA > nameB) { + return 1; + } + return 0; +} + /** * Function to link an external type uses `NATIVES` object * @method NATIVES_LINKER diff --git a/lib/firedoc.js b/lib/firedoc.js index 18ca99ae..fcfb9302 100755 --- a/lib/firedoc.js +++ b/lib/firedoc.js @@ -85,6 +85,16 @@ function Firedoc (config) { if (fs.existsSync(cwd + '/yuidoc.json')) { pkg = require(cwd + '/yuidoc.json'); firedocOptions = pkg.options; + // change the default branch (master) to commit id. + var myPath = __dirname.replace(/\\node_modules\\.+/, ''); + myPath = path.resolve(myPath, './../engine'); + var command = spawn('git', ['log','--format="%H"', '-n' ,'1'], { + cwd: myPath, + }); + command.stdout.on('data', function (data) { + firedocOptions.sourceURL.branch = data.toString().trim().replace(/"/g, ''); + }); + delete pkg.options; } else if (fs.existsSync(cwd + '/package.json')) { pkg = require(cwd + '/package.json'); diff --git a/lib/helpers.js b/lib/helpers.js index 3e1f4827..b739e86a 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -47,7 +47,7 @@ exports.crossLink = function oncrossLink (item, options) { _.each(parts, function (i) { p.push(this._parseCrossLink.call(this, i)); }, this); - str = p.join(' | '); + str = p.join(' | '); } else { var ctx = ''; if (typeof options.fn === 'function') { @@ -110,3 +110,20 @@ exports.shouldShowInherit = function shouldShowInherit (item, options) { return options.inverse(this); } }; + +exports.getSourceFile = function getSourceFile (item, options) { + var sourceURL = this.options.sourceURL; + var org = sourceURL.org, repo = sourceURL.repo, branch = sourceURL.branch; + var path = require('path'); + var relativePath = path.relative(path.join(this.options.paths[0], repo), item).replace(/\\/g, '/'); + var baseStr = `https://github.com/${org}/${repo}/blob/${branch}/` + relativePath; + return baseStr; +}; + +exports.getVersion = function getVersion () { + return this.options.version; +}; + +exports.encodeName = function encodeName (item, options) { + return encodeURI(item); +}; \ No newline at end of file diff --git a/lib/locals.js b/lib/locals.js index ed633752..78b846cf 100644 --- a/lib/locals.js +++ b/lib/locals.js @@ -220,6 +220,9 @@ var Locals = { html = html.replace(/
/g, '\n');
// TODO(Yorkie): request to underscore, this is not working with '
html = html.replace(/'/g, '\'');
+ if (this.options.markdown) {
+ html = html.replace(/(\d+);/g, function (m, p) { return String.fromCharCode(p); });
+ }
return _.unescape(html);
},
@@ -233,6 +236,13 @@ var Locals = {
markdown: function (data) {
var self = this;
if (this.options.markdown) {
+ if (data.indexOf('{{#crossLink') > -1) {
+ var regex = /({{#crossLink\w*\s".*"}}.*{{\/crossLink\w*}})/g;
+ var result = data.replace(regex, function(match) {
+ return (Handlebars.compile(match))({});
+ });
+ return result;
+ }
return data;
}
var html = _.unescape(md.render(data || ''));
@@ -265,6 +275,10 @@ var Locals = {
if (mod) {
if (!_.isArray(mod.classes)) mod.classes = [];
mod.classes.push(clazz);
+ if (clazz.isEnum) {
+ // for markdown template checking whether should render enum section
+ mod.hasEnum = true;
+ }
}
return clazz;
},
@@ -342,7 +356,7 @@ var Locals = {
}
if (this.options.markdown) {
- member.markdownLink = utils.markdownLink(member.itemtype + ':' + member.name);
+ member.markdownLink = utils.markdownLink(member.name);
}
if (member.example) {
if (!_.isArray(member.example)) {
diff --git a/lib/utils.js b/lib/utils.js
index 8bb98e57..ca1d76ef 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -373,7 +373,7 @@ exports.localize = localize;
function markdownLink (str) {
return str
.replace(/[:,]/g, '-')
- .replace(/[\s\(\)\[\]=]/g, '')
+ .replace(/[\s\(\)\[\]=_]/g, '')
.toLowerCase();
}
exports.markdownLink = markdownLink;
diff --git a/package.json b/package.json
index bd7817b9..26e9f940 100644
--- a/package.json
+++ b/package.json
@@ -102,7 +102,9 @@
},
"scripts": {
"docs": "make docs",
- "test": "make test.nocoverage"
+ "test": "make test.nocoverage",
+ "build-api": "node ./bin/firedoc.js build -M --lang zh",
+ "build-api-en": "node ./bin/firedoc.js build -M --lang en"
},
"preferGlobal": "true",
"licenses": [
diff --git a/themes/markdown/layouts/main.mdt b/themes/markdown/layouts/main.mdt
index a15ddff3..47dd1df6 100644
--- a/themes/markdown/layouts/main.mdt
+++ b/themes/markdown/layouts/main.mdt
@@ -1,14 +1 @@
-
-{{#if globals.project.name}}
-# {{globals.project.name}} {{globals.project.version}}
-{{else}}
-# Fireball Engine API
-{{/if}}
-
-{{#if project.description}}
-{{project.description}}
-{{else}}
-Fireball is the game engine for the future.
-{{/if}}
-
{{> layout_content}}
diff --git a/themes/markdown/partials/attrs.mdt b/themes/markdown/partials/attrs.mdt
index 53db9a05..a9ceeec8 100644
--- a/themes/markdown/partials/attrs.mdt
+++ b/themes/markdown/partials/attrs.mdt
@@ -7,7 +7,7 @@
{{#if extended_from}}
> Inherited from `{{extended_from}}`
{{/if}}
-Defined in `{{{file}}}:{{{line}}}`
+Defined in [{{getSourceFile file}}:{{{line}}}]({{getSourceFile file}}#L{{{line}}})
{{/if}}
{{#if deprecationMessage}}
diff --git a/themes/markdown/partials/class.mdt b/themes/markdown/partials/class.mdt
index 79c6dafc..cb94e71d 100644
--- a/themes/markdown/partials/class.mdt
+++ b/themes/markdown/partials/class.mdt
@@ -1,11 +1,11 @@
-### `{{name}}` Class
+## `{{name}}` Class
{{#if extends}}
-Extends `{{extends}}`
+Extends [`{{extends}}`]({{extends}}.md)
{{/if}}
{{#if foundAt}}
-Defined in: [{{{file}}}:{{{line}}}](../files/{{{file}}}.js)
+Defined in: [{{getSourceFile file}}:{{{line}}}]({{getSourceFile file}}#L{{{line}}})
{{/if}}
{{#if module}}
diff --git a/themes/markdown/partials/enum.mdt b/themes/markdown/partials/enum.mdt
index 996154bf..07811be4 100644
--- a/themes/markdown/partials/enum.mdt
+++ b/themes/markdown/partials/enum.mdt
@@ -5,7 +5,7 @@ Extends `{{extends}}`
{{/if}}
{{#if foundAt}}
-Defined in: [{{{file}}}:{{{line}}}](../files/{{{file}}}.js)
+Defined in: [{{getSourceFile file}}:{{{line}}}]({{getSourceFile file}}#L{{{line}}})
{{/if}}
{{#if module}}
diff --git a/themes/markdown/partials/events.mdt b/themes/markdown/partials/events.mdt
index 7aa366a9..82fa1ea7 100644
--- a/themes/markdown/partials/events.mdt
+++ b/themes/markdown/partials/events.mdt
@@ -5,7 +5,7 @@ Extends `{{extends}}`
{{/if}}
{{#if foundAt}}
-Defined in: [{{{file}}}:{{{line}}}]({{foundAt}})
+Defined in: [{{getSourceFile file}}:{{{line}}}]({{getSourceFile file}}#L{{{line}}})
{{/if}}
{{#if module}}
diff --git a/themes/markdown/partials/index.mdt b/themes/markdown/partials/index.mdt
index ccd57eef..fbb5cfc2 100644
--- a/themes/markdown/partials/index.mdt
+++ b/themes/markdown/partials/index.mdt
@@ -1,23 +1,31 @@
+# Index
-{{#if enums}}
-### Enums
-{{#enums}}
-{{#if is_enum}}
-- [`{{name}}`](enums/{{name}}.md) from [{{module}}](modules/{{module}}.md)
-{{/if}}
-{{/enums}}
+Cocos Creator v{{getVersion}}
+
+Welcome to Cocos Creator JavaScript engine API reference. You can search anything in top left search filed.
+
+All enums and classes are under `cc` module if not specified otherwise.
+
+{{#if modules}}
+### Module
+
+{{#modules}}
+- [`{{name}}`](modules/{{encodeName name}}.md)
+{{/modules}}
{{/if}}
{{#if classes}}
### Classes
+
{{#classes}}
- [`{{name}}`](classes/{{name}}.md) from [{{module}}](modules/{{module}}.md)
{{/classes}}
{{/if}}
-{{#if modules}}
-### Module
-{{#modules}}
-- [`{{name}}`](modules/{{name}}.md)
-{{/modules}}
+{{#if enums}}
+### Enums
+
+{{#enums}}
+- [`{{name}}`](enums/{{name}}.md) from [{{module}}](modules/{{module}}.md)
+{{/enums}}
{{/if}}
diff --git a/themes/markdown/partials/items-index.mdt b/themes/markdown/partials/items-index.mdt
index 98c8011b..19e62e8e 100644
--- a/themes/markdown/partials/items-index.mdt
+++ b/themes/markdown/partials/items-index.mdt
@@ -38,40 +38,4 @@
- [`{{name}}`](#{{markdownLink}}) {{{description}}}
{{/members.events}}
-{{/if}}
-
-{{#if members.inherited}}
-
-### Inherited members
-
-##### Properties
-
-{{#members.inherited.properties}}
-- [`{{name}}`](#{{markdownLink}})
-{{/members.inherited.properties}}
-
-##### Attributes
-
-{{#members.inherited.attributes}}
-- [`{{name}}`](#{{markdownLink}})
-{{/members.inherited.attributes}}
-
-##### Methods
-
-{{#members.inherited.methods}}
-- [`{{methodName}}`](#{{markdownLink}})
-{{/members.inherited.methods}}
-
-##### Events
-
-{{#members.inherited.events}}
-- [`{{name}}`](#{{markdownLink}})
-{{/members.inherited.events}}
-
-{{/if}}
-
-{{#if children}}
-
-### Inheritance tree
-
{{/if}}
\ No newline at end of file
diff --git a/themes/markdown/partials/method.mdt b/themes/markdown/partials/method.mdt
index 22e5a210..55299c8b 100644
--- a/themes/markdown/partials/method.mdt
+++ b/themes/markdown/partials/method.mdt
@@ -12,7 +12,7 @@
| Extends | `{{extended_from}}` |
{{/if}}
{{/if}}
-| Defined | [{{{file}}}:{{{line}}}]({{foundAt}}) |
+| Defined | [{{getSourceFile file}}:{{{line}}}]({{getSourceFile file}}#L{{{line}}}) |
{{#if deprecationMessage}}
| Deprecated | {{deprecationMessage}} |
{{/if}}
@@ -44,6 +44,7 @@
{{/if}}
{{#example}}
-**Examples**
+##### Example
+
{{{.}}}
{{/example}}
diff --git a/themes/markdown/partials/module.mdt b/themes/markdown/partials/module.mdt
index 4a7f1a6d..2c3e3bef 100644
--- a/themes/markdown/partials/module.mdt
+++ b/themes/markdown/partials/module.mdt
@@ -15,7 +15,7 @@
{{/if}}
{{#if foundAt}}
-Defined in [{{{file}}}:{{{line}}}]({{foundAt}})
+Defined in [{{getSourceFile file}}:{{{line}}}]({{getSourceFile file}}#L{{{line}}})
{{/if}}
{{#if since}}
@@ -37,17 +37,19 @@ This module is deprecated.
{{{.}}}
{{/example}}
-{{#if classes}}
+{{#if hasClasses}}
### Classes
+
{{#classes}}
- [{{name}}](../classes/{{name}}.md)
{{/classes}}
{{/if}}
-{{#if classes}}
+{{#if hasEnum}}
### Enums
+
{{#classes}}
- {{#if is_enum}}
+ {{#if isEnum}}
- [{{name}}](../enums/{{name}}.md)
{{/if}}
{{/classes}}
@@ -55,12 +57,59 @@ This module is deprecated.
{{#if subModules}}
### Sub Modules
+
{{#subModules}}
- [{{name}}]({{name}}.md) {{{description}}}
{{/subModules}}
{{/if}}
{{#if members}}
-### Direct Members
{{> items-index}}
+{{/if}}
+
+### Details
+
+{{#if members.properties}}
+
+#### Properties
+
+{{#members.properties}}
+{{> props}}
+{{/members.properties}}
+
+{{/if}}
+
+{{#if members.attributes}}
+
+#### Attributes
+
+{{#members.attributes}}
+{{> attrs}}
+{{/members.attributes}}
+
+{{/if}}
+
+{{#if members.methods}}
+
+
+#### Methods
+
+{{#is_constructor}}
+##### Constructor
+{{> method}}
+{{/is_constructor}}
+{{#members.methods}}
+{{> method}}
+{{/members.methods}}
+
+{{/if}}
+
+{{#if members.events}}
+
+#### Events
+
+{{#members.events}}
+{{> events}}
+{{/members.events}}
+
{{/if}}
\ No newline at end of file
diff --git a/themes/markdown/partials/props.mdt b/themes/markdown/partials/props.mdt
index 6d65f898..36d28294 100644
--- a/themes/markdown/partials/props.mdt
+++ b/themes/markdown/partials/props.mdt
@@ -13,7 +13,7 @@
| Extends | `{{extended_from}}` |
{{/if}}
{{/if}}
-| Defined | [{{{file}}}:{{{line}}}]({{foundAt}}) |
+| Defined | [{{getSourceFile file}}:{{{line}}}]({{getSourceFile file}}#L{{{line}}}) |
{{#if deprecationMessage}}
| Deprecated | {{deprecationMessage}} |
{{/if}}
diff --git a/yuidoc.json b/yuidoc.json
new file mode 100644
index 00000000..fe3f6f1b
--- /dev/null
+++ b/yuidoc.json
@@ -0,0 +1,21 @@
+{
+ "name": "Cocos Creator API",
+ "description": "",
+ "version": "1.5.x",
+ "url": "http://cocos.com/creator",
+ "logo": "",
+ "options": {
+ "version": "1.5.x",
+ "outdir": "../../creator-api-doc/zh",
+ "sourceURL": {
+ "org": "cocos-creator",
+ "repo": "engine",
+ "branch": "master"
+ },
+ "linkNatives": true,
+ "paths": [
+ "../../fbnew/utils/api/engine"
+ ],
+ "tabtospace": 4
+ }
+}