git_camera 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in git_camera.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/git_camera ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'git_camera'
4
+
5
+ pointless_ascii_camera = <<-EOS
6
+ ____
7
+ _[]_/____\\__n_
8
+ |_____.--.__()_|
9
+ |LI //# \\\\ |
10
+ | \\\\__// |
11
+ | '--' |
12
+ '--------------'
13
+ EOS
14
+ # borrowed without much asking from http://www.chris.com/ascii/index.php?art=objects%2Fcameras
15
+ puts pointless_ascii_camera
16
+
17
+ config = GitCamera::Config.new
18
+ if config.exists?
19
+ capture_session = GitCamera::CaptureSession.new
20
+ config.load_to_session(capture_session)
21
+ capture_session.start_capture
22
+ else
23
+ config.init_project
24
+ puts "It looks like this is the first time you've used git-camera on this project. Default config has been initialised to git-camera/git-cam.conf. Run this again to start capturing"
25
+ end
@@ -0,0 +1,32 @@
1
+ # The page to capture
2
+ page_url "http://tomorrowsharvest.dev"
3
+
4
+ # The path of the project. Will assume current directory if not set (doesn't work yet)
5
+ # repo_path "/Users/skattyadz/Dropbox/code/tomorrowsharvest"
6
+
7
+ # Screen resolution to render at
8
+ resolution "800x600"
9
+
10
+ # Optional delay (in milliseconds) to wait for the server to load before taking a screenshot
11
+ # delay 250
12
+
13
+ # Optional hooks for before/after each individual screenshot, as well as before/after the capture session as a whole
14
+ # Each hook can either be a string to be executed on the command line, or a block of Ruby code
15
+
16
+ before_each "forever start server.js"
17
+ after_each "forever stop server.js"
18
+
19
+ before_all do
20
+ puts "This is some ruby code executed before capturing starts"
21
+ end
22
+
23
+ after_all do
24
+ puts "This code will run after everything's finished"
25
+ end
26
+
27
+ # I'd hope this one's obvious enough
28
+ frames_per_second 1
29
+
30
+ # Uncomment if you don't want to delete the source frames when finished (doesn't work yet)
31
+ # keep_images
32
+
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "git_camera/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "git_camera"
7
+ s.version = GitCamera::VERSION
8
+ s.authors = ["Adam Howard"]
9
+ s.email = ["skattyadz+rubygems@gmail.com"]
10
+ s.homepage = 'http://rubygems.org/gems/git-camera'
11
+ s.summary = "Git Camera"
12
+ s.description = "Command line tool to capture the visual evolution of a website over time"
13
+
14
+ s.rubyforge_project = "git_camera"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "grit"
24
+ end
@@ -0,0 +1,29 @@
1
+ # The page to capture
2
+ page_url "http://tomorrowsharvest.dev"
3
+
4
+ # Screen resolution to render at
5
+ resolution "800x600"
6
+
7
+ # Optional delay (in milliseconds) to wait for the server to load before taking a screenshot
8
+ # delay 250
9
+
10
+ # Optional hooks for before/after each individual screenshot, as well as before/after the capture session as a whole
11
+ # Each hook can either be a string to be executed on the command line or a block of Ruby code
12
+
13
+ before_each "forever start server.js"
14
+ after_each "forever stop server.js"
15
+
16
+ before_all do
17
+ puts "Starting capture session"
18
+ end
19
+
20
+ after_all do
21
+ puts "Finished capture session"
22
+ end
23
+
24
+ # I'd hope this one's obvious enough
25
+ frames_per_second 1
26
+
27
+ # Uncomment if you don't want to delete the source frames when finished (doesn't work yet)
28
+ # keep_images
29
+
@@ -0,0 +1,67 @@
1
+ require 'grit'
2
+
3
+ module GitCamera
4
+ class CaptureSession
5
+
6
+ attr_accessor :before_all_command, :before_all_block, :before_each_command, :before_each_block
7
+ attr_accessor :after_all_command, :after_all_block, :after_each_command, :after_each_block
8
+
9
+ attr_accessor :page_url, :repo_path, :resolution, :delay, :fps
10
+
11
+ def start_capture
12
+ FileUtils.mkdir('git_camera/frames') unless Dir.exist?('git_camera/frames')
13
+
14
+ repo = Grit::Repo.new(repo_path || Dir.getwd)
15
+
16
+ before_all_block.call if before_all_block
17
+ puts 'Snapping:'
18
+
19
+ repo.commits('master', 99999).reverse.each_with_index do |commit, i|
20
+ before_each_block.call if before_each_block
21
+
22
+ repo.git.native :checkout, {:raise=>true}, commit.sha
23
+ destination = "git_camera/frames/frame_#{"%05d" % i}.png"
24
+ before_each_block.call if before_each_block
25
+ # get unique destination path
26
+
27
+ take_screenshot(destination)
28
+ puts '- '+commit.message
29
+
30
+ after_each_block.call if after_each_block
31
+ end
32
+
33
+ compile_to_video
34
+
35
+ delete_images
36
+
37
+ after_all_block.call if after_all_block
38
+
39
+ repo.git.native :checkout, {}, 'master'
40
+ end
41
+
42
+ private
43
+
44
+ def take_screenshot(destination)
45
+ lib_path = File.expand_path("..", File.dirname(__FILE__))
46
+
47
+ phantom_command = [
48
+ 'phantomjs',
49
+ "#{lib_path}/phantom_task.js",
50
+ page_url,
51
+ destination,
52
+ resolution,
53
+ delay
54
+ ].join(' ')
55
+
56
+ system phantom_command
57
+ end
58
+
59
+ def compile_to_video
60
+ `ffmpeg -f image2 -r #{fps} -i git_camera/frames/frame_%05d.png -y git_camera_video.mp4`
61
+ end
62
+
63
+ def delete_images
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,62 @@
1
+ require 'fileutils'
2
+
3
+ module GitCamera
4
+ class Config
5
+
6
+ def exists?
7
+ dir = 'git_camera'
8
+ Dir.exist?(dir)
9
+ end
10
+
11
+ def load_to_session(capture_session)
12
+ @c = capture_session
13
+ instance_eval(File.read('git_camera/default_config.rb'))
14
+ end
15
+
16
+ def init_project
17
+ FileUtils.mkdir('git_camera')
18
+
19
+ default_conf_location = File.expand_path("../../default_config.rb", __FILE__)
20
+ FileUtils.cp(default_conf_location, 'git_camera/default_config.rb')
21
+ end
22
+
23
+ private
24
+
25
+ def before_all(command=nil, &block)
26
+ @c.before_all_command = command
27
+ @c.before_all_block = block
28
+ end
29
+ def before_each(command=nil, &block)
30
+ @c.before_each_command = command
31
+ @c.before_each_block = block
32
+ end
33
+ def after_all(command=nil, &block)
34
+ @c.after_all_command = command
35
+ @c.after_all_block = block
36
+ end
37
+ def after_each(command=nil, &block)
38
+ @c.after_each_command = command
39
+ @c.after_each_block = block
40
+ end
41
+
42
+ def page_url(url)
43
+ @c.page_url = url
44
+ end
45
+
46
+ def repo_path(path)
47
+ @c.repo_path = path
48
+ end
49
+
50
+ def resolution(res)
51
+ @c.resolution = res
52
+ end
53
+
54
+ def delay(delay_amount)
55
+ @c.delay = delay_amount
56
+ end
57
+
58
+ def frames_per_second(fps)
59
+ @c.fps = fps
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module GitCamera
2
+ VERSION = "0.0.1"
3
+ end
data/lib/git_camera.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "git_camera/version"
2
+ require "git_camera/config"
3
+ require "git_camera/capture_session"
4
+
5
+ module GitCamera
6
+ end
@@ -0,0 +1,14 @@
1
+ var page = require('webpage').create();
2
+
3
+ var url = phantom.args[0]
4
+ , destination = phantom.args[1]
5
+ , resolution = phantom.args[2].split('x');
6
+
7
+ // console.log(JSON.stringify(phantom.args));
8
+
9
+ page.viewportSize = { width: resolution[0], height: resolution[1] };
10
+
11
+ page.open(url, function () {
12
+ page.render(destination);
13
+ phantom.exit();
14
+ });
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_camera
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Howard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: grit
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
+ description: Command line tool to capture the visual evolution of a website over time
31
+ email:
32
+ - skattyadz+rubygems@gmail.com
33
+ executables:
34
+ - git_camera
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - Rakefile
41
+ - bin/git_camera
42
+ - git_camera.gemspec
43
+ - git_camera/default_config.rb
44
+ - lib/default_config.rb
45
+ - lib/git_camera.rb
46
+ - lib/git_camera/capture_session.rb
47
+ - lib/git_camera/config.rb
48
+ - lib/git_camera/version.rb
49
+ - lib/phantom_task.js
50
+ homepage: http://rubygems.org/gems/git-camera
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project: git_camera
70
+ rubygems_version: 1.8.24
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Git Camera
74
+ test_files: []