From 657d7c740773bfbdfcd401d303be92015b64e00d Mon Sep 17 00:00:00 2001 From: efim Date: Thu, 29 Jun 2023 16:56:36 +0000 Subject: [PATCH] feat: repeating dynamic testimonial section --- .../java/testimonialsgrid/JTestimonial.java | 40 ------------- .../src/main/resources/templates/index.html | 23 ++++++-- .../main/scala/testimonialsgrid/Main.scala | 58 +++++++------------ .../tailwind.config.js | 2 +- 4 files changed, 40 insertions(+), 83 deletions(-) delete mode 100644 13-testimonials-grid-section/src/main/java/testimonialsgrid/JTestimonial.java diff --git a/13-testimonials-grid-section/src/main/java/testimonialsgrid/JTestimonial.java b/13-testimonials-grid-section/src/main/java/testimonialsgrid/JTestimonial.java deleted file mode 100644 index 4227b89..0000000 --- a/13-testimonials-grid-section/src/main/java/testimonialsgrid/JTestimonial.java +++ /dev/null @@ -1,40 +0,0 @@ -package testimonialsgrid; - -public class JTestimonial { - private String author; - private String text; - private int age; - - // Constructor - public JTestimonial(String author, String text, int age) { - this.author = author; - this.text = text; - this.age = age; - } - - // Getters - public String getAuthor() { - return author; - } - - public String getText() { - return text; - } - - public int getAge() { - return age; - } - - // Setters - public void setAuthor(String author) { - this.author = author; - } - - public void setText(String text) { - this.text = text; - } - - public void setAge(int age) { - this.age = age; - } -} diff --git a/13-testimonials-grid-section/src/main/resources/templates/index.html b/13-testimonials-grid-section/src/main/resources/templates/index.html index ccca6d1..6f87d51 100644 --- a/13-testimonials-grid-section/src/main/resources/templates/index.html +++ b/13-testimonials-grid-section/src/main/resources/templates/index.html @@ -32,27 +32,36 @@ -
+
Avatar image
-

Daniel Clifford

+

Daniel Clifford

Verified Graduate

-

+

I received a job offer mid-course, and the subjects I learned were current, if not more so, in the company I joined. I honestly feel I got every penny’s worth.

-

+

“ I was an EMT for many years before I joined the bootcamp. I’ve been looking to make a transition and have heard some people who had an amazing experience here. I signed up for the free intro course and @@ -64,6 +73,7 @@

@@ -87,6 +97,7 @@

@@ -107,6 +118,7 @@

@@ -136,6 +148,7 @@
diff --git a/13-testimonials-grid-section/src/main/scala/testimonialsgrid/Main.scala b/13-testimonials-grid-section/src/main/scala/testimonialsgrid/Main.scala index d3bce98..c972980 100644 --- a/13-testimonials-grid-section/src/main/scala/testimonialsgrid/Main.scala +++ b/13-testimonials-grid-section/src/main/scala/testimonialsgrid/Main.scala @@ -6,6 +6,7 @@ import cask.main.Routes import org.thymeleaf.context.Context import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver import org.thymeleaf.TemplateEngine +import scala.beans.BeanProperty import scala.jdk.CollectionConverters._ @@ -45,51 +46,34 @@ object Main { def index() = { val context = new Context() - import scala.beans.BeanProperty final case class Testimonial( + @BeanProperty var avatarUrl: String, @BeanProperty var author: String, + @BeanProperty var header: String, @BeanProperty var text: String, - @BeanProperty var age: Int + @BeanProperty var age: Int, + @BeanProperty var additionalClasses: String ) - class CompatTestimonial { - @BeanProperty var author: String = _ - @BeanProperty var text: String = _ - @BeanProperty var age: Int = _ - - // Auxiliary constructor - def this(author: String, text: String, age: Int) = { - this() // Call to the primary constructor - this.author = author - this.text = text - this.age = age - } - } - val yo = new CompatTestimonial("Leopold", "Miawu", 188) - // val yo = Testimonial("Leopold", "Miawu", 188) - - // let's experiment. ugh - class Person( - @BeanProperty var firstName: String, - @BeanProperty var lastName: String, - @BeanProperty var age: Int - ) { - override def toString: String = - return String.format("%s, %s, %d", firstName, lastName, age) - } - val p = new Person("Efim", "Nefedov", 31) - println(p) - // println(p.getFirstName) - - val ugh = new JTestimonial("Hell", "lala", 1234) - - context.setVariable("justString", "oh why oh why") - context.setVariable("oneTestimonial", ugh) context.setVariable( "testimonials", List( - new JTestimonial("Leopold", "Miawu", 91), - new JTestimonial("Aragorn", "And my sword!", 55) + new Testimonial( + "public/images/image-patrick.jpg", + "Leopold", + " Odio facilisis mauris sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac odio tempor orci dapibus ultrices. ", + " Nibh sed pulvinar proin gravida hendrerit? Massa tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc, consequat interdum varius sit amet, mattis vulputate enim nulla aliquet porttitor lacus! ", + 91, + "!bg-red-500" + ), + new Testimonial( + "public/images/image-jonathan.jpg", + "Aragorn", + " Eleifend donec pretium vulputate sapien nec sagittis aliquam malesuada bibendum! ", + " Egestas fringilla phasellus faucibus scelerisque eleifend! Dignissim enim, sit amet venenatis urna cursus eget nunc scelerisque viverra mauris, in aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod in! ", + 55, + "!bg-blue-500" + ) ).asJava ) val result = templateEngine.process("index", context) diff --git a/13-testimonials-grid-section/tailwind.config.js b/13-testimonials-grid-section/tailwind.config.js index ff247f5..d5e2cb6 100644 --- a/13-testimonials-grid-section/tailwind.config.js +++ b/13-testimonials-grid-section/tailwind.config.js @@ -1,6 +1,6 @@ /** @type {import('tailwindcss').Config} */ module.exports = { - content: ["./src/**/*.{html, scala}"], + content: ["./src/**/*.{html,scala}"], theme: { extend: { colors: {