feat: extract wiki data badge into a shared partial
- Replace inline wiki data badge code with a render call to a new shared partial. - This change promotes code reuse and simplifies the view templates for cities and weather arts. - The shared partial handles the condition for displaying the badge based on the presence of `wiki_data_id`. This refactor enhances maintainability and adheres to DRY principles, allowing for easier updates or changes to the wiki badge display in one location instead of multiple views.
This commit is contained in:
parent
3bfc64b0c8
commit
1cc1af0ff2
@ -35,18 +35,7 @@
|
|||||||
<div class="badge badge-lg badge-secondary gap-2">
|
<div class="badge badge-lg badge-secondary gap-2">
|
||||||
<%= @city&.state&.name %>
|
<%= @city&.state&.name %>
|
||||||
</div>
|
</div>
|
||||||
<% if @city.wiki_data_id.present? %>
|
<% render "shared/wiki_data_badge", city: @city %>
|
||||||
<%= link_to "https://www.wikidata.org/wiki/#{@city.wiki_data_id}",
|
|
||||||
target: "_blank",
|
|
||||||
rel: "noopener noreferrer",
|
|
||||||
class: "badge badge-lg badge-outline badge-info gap-2",
|
|
||||||
data: { controller: "tooltip", tooltip_target: "tooltip", tooltip_content: "View on WikiData" } do %>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
||||||
</svg>
|
|
||||||
<%= t("text.wiki_data") %>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 主要统计信息 -->
|
<!-- 主要统计信息 -->
|
||||||
|
12
app/views/shared/_wiki_data_badge.html.erb
Normal file
12
app/views/shared/_wiki_data_badge.html.erb
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<% if city.wiki_data_id.present? %>
|
||||||
|
<%= link_to "https://www.wikidata.org/wiki/#{city.wiki_data_id}",
|
||||||
|
target: "_blank",
|
||||||
|
rel: "noopener noreferrer",
|
||||||
|
class: "badge badge-lg badge-outline badge-info gap-2",
|
||||||
|
data: { controller: "tooltip", tooltip_target: "tooltip", tooltip_content: "View on WikiData" } do %>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<%= t("text.wiki_data") %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
@ -28,6 +28,7 @@
|
|||||||
<div class="badge badge-lg badge-secondary">
|
<div class="badge badge-lg badge-secondary">
|
||||||
<%= @weather_art&.city&.state&.name %>
|
<%= @weather_art&.city&.state&.name %>
|
||||||
</div>
|
</div>
|
||||||
|
<% render "shared/wiki_data_badge", city: @weather_art&.city %>
|
||||||
<div class="badge badge-lg badge-ghost">
|
<div class="badge badge-lg badge-ghost">
|
||||||
<%= @weather_art.formatted_time(:date) %>
|
<%= @weather_art.formatted_time(:date) %>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user