Skip to content

Commit

Permalink
Merge branch 'static-path-only'
Browse files Browse the repository at this point in the history
  • Loading branch information
wildjcrt committed Sep 30, 2024
2 parents 3610b69 + 0f8753e commit 6bfc26a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/api/v2/terms_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TermsAPI < Base
term_hash[:stem] = term.stem.name if term.stem.present?
term_hash[:lower_name] = term.lower_name if term.name != term.lower_name
term_hash[:repetition] = term.repetition if term.repetition.present?
term_hash[:audio] = term.audio if term.audio.present?
term_hash[:audio] = term.audio_url

term.descriptions.each do |description|
description_hash = {
Expand All @@ -33,7 +33,9 @@ class TermsAPI < Base
description_hash[:type] = description.description_type if description.description_type.present?
description_hash[:glossary_serial] = description.glossary_serial if description.glossary_serial.present?
description_hash[:glossary_level] = description.glossary_level if description.glossary_level.present?
description_hash[:image] = description.image if description.image.present?
description_hash[:image1] = description.image1_url
description_hash[:image2] = description.image2_url
description_hash[:image3] = description.image3_url

description.examples.each do |example|
example_hash = { content: example.content }
Expand Down
27 changes: 26 additions & 1 deletion app/models/description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#

class Description < ApplicationRecord
store :customized_text, accessors: %i[image]
store :customized_text, accessors: %i[image1 image1_alt image2 image2_alt
image3 image3_alt focus category]

belongs_to :term
has_many :examples, dependent: :destroy
Expand All @@ -28,6 +29,30 @@ def self.ransackable_attributes(auth_object = nil)
%w[content]
end

def image1_url
"https://g0v.github.io/amis-moedict-static#{image1}" if image1.present?
end

def image2_url
"https://g0v.github.io/amis-moedict-static#{image2}" if image2.present?
end

def image3_url
"https://g0v.github.io/amis-moedict-static#{image3}" if image3.present?
end

def image1_text
image1_alt.present? ? image1_alt : content
end

def image2_text
image2_alt.present? ? image2_alt : content
end

def image3_text
image3_alt.present? ? image3_alt : content
end

private

def clean_content
Expand Down
4 changes: 4 additions & 0 deletions app/models/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def audio_id
audio.match(%r{/(\d+)/(\d+_\d+)\.wav$})[1..2].join("-")
end

def audio_url
"https://g0v.github.io/amis-moedict-static#{audio}" if audio.present?
end

private

def clean_name_and_set_lower_name
Expand Down
14 changes: 11 additions & 3 deletions app/views/terms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<button>
<i class="fa-solid fa-volume-high" onclick="document.getElementById('audio-<%= term.audio_id %>').play()"></i>
</button>
<%= audio_tag term.audio, id: "audio-#{term.audio_id}" %>
<%= audio_tag term.audio_url, id: "audio-#{term.audio_id}" %>
<% end %>

<button class="float-right block">
Expand All @@ -64,8 +64,16 @@
<% term.descriptions.each do |description| %>
<li>
<%= simple_format(description.content) %>
<% if description.image.present? %>
<p><%= image_tag description.image, alt: description.content, width: '100' %></p>
<% if description.image1.present? %>
<p>
<%= image_tag description.image1_url, alt: description.image1_text, width: '100' %>
<% if description.image2.present? %>
<%= image_tag description.image2_url, alt: description.image2_text, width: '100' %>
<% end %>
<% if description.image3.present? %>
<%= image_tag description.image3_url, alt: description.image3_text, width: '100' %>
<% end %>
</p>
<% end %>
<% if description.examples.present? %>
<ul class="list-disc list-inside space-y-1">
Expand Down
Binary file modified storage/amis-moedict.sqlite3
Binary file not shown.

0 comments on commit 6bfc26a

Please sign in to comment.