class Inkcite::Renderer::Social
Public Class Methods
new(defaults)
click to toggle source
# File lib/inkcite/renderer/social.rb, line 79 def initialize defaults @defaults = defaults # Ensure a default scale of 1:1 is installed into the defaults # if one is not otherwise provided. @defaults[:scale] ||= 1.0 end
Public Instance Methods
render(tag, opts, ctx)
click to toggle source
# File lib/inkcite/renderer/social.rb, line 88 def render tag, opts, ctx id = opts[:id] share_url = opts.delete(:href).to_s #ctx.error("Social sharing 'href' attribute can't be blank", :tag => tag, :id => id) if share_url.blank? share_text = opts.delete(:text).to_s #ctx.error("Social sharing 'text' attribute can't be blank", :tag => tag, :id => id, :href => share_url) if share_text.blank? # Let the extending class format the fully-qualified URL to the sharing service. service_href = get_share_href Util.escape(share_url), Util.escape(share_text), opts, ctx # Check to see if there is a special color for this link (e.g. Pintrest) or # if it has been specified by the caller. opts[:color] ||= @defaults[:color] if icon = !opts[:noicon] # Ensure that the sharing icon exists in the project. ensure_icon_exists ctx height = (opts.delete(:size) || opts.delete(:height) || 15).to_i width = (height / @defaults[:scale]).round # Force the font size and line height to match the size of the # icon being used - this ensures proper vertical middle alignment. opts[FONT_SIZE] = height opts[LINE_HEIGHT] = height end cta = opts[:cta] || @defaults[:cta] html = %Q({a href="#{service_href}" #{Renderer.join_hash(opts)}}) html << %Q({img src=#{@defaults[:src]} height=#{height} width=#{width} display=inline alt="#{@defaults[:alt]}"} ) if icon html << %Q(#{cta}{/a}) html end
Protected Instance Methods
ensure_icon_exists(ctx)
click to toggle source
# File lib/inkcite/renderer/social.rb, line 131 def ensure_icon_exists ctx src = @defaults[:src] # Get the full destination path to the icon in the current project. If # the icon already exists, then there is nothing left to do. dest_icon_path = ctx.email.image_path(src) return if File.exist?(dest_icon_path) # Get the full path to the source icon bundled with Inkcite. source_icon_path = File.join(Inkcite.asset_path, 'social', src) # Ensure that the images/ directory exists in the project, then copy # the image into it. FileUtils.mkpath(ctx.email.image_dir) FileUtils.cp(source_icon_path, dest_icon_path) end