require 'net/http' require 'uri' require 'ahc_helper' class Ahc class << self attr_accessor :host, :port, :fake end def self.root @root ||= File.expand_path '../..', __FILE__ @root end def self.render(template, data) return '' if @fake begin res = Net::HTTP.post_form(URI.parse("http://#{@host || default_host}:#{@port || default_port}/t/" + template), {'params'=> data.to_json}) return res.body rescue return File.read(self.root + '/static/error.html') end end def self.default_host '127.0.0.1' end def self.default_port '8080' end end if defined? Rails config_path = "#{Rails.root}/config/ahc.yml" config = {} if File.exists?(config_path) config = YAML.load_file(config_path)[Rails.env] || {} end Ahc.host = config['host'] Ahc.port = config['port'] Ahc.fake = config['fake'] end