keynote-client 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -60
- data/lib/keynote/document.rb +38 -66
- data/lib/keynote/slide.rb +31 -4
- data/lib/keynote/slide_array.rb +53 -0
- data/lib/keynote/theme.rb +11 -3
- data/lib/keynote/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 199382e0930b6b78573c3991566bd4486beef77a
|
4
|
+
data.tar.gz: 8cf1d0be8b19e9725a9e4612c28e90d5dff92260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57f4e0440b614ae1faca604b5e1b0be7ade18cdcfabaabf21cdc0f60295a96bc6ed31f6a299f7ec45bd94ab5e66389a3e7545da97fc7d8de6e2282916a199915
|
7
|
+
data.tar.gz: 06552907f222c935ff961cf44eb2051826b6fe7f0ac993fe10128e3943fc44a627e4170f9aff686e7aff8c7ab681a76d2f30298b73211d6a3eb724156056d97f
|
data/README.md
CHANGED
@@ -4,16 +4,17 @@
|
|
4
4
|
|
5
5
|
Currently this project is in alpha stage. It supports these features.
|
6
6
|
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
7
|
+
- Create a new document with specified theme
|
8
|
+
- Append a new slide with specified master slide
|
9
|
+
- Update slides
|
10
|
+
- Save a document
|
10
11
|
|
11
12
|
## Install
|
12
13
|
|
13
14
|
Add this line to your application's Gemfile:
|
14
15
|
|
15
16
|
```sh
|
16
|
-
gem keynote-client'
|
17
|
+
gem 'keynote-client'
|
17
18
|
```
|
18
19
|
|
19
20
|
And then execute:
|
@@ -35,69 +36,31 @@ $ gem install keynote-client
|
|
35
36
|
require 'keynote-client'
|
36
37
|
inlude Keynote
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
# #<Keynote::Theme:0x007fd9ec821518 @id="Application/White/Standard", @name="ホワイト">,
|
41
|
-
# #<Keynote::Theme:0x007fd9ec820fa0 @id="Application/Gradient/Standard", @name="グラデーション">,
|
42
|
-
# #<Keynote::Theme:0x007fd9ec813e40 @id="Application/Parchment/Standard", @name="羊皮紙">,
|
43
|
-
# ...
|
44
|
-
# #<Keynote::Theme:0x007fd9ec813d78 @id="User/AC506922-367E-4300-AF77-8040B9CFA2B7", @name="cookpad">]
|
39
|
+
# Fetch all themes
|
40
|
+
themes = Theme.all
|
45
41
|
|
42
|
+
# Fetch theme specified name
|
46
43
|
theme = Theme.find_by(name: 'ブラック').first
|
47
|
-
# #<Keynote::Theme:0x007fd9ec821748 @id="Application/Black/Standard", @name="ブラック">,
|
48
44
|
|
45
|
+
# Create a new document with theme
|
49
46
|
doc = Document.create(theme: theme, file_path: '/path/to/foo.key')
|
50
|
-
# => #<Keynote::Document:0x007fbe03224228
|
51
|
-
# @auto_loop=false,
|
52
|
-
# @auto_play=false,
|
53
|
-
# @auto_restart=false,
|
54
|
-
# @current_slide=nil,
|
55
|
-
# @document_theme=#<Keynote::Theme:0x007fbe031f6e68 @id="Application/Black/Standard", @name="ブラック">,
|
56
|
-
# @height=768,
|
57
|
-
# @maximum_idle_duration=15,
|
58
|
-
# @name="名称未設定",
|
59
|
-
# @slide_numbers_showing=false,
|
60
|
-
# @slides=[],
|
61
|
-
# @width=1024>
|
62
47
|
|
48
|
+
# Save a document at file_path
|
63
49
|
doc.save
|
64
|
-
# => true
|
65
|
-
|
66
|
-
doc.slides
|
67
|
-
# => [#<Keynote::Slide:0x007fa17c2bcb98
|
68
|
-
# @base_slide=#<Keynote::MasterSlide:0x007fa17c2bcbe8 @name="タイトル & サブタイトル">,
|
69
|
-
# @body_showing=true,
|
70
|
-
# @default_body_item=nil,
|
71
|
-
# @default_title_item=nil,
|
72
|
-
# @presenter_notes="",
|
73
|
-
# @skipped=false,
|
74
|
-
# @slide_number=1,
|
75
|
-
# @title_showing=true,
|
76
|
-
# @transition_properties={"transitionDelay"=>0.5, "automaticTransition"=>false, "transitionEffect"=>"no transition effect", "transitionDuration"=>1}>]
|
77
|
-
|
78
|
-
doc.append_slide("空白")
|
79
|
-
# => [#<Keynote::Slide:0x007fa17c2bcb98
|
80
|
-
# @base_slide=#<Keynote::MasterSlide:0x007fa17c2bcbe8 @name="タイトル & サブタイトル">,
|
81
|
-
# @body_showing=true,
|
82
|
-
# @default_body_item=nil,
|
83
|
-
# @default_title_item=nil,
|
84
|
-
# @presenter_notes="",
|
85
|
-
# @skipped=false,
|
86
|
-
# @slide_number=1,
|
87
|
-
# @title_showing=true,
|
88
|
-
# @transition_properties={"transitionDelay"=>0.5, "automaticTransition"=>false, "transitionEffect"=>"no transition effect", "transitionDuration"=>1}>,
|
89
|
-
# #<Keynote::Slide:0x007fa17a8bbc08
|
90
|
-
# @base_slide=#<Keynote::MasterSlide:0x007fa17a8bbc58 @name="空白">,
|
91
|
-
# @body_showing=false,
|
92
|
-
# @default_body_item=nil,
|
93
|
-
# @default_title_item=nil,
|
94
|
-
# @presenter_notes="",
|
95
|
-
# @skipped=false,
|
96
|
-
# @slide_number=2,
|
97
|
-
# @title_showing=false,
|
98
|
-
# @transition_properties={"transitionDelay"=>0.5, "automaticTransition"=>false, "transitionEffect"=>"no transition effect", "transitionDuration"=>1}>]
|
99
|
-
```
|
100
50
|
|
51
|
+
# Initialize a new slide
|
52
|
+
slide = Slide.new("タイトル & 箇条書き", title: 'Pen', body: ["This is a pen", "Is this a pen?"].join("\n"))
|
53
|
+
|
54
|
+
# Append slides
|
55
|
+
doc.slides << slide
|
56
|
+
|
57
|
+
# Fetch last slide
|
58
|
+
slide = doc.slides.last
|
59
|
+
|
60
|
+
# Update a slide
|
61
|
+
slide.title = "About pen"
|
62
|
+
slide.body = "Hello, pen."
|
63
|
+
```
|
101
64
|
|
102
65
|
## Supported OS
|
103
66
|
- OSX Mavericks
|
data/lib/keynote/document.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'unindent'
|
2
2
|
require 'keynote/theme'
|
3
|
+
require 'keynote/slide_array'
|
3
4
|
require 'keynote/util'
|
4
5
|
|
5
6
|
module Keynote
|
@@ -78,8 +79,8 @@ module Keynote
|
|
78
79
|
skipped: slide.skipped(),
|
79
80
|
slide_number: slide.slideNumber(),
|
80
81
|
title_showing: slide.titleShowing(),
|
81
|
-
|
82
|
-
|
82
|
+
body: slide.defaultBodyItem.objectText(),
|
83
|
+
title: slide.defaultTitleItem.objectText(),
|
83
84
|
presenter_notes: slide.presenterNotes(),
|
84
85
|
transition_properties: slide.transitionProperties()
|
85
86
|
})
|
@@ -87,59 +88,24 @@ module Keynote
|
|
87
88
|
JSON.stringify(results);
|
88
89
|
APPLE
|
89
90
|
|
90
|
-
@slides =
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# arguments is not implemented
|
106
|
-
# It will support title, body, ... or so on.
|
107
|
-
def append_slide(master_slide_name, arguments = {})
|
108
|
-
raise ArgumentError.new "nil master_slide_name is given" unless master_slide_name
|
109
|
-
|
110
|
-
result = eval_script <<-APPLE.unindent
|
111
|
-
var Keynote = Application("Keynote")
|
112
|
-
var doc = Keynote.documents.byId("#{self.id}")
|
113
|
-
var masterSlide = doc.masterSlides.whose({name: "#{master_slide_name}"}).first
|
114
|
-
var slide = Keynote.Slide({ baseSlide: masterSlide })
|
115
|
-
doc.slides.push(slide)
|
116
|
-
slide = doc.slides()[doc.slides().length - 1]
|
117
|
-
|
118
|
-
var slideResult = {
|
119
|
-
body_showing: slide.bodyShowing(),
|
120
|
-
skipped: slide.skipped(),
|
121
|
-
slide_number: slide.slideNumber(),
|
122
|
-
title_showing: slide.titleShowing(),
|
123
|
-
default_body_item: slide.defaultBodyItem(),
|
124
|
-
default_title_item: slide.defaultTitleItem(),
|
125
|
-
presenter_notes: slide.presenterNotes(),
|
126
|
-
transition_properties: slide.transitionProperties()
|
127
|
-
}
|
128
|
-
JSON.stringify(slideResult)
|
129
|
-
APPLE
|
130
|
-
|
131
|
-
slide = Slide.new(
|
132
|
-
base_slide: MasterSlide.new(master_slide_name),
|
133
|
-
body_showing: result["body_showing"],
|
134
|
-
skipped: result["skipped"],
|
135
|
-
slide_number: result["slide_number"],
|
136
|
-
title_showing: result["title_showing"],
|
137
|
-
default_body_item: result["default_body_item"],
|
138
|
-
default_title_item: result["default_title_item"],
|
139
|
-
presenter_notes: result["presenter_notes"],
|
140
|
-
transition_properties: result["transition_properties"],
|
91
|
+
@slides = SlideArray.new(
|
92
|
+
results.map do |result|
|
93
|
+
Slide.new(
|
94
|
+
MasterSlide.new(result["base_slide"]),
|
95
|
+
document: self,
|
96
|
+
body_showing: result["body_showing"],
|
97
|
+
skipped: result["skipped"],
|
98
|
+
slide_number: result["slide_number"],
|
99
|
+
title_showing: result["title_showing"],
|
100
|
+
body: result["body"],
|
101
|
+
title: result["title"],
|
102
|
+
presenter_notes: result["presenter_notes"],
|
103
|
+
transition_properties: result["transition_properties"],
|
104
|
+
)
|
105
|
+
end
|
141
106
|
)
|
142
|
-
@slides
|
107
|
+
@slides.document = self
|
108
|
+
@slides
|
143
109
|
end
|
144
110
|
|
145
111
|
def save
|
@@ -182,17 +148,33 @@ module Keynote
|
|
182
148
|
self.new(symbolize_keys(result).merge(theme: theme, width: width, height: height))
|
183
149
|
end
|
184
150
|
|
151
|
+
def self.all
|
152
|
+
self.find_with_conditions
|
153
|
+
end
|
154
|
+
|
185
155
|
def self.find_by(args)
|
186
156
|
raise ArgumentError.new('nil argument is given') unless args
|
187
157
|
|
188
158
|
if args.is_a?(Hash) && args.has_key?(:id)
|
189
159
|
conditions = ".whose({ id: '#{args[:id]}' })"
|
190
|
-
elsif args == :all
|
191
|
-
conditions = ''
|
192
160
|
else
|
193
161
|
raise ArgumentError.new('Unsupported argument is given')
|
194
162
|
end
|
195
163
|
|
164
|
+
find_with_conditions(conditions)
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.current
|
168
|
+
self.all.first
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
|
173
|
+
def self.symbolize_keys(hash)
|
174
|
+
Hash[hash.map { |k, v| [k.to_sym, v] }]
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.find_with_conditions(conditions = '')
|
196
178
|
results = eval_script <<-APPLE.unindent
|
197
179
|
var documents = Application("Keynote").documents#{conditions};
|
198
180
|
var results = [];
|
@@ -208,15 +190,5 @@ module Keynote
|
|
208
190
|
self.new(symbolize_keys(result))
|
209
191
|
end
|
210
192
|
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] }]
|
220
|
-
end
|
221
193
|
end
|
222
194
|
end
|
data/lib/keynote/slide.rb
CHANGED
@@ -7,22 +7,49 @@ module Keynote
|
|
7
7
|
include Keynote::Util
|
8
8
|
|
9
9
|
attr_accessor(
|
10
|
-
:
|
10
|
+
:document,
|
11
11
|
:base_slide,
|
12
12
|
:body_showing,
|
13
13
|
:skipped,
|
14
14
|
:slide_number,
|
15
15
|
:title_showing,
|
16
|
-
:
|
17
|
-
:
|
16
|
+
:body,
|
17
|
+
:title,
|
18
18
|
:presenter_notes,
|
19
19
|
:transition_properties,
|
20
20
|
)
|
21
21
|
|
22
|
-
def initialize(arguments = {})
|
22
|
+
def initialize(base_slide, arguments = {})
|
23
|
+
@base_slide = base_slide
|
23
24
|
arguments.each do |attr, val|
|
24
25
|
send("#{attr}=", val)
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
29
|
+
def title=(title)
|
30
|
+
@title = title
|
31
|
+
return unless @document
|
32
|
+
return unless @slide_number
|
33
|
+
result = eval_script <<-APPLE.unindent
|
34
|
+
var Keynote = Application("Keynote")
|
35
|
+
var doc = Keynote.documents.byId("#{@document.id}")
|
36
|
+
var slide = doc.slides()[#{@slide_number - 1}]
|
37
|
+
slide.defaultTitleItem.objectText = "#{title}"
|
38
|
+
JSON.stringify({ result: true })
|
39
|
+
APPLE
|
40
|
+
end
|
41
|
+
|
42
|
+
def body=(body)
|
43
|
+
@body = body
|
44
|
+
return unless @document
|
45
|
+
return unless @slide_number
|
46
|
+
result = eval_script <<-APPLE.unindent
|
47
|
+
var Keynote = Application("Keynote")
|
48
|
+
var doc = Keynote.documents.byId("#{@document.id}")
|
49
|
+
var slide = doc.slides()[#{@slide_number - 1}]
|
50
|
+
slide.defaultBodyItem.objectText = "#{body}"
|
51
|
+
JSON.stringify({ result: true })
|
52
|
+
APPLE
|
53
|
+
end
|
27
54
|
end
|
28
55
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'unindent'
|
2
|
+
require 'keynote/util'
|
3
|
+
|
4
|
+
module Keynote
|
5
|
+
module ArrayMethods
|
6
|
+
def <<(slide)
|
7
|
+
raise ArgumentError.new "master_slide_name is not specified" unless slide.base_slide
|
8
|
+
|
9
|
+
title = slide.title.gsub(/(\r\n|\r|\n)/) { '\\n' }
|
10
|
+
body = slide.body.gsub(/(\r\n|\r|\n)/) { '\\n' }
|
11
|
+
|
12
|
+
result = eval_script <<-APPLE.unindent
|
13
|
+
var Keynote = Application("Keynote")
|
14
|
+
var doc = Keynote.documents.byId("#{self.document.id}")
|
15
|
+
var masterSlide = doc.masterSlides.whose({name: "#{slide.base_slide}"}).first
|
16
|
+
var slide = Keynote.Slide({ baseSlide: masterSlide })
|
17
|
+
doc.slides.push(slide)
|
18
|
+
slide = doc.slides()[doc.slides().length - 1]
|
19
|
+
slide.defaultTitleItem.objectText = "#{title}"
|
20
|
+
slide.defaultBodyItem.objectText = "#{body}"
|
21
|
+
|
22
|
+
var slideResult = {
|
23
|
+
body_showing: slide.bodyShowing(),
|
24
|
+
skipped: slide.skipped(),
|
25
|
+
slide_number: slide.slideNumber(),
|
26
|
+
title_showing: slide.titleShowing(),
|
27
|
+
body: slide.defaultBodyItem.objectText(),
|
28
|
+
title: slide.defaultTitleItem.objectText(),
|
29
|
+
presenter_notes: slide.presenterNotes(),
|
30
|
+
transition_properties: slide.transitionProperties()
|
31
|
+
}
|
32
|
+
JSON.stringify(slideResult)
|
33
|
+
APPLE
|
34
|
+
|
35
|
+
slide.document = self.document
|
36
|
+
slide.body_showing = result["body_showing"]
|
37
|
+
slide.skipped = result["skipped"]
|
38
|
+
slide.slide_number = result["slide_number"]
|
39
|
+
slide.title_showing = result["title_showing"]
|
40
|
+
slide.presenter_notes = result["presenter_notes"]
|
41
|
+
slide.transition_properties = result["transition_properties"]
|
42
|
+
|
43
|
+
super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class SlideArray < Array
|
48
|
+
prepend ArrayMethods
|
49
|
+
attr_accessor :document
|
50
|
+
|
51
|
+
include Keynote::Util
|
52
|
+
end
|
53
|
+
end
|
data/lib/keynote/theme.rb
CHANGED
@@ -13,7 +13,11 @@ module Keynote
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.default
|
16
|
-
self.
|
16
|
+
self.all.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.all
|
20
|
+
self.find_with_conditions
|
17
21
|
end
|
18
22
|
|
19
23
|
def self.find_by(args)
|
@@ -21,12 +25,16 @@ module Keynote
|
|
21
25
|
|
22
26
|
if args.is_a?(Hash) && args.has_key?(:name)
|
23
27
|
conditions = ".whose({ name: '#{args[:name]}' })"
|
24
|
-
elsif args == :all
|
25
|
-
conditions = ''
|
26
28
|
else
|
27
29
|
raise ArgumentError.new('Unsupported argument is given')
|
28
30
|
end
|
29
31
|
|
32
|
+
find_with_conditions(conditions)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.find_with_conditions(conditions = '')
|
30
38
|
results = eval_script <<-APPLE.unindent
|
31
39
|
var themes = Application("Keynote").themes#{conditions};
|
32
40
|
var results = [];
|
data/lib/keynote/version.rb
CHANGED
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
|
4
|
+
version: 0.1.0
|
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-
|
11
|
+
date: 2015-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/keynote/document.rb
|
101
101
|
- lib/keynote/master_slide.rb
|
102
102
|
- lib/keynote/slide.rb
|
103
|
+
- lib/keynote/slide_array.rb
|
103
104
|
- lib/keynote/theme.rb
|
104
105
|
- lib/keynote/util.rb
|
105
106
|
- lib/keynote/version.rb
|
@@ -125,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
126
|
version: '0'
|
126
127
|
requirements: []
|
127
128
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.4.5
|
129
130
|
signing_key:
|
130
131
|
specification_version: 4
|
131
132
|
summary: keynote client with high level API.
|