module Awestruct::Extensions::RemotePartial

Public Instance Methods

get_or_cache(tmp_file, url) click to toggle source
# File lib/awestruct/extensions/remotePartial.rb, line 17
def get_or_cache(tmp_file, url)
  response_body = ""
  if !File.exist?tmp_file
    $LOG.info url if $LOG.info? && !config.quiet
    response_body = RestClient.get(url, :cache => false) { |response, request, result, &block|
      case response.code
      when 404
          response
      else
        response.return!(request, result, &block)
      end
    }.body;
    File.open(tmp_file, 'w') do |out|
      out.write response_body
    end
  else
    response_body = File.read(tmp_file)
  end
  return response_body
end
remotePartial(url)
Alias for: remote_partial
remote_partial(url) click to toggle source
# File lib/awestruct/extensions/remotePartial.rb, line 8
def remote_partial(url)
  url_tmp = url.sub('http://', '')
  r = 'remote_partial/' + url_tmp[/(.*)\/[^\/].+$/, 1]
  tmp = File.join(tmp(site.tmp_dir, r), File.basename(url_tmp))
  get_or_cache(tmp, url)
end
Also aliased as: remotePartial