Sha256: 6d4efdfe5db807ab922fe67a159efb264656e7e7bc75f4414fcb84117dd8b827

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

module Shutterbug
  class Configuration

    attr_accessor :uri_prefix
    attr_accessor :path_prefix
    attr_accessor :resource_dir
    attr_accessor :phantom_bin_path

    def self.instance(opts={})
      return @instance || @instance = self.new(opts)
    end

    def initialize(opts={})
      self.uri_prefix       = opts[:uri_prefix]       || ""
      self.path_prefix      = opts[:path_prefix]      || "/shutterbug"
      self.resource_dir     = opts[:resource_dir]     || Dir.tmpdir
      self.phantom_bin_path = opts[:phantom_bin_path] || "phantomjs"
    end

    def js_path
      "#{uri_prefix}#{path_prefix}/shutterbug.js"
    end

    def js_regex
      /#{path_prefix}\/shutterbug.js/
    end

    def js_file
      File.join(File.dirname(__FILE__),"shutterbug.js")
    end

    def convert_path
      "#{uri_prefix}#{path_prefix}/make_snapshot"
    end
    def convert_regex
      /#{path_prefix}\/make_snapshot/
    end

    def png_path(sha='')
      "#{uri_prefix}#{path_prefix}/get_png/#{sha}"
    end
    def png_regex
      /#{path_prefix}\/get_png\/([^\/]+)/
    end

    def html_path(sha='')
      "#{uri_prefix}#{path_prefix}/get_html/#{sha}"
    end
    def html_regex
      /#{path_prefix}\/get_html\/([^\/]+)/
    end

    def base_url(req)
      req.POST()['base_url'] ||  req.referrer || "#{req.scheme}://#{req.host_with_port}"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shutterbug-0.0.11 lib/shutterbug/configuration.rb
shutterbug-0.0.10 lib/shutterbug/configuration.rb
shutterbug-0.0.9 lib/shutterbug/configuration.rb
shutterbug-0.0.8 lib/shutterbug/configuration.rb
shutterbug-0.0.7 lib/shutterbug/configuration.rb