Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arg/phantomrb
An interface with PhantomJS for Ruby.
https://github.com/arg/phantomrb
Last synced: about 7 hours ago
JSON representation
An interface with PhantomJS for Ruby.
- Host: GitHub
- URL: https://github.com/arg/phantomrb
- Owner: arg
- License: mit
- Created: 2013-09-10T14:42:51.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-09-16T12:46:40.000Z (about 11 years ago)
- Last Synced: 2024-10-31T14:16:25.647Z (8 days ago)
- Language: Ruby
- Homepage:
- Size: 129 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Phantomrb
An interface with PhantomJS for Ruby.
[![Gem Version](https://badge.fury.io/rb/phantomrb.png)](http://badge.fury.io/rb/phantomrb)
[![Build Status](https://travis-ci.org/agladkyi/phantomrb.png?branch=master)](https://travis-ci.org/agladkyi/phantomrb)
## Dependencies
[PhantomJS](http://phantomjs.org) must be installed on your system.
## Installation
Add this line to your application's Gemfile:
gem 'phantomrb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install phantomrb
## Usage
### Simple
Phantomrb.run('/path/to/script', arg1, arg2, ...)
### With block
Phantomrb.run('/path/to/script', arg1, arg2, ...) { |line| ... }
### Notes
* Path can be absolute or relative to app directory.
* All arguments are optional.
* If block is specified it will be called with each line from PhantomJS stdout.### Example
// echo.js
for (var i = 0; i < phantom.args.length; i++) {
console.log(phantom.args[i]);
}In your ruby code:
Phantomrb.run('echo.js', 'line one', 'line two') { |line| puts line }
Will output:
test1
test2### Return value
Phantomrb returns an OpenStruct object with following data:
* `output` - full stdout from PhantomJS
* `exit_status` - exit status code
* `command_line` - full command line for PhantomJS## Configuration
Phantomrb provides a way to define a list of command line options for PhantomJS.
Create an initializer `config/initializers/phantomrb.rb` with following code:Phantomrb.configure do
option '',
end### Example
# config/initializers/phantomrb.rb
Phantomrb.configure do
option 'load-images', false
option 'ignore-ssl-errors', true
endPhantomrb.run('myscript.js', 'arg1', 'arg2')
will run `phantomjs --load-images=false --ignore-ssl-errors=true /absolute/path/to/myscript.js arg1 arg2`
More info about PhantomJS command line options you can found in [wiki](https://github.com/ariya/phantomjs/wiki/API-Reference#command-line-options).
## License
Licensed under the MIT license.
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request