class Shrimple
Here is a list of all the phantomjs settings that we know about. Note that you can set any option you want. It need not be listed here.
nil means leave unset – use Phantom’s defaults
Constants
- DefaultConfig
Attributes
options[RW]
Public Class Methods
compact!(hash)
click to toggle source
how are these not a part of Hash?
# File lib/shrimple.rb, line 101 def self.compact! hash hash.delete_if { |k,v| v.nil? or (v.is_a?(Hash) && compact!(v).empty?) or (v.respond_to?('empty?') && v.empty?) } end
deep_dup(hash)
click to toggle source
# File lib/shrimple.rb, line 105 def self.deep_dup hash Marshal.load(Marshal.dump(hash)) end
default_executable()
click to toggle source
# File lib/shrimple.rb, line 118 def self.default_executable (defined?(Bundler::GemfileError) ? `bundle exec which phantomjs` : `which phantomjs`).chomp end
default_renderer()
click to toggle source
# File lib/shrimple.rb, line 114 def self.default_renderer File.expand_path('../render.js', __FILE__) end
new(opts={})
click to toggle source
# File lib/shrimple.rb, line 40 def initialize opts={} @options = Hashie::Mash.new(Shrimple::DefaultConfig) @options.deep_merge!(opts) self.executable ||= self.class.default_executable self.renderer ||= self.class.default_renderer end
processes()
click to toggle source
# File lib/shrimple.rb, line 110 def self.processes @processes ||= Shrimple::ProcessMonitor.new end
Public Instance Methods
get_full_options(src, *inopts)
click to toggle source
# File lib/shrimple.rb, line 82 def get_full_options src, *inopts exopts = options.dup # can't deep_dup procs so remove them and add them back onSuccess = exopts.delete(:onSuccess) onError = exopts.delete(:onError) full_opts = Shrimple.deep_dup(exopts) full_opts.merge!(onSuccess: onSuccess, onError: onError) full_opts.deep_merge!(src) if src && src.kind_of?(Hash) inopts.each { |opt| full_opts.deep_merge!(opt) } full_opts.merge!(input: src) if src && !src.kind_of?(Hash) full_opts.merge!(output: full_opts.delete(:to)) if full_opts[:to] self.class.compact!(full_opts) full_opts end
method_missing(name, *args, &block)
click to toggle source
allows setting config options directly on this object: s.timeout = 10
# File lib/shrimple.rb, line 35 def method_missing name, *args, &block options.send(name, *args, &block) end
render(src={})
click to toggle source
# File lib/shrimple.rb, line 75 def render src={}, *opts full_opts = get_full_options(src, *opts) phantom = Shrimple::Phantom.new(full_opts) phantom.wait unless full_opts[:background] phantom end
render_gif(src, *opts)
click to toggle source
# File lib/shrimple.rb, line 61 def render_gif src, *opts render src, {render: {format: 'gif'}}, *opts end
render_html(src, *opts)
click to toggle source
# File lib/shrimple.rb, line 65 def render_html src, *opts render src, {render: {format: 'html'}}, *opts end
render_jpeg(src, *opts)
click to toggle source
# File lib/shrimple.rb, line 57 def render_jpeg src, *opts render src, {render: {format: 'jpeg'}}, *opts end
render_pdf(src, *opts)
click to toggle source
might be time to allow method_missing
to handle these helpers…
# File lib/shrimple.rb, line 49 def render_pdf src, *opts render src, {render: {format: 'pdf'}}, *opts end
render_png(src, *opts)
click to toggle source
# File lib/shrimple.rb, line 53 def render_png src, *opts render src, {render: {format: 'png'}}, *opts end
render_text(src, *opts)
click to toggle source
# File lib/shrimple.rb, line 69 def render_text src, *opts render src, {render: {format: 'text'}}, *opts end