Clean up frontend, DRY up templates

This commit is contained in:
maddiebaka 2023-10-22 14:05:01 -04:00
parent c5cbffb4e5
commit 66fc396504
5 changed files with 45 additions and 37 deletions

View File

@ -0,0 +1,14 @@
<h1>Parts of Speech</h1>
<table>
<tr>
<td><b>Part of Speech</b></td>
<td><b>Definition</b></td>
</tr>
<% parts_of_speech.each do |item| %>
<tr>
<td><b><%= item.pos %></b></td>
<td><%= item.definition %></td>
</tr>
<% end %>
</table>

View File

@ -1,39 +1,9 @@
<h1>Dictionary#index</h1> <br/>
<p>Find me in app/views/dictionary/index.html.erb</p> <br/>
<%= sanitize alphabetical_links, tags: ["a"] %> <%= sanitize alphabetical_links, tags: ["a"] %>
<p><%= @parts_of_speech.count %> parts of speech entries in database</p> <p><%= @parts_of_speech.count %> parts of speech entries in database</p>
<h1>Parts of Speech</h1> <p><%= @words.count %> word entries in database</p>
<table>
<tr>
<td><b>Part of Speech</b></td>
<td><b>Definition</b></td>
</tr>
<% @parts_of_speech.each do |item| %>
<tr>
<td><b><%= item.pos %></b></td>
<td><%= item.definition %></td>
</tr>
<% end %>
</table>
<h1>Words</h1> <%= render "partsofspeech", parts_of_speech: @parts_of_speech %>
<% @words.each do |word| %>
<h2><%= word.word %></h2>
<%= render "application/definitions", word: word %>
<!--
<table>
<tr>
<td><b>Part of Speech</b></td>
<td><b>Definition</b></td>
</tr>
<% word.definitions.each do |definition| %>
<tr>
<td><b><%= definition.pos %></b></td>
<td><%= definition.definition %></td>
</tr>
<% end %>
</table>
-->
<% end %>

View File

@ -1,9 +1,10 @@
<div> <div>
<%= @letter.to_s %> <h1><%= @letter.to_s %></h1>
</div> </div>
<% @words.each do |word| %> <% @words.each do |word| %>
<div> <div>
<h1><%= word.word %></h1> <h2><%= word.word %></h2>
<%= render "definitions", word: word %>
</div> </div>
<% end %> <% end %>

View File

@ -1,3 +1,3 @@
<h1><%= @word.word %></h1> <h1><%= @word.word %></h1>
<%= render "application/definitions", word: @word %> <%= render "definitions", word: @word %>

View File

@ -6,6 +6,23 @@ RSpec.describe "Dictionary", type: :request do
get "/dictionary" get "/dictionary"
expect(response).to render_template(:index) expect(response).to render_template(:index)
end end
it "renders the parts_of_speech partial" do
get "/dictionary"
expect(response).to render_template(partial: "_partsofspeech")
end
it "shows the count of parts of speech in the database" do
5.times { FactoryBot.create(:part_of_speech) }
get "/dictionary"
expect(response.body).to include("#{PartOfSpeech.count} parts of speech entries in database")
end
it "shows the count of words in the database" do
5.times { FactoryBot.create(:word) }
get "/dictionary"
expect(response.body).to include("#{Word.count} word entries in database")
end
end end
describe "GET /show" do describe "GET /show" do
@ -23,5 +40,11 @@ RSpec.describe "Dictionary", type: :request do
get "/dictionary/a" get "/dictionary/a"
expect(assigns(:words)).to be_a(ActiveRecord::Relation) expect(assigns(:words)).to be_a(ActiveRecord::Relation)
end end
it "renders the definitions partial" do
FactoryBot.create(:definition)
get "/dictionary/t"
expect(response).to render_template(partial: "_definitions")
end
end end
end end