module DiscourseNarrativeBot class CertificateGenerator def initialize(user, date) @user = user @date = I18n.l(Date.parse(date), format: :date_only) @discobot_user = User.find(-2) end def new_user_track width = 538.583 # Default width for the SVG svg = <<~SVG test_cert #{I18n.t('discourse_narrative_bot.new_user_narrative.cert_title')} #{@discobot_user.username} #{@date} #{name} #{logo_group(40, width, 280)} SVG end def advanced_user_track width = 722.8 # Default width for the SVG <<~SVG #{I18n.t('discourse_narrative_bot.advanced_user_narrative.cert_title')} #{@date} #{@discobot_user.username} #{name} #{logo_group(55, width, 350)} SVG end private def name @user.username.titleize end def logo_group(size, width, height) begin uri = URI(SiteSetting.logo_small_url) logo_uri = if uri.host.blank? || uri.scheme.blank? URI("#{Discourse.base_url}/#{uri.path}") else uri end <<~URL URL rescue URI::InvalidURIError '' end end def avatar_url UrlHelper.absolute(Discourse.base_uri + @user.avatar_template.gsub('{size}', '250')) end end end