Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #40 from NijiDigital/improve_template_android
Browse files Browse the repository at this point in the history
Improve android template to add default values
  • Loading branch information
AliSoftware authored Dec 20, 2017
2 parents 0818706 + 506fdab commit ddf4e1d
Show file tree
Hide file tree
Showing 25 changed files with 45 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Master

* Improve Android (Java) templates. Set default values for attributes.
[Benoit Marty](https://github.com/bmarty)
[#40](https://github.com/NijiDigital/gyro/pull/40)
* `Decodable` - Add `JSONIgnored` userinfo's attribute (decodable usage only).
[Arnaud Bretagne](https://github.com/abretagne)
[#38](https://github.com/NijiDigital/gyro/pull/38)
Expand Down
17 changes: 14 additions & 3 deletions lib/templates/android/inc/_attributes_properties.liquid
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

{%- for attribute in entity.attributes -%}
{% for attribute in entity.attributes -%}
{%- if attribute.realm_read_only.size == 0 -%}
{%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%}
{%- capture convert_type -%}
Expand All @@ -14,6 +13,18 @@
{%- endif -%}
{%- endcapture -%}

{%- capture default_value %}
{%- if attribute.default.size > 0 %} =
{%- if convert_type == "boolean" %}
{%- if attribute.default == "YES" %} true
{%- else %} false
{%- endif %}
{%- elsif convert_type == "String" %} "{{ attribute.default }}"
{%- else %} {{ attribute.default }}
{%- endif %}
{%- endif %}
{%- endcapture %}

{%- assign name = attribute.name -%}
{%- if name == primary_key %}
@PrimaryKey
Expand All @@ -30,6 +41,6 @@
{%- if params.support_annotations.size > 0 and attribute.support_annotation.size > 0 %}
@android.support.annotation.{{ attribute.support_annotation }}
{%- endif %}
private {{ convert_type }} {{ name }};
private {{ convert_type }} {{ name }}{{ default_value }};
{%- endif -%}
{%- endfor -%}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{%- else %}
{%- if relationship.destination.size == 0 %}
{%- if relationship.type != "to_many" -%}
{{ relationship.inverse_type }}
{{ relationship.inverse_type }}
{%- else -%}
RealmList<{{ relationship.inverse_type }}>
{%- endif %}
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/android/inc/_relationships_properties.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- else -%}
{%- if relationship.destination.size == 0 -%}
{%- if relationship.type != "to_many" -%}
{{ relationship.inverse_type }}
{{ relationship.inverse_type }}
{%- else -%}
RealmList<{{ relationship.inverse_type }}>
{%- endif -%}
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/swift3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ final class Product: Object {

let users = List<Users>()
}
```
```
2 changes: 1 addition & 1 deletion spec/fixtures/java/annotations/FidelityCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private Relationships() {

private short identifier;
@android.support.annotation.IntRange(from=0,to=255)
private int points;
private int points = 0;
private User user;

public short getIdentifier() {
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/annotations/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private Attributes() {

private String brand;
private String name;
private int price;
private int price = 0;

@android.support.annotation.Nullable
public String getBrand() {
Expand Down
8 changes: 4 additions & 4 deletions spec/fixtures/java/default/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ private Attributes() {
}
}

private boolean active;
private double budget;
private boolean active = true;
private double budget = 26000.35;
private boolean isOpen;
private String name;
private int numberOfArrivals;
private int numberOfProducts;
private int numberOfProducts = 155;
private double promo;
private String slogan;
private String slogan = "The best place to be";

public boolean getActive() {
return active;
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/enum_multi/FidelityCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private Relationships() {
}

private short identifier;
private int points;
private int points = 0;
private User user;

public short getIdentifier() {
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/enum_multi/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private Relationships() {

private String brand;
private String name;
private int price;
private int price = 0;
private String type;
private Shop shop;

Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/inverse/Dog.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private Attributes() {
}
}

private short age;
private short age = 0;
private String name;

public short getAge() {
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/primary/FidelityCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private Relationships() {

@PrimaryKey
private short identifier;
private int points;
private int points = 0;
private User user;

public short getIdentifier() {
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/primary/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private Attributes() {
private String brand;
@PrimaryKey
private String name;
private int price;
private int price = 0;

public String getBrand() {
return brand;
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/realm/FidelityCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private Relationships() {
}

private short identifier;
private int points;
private int points = 0;
private User user;

public short getIdentifier() {
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/realm/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private Attributes() {

private String brand;
private String name;
private int price;
private int price = 0;

public String getBrand() {
return brand;
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/wrappers/FidelityCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private Relationships() {
}

private short identifier;
private Integer points;
private Integer points = 0;
private User user;

public short getIdentifier() {
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/wrappers/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private Attributes() {

private String brand;
private String name;
private Integer price;
private Integer price = 0;

public String getBrand() {
return brand;
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/wrappers_annotations/FidelityCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private Relationships() {

private short identifier;
@android.support.annotation.IntRange(from=0,to=255)
private Integer points;
private Integer points = 0;
private User user;

public short getIdentifier() {
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/java/wrappers_annotations/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private Attributes() {

private String brand;
private String name;
private Integer price;
private Integer price = 0;

@android.support.annotation.Nullable
public String getBrand() {
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/xcdatamodel/enum.xcdatamodel/contents
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="12141" systemVersion="16E195" minimumToolsVersion="Xcode 4.3" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<entity name="Shop" syncable="YES">
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="optionalValue" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES">
<attribute name="optionalValue" optional="YES" attributeType="Integer 16" usesScalarValueType="NO" syncable="YES">
<userInfo>
<entry key="enumType" value="OptValue"/>
<entry key="enumValues" value="OptValueOne,OptValueTwo,OptValueThree"/>
</userInfo>
</attribute>
<attribute name="type" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES">
<attribute name="type" attributeType="Integer 16" usesScalarValueType="NO" syncable="YES">
<userInfo>
<entry key="enumType" value="Type"/>
<entry key="enumValues" value="TypeOne,TypeTwo,TypeThree"/>
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/xcdatamodel/enum_json.xcdatamodel/contents
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="12141" systemVersion="16E195" minimumToolsVersion="Xcode 4.3" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<entity name="Shop" syncable="YES">
<attribute name="name" attributeType="String" syncable="YES"/>
<attribute name="type" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES">
<attribute name="type" attributeType="Integer 16" usesScalarValueType="NO" syncable="YES">
<userInfo>
<entry key="enumType" value="Type"/>
<entry key="enumValues" value="TypeOne,TypeTwo,TypeThree"/>
<entry key="JSONKeyPath" value="type"/>
<entry key="JSONValues" value="json_type_one,json_type_two,json_type_three"/>
</userInfo>
</attribute>
<attribute name="typeOptional" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES">
<attribute name="typeOptional" optional="YES" attributeType="Integer 16" usesScalarValueType="NO" syncable="YES">
<userInfo>
<entry key="enumType" value="Type2"/>
<entry key="enumValues" value="Type2One,Type2Two,Type2Three"/>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/xcdatamodel/enum_multi.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="12141" systemVersion="16E195" minimumToolsVersion="Xcode 4.3" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<entity name="FidelityCard" syncable="YES">
<attribute name="identifier" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<attribute name="identifier" attributeType="Integer 16" usesScalarValueType="NO" syncable="YES"/>
<attribute name="points" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<relationship name="user" maxCount="1" deletionRule="Nullify" destinationEntity="User" inverseName="fidelityCard" inverseEntity="User" syncable="YES"/>
</entity>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/xcdatamodel/optional.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="12141" systemVersion="16E195" minimumToolsVersion="Xcode 4.3" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<entity name="FidelityCard" syncable="YES">
<attribute name="identifier" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<attribute name="identifier" attributeType="Integer 16" usesScalarValueType="NO" syncable="YES"/>
<attribute name="points" optional="YES" attributeType="Integer 32" minValueString="0" maxValueString="500" defaultValueString="0" usesScalarValueType="NO" syncable="YES">
<userInfo>
<entry key="supportAnnotation" value="IntRange(from=0,to=255)"/>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/xcdatamodel/primary.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="12141" systemVersion="16E195" minimumToolsVersion="Xcode 4.3" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<entity name="FidelityCard" syncable="YES">
<attribute name="identifier" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<attribute name="identifier" attributeType="Integer 16" usesScalarValueType="NO" syncable="YES"/>
<attribute name="points" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<relationship name="user" maxCount="1" deletionRule="Nullify" destinationEntity="User" inverseName="fidelityCard" inverseEntity="User" syncable="YES"/>
<userInfo>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/xcdatamodel/realm.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="12141" systemVersion="16E195" minimumToolsVersion="Xcode 4.3" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<entity name="FidelityCard" syncable="YES">
<attribute name="identifier" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<attribute name="identifier" attributeType="Integer 16" usesScalarValueType="NO" syncable="YES"/>
<attribute name="points" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
<relationship name="user" maxCount="1" deletionRule="Nullify" destinationEntity="User" inverseName="fidelityCard" inverseEntity="User" syncable="YES"/>
</entity>
Expand Down

0 comments on commit ddf4e1d

Please sign in to comment.