Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make entry show an icon and add icon link to original page #595

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem 'bootsnap', require: false # Reduces boot times through caching; required in
gem 'feedjira' # Parse RSS feeds
gem 'good_job' # Multithreaded, Postgres-based, ActiveJob backend for Ruby on Rails
gem 'image_processing' # Use Active Storage variants
gem 'inline_svg' # Render inline SVGs
chvp marked this conversation as resolved.
Show resolved Hide resolved
gem 'pagy' # Use pagy for pagination
gem 'pg' # Use postgresql as the database for Active Record
gem 'puma' # Use the Puma web server [https://github.com/puma/puma]
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ GEM
image_processing (1.13.0)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
inline_svg (1.10.0)
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.8.0)
irb (1.15.1)
pp (>= 0.6.0)
Expand Down Expand Up @@ -384,6 +387,7 @@ DEPENDENCIES
feedjira
good_job
image_processing
inline_svg
pagy
pg
pgreset
Expand Down
3 changes: 3 additions & 0 deletions app/assets/images/icons/arrow-top-right-on-square.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/assets/images/icons/eye.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/assets/styles/base/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ html {
font-size: var(--text-base);
font-family: var(--font-body);
}

.table__cell--actions {
white-space: nowrap;
}

.icon {
width: 2rem;
height: 2rem;
}
9 changes: 7 additions & 2 deletions app/views/entries/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
<%= content_tag :td, entry.author, class: 'table__cell' %>
<%= content_tag :td, entry.published_at.present? ? l(entry.published_at) : t('.published_at_unknown'), class: 'table__cell' %>
<%= content_tag :td, entry.read?, class: 'table__cell' %>
<%= content_tag :td, class: 'table__cell' do %>
<%= link_to t('.show'), entry, class: 'table__link' %>
<%= content_tag :td, class: 'table__cell table__cell--actions' do %>
<%= link_to entry, class: 'table__link', aria: { label: t('.show') } do %>
<%= inline_svg_tag 'images/icons/eye.svg', class: 'icon' %>
<% end %>
<%= link_to entry.url, class: 'table__link', aria: { label: t('.go_to_original') } do %>
<%= inline_svg_tag 'images/icons/arrow-top-right-on-square.svg', class: 'icon' %>
<% end %>
<% end %>
</tr>
<%- end %>
Expand Down
9 changes: 7 additions & 2 deletions app/views/subscriptions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
<%= content_tag :td, entry.title, class: 'table__cell' %>
<%= content_tag :td, entry.author, class: 'table__cell' %>
<%= content_tag :td, entry.published_at.present? ? l(entry.published_at) : t('.published_at_unknown'), class: 'table__cell' %>
<%= content_tag :td, class: 'table__cell' do %>
<%= link_to t('.show'), entry, class: 'table__link' %>
<%= content_tag :td, class: 'table__cell table__cell--actions' do %>
<%= link_to entry, class: 'table__link', aria: { label: t('.show') } do %>
<%= inline_svg_tag 'images/icons/eye.svg', class: 'icon' %>
<% end %>
<%= link_to entry.url, class: 'table__link', aria: { label: t('.go_to_original') } do %>
<%= inline_svg_tag 'images/icons/arrow-top-right-on-square.svg', class: 'icon' %>
<% end %>
<% end %>
</tr>
<%- end %>
Expand Down
8 changes: 8 additions & 0 deletions config/initializers/inline_svg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require 'inline_svg/vite_file_loader'

InlineSvg.configure do |config|
config.asset_file = InlineSvg::ViteFileLoader
chvp marked this conversation as resolved.
Show resolved Hide resolved
config.raise_on_file_not_found = Rails.env.test?
end
11 changes: 11 additions & 0 deletions gemset.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions lib/inline_svg/vite_file_loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'open-uri'

module InlineSvg
class ViteFileLoader
def self.named(filename)
path = ViteRuby.instance.manifest.path_for(filename)

return fetch_from_dev_server(path) if ViteRuby.instance.dev_server_running?

Rails.public_path.join(path[1..]).read
end

def self.fetch_from_dev_server(path)
config = ViteRuby.config

path = "#{config.protocol}://#{config.host_with_port}#{path}"

# rubocop:disable Security/Open
# This is only used in dev to load an inline SVG, so security implications are very limited.
URI.open(path)
# rubocop:enable Security/Open
end
end
end
Loading