Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiJingLong committed Aug 11, 2018
1 parent 103d92b commit 8bf4ebe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 0 additions & 1 deletion lib/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class Generator {
var fieldList = template.fieldList;
fieldList.forEach((filed) {
if (filed is MapField) {
// filed.typeString
DefaultTemplate template = DefaultTemplate(
srcJson: json.encode(filed.map), className: filed.typeString);
templateList.add(template);
Expand Down
3 changes: 2 additions & 1 deletion lib/json_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ void main() async {
// FileWriter fw = await fileEntry.createWriter();
// fw.write(blob);
// File file = await fileEntry.file();
AnchorElement saveLink = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
AnchorElement saveLink =
document.createElementNS("http://www.w3.org/1999/xhtml", "a");
saveLink.href = Url.createObjectUrlFromBlob(blob);
// saveLink.type = "download";
saveLink.download = downloadFileName;
Expand Down
22 changes: 15 additions & 7 deletions lib/template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,27 @@ class DefaultTemplate extends Template {
if (this is ListTemplate) {
return this;
}
return ListTemplate(srcJson: srcJson, className: className, delegateTemplate: this);
return ListTemplate(
srcJson: srcJson, className: className, delegateTemplate: this);
}
}

class ListTemplate extends DefaultTemplate {
Template delegateTemplate;

ListTemplate({String srcJson, String className = "Entity", this.delegateTemplate}) : super(className: className, srcJson: srcJson);
ListTemplate(
{String srcJson, String className = "Entity", this.delegateTemplate})
: super(className: className, srcJson: srcJson);

@override
String declare() {
return _declareListMethod() + "\n" + delegateTemplate?.declare() ?? super.declare();
return _declareListMethod() + "\n" + delegateTemplate?.declare() ??
super.declare();
}

String _declareListMethod() {
var listMethod = """List<$className> get${className}List(List<dynamic> list){
var listMethod =
"""List<$className> get${className}List(List<dynamic> list){
List<$className> result = [];
list.forEach((item){
result.add($className.fromJson(item));
Expand Down Expand Up @@ -154,11 +159,13 @@ class ListTemplate extends DefaultTemplate {
}

@override
List<Field> get fieldList => FieldHelper(json.encode(json.decode(srcJson)[0])).getFields();
List<Field> get fieldList =>
FieldHelper(json.encode(json.decode(srcJson)[0])).getFields();
}

class V1Template extends DefaultTemplate {
V1Template({String srcJson, String className = "Entity"}) : super(className: className, srcJson: srcJson);
V1Template({String srcJson, String className = "Entity"})
: super(className: className, srcJson: srcJson);

@override
String interface() => "";
Expand All @@ -168,7 +175,8 @@ class V1Template extends DefaultTemplate {
var result = StringBuffer();
result.writeln(super.method());
result.writeln();
result.write(" Map<String, dynamic> toJson() => _\$${className}ToJson(this);");
result.write(
" Map<String, dynamic> toJson() => _\$${className}ToJson(this);");
return result.toString();
}
}
Expand Down

0 comments on commit 8bf4ebe

Please sign in to comment.