Sha256: f0f39a5d9315cab33ed8fa0eb0d8a23267ee9705285a521d13dbb7d19d5dfbe1
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
require 'avatar/source/wrapper/abstract_source_wrapper' require 'action_view/helpers/asset_tag_helper' module Avatar # :nodoc: module Source # :nodoc: module Wrapper # Wraps a Source using Rails' <code>AssetTagHelper#image_path</code>, # which can turn path URLs (e.g. '/images/my_avatar.png') # into absolute URLs( e.g. 'http://assets.mysite.com/images/my_avatar.png'). class RailsAssetSourceWrapper < AbstractSourceWrapper attr_reader :url_helper private :url_helper def initialize(source) super @url_helper = Object.new @url_helper.extend(ActionView::Helpers::AssetTagHelper) end # Passes +url+ to <code>AssetTagHelper#image_path</code>. Raises # an error if it cannot generate a fully-qualified URI. Try # setting <code>ActionController::Base.asset_host</code> to # avoid this error. def wrap(url, person, options = {}) # url will never be nil b/c of guarantee in AbstractSourceWrapper result = url_helper.image_path(url) raise "could not generate protocol and host for #{url}. Have you set ActionController::Base.asset_host?" unless result =~ /^http[s]?\:\/\// result end end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
gcnovus-avatar-0.0.7 | lib/avatar/source/wrapper/rails_asset_source_wrapper.rb |
avatar-0.0.5 | lib/avatar/source/wrapper/rails_asset_source_wrapper.rb |