Sha256: 1fc29793b8d8044e7ff39a470cbfe49859325428bb2d7fb36cb38c1eca34b3e9

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'tmpdir'
module Shrimp
  class Configuration
    attr_accessor :default_options
    attr_writer :phantomjs

    [:format, :margin, :zoom, :orientation, :tmpdir, :rendering_timeout, :rendering_time, :command_config_file].each do |m|
      define_method("#{m}=") do |val|
        @default_options[m]=val
      end
    end

    def initialize
      @default_options = {
          :format               => 'A4',
          :margin               => '1cm',
          :zoom                 => 1,
          :orientation          => 'portrait',
          :tmpdir               => Dir.tmpdir,
          :rendering_timeout    => 90000,
          :rendering_time       => 1000,
          :command_config_file  => File.expand_path('../config.json', __FILE__)
      }
    end

    def phantomjs
      @phantomjs ||= (defined?(Bundler::GemfileError) ? `bundle exec which phantomjs` : `which phantomjs`).chomp
    end
  end

  class << self
    attr_accessor :configuration
  end

  # Configure Phantomjs someplace sensible,
  # like config/initializers/phantomjs.rb
  #
  # @example
  #   Shrimp.configure do |config|
  #     config.phantomjs = '/usr/local/bin/phantomjs'
  #     config.format = 'Letter'
  #   end

  def self.configuration
    @configuration ||= Configuration.new
  end

  def self.configure
    yield(configuration)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shrimp-0.0.3 lib/shrimp/configuration.rb