Skip to content

Commit b6adbc8

Browse files
committed
Change github actions/workflow to use ruby/setup-ruby. actions/setup_ruby is deprecated
Merge imagePresenter and collectionPresenter. Tests pass.
1 parent 42ffbb6 commit b6adbc8

File tree

12 files changed

+188
-144
lines changed

12 files changed

+188
-144
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
matrix:
99
database: [ mysql, postgresql ]
1010
extension: [ core, dragonfly, images, pages, resources ]
11-
ruby: [ "2.7.x", "2.6.x" ]
11+
ruby: [ "2.7.2", "2.6.6" ]
1212
fail-fast: false
1313
max-parallel: 10
1414
runs-on: ubuntu-latest
@@ -25,10 +25,11 @@ jobs:
2525

2626
name: ${{ matrix.extension }} ${{ matrix.ruby }} ${{ matrix.database }}
2727
steps:
28-
- uses: actions/setup-ruby@v1.0.0
29-
with:
30-
version: ${{ matrix.ruby }}
3128
- uses: actions/checkout@v2
29+
- uses: ruby/setup-ruby@v1
30+
with:
31+
ruby-version: ${{ matrix.ruby }}
32+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
3233
- run: sudo apt-get update && sudo apt-get install libpq-dev libmysqlclient-dev libsqlite3-dev -y
3334
- run: sudo systemctl start mysql.service
3435
- id: cache-bundler

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
source 'https://rubygems.org'
22

33
gemspec
4+
gem 'rails', '~>6.0'
45

56
path "./" do
67
gem "refinerycms-core"

core/app/assets/stylesheets/refinery/sections/_layout.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ ul#image_grid {
14681468
.actions {
14691469
position : absolute;
14701470
line-height : 24px;
1471-
background-color : rgba(255, 255, 255, 0.4);
1471+
//background-color : rgba(255, 255, 255, 0.4);
14721472
display : flex;
14731473
flex-direction : row;
14741474
flex-wrap : wrap;

images/app/presenters/refinery/admin/images/collection_presenter.rb renamed to images/app/presenters/refinery/admin/collection_presenter.rb

File renamed without changes.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
require 'action_view/helpers/tag_helper'
2+
require 'action_view/helpers/url_helper'
3+
4+
module Refinery
5+
module Admin
6+
class ImagePresenter < Refinery::BasePresenter
7+
include ActionView::Helpers::TagHelper
8+
include ActionView::Helpers::UrlHelper
9+
include Refinery::ImageHelper
10+
include Refinery::TagHelper
11+
include Refinery::TranslationHelper
12+
13+
attr_accessor :image, :created_at, :context, :urls
14+
delegate :refinery, :params, :output_buffer, :output_buffer=, :t, to: :context
15+
delegate_missing_to :image
16+
17+
def initialize(image, context)
18+
@context = context
19+
@created_at = image.created_at
20+
@image = image
21+
@urls = {
22+
edit: refinery.edit_admin_image_path(image),
23+
delete: refinery.admin_image_path(image),
24+
preview: image.url
25+
}
26+
end
27+
28+
class << self
29+
attr_accessor :context, :images, :view, :pagination_class
30+
delegate :tag, :group_by_date, to: :context
31+
32+
def collection(images, view_format, context)
33+
@view = "#{view_format}_view"
34+
@context = context
35+
@pagination_class = context.pagination_css_class
36+
@collection_id = "image_#{view_format}"
37+
@images = images.map { |image| self.new(image, context) }
38+
self
39+
end
40+
41+
def to_html
42+
tag.ul id: @collection_id, class: ['clearfix', 'pagination_frame', pagination_class] do
43+
self.send(@view)
44+
end
45+
end
46+
47+
def grid_view
48+
images.each.reduce(ActiveSupport::SafeBuffer.new) do |buffer, image|
49+
buffer << image.to_html { image.grid_entry }
50+
end
51+
end
52+
53+
def list_view
54+
group_by_date(images)
55+
.each
56+
.reduce(ActiveSupport::SafeBuffer.new) do |groups_buffer, (_container, image_group)|
57+
date_time = image_group.first.created_at
58+
date_header = tag.h3 context.l(Date.parse(date_time.to_s), format: :long)
59+
# darn zebra striping
60+
images = image_group.each_with_index.reduce(ActiveSupport::SafeBuffer.new) do |items_buffer, (image, index)|
61+
items_buffer << image.to_html(index.odd?) { image.list_entry }
62+
end
63+
groups_buffer << [date_header, images].join(' ').html_safe
64+
end
65+
end
66+
67+
def view_classes
68+
['clearfix', 'pagination_frame', 'images_list', pagination_class]
69+
end
70+
end
71+
72+
def to_html(stripe = true)
73+
stripe_class = stripe ? 'on-hover' : 'on'
74+
tag.li id: "image_#{image.id}", class: stripe_class do
75+
entry = tag.span class: :item do
76+
[yield, *translations, image_settings].join.html_safe
77+
end
78+
entry << actions
79+
end
80+
end
81+
82+
def list_entry
83+
edit_link { image.title }
84+
end
85+
86+
def grid_entry
87+
edit_link { context.image_fu image, '149x149#c', title: image_title, alt: image.alt }
88+
end
89+
90+
private
91+
92+
def edit_link
93+
link_to urls[:edit], class: [:edit, :title],
94+
tooltip: t('edit', scope: 'refinery.admin.images') do
95+
yield
96+
end
97+
end
98+
99+
def image_settings
100+
tag.span class: [:preview] do
101+
image_information
102+
end
103+
end
104+
105+
def actions
106+
tag.span class: :actions do
107+
[edit_icon, info_icon, delete_icon, preview_icon].join(' ').html_safe
108+
end
109+
end
110+
111+
# Actions
112+
def preview_icon
113+
action_icon :preview, urls[:preview], t('view_live_html', scope: 'refinery.admin.images')
114+
end
115+
116+
def edit_icon
117+
action_icon :edit, urls[:edit], t('edit', scope: 'refinery.admin.images', title: image_title)
118+
end
119+
120+
def delete_icon
121+
delete_options = {
122+
class: %w[cancel confirm-delete],
123+
data: { confirm: ::I18n.t('message', scope: 'refinery.admin.delete', title: image_title) }
124+
}
125+
action_icon :delete, urls[:delete], t('delete', scope: 'refinery.admin.images'), delete_options
126+
end
127+
128+
def info_icon
129+
action_icon :info, '', image_information
130+
end
131+
132+
def image_information
133+
# give as much info as we have, but without duplication
134+
# title, alt and filename may all be different, or any two may be the same. Only show what is different
135+
# Title is already shown in the edit_link
136+
#
137+
filename = image.image_name.split('.').first
138+
139+
settings = ["Title: #{title}"]
140+
settings << "File: #{filename}" unless filename == title
141+
settings << "Alt: #{image_alt}" unless image_alt.nil? || image_alt == filename || image_alt == title
142+
settings << "Type: #{image.image.mime_type}"
143+
settings << "Size: #{context.number_to_human_size(image.size)}"
144+
settings.join(', ').html_safe
145+
end
146+
147+
def translations
148+
if Refinery::I18n.frontend_locales.many?
149+
tag.span class: :locales do
150+
switch_locale(image, urls[:edit], :image_title).html_safe
151+
end
152+
end
153+
end
154+
155+
end
156+
end
157+
end
158+
159+

images/app/presenters/refinery/admin/images/image_presenter.rb

Lines changed: 0 additions & 117 deletions
This file was deleted.

images/app/views/refinery/admin/images/_images.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<%
44
requested_view = Refinery::Images.preferred_image_view
5-
presenter = Refinery::Admin::Images::CollectionPresenter.new(@images, requested_view, self)
5+
presenter = Refinery::Admin::ImagePresenter.collection(@images, requested_view, self)
66
%>
77
<%= presenter.to_html %>
88

images/config/locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ en:
88
locale_picker:
99
language: Language
1010
images:
11-
edit: Edit %{title}
11+
edit: Edit this image
1212
delete: Remove this image forever
1313
form:
1414
image: Image
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
shared_context "no existing images" do
2+
Refinery::Image.delete_all
23
let(:image) { FactoryBot.create(:image) }
34
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
shared_context "one image" do
2+
Refinery::Image.delete_all
23
let!(:image) { FactoryBot.create(:image) }
34
end

0 commit comments

Comments
 (0)