Skip to content

Instantly share code, notes, and snippets.

@spullara
Last active August 7, 2021 05:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spullara/4532118 to your computer and use it in GitHub Desktop.
Save spullara/4532118 to your computer and use it in GitHub Desktop.
Output a star rating using Java backing code.
public class Rated {
public Rated(JsonNode node) {
starRating = node.get("rating").intValue();
}
int starRating;
class Star {
boolean active;
int num;
}
List<Star> stars() {
List<Star> stars = new ArrayList<Star>();
for (int i = 1; i <= 5; i++) {
Star star = new Star();
star.active = starRating >= i;
star.num = i;
stars.add(star);
}
return stars;
}
}
{{#stars}}
<span class="star {{#active}}activeStar{{/active}}">{{num}}</span>
{{/stars}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment