motion-screenshots 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e45e4d791f33c71d3d293f9378b29f3507bb16a
4
+ data.tar.gz: ac7d5bbf01f869d5c460c523bb2d0cbddd5b8b83
5
+ SHA512:
6
+ metadata.gz: 14ed0214424a55bd7cc9b3a5dce879a00052ff650d878cef4fa704380d4d0adc3380c6104ed2be1eab236cb60d05954eeae9ee0475751e55caca9d2dab9ae1d3
7
+ data.tar.gz: 9bdde2151c34ee0b6a9b6944479d5e37020ffd271c4c227deb32f443fb8b94e18f006af64d9c2edaeb2b1ee91329c3019c238f498517937a1feba2c1da067287
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # motion-screenshots
2
+
3
+ Automate your App Store screenshots with `rake screenshots`. Powered by [KSScreenshotManager](https://github.com/ksuther/KSScreenshotManager).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'motion-screenshots'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install motion-screenshots
18
+
19
+ ## Usage
20
+
21
+ ### Configuration
22
+
23
+ By default, screenshots will be placed in a `./screenshots/#{timestamp}` directory in your project. You can configure this a few different ways:
24
+
25
+ - `ENV['SCREENSHOTS_DIR']` - use this environment variable
26
+ - `app.screenshots_output_path=` - set this value in your Rakefile
27
+ - `app.manage_screenshots do |output_path|` - add this block in your Rakefile
28
+
29
+ ### Code
30
+
31
+ Create one or more subclasses of `Motion::Screenshots::Base` and add them to `./app/screenshots`. This class uses a DSL you can use to setup what happens before and after various screenshots are taken.
32
+
33
+ ```ruby
34
+ class AppScreenshots < Motion::Screenshots::Base
35
+
36
+ # Use `.screenshot` to take a synchronous shot
37
+ screenshot "menu" do
38
+ before do
39
+ # scroll down for a nice action shot
40
+ App.delegate.table_view_controller.scrollToRowAtIndexPath(
41
+ NSIndexPath.indexPathForRow(2, inSection: 1),
42
+ animated: false,
43
+ scrollPosition: UITableViewScrollPositionMiddle
44
+ )
45
+ end
46
+ end
47
+
48
+ # Use `.async_screenshot` to take a screenshot
49
+ # at some point in the future (i.e. a timer, network calls, etc)
50
+ # Invoke `#ready!` to take the shot
51
+ async_screenshot "profile" do
52
+ before do
53
+ App.delegate.table_view_controller.selectRowAtIndexPath(
54
+ NSIndexPath.indexPathForRow(0, inSection: 1),
55
+ animated: false,
56
+ scrollPosition: UITableViewScrollPositionNone
57
+ )
58
+
59
+ # give the network some time...
60
+ Dispatch::Queue.main.after(3) {
61
+ ready!
62
+ }
63
+ end
64
+
65
+ # clean-up
66
+ after do
67
+ App.window.rootViewController.popViewControllerAnimated(false)
68
+ end
69
+ end
70
+ end
71
+ ```
72
+
73
+ Then, elsewhere in your code, simply let motion-screenshots know when to start the process:
74
+
75
+ ```ruby
76
+ class AppDelegate
77
+
78
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
79
+ # do other stuff...
80
+
81
+ AppScreenshots.start!
82
+ end
83
+ end
84
+ ```
85
+
86
+ Screenshots are executed in the order listed in your class - doing any cleanup or pre-screenshot preparation is left to you.
87
+
88
+ ### Running
89
+
90
+ Simple run `rake screenshots` and you're off! The task will uninstall and reinstall your CocoaPods, as to not include any of the private APIs bundled with `KSScreenshotManager`.
91
+
92
+ ## Contact
93
+
94
+ [Clay Allsopp](http://clayallsopp.com/)
95
+ [@clayallsopp](https://twitter.com/clayallsopp)
@@ -0,0 +1,108 @@
1
+ if !Kernel.const_defined?(:KSScreenshotManager)
2
+ class KSScreenshotManager
3
+ def init
4
+ @started = true
5
+ end
6
+ end
7
+ end
8
+
9
+ module Motion
10
+ module Screenshots
11
+ class Base < KSScreenshotManager
12
+ SCREENSHOTS_BASE_FOLDER = "motion_screenshots"
13
+ class << self
14
+ # Adds a namespace folder for this screenshot class
15
+ def group_by(&block)
16
+ shared.group_by_block = block
17
+ end
18
+
19
+ def async_screenshot(title, &block)
20
+ shared.async_screenshot(title, &block)
21
+ end
22
+
23
+ def screenshot(title, &block)
24
+ shared.screenshot(title, &block)
25
+ end
26
+
27
+ def start!
28
+ shared.start!
29
+ end
30
+
31
+ private
32
+ def shared
33
+ @shared ||= alloc.init
34
+ end
35
+ end
36
+
37
+ attr_accessor :group_by_block, :screenshot_groups
38
+
39
+ def init
40
+ super
41
+ @group_by_block = nil
42
+ @screenshot_groups = []
43
+ self
44
+ end
45
+
46
+ def group_by(&block)
47
+ @group_by_block = block
48
+ end
49
+
50
+ def async_screenshot(title, &block)
51
+ @screenshot_groups << ScreenshotGroup.new(title, true, self, &block)
52
+ end
53
+
54
+ def screenshot(title, &block)
55
+ @screenshot_groups << ScreenshotGroup.new(title, false, self, &block)
56
+ end
57
+
58
+ def setupScreenshotActions
59
+ @screenshot_groups.each do |sg|
60
+ addScreenshotAction sg.to_KSScreenshotAction
61
+ end
62
+ end
63
+
64
+ def start!
65
+ return if @started
66
+
67
+ @started = true
68
+
69
+ documents_path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0].retain
70
+ screenshot_path = File.join(documents_path, SCREENSHOTS_BASE_FOLDER)
71
+ screenshot_path = File.join(screenshot_path, group_by_block.call) if @group_by_block
72
+ self.screenshotsURL = NSURL.fileURLWithPath(screenshot_path)
73
+
74
+ takeScreenshots
75
+ end
76
+ end
77
+
78
+ class ScreenshotGroup
79
+ def initialize(title, is_async, manager, &eval_block)
80
+ @title = title
81
+ @is_async = is_async
82
+ @manager = manager
83
+ @before_actions = nil
84
+ @after_actions = nil
85
+ instance_eval(&eval_block) if eval_block
86
+ end
87
+
88
+ def before(&actions)
89
+ @before_actions = actions
90
+ end
91
+
92
+ def after(&actions)
93
+ @after_actions = actions
94
+ end
95
+
96
+ def ready!
97
+ @manager.actionIsReady
98
+ end
99
+
100
+ def to_KSScreenshotAction
101
+ KSScreenshotAction.actionWithName(@title, asynchronous: @is_async,
102
+ actionBlock:-> { @before_actions.call if @before_actions },
103
+ cleanupBlock: -> { @after_actions.call if @after_actions }
104
+ )
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,64 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ require 'motion-cocoapods'
6
+ require 'fileutils'
7
+ require 'shellwords'
8
+
9
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
10
+ Motion::Project::App.setup do |app|
11
+ gem_files = Dir.glob(File.join(lib_dir_path, "motion/**/*.rb"))
12
+ app.files.unshift(gem_files).flatten!
13
+ end
14
+
15
+ module Motion; module Project; class Config
16
+ attr_accessor :screenshot_callback
17
+
18
+ variable :screenshots_output_path
19
+
20
+ def manage_screenshots(&block)
21
+ @screenshot_callback = block
22
+ end
23
+ end; end; end
24
+
25
+ namespace 'screenshots' do
26
+ task :start do
27
+ screenshots_output_path = ENV['SCREENSHOTS_DIR']
28
+ screenshots_output_path ||= App.config.screenshots_output_path
29
+ screenshots_output_path ||= File.join(`pwd`.strip, "screenshots", Time.now.to_i.to_s)
30
+ FileUtils.mkdir_p screenshots_output_path
31
+
32
+ app_config = Motion::Project::App.config_without_setup
33
+ app_config.pods do
34
+ pod 'KSScreenshotManager'
35
+ end
36
+
37
+ at_exit {
38
+ # Copy files
39
+ target = ENV['target'] || app_config.sdk_version
40
+ sim_apps = File.expand_path("~/Library/Application Support/iPhone Simulator/*/Applications")
41
+ app_dir = nil
42
+ app = app_config.app_bundle('iPhoneSimulator')
43
+ app_dir = File.dirname(Dir.glob("#{sim_apps}/**/#{File.basename(app)}").sort_by { |f|
44
+ File.mtime(f)
45
+ }.reverse.first)
46
+ motion_screenshots = File.join(app_dir, "Documents", "motion_screenshots")
47
+ screenshot_files = Dir[File.join(motion_screenshots, "**", "*")]
48
+ FileUtils.cp_r(screenshot_files, screenshots_output_path)
49
+ if app_config.screenshot_callback
50
+ app_config.screenshot_callback.call(screenshots_output_path)
51
+ else
52
+ `open #{screenshots_output_path.shellescape}`
53
+ end
54
+ puts "Re-installing pods..."
55
+ `bundle exec rake pod:install`
56
+ }
57
+
58
+ Rake::Task["pod:install"].invoke
59
+ Rake::Task["default"].invoke
60
+ end
61
+ end
62
+
63
+ desc "Take screenshots in your app"
64
+ task :screenshots => "screenshots:start"
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-screenshots
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Clay Allsopp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: motion-cocoapods
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Take screenshots with RubyMotion
42
+ email:
43
+ - clay@usepropeller.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/motion/motion-screenshots.rb
50
+ - lib/motion-screenshots.rb
51
+ homepage: https://github.com/usepropeller/motion-screenshots
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.3
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Take screenshots with RubyMotion
75
+ test_files: []