pagelapse 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f8d6638ceb44da7aa0d6baaaf1c69e17da1cdfd
4
- data.tar.gz: a0eec7989c94fb441e0605de10d224010703fe1a
3
+ metadata.gz: 8d7844184aa0b984de300e0a956b56549aa7bfbc
4
+ data.tar.gz: 7cb3a962d4786561df52daf3620019a544f98174
5
5
  SHA512:
6
- metadata.gz: d1f965cab3bad214de6f0866b2a49a3833d99f763e48ca315e50cb3fcca6c68d2fcf7bc6a1d2ff6330de8e47c9ea9669f8be9347449bcd5d78b758eea9e7adfc
7
- data.tar.gz: c14caa22ad972f86ec36b314fe1e2d4c22e5ce435e9b7a11c9be6cf57536992685ea2a7c1f4b15749e49e191426deec76a0de4451276da4db5aa360e12ee4d0f
6
+ metadata.gz: cae93edf1b2a0b693c0f70eac4601068ec6b919e220bb4f0d913467001b384686dc99f810e67e35ca774bb1eb7fed97d7f337be9554f85a5f01166f83fa34ec3
7
+ data.tar.gz: 14e3f0cca9f3c4490ea0ca9df9262b960c3036158e12db040ac6e09d5a9a334b889cfec5e4e2e98d604754ee91833be65a165150c4c8c3f1f1080c4f296e9778
data/README.md CHANGED
@@ -14,26 +14,61 @@ And then install pagelapse:
14
14
 
15
15
  ## Usage
16
16
 
17
- Add a page to start capturing:
18
-
19
- $ pagelapse record http://reddit.com
20
-
21
- Pagelapse will check the website every 20 seconds for changes. There are some settings, too:
22
-
23
- $ pagelapse record http://reddit.com --interval 60 --width 1200 --height 1000 --full-page false
17
+ To create a new pagelapse, add a `Lapsefile` to the current directory. If your timelapse is associated with a project, you may want to add this to the root directory of your project.
18
+
19
+ In the `Lapsefile`, you can specify (using Ruby) which pages you'd like to record. For instance, to record a screenshot of my blog, `lord.io`, every 10 seconds with a browser window 1000 pixels by 800 pixels:
20
+
21
+ ```ruby
22
+ record "lord", "http://www.lord.io/blog" do |r|
23
+ r.width = 1000
24
+ r.height = 800
25
+ r.interval = 10
26
+ end
27
+ ```
28
+
29
+ You can also run Capybara commands before the screenshot is taken:
30
+
31
+ ```ruby
32
+ record "github", "http://github.com/login" do |r|
33
+ r.interval = 10
34
+ r.before_capture do
35
+ page.fill_in('login', :with => 'lord')
36
+ page.fill_in('password', :with => 'my password here')
37
+ page.click_button('Sign in')
38
+ end
39
+ end
40
+ ```
41
+
42
+ There are a couple other settings. The default behavior is capture pages only if they return a HTTP 200. You can change this by setting a `capture_if`, for instance if you only want to record if the page contains certain elements, or based on the status code:
43
+
44
+ ```ruby
45
+ record "lord", "http://www.lord.io/blog" do |r|
46
+ r.capture_if do
47
+ page.driver.status_code == 404
48
+ end
49
+ end
50
+ ```
51
+
52
+ For instance, the above code will only capture the page *if* a 404 error code was generated.
53
+
54
+ By default, new screenshots will be deleted if they are exactly the same as the previous screenshot. You can override this with `save_if`:
55
+
56
+ ```ruby
57
+ record "lord", "http://www.lord.io/blog" do |r|
58
+ r.save_if do |old_file, new_file|
59
+ # Add checking code here
60
+ true
61
+ end
62
+ end
63
+ ```
64
+
65
+ For example, the code above will always save new screenshots. You could potentially use the `old_file` and `new_file` parameters passed (as file names) to the `save_if` block with Imagemagick or some other image program to determine if the images are different enough to save. The default method is to check the cryptographic hashes of the two files are the same.
24
66
 
25
67
  To view the websites you've recorded in a nice web interface:
26
68
 
27
69
  $ pagelapse view
28
70
 
29
- To stop recording a page:
30
-
31
- $ pagelapse stop http://reddit.com
32
-
33
- To pause and resume the background server:
34
-
35
- $ pagelapse pause
36
- $ pagelapse resume
71
+ Drag your cursor from left to right to play the timelapse.
37
72
 
38
73
  ## Contributing
39
74
 
@@ -49,18 +49,16 @@ module Pagelapse
49
49
  def capture
50
50
  @timer = Time.now
51
51
  ws = Pagelapse::Screenshot.new
52
- if @on_load
53
- ws.start_session(&@on_load)
54
- else
55
- ws.start_session
56
- end.capture(
52
+
53
+ ws.capture(
57
54
  @url,
58
55
  filename,
59
56
  width: @width,
60
57
  height: @height,
61
58
  timeout: @timeout,
62
59
  capture_if: @capture_if,
63
- save_if: @save_if
60
+ save_if: @save_if,
61
+ on_load: @on_load
64
62
  )
65
63
  end
66
64
  end
@@ -8,19 +8,23 @@ module Pagelapse
8
8
  include Capybara::DSL
9
9
 
10
10
  # Captures a screenshot of +url+ saving it to +output_path+.
11
- def capture(url, output_path, width: 1024, height: 768, full: false, timeout: false, capture_if: nil, save_if: nil)
11
+ def capture(url, output_path, width: 1024, height: 768, full: false, timeout: false, capture_if: nil, save_if: nil, on_load: nil)
12
+
13
+ # Reset session
14
+ Capybara.reset_sessions!
15
+
12
16
  # Browser settings
13
17
  page.driver.resize(width, height)
14
18
  page.driver.headers = {
15
19
  "User-Agent" => "Pagelapse #{Pagelapse::VERSION}",
16
20
  }
17
21
 
22
+ # Set default capture_if and save_if
18
23
  unless capture_if
19
24
  capture_if = Proc.new do
20
25
  page.driver.status_code == 200
21
26
  end
22
27
  end
23
-
24
28
  unless save_if
25
29
  save_if = Proc.new do |old_file, new_file|
26
30
  Digest::MD5.file(old_file).hexdigest != Digest::MD5.file(new_file).hexdigest
@@ -30,6 +34,9 @@ module Pagelapse
30
34
  # Open page
31
35
  visit url
32
36
 
37
+ # Run on_load
38
+ instance_eval(&on_load) if on_load
39
+
33
40
  # Timeout
34
41
  sleep timeout if timeout
35
42
 
@@ -54,8 +61,6 @@ module Pagelapse
54
61
  end
55
62
 
56
63
  def start_session(&block)
57
- Capybara.reset_sessions!
58
- Capybara.current_session.instance_eval(&block) if block_given?
59
64
  self
60
65
  end
61
66
 
@@ -1,3 +1,3 @@
1
1
  module Pagelapse
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagelapse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Lord
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-06 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler