browse 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Tom Benner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ Browse
2
+ ======
3
+ Open Mechanize pages in a (human-readable) browser
4
+
5
+ Description
6
+ -----------
7
+
8
+ Browse lets you open Mechanize pages in a web browser (like Chrome). This is useful for debugging: when you're using Mechanize and want to examine a page, instead of having to view the page's source in a console, Browse lets you open the page in Chrome, fully rendered.
9
+
10
+ ```ruby
11
+ agent = Mechanize.new
12
+ page = agent.get('https://www.google.com/')
13
+ page.browse # Chrome opens, showing the page!
14
+ ```
15
+
16
+ Installation
17
+ ------------
18
+
19
+ Add Browse to your Gemfile:
20
+
21
+ ```ruby
22
+ gem 'browse'
23
+ ```
24
+
25
+ Notes
26
+ -----
27
+
28
+ Browse doesn't open the URL (e.g. `https://www.google.com/`) in Chrome, as that wouldn't show what is currently going on in the Mechanize session. Instead, it opens a locally-saved HTML page that has `page.body` as its source.
29
+
30
+ Browse is currently tested on OS X with Google Chrome. If you'd like to add support for any other OS and/or browser, please feel free to open a PR.
31
+
32
+ License
33
+ -------
34
+
35
+ Browse is released under the MIT License. Please see the MIT-LICENSE file for details.
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Browse'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.md')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new('spec')
27
+
28
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ require 'mechanize'
2
+ require 'active_support/core_ext'
3
+
4
+ module Browse
5
+ end
6
+
7
+ directory = Pathname.new(File.dirname(__FILE__))
8
+ Dir.glob(directory.join('browse', '*.rb')) { |file| require file }
9
+ Dir.glob(directory.join('mechanize', '*.rb')) { |file| require file }
@@ -0,0 +1,3 @@
1
+ module Browse
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,12 @@
1
+ class Mechanize::File
2
+ def browse
3
+ timestamp_string = Time.now.to_f.round(3).to_s.sub('.', '_')
4
+ file_name = timestamp_string + '.html'
5
+ if uri
6
+ file_name = uri.to_s.parameterize + '_' + file_name
7
+ end
8
+ file_path = Pathname.new(ENV['TMPDIR']).join(file_name)
9
+ save(file_path)
10
+ system("open -a 'Google Chrome' 'file://#{file_path}'")
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Test</title>
6
+ </head>
7
+
8
+ <body>
9
+ <div class="main">
10
+ </div>
11
+ </body>
12
+ </html>
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mechanize::File do
4
+ before(:each) do
5
+ files_directory = File.expand_path(File.join(File.dirname(__FILE__), '..', 'files'))
6
+ html_file = File.join(files_directory, 'test.html')
7
+ @file = Mechanize::File.new(nil, nil, File.read(html_file))
8
+ end
9
+
10
+ describe '#browse' do
11
+ it 'runs the open command' do
12
+ Time.stub(:now) { Time.mktime(1970, 1, 1) }
13
+ @file.stub(:save)
14
+ @file.should_receive(:system).with(/^open -a 'Google Chrome' 'file:\/\/.*?\/28800_0\.html'$/)
15
+ @file.browse
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ require 'rspec'
4
+ require 'browse'
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ config.formatter = 'documentation'
9
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: browse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tom Benner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Open Mechanize pages in a (human-readable) browser
79
+ email:
80
+ - tombenner@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - lib/browse/version.rb
86
+ - lib/browse.rb
87
+ - lib/mechanize/file.rb
88
+ - MIT-LICENSE
89
+ - Rakefile
90
+ - README.md
91
+ - spec/files/test.html
92
+ - spec/mechanize/file_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: https://github.com/tombenner/browse
95
+ licenses: []
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.24
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Open Mechanize pages in a (human-readable) browser
118
+ test_files:
119
+ - spec/files/test.html
120
+ - spec/mechanize/file_spec.rb
121
+ - spec/spec_helper.rb