keynote-client 0.0.1 → 0.0.2

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: 50cfb8dc4b8875c72701235b4dd69b341e3f3403
4
- data.tar.gz: 08ca6c611ea8ab9b898603579b145cb08d166cda
3
+ metadata.gz: 4c4744a2aa2fb814a90ac556a0713e2eb774c9f2
4
+ data.tar.gz: 10a2e69dce31aede9cb96c6c340250a7dce40c87
5
5
  SHA512:
6
- metadata.gz: 7f97140e20d61d439b25a5d6cc55ac92c11675074bf747965b813e9e91b2c828ba7f3ede0473884a7bb6fcffdea710704cadbceaec74d6b003e86899ca43f44a
7
- data.tar.gz: 21f615964d153831968f8edba649fbbaaa331c6c9a772e3088a721d899435e2618bec1a2f8a1567d04b7c564f040ad96188da4216f85c06272580d9ac5ab4a0f
6
+ metadata.gz: 7885c96f7b91d6d5e89ff5d135d05c1745c8a911834eb10843725e7a74925cc947200cfd341fc025aeb3e97e40edc86ff815ee9c10f8a4c12076bdfd8678c938
7
+ data.tar.gz: b053a819f7e65aced80c6bf0ecac85c4db65606938b258e38ba3f2c947d9389519dd7449d0357cddf7142c26ff0de8fe6ad148ea95eddda925c674c20abf2964
data/README.md CHANGED
@@ -8,6 +8,27 @@ Currently this project is in alpha stage. It supports these features.
8
8
  - Appending a new slide with specified master slide
9
9
  - Saving a document
10
10
 
11
+ ## Install
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```sh
16
+ gem keynote-client'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```sh
22
+ $ bundle
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```sh
28
+ $ gem install keynote-client
29
+ ```
30
+
31
+
11
32
  ## Usage
12
33
 
13
34
  ```ruby
@@ -25,7 +46,7 @@ themes = Theme.find_by(:all)
25
46
  theme = Theme.find_by(name: 'ブラック').first
26
47
  # #<Keynote::Theme:0x007fd9ec821748 @id="Application/Black/Standard", @name="ブラック">,
27
48
 
28
- doc = Document.new(theme: theme, file_path: '/path/to/foo.key')
49
+ doc = Document.create(theme: theme, file_path: '/path/to/foo.key')
29
50
  # => #<Keynote::Document:0x007fbe03224228
30
51
  # @auto_loop=false,
31
52
  # @auto_play=false,
@@ -35,17 +35,15 @@ module Keynote
35
35
  @width = arguments.has_key?(:wide) && arguments[:wide] ? WIDE_WIDTH : DEFAULT_WIDTH
36
36
  @height = arguments.has_key?(:wide) && arguments[:wide] ? WIDE_HEIGHT : DEFAULT_HEIGHT
37
37
  @file_path = arguments[:file_path]
38
-
39
- result = Document.create(theme: @document_theme, width: @width, height: @height)
40
- @id = result["id"]
41
- @maximum_idle_duration = result["maximumIdleDuration"]
42
- @current_slide = result["currentSlide"]
43
- @slide_numbers_showing = result["slideNumbersShowing"]
44
- @auto_loop = result["autoLoop"]
45
- @auto_play = result["autoPlay"]
46
- @auto_restart = result["autoRestart"]
47
- @maximum_idle_duration = result["maximumIdleDuration"]
48
- @name = result["name"]
38
+ @id = arguments[:id]
39
+ @maximum_idle_duration = arguments[:maximumIdleDuration]
40
+ @current_slide = arguments[:currentSlide]
41
+ @slide_numbers_showing = arguments[:slideNumbersShowing]
42
+ @auto_loop = arguments[:autoLoop]
43
+ @auto_play = arguments[:autoPlay]
44
+ @auto_restart = arguments[:autoRestart]
45
+ @maximum_idle_duration = arguments[:maximumIdleDuration]
46
+ @name = arguments[:name]
49
47
  end
50
48
 
51
49
  def master_slides
@@ -170,26 +168,55 @@ module Keynote
170
168
 
171
169
  def self.create(arguments = {})
172
170
  theme = arguments[:theme] || Theme.default
173
- width = arguments[:width]
174
- height = arguments[:height]
171
+ width = arguments[:wide] ? WIDE_WIDTH : DEFAULT_WIDTH
172
+ height = arguments[:wide] ? WIDE_HEIGHT : DEFAULT_HEIGHT
175
173
 
176
- eval_script <<-APPLE.unindent
174
+ result = eval_script <<-APPLE.unindent
177
175
  var Keynote = Application("Keynote")
178
176
  var theme = Keynote.themes.whose({ id: "#{theme.id}" }).first
179
- Keynote.documents.push(Keynote.Document({ documentTheme: theme, width: #{width}, height: #{height} }));
180
- var doc = Keynote.documents()[Keynote.documents().length - 1];
181
- JSON.stringify({
182
- id: doc.id(),
183
- height: doc.height(),
184
- autoRestart: doc.autoRestart(),
185
- maximumIdleDuration: doc.maximumIdleDuration(),
186
- width: doc.width(),
187
- slideNumbersShowing: doc.slideNumbersShowing(),
188
- autoPlay: doc.autoPlay(),
189
- autoLoop: doc.autoLoop(),
190
- name: doc.name()
191
- });
177
+ var doc = Keynote.Document({ documentTheme: theme, width: #{width}, height: #{height} });
178
+ Keynote.documents.push(doc);
179
+ JSON.stringify(doc.properties());
192
180
  APPLE
181
+
182
+ self.new(symbolize_keys(result).merge(theme: theme, width: width, height: height))
183
+ end
184
+
185
+ def self.find_by(args)
186
+ raise ArgumentError.new('nil argument is given') unless args
187
+
188
+ if args.is_a?(Hash) && args.has_key?(:id)
189
+ conditions = ".whose({ id: '#{args[:id]}' })"
190
+ elsif args == :all
191
+ conditions = ''
192
+ else
193
+ raise ArgumentError.new('Unsupported argument is given')
194
+ end
195
+
196
+ results = eval_script <<-APPLE.unindent
197
+ var documents = Application("Keynote").documents#{conditions};
198
+ var results = [];
199
+ for(var i = 0, len = documents.length; i < len; i++) {
200
+ results.push(documents[i].properties());
201
+ }
202
+ JSON.stringify(results);
203
+ APPLE
204
+
205
+ return [] unless results
206
+
207
+ results.map do |result|
208
+ self.new(symbolize_keys(result))
209
+ end
210
+ end
211
+
212
+ def self.current
213
+ self.find_by(:all).first
214
+ end
215
+
216
+ private
217
+
218
+ def self.symbolize_keys(hash)
219
+ Hash[hash.map { |k, v| [k.to_sym, v] }]
193
220
  end
194
221
  end
195
222
  end
@@ -1,5 +1,5 @@
1
1
  module Keynote
2
2
  module Client
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keynote-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryo katsuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-09 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.4.5
128
+ rubygems_version: 2.2.2
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: keynote client with high level API.