diff --git a/Gemfile b/Gemfile index fb5934b..7667513 100644 --- a/Gemfile +++ b/Gemfile @@ -62,6 +62,8 @@ gem "faraday" gem "rqrcode" +gem "draper" + group :development do gem "spring" gem "spring-commands-rspec" diff --git a/Gemfile.lock b/Gemfile.lock index f047254..13ae451 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,6 +37,10 @@ GEM globalid (>= 0.3.6) activemodel (5.2.3) activesupport (= 5.2.3) + activemodel-serializers-xml (1.0.2) + activemodel (> 5.x) + activesupport (> 5.x) + builder (~> 3.1) activerecord (5.2.3) activemodel (= 5.2.3) activesupport (= 5.2.3) @@ -139,6 +143,12 @@ GEM devise (>= 4.6) diff-lcs (1.3) docile (1.3.2) + draper (3.1.0) + actionpack (>= 5.0) + activemodel (>= 5.0) + activemodel-serializers-xml (>= 1.0) + activesupport (>= 5.0) + request_store (>= 1.0) erubi (1.9.0) execjs (2.7.0) factory_bot (5.1.1) @@ -454,6 +464,7 @@ DEPENDENCIES delorean devise devise-i18n + draper factory_bot_rails faker faraday diff --git a/app/controllers/public/event_feedback_qrcodes_controller.rb b/app/controllers/public/event_feedback_qrcodes_controller.rb index c3bad51..5754fc9 100644 --- a/app/controllers/public/event_feedback_qrcodes_controller.rb +++ b/app/controllers/public/event_feedback_qrcodes_controller.rb @@ -1,10 +1,10 @@ class Public::EventFeedbackQrcodesController < Public::ApplicationController def show - event = current_conference.events.joins(:proposition).approved.find(params[:event_id]) + event = current_conference.events.joins(:proposition).approved.find(params[:event_id]).decorate respond_to do |format| format.svg do - render(inline: helpers.feedback_qr_code_as_svg(event.id), + render(inline: event.feedback_qr_code_as_svg, filename: "feedback_qr_code_#{event.id}.svg") end end diff --git a/app/decorators/application_decorator.rb b/app/decorators/application_decorator.rb new file mode 100644 index 0000000..5caf08b --- /dev/null +++ b/app/decorators/application_decorator.rb @@ -0,0 +1,8 @@ +class ApplicationDecorator < Draper::Decorator + # Define methods for all decorated objects. + # Helpers are accessed through `helpers` (aka `h`). For example: + # + # def percent_amount + # h.number_to_percentage object.amount, precision: 2 + # end +end diff --git a/app/decorators/event_decorator.rb b/app/decorators/event_decorator.rb new file mode 100644 index 0000000..6e507e8 --- /dev/null +++ b/app/decorators/event_decorator.rb @@ -0,0 +1,20 @@ +class EventDecorator < Draper::Decorator + delegate_all + + # Define presentation-specific methods here. Helpers are accessed through + # `helpers` (aka `h`). You can override attributes, for example: + # + # def created_at + # helpers.content_tag :span, class: 'time' do + # object.created_at.strftime("%a %m/%d/%y") + # end + # end + + def feedback_qr_code + RQRCode::QRCode.new(h.new_event_feedback_url(event_id: id), level: :l) + end + + def feedback_qr_code_as_svg + feedback_qr_code.as_svg(shape_rendering: "crispEdges", module_size: 11, fill: "ffffff", offset: 10) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 978f2f3..a9fbfa1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -85,12 +85,4 @@ module ApplicationHelper when 6 then t('ratings.excellent') end end - - def feedback_qr_code(event_id) - RQRCode::QRCode.new(new_event_feedback_url(event_id: event_id), level: :l) - end - - def feedback_qr_code_as_svg(event_id) - feedback_qr_code(event_id).as_svg(shape_rendering: "crispEdges", module_size: 11, fill: "ffffff", offset: 10) - end end diff --git a/app/mailers/event_mailer.rb b/app/mailers/event_mailer.rb index 023dc3c..2b4be27 100644 --- a/app/mailers/event_mailer.rb +++ b/app/mailers/event_mailer.rb @@ -1,11 +1,15 @@ class EventMailer < ActionMailer::Base + helper ApplicationHelper + def confirmation_request(event) - @event = event + @event = event.decorate I18n.locale = @event.proposer.language + attachments['feedback-link-qr-code.svg'] = { mime_type: 'image/svg+xml', - content: helpers.feedback_qr_code_as_svg(@event.id) + content: @event.feedback_qr_code_as_svg } + mail to: @event.proposer.email, from: "program@openfest.org", subject: I18n.t("event_mailer.acceptance_notification.subject",