Просмотр исходного кода

Change attributes of work component

theenglishway (time) 2 лет назад
Родитель
Сommit
d85fc4be29
2 измененных файлов с 13 добавлено и 9 удалено
  1. 1 1
      lib/templates/cv.html.heex
  2. 12 8
      lib/views/work.ex

+ 1 - 1
lib/templates/cv.html.heex

@@ -60,7 +60,7 @@
       <ol>
         <%= for work <- @work do %>
           <li>
-            <Work.work work={work} />
+            <Work.work {work} />
           </li>
         <% end %>
       </ol>

+ 12 - 8
lib/views/work.ex

@@ -2,30 +2,34 @@ defmodule CvGenView.Work do
   use Phoenix.Component
   import CvGenView.Date, only: [date: 1]
 
-  attr(:work, :map)
+  attr(:name, :string, required: true)
+  attr(:start_date, :any, required: true)
+  attr(:end_date, :any, default: nil)
+  attr(:summary, :string, required: true)
+  attr(:highlights, :list, required: true)
 
   def work(assigns) do
     ~H"""
     <div>
-      <h1><%= @work.name %></h1>
+      <h1><%= @name %></h1>
 
       <dl>
         <dt class="position" lang="fr">Poste</dt>
-        <dd lang="fr"><%= @work.position %></dd>
+        <dd lang="fr"><%= @position %></dd>
         <dt class="start_date">Date début</dt>
-        <dd><.date class="start_date" date={@work.start_date} /></dd>
-        <%= unless is_nil(@work[:end_date]) do %>
+        <dd><.date class="start_date" date={@start_date} /></dd>
+        <%= unless is_nil(@end_date) do %>
           <dt class="end_date">Date fin</dt>
-          <dd><.date class="end_date" date={@work.end_date} /></dd>
+          <dd><.date class="end_date" date={@end_date} /></dd>
         <% end %>
         <dt class="work_location"></dt>
         <dd>Paris</dd>
       </dl>
 
-      <p class="summary" lang="en"><%= @work.summary %></p>
+      <p class="summary" lang="en"><%= @summary %></p>
 
       <ul class="highlights">
-        <%= for highlight <- @work.highlights do %>
+        <%= for highlight <- @highlights do %>
           <li><%= highlight %></li>
         <% end %>
       </ul>