Skip to content

Commit

Permalink
Add a --keep-field-order argument
Browse files Browse the repository at this point in the history
closes #258
  • Loading branch information
Gama11 committed Apr 7, 2020
1 parent f860641 commit 959b5d3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- added a "final" prefix for final classes and interfaces
- added support for deprecation messages on types ([#261](https://github.com/HaxeFoundation/dox/issues/261))
- added support for `@:noCompletion` implying `@:dox(hide)` ([#250](https://github.com/HaxeFoundation/dox/issues/250))
- added a `--keep-field-order` argument ([#258](https://github.com/HaxeFoundation/dox/issues/258))
- improved function type printing to use Haxe 4 syntax ([#273](https://github.com/HaxeFoundation/dox/issues/273))
- fixed JS version being used if the node version is not supported (< 8.10.0)
- fixed interfaces with multiple `extends` only showing the first one ([#260](https://github.com/HaxeFoundation/dox/issues/260))
Expand Down
Binary file modified run.n
Binary file not shown.
28 changes: 16 additions & 12 deletions src/dox/Api.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Api {
public var currentPageUrl:Null<String>;

/**
* Expose Std for theme.
*/
Expose Std for theme.
**/
public var std = Std;

public function new(cfg:Config, infos:Infos) {
Expand Down Expand Up @@ -380,8 +380,7 @@ class Api {
}

/**
Returns an array of all member fields of `c` respecting the inheritance
chain.
Returns an array of all member fields of `c` respecting the inheritance chain.
**/
public function getAllFields(c:Classdef):Array<MemberField> {
var allFields = [];
Expand All @@ -401,7 +400,9 @@ class Api {
}
}
loop(c);
allFields.sort((f1, f2) -> Reflect.compare(f1.field.name, f2.field.name));
if (!config.keepFieldOrder) {
allFields.sort((f1, f2) -> Reflect.compare(f1.field.name, f2.field.name));
}
return allFields;
}

Expand Down Expand Up @@ -450,11 +451,14 @@ class Api {
else
addFieldTo(f, inheritedFields.fields);
}
for (fields in inheritedFields.methods) {
fields.sort((f1, f2) -> Reflect.compare(f1.name, f2.name));
}
for (fields in inheritedFields.fields) {
fields.sort((f1, f2) -> Reflect.compare(f1.name, f2.name));

if (!config.keepFieldOrder) {
for (fields in inheritedFields.methods) {
fields.sort((f1, f2) -> Reflect.compare(f1.name, f2.name));
}
for (fields in inheritedFields.fields) {
fields.sort((f1, f2) -> Reflect.compare(f1.name, f2.name));
}
}

return inheritedFields;
Expand All @@ -472,12 +476,12 @@ typedef FieldInfo = {
/**
The kind of the field. See `FieldKind`.
**/
kind:FieldKind,
var kind:FieldKind;

/**
The field modifiers. See `FieldModifiers`.
**/
modifiers:FieldModifiers
var modifiers:FieldModifiers;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/dox/Config.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Config {
public var toplevelPackage:String;
public var useMarkdown:Bool;
public var includePrivate:Bool;
public var keepFieldOrder:Bool;
public var date:Date;
public var outputPath(default, set):String = "pages";
public var inputPath(default, set):String = "xml";
Expand All @@ -46,6 +47,7 @@ class Config {
toplevelPackage = "";
useMarkdown = true;
includePrivate = false;
keepFieldOrder = false;
defines = new Map();
pathFilters = new GenericStack<Filter>();
templatePaths = new GenericStack<String>();
Expand Down
3 changes: 3 additions & 0 deletions src/dox/Dox.hx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class Dox {
@doc("Include private fields and types")
["--include-private"] => function() cfg.includePrivate = true,

@doc("Don't sort fields alphabetically")
["--keep-field-order"] => function() cfg.keepFieldOrder = true,

@doc("Set the theme name or path")
["-theme"] => function(name:String) cfg.loadTheme(owd, name),

Expand Down
4 changes: 3 additions & 1 deletion src/dox/Processor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ class Processor {
}

inline function sortFields(fields:Array<ClassField>) {
return fields.sort(compareFields);
if (!config.keepFieldOrder) {
fields.sort(compareFields);
}
}

function sort(t:TypeTree) {
Expand Down

0 comments on commit 959b5d3

Please sign in to comment.