class DistributionWrappers::Email

Public Instance Methods

prepare(email) click to toggle source
# File lib/distribution_wrappers/email/_email.rb, line 4
def prepare(email)
  @params[:email] = email
  template = Tilt::HamlTemplate.new(File.join(File.dirname(__FILE__), 'template.html.haml'))

  doc = Nokogiri::HTML(@params[:post].draft_content)

  doc = replace_video(doc)

  doc = append_parameters(doc)

  doc = redirect_links(doc)

  @params[:draft_content] = html

  body_html = template.render(@params)

  body_html
end

Private Instance Methods

replace_video(doc) click to toggle source
# File lib/distribution_wrappers/email/_email.rb, line 25
def replace_video(doc)
  VideoInfo.provider_api_keys = {youtube: '294129192803.apps.googleusercontent.com', vimeo: 'cb5e2b895a44ce8a74336fc1dde69f2e9e2ca172'}
  video_iframes = doc.css('span iframe').select{|iframe| URI.unescape(iframe.attr('src')).match(/(?<=youtube\.com\/embed\/)(.+?)(?=\?|$)/)}

  video_iframes.each do |iframe|
    id = URI.unescape(iframe.attr('src')).scan(/(?<=youtube\.com\/embed\/)(.+?)(?=\?|$)/).flatten[0]
    new_node = doc.create_element "div"
    video_info = VideoInfo.new("http://www.youtube.com/watch?v=#{id}")
    new_node.inner_html = """<table width='100%' border='0' cellspacing='0' cellpadding='0'>
                              <tr>
                                <td align='center'>
                                  <a href='http://www.youtube.com/watch?v=#{id}'>
                                    <img src='#{video_info.thumbnail_large}' style='height:360px;width:480px;display:block;'>
                                    <img src='http://images-backstitch.s3.amazonaws.com/emails/video_info.png' style='width:480px;display:block;'>
                                  </a>
                                </td>
                              </tr>
                            </table>"""
    iframe.parent.replace new_node
  end
  doc
end