fastlane-plugin-framer 0.1.0

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: 9ac4706b2a926352904eaaae3091e02ebf3ff9f2
4
+ data.tar.gz: 3746ed04028126a2fcbfb3a7be5e5128cba0f6cd
5
+ SHA512:
6
+ metadata.gz: 942ac782050e71f02d823755eb6b38f1618ec3f5ed57c2f54db139344a1c16287eea1596b2a81ca1b88b60de198972c63c210f278f72e97c6e3f29d298e15516
7
+ data.tar.gz: f826dd182be3393bc537deb93b5cf40516c3dc1216be020ae46fc87f6ef996aa4f929cc61a284f47603bd1556d0cdf5c382e94370f106ffc3df1ed60a4f20331
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 DrAL3X <alessandro.calzavara@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # framer plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-framer)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-framer`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin framer
11
+ ```
12
+
13
+ ## About framer
14
+
15
+ Create images combining app screenshots to templates to make nice pictures to upload in App Store.
16
+
17
+ It gives you the freedom to customize the looks of each image (your designers will love that!) while keep their generation fully automated.
18
+
19
+ ## Example
20
+
21
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
22
+
23
+ ## Run tests for this plugin
24
+
25
+ To run both the tests, and code style validation, run
26
+
27
+ ```
28
+ rake
29
+ ```
30
+
31
+ To automatically fix many of the styling issues, use
32
+ ```
33
+ rubocop -a
34
+ ```
35
+
36
+ ## Issues and Feedback
37
+
38
+ For any other issues and feedback about this plugin, please submit it to this repository.
39
+
40
+ ## Troubleshooting
41
+
42
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/PluginsTroubleshooting.md) doc in the main `fastlane` repo.
43
+
44
+ ## Using `fastlane` Plugins
45
+
46
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Plugins.md).
47
+
48
+ ## About `fastlane`
49
+
50
+ `fastlane` is the easiest way to automate building and releasing your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,276 @@
1
+ require 'mini_magick'
2
+ require 'json'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class Template
7
+ attr_accessor :name
8
+ attr_accessor :size
9
+
10
+ attr_accessor :file
11
+ attr_accessor :imageOffset, :imageWidth
12
+ attr_accessor :textOffsetX, :textOffsetY, :textWidth, :textHeight, :textPadding, :textSize, :textFont, :textColor
13
+ end
14
+
15
+ class FramerAction < Action
16
+ def self.run(params)
17
+ source_folder = params[:source_folder]
18
+ output_folder = params[:output_folder]
19
+ template_folder = params[:template_folder]
20
+ templates = []
21
+
22
+ # Read config
23
+ UI.success "Fetching templates from #{template_folder}"
24
+ templates = self.load_templates(template_folder)
25
+
26
+ # Process each screen
27
+ UI.success "Processing screenshots from #{source_folder}"
28
+ Dir.glob("#{source_folder}/**/*.png") do |file|
29
+ UI.message "Processing #{file}"
30
+
31
+ template = self.find_template(templates, file)
32
+ text = self.find_text(file)
33
+ output = self.find_output(source_folder, file, output_folder, params[:output_suffix])
34
+
35
+ if template.nil?
36
+ UI.error "Unable to find template for screenshot #{file}"
37
+ next
38
+ end
39
+
40
+ UI.verbose "Using template: #{template.name} (#{template.size})"
41
+ UI.verbose "Using text: #{text}"
42
+ UI.verbose "Saving to: #{output}"
43
+
44
+ # Do the magic
45
+ self.combine(file, template, text, output)
46
+
47
+ UI.verbose "Framed screenshot #{output}"
48
+ end
49
+
50
+ # Done
51
+ UI.success "All screenshots are now framed!"
52
+ end
53
+
54
+ def self.load_templates(template_folder)
55
+ json_file_path = "#{template_folder}/Config.json"
56
+
57
+ UI.user_error!("Missing Config.json file in template folder") unless File.exist?(json_file_path)
58
+
59
+ # Read JSON configuration
60
+ json_file = File.read(json_file_path)
61
+ json_config = JSON.parse(json_file)
62
+
63
+ config_default = json_config['default']
64
+
65
+ # Detect available templates
66
+ templates = []
67
+
68
+ Dir.glob("#{template_folder}/*.png") do |file|
69
+
70
+ name = File.basename(file, ".png")
71
+ UI.message "Loading template #{name}"
72
+
73
+ template = Template.new
74
+ template.file = file
75
+ template.name = name
76
+
77
+ # Read template image size
78
+ img = MiniMagick::Image.open(file)
79
+ template.size = "#{img.width}x#{img.height}"
80
+ img.destroy!
81
+
82
+ # Get template config
83
+ config_custom = json_config[name]
84
+
85
+ if config_custom.nil?
86
+ UI.error "Missing configuration for template #{name}"
87
+ next
88
+ end
89
+
90
+ # Set config
91
+ template.imageOffset = (config_custom['image'] && config_custom['image']['offset']) || (config_default['image'] && config_default['image']['offset'])
92
+ template.imageWidth = (config_custom['image'] && config_custom['image']['width']) || (config_default['image'] && config_default['image']['width'])
93
+
94
+ template.textColor = (config_custom['text'] && config_custom['text']['color']) || (config_default['text'] && config_default['text']['color'])
95
+ template.textFont = (config_custom['text'] && config_custom['text']['font']) || (config_default['text'] && config_default['text']['font'])
96
+ template.textSize = (config_custom['text'] && config_custom['text']['size']) || (config_default['text'] && config_default['text']['size'])
97
+ template.textWidth = (config_custom['text'] && config_custom['text']['width']) || (config_default['text'] && config_default['text']['width'])
98
+ template.textHeight = (config_custom['text'] && config_custom['text']['height']) || (config_default['text'] && config_default['text']['height'])
99
+ template.textPadding = (config_custom['text'] && config_custom['text']['padding']) || (config_default['text'] && config_default['text']['padding']) || 0
100
+ template.textOffsetX = (config_custom['text'] && config_custom['text']['offset_x']) || (config_default['text'] && config_default['text']['offset_x']) || 0
101
+ template.textOffsetY = (config_custom['text'] && config_custom['text']['offset_y']) || (config_default['text'] && config_default['text']['offset_y']) || 0
102
+
103
+ templates << template
104
+ end
105
+
106
+ return templates
107
+ end
108
+
109
+ def self.find_template(templates, screenshot_file)
110
+ # Read screenshot image size
111
+ img = MiniMagick::Image.open(screenshot_file)
112
+ size = "#{img.width}x#{img.height}"
113
+ img.destroy!
114
+
115
+ # Search template that matches that size
116
+ return templates.find { |template| template.size == size }
117
+ end
118
+
119
+ def self.find_text(screenshot_file)
120
+ directory = File.dirname(screenshot_file)
121
+ strings_path = File.join(directory, "text.json")
122
+ return nil unless File.exist?(strings_path)
123
+
124
+ text = JSON.parse(File.read(strings_path))
125
+
126
+ result = text.find { |k, v| File.basename(screenshot_file).upcase.include? k.upcase }
127
+ return result.last if result
128
+ end
129
+
130
+ def self.find_output(source_folder, screenshot_file, output_folder, output_suffix)
131
+ # Prepare file name
132
+ if output_suffix.empty?
133
+ file = File.basename(screenshot_file)
134
+ else
135
+ filename = File.basename(screenshot_file, ".*")
136
+ extention = File.extname(screenshot_file)
137
+
138
+ file = filename + output_suffix + extention
139
+ end
140
+
141
+ sub_path = File.dirname(screenshot_file).sub(source_folder, "")
142
+
143
+ # Prepare file path
144
+ file_path = File.join(File.join(output_folder, sub_path), file)
145
+
146
+ # Ensure output dir exist
147
+ folder = File.dirname(file_path)
148
+ Dir.mkdir(folder) unless File.exist?(folder)
149
+
150
+ return file_path
151
+ end
152
+
153
+ def self.combine(screenshot_file, template, text, output_file)
154
+ # Get template image
155
+ template_img = MiniMagick::Image.open(template.file)
156
+
157
+ # Get screenshot image
158
+ screenshot_img = MiniMagick::Image.open(screenshot_file)
159
+
160
+ # Resize screenshot to fit template
161
+ screenshot_img.resize "#{template.imageWidth}x"
162
+
163
+ # Put screenshot over template
164
+ result_img = template_img.composite(screenshot_img) do |c|
165
+ c.compose "Over"
166
+ c.geometry template.imageOffset.to_s
167
+ end
168
+
169
+ unless text.nil?
170
+ # Clean text string before using it
171
+ text.gsub! '\n', "\n"
172
+ text.gsub!(/(?<!\\)(')/) { |s| "\\#{s}" } # escape unescaped apostrophes with a backslash
173
+
174
+ # Create image with text
175
+ text_img = MiniMagick::Image.open("#{Framer::ROOT}/assets/background.png")
176
+ text_img.resize "2732x2732!" # Max space available. `!` says it should ignore the ratio
177
+
178
+ text_font = template.textFont.nil? ? "Helvetica" : template.textFont
179
+
180
+ text_img.combine_options do |c|
181
+ c.font text_font
182
+ c.pointsize template.textSize.to_s
183
+ c.gravity "Center"
184
+ c.draw "text 0,0 '#{text}'"
185
+ c.fill template.textColor.to_s
186
+ end
187
+ text_img.trim # remove white space
188
+
189
+ UI.verbose "text requires an area of #{text_img.width}x#{text_img.height}"
190
+
191
+ # Scale down to fit space (if needed)
192
+ available_width = (template.textWidth || template_img.width) - template.textPadding * 2
193
+ available_height = template.textHeight
194
+
195
+ ratio = available_width.to_f / text_img.width.to_f
196
+ if ratio < 1
197
+ UI.important "Scaling down text to fit in space (ratio: #{ratio.round(3)})"
198
+ text_img.resize "#{available_width}x"
199
+ end
200
+ UI.verbose "text area is now #{text_img.width}x#{text_img.height}"
201
+
202
+ # Put text image over template
203
+ offset_x = ((available_width - text_img.width) / 2.0 + template.textPadding).round + template.textOffsetX
204
+ offset_y = ((available_height - text_img.height) / 2.0).round + template.textOffsetY
205
+ UI.verbose "text final offset x: #{offset_x} y: #{offset_y}"
206
+
207
+ result_img = result_img.composite(text_img) do |c|
208
+ c.compose "Over"
209
+ c.geometry "+#{offset_x}+#{offset_y}"
210
+ end
211
+
212
+ text_img.destroy!
213
+ end
214
+
215
+ # Save result
216
+ result_img.format "png"
217
+ result_img.write output_file
218
+
219
+ # Cleanup temp files
220
+ result_img.destroy!
221
+ screenshot_img.destroy!
222
+ template_img.destroy!
223
+ end
224
+
225
+ #####################################################
226
+ # @!group Documentation
227
+ #####################################################
228
+
229
+ def self.description
230
+ "Create images combining app screenshots to templates to make a nice \'screenshot\' to upload in App Store"
231
+ end
232
+
233
+ def self.authors
234
+ ["DrAL3X"]
235
+ end
236
+
237
+ def self.available_options
238
+ [
239
+ FastlaneCore::ConfigItem.new(key: :source_folder,
240
+ env_name: "FL_FRAMER_SOURCE_FOLDER",
241
+ description: "Folder that contains screenshots to frame",
242
+ is_string: true,
243
+ default_value: "./fastlane/framer/screens",
244
+ verify_block: proc do |value|
245
+ UI.user_error!("Couldn't find folder at path '#{value}'") unless File.exist?(value)
246
+ end),
247
+ FastlaneCore::ConfigItem.new(key: :template_folder,
248
+ env_name: "FL_FRAMER_TEMPLATE_FOLDER",
249
+ description: "Folder that contains frames",
250
+ is_string: true,
251
+ default_value: "./fastlane/framer/templates",
252
+ verify_block: proc do |value|
253
+ UI.user_error!("Couldn't find folder at path '#{value}'") unless File.exist?(value)
254
+ end),
255
+ FastlaneCore::ConfigItem.new(key: :output_folder,
256
+ env_name: "FL_FRAMER_OUTPUT_FOLDER",
257
+ description: "Folder that will contains framed screenshots",
258
+ is_string: true,
259
+ default_value: "./fastlane/screenshots",
260
+ verify_block: proc do |value|
261
+ UI.user_error!("Couldn't find folder at path '#{value}'") unless File.exist?(value)
262
+ end),
263
+ FastlaneCore::ConfigItem.new(key: :output_suffix,
264
+ env_name: "FL_FRAMER_OUTPUT_FILE_SUFFIX",
265
+ description: "Suffix added to each framed screenshot in the output folder",
266
+ is_string: true,
267
+ default_value: "-framed")
268
+ ]
269
+ end
270
+
271
+ def self.is_supported?(platform)
272
+ true
273
+ end
274
+ end
275
+ end
276
+ end
@@ -0,0 +1,12 @@
1
+ module Fastlane
2
+ module Helper
3
+ class FramerHelper
4
+ # class methods that you define here become available in your action
5
+ # as `Helper::FramerHelper.your_method`
6
+ #
7
+ def self.show_message
8
+ UI.message("Hello from the framer plugin helper!")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module Framer
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ require 'fastlane/plugin/framer/version'
2
+
3
+ module Fastlane
4
+
5
+ module Framer
6
+
7
+ ROOT = Pathname.new(File.join(File.dirname(__FILE__), 'framer'))
8
+
9
+ # Return all .rb files inside the "actions" and "helper" directory
10
+ def self.all_classes
11
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
12
+ end
13
+ end
14
+ end
15
+
16
+ # By default we want to import all available actions and helpers
17
+ # A plugin can contain any number of actions and plugins
18
+ Fastlane::Framer.all_classes.each do |current|
19
+ require current
20
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-framer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - DrAL3X
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini_magick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.5.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.5.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fastlane
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 1.100.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 1.100.0
125
+ description:
126
+ email: alessandro.calzavara@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - LICENSE
132
+ - README.md
133
+ - lib/fastlane/plugin/framer.rb
134
+ - lib/fastlane/plugin/framer/actions/framer_action.rb
135
+ - lib/fastlane/plugin/framer/assets/background.png
136
+ - lib/fastlane/plugin/framer/helper/framer_helper.rb
137
+ - lib/fastlane/plugin/framer/version.rb
138
+ homepage: https://github.com/spreaker/fastlane-framer-plugin
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.6.6
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Create images combining app screenshots with templates to make nice pictures
162
+ for the App Store
163
+ test_files: []
164
+ has_rdoc: