Skip to content

Instantly share code, notes, and snippets.

@dalpo
Created April 24, 2014 13:23
Show Gist options
  • Save dalpo/11254442 to your computer and use it in GitHub Desktop.
Save dalpo/11254442 to your computer and use it in GitHub Desktop.
module PdfHelper
def wicked_pdf_stylesheet_link_tag(*sources)
sources.collect { |source|
asset = Rails.application.assets.find_asset("#{source}.css")
if asset.nil?
raise "could not find asset for #{source}.css"
else
"<style type='text/css'>#{asset.body}</style>"
end
}.join("\n").gsub(/url\(['"](.+)['"]\)(.+)/,%[url("#{wicked_pdf_image_location("\1")}")\2]).html_safe
end
def wicked_pdf_stylesheet_link_tag(*sources)
sources.collect { |source|
"<style type='text/css'>#{Rails.application.assets.find_asset("#{source}.css")}</style>"
}.join("\n").gsub(/url\(['"](.+)['"]\)(.+)/,%[url("#{wicked_pdf_image_location("\\1")}")\\2]).html_safe
end
def wicked_pdf_image_tag(img, options={})
image_tag wicked_pdf_image_location(img), options
end
def wicked_pdf_image_location(img)
if img.present?
"file://#{Rails.root.join('app', 'assets', 'images', img)}"
else
""
end
end
def wicked_pdf_javascript_src_tag(source)
"<script type='text/javascript'>#{Rails.application.assets.find_asset("#{source}.js").body}</script>"
end
def wicked_pdf_javascript_include_tag(*sources)
sources.collect{ |source| wicked_pdf_javascript_src_tag(source) }.join("\n").html_safe
end
#longitude,latitude,icon_url
def wiked_pdf_ubiest_map(params={})
url_params={}
url_params[:center] = [params[:latitude], params[:longitude]].join(",")
url_params[:idcust] = Settings[:ubiest_key]
url_params[:format] = params[:format] || "jpg"
url_params[:zoom] = params[:zoom] || 14
url_params[:size] = params[:size] || "900x450"
url_params[:markers] = [ "icon:#{Settings[:domain]}/#{params[:icon_url]}", url_params[:center] ].join("|")
"http://maps.ubiest.com/api/staticmap?#{url_params.to_param}".html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment