md2key 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/README.md +3 -0
- data/lib/md2key/applescripts/activate_last_slide.applescript +14 -0
- data/lib/md2key/applescripts/create_slide.applescript +19 -0
- data/lib/md2key/applescripts/delete_extra_slides.applescript +15 -0
- data/lib/md2key/applescripts/delete_template_slide.applescript +6 -0
- data/lib/md2key/applescripts/ensure_template_slide_availability.applescript +5 -0
- data/lib/md2key/applescripts/insert_code_background.applescript +17 -0
- data/lib/md2key/applescripts/insert_image.applescript +28 -0
- data/lib/md2key/applescripts/paste_clipboard.applescript +7 -0
- data/lib/md2key/applescripts/slides_count.applescript +8 -0
- data/lib/md2key/applescripts/update_cover.applescript +14 -0
- data/lib/md2key/converter.rb +2 -2
- data/lib/md2key/keynote.rb +20 -124
- data/lib/md2key/version.rb +1 -1
- metadata +11 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd96ffc0f4fefb99341bfed8c3f4f3c09ed3edb
|
4
|
+
data.tar.gz: e8734c6294e3bfc804ca93be06cc7e9f954acbf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6cbc4dea1091b64fcbcd5c70d4cbf824a313955bb4b15f12c9dd41e35c0a1b360834f753658459ffb4fc3f2651b71b8e6d4a3c2147a9b447d99edbc4c7b2e49
|
7
|
+
data.tar.gz: d340cb217bdcbb479f84da983f3a9459bd12f61bf622a2439692ff190c6e496b85361b8113d37d17850d67704f4885371dd585d49e288b4af2d2ee5dcdecab88
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# v0.4.1
|
2
|
+
|
3
|
+
- Performance improvement
|
4
|
+
- Stop generating applescript every time
|
5
|
+
- Thanks to @bogem
|
6
|
+
|
1
7
|
# v0.4.0
|
2
8
|
|
3
9
|
- Support sintax-highlighted source code insert
|
@@ -40,6 +46,7 @@
|
|
40
46
|
- Temporarily support skipping `---`
|
41
47
|
- Still expecting users to write a format like Deckset
|
42
48
|
- https://github.com/k0kubun/md2key/pull/2
|
49
|
+
- Thanks to @liubin
|
43
50
|
|
44
51
|
# v0.1.1
|
45
52
|
|
data/README.md
CHANGED
@@ -43,6 +43,9 @@ You can separate slides with `---` just for readability.
|
|
43
43
|
|
44
44
|
### Insert source code
|
45
45
|
|
46
|
+
If you have `highlight` command, you can insert syntax-highlighted source code.
|
47
|
+
If you don't have it, execute `brew install highlight`.
|
48
|
+
|
46
49
|
<img src='https://i.gyazo.com/7ff36be267652ab567191a6d5cae1d0f.png' width='60%'>
|
47
50
|
|
48
51
|
<pre>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
-- First argument - title
|
2
|
+
-- Second arument - content
|
3
|
+
on run argv
|
4
|
+
tell application "Keynote"
|
5
|
+
tell the front document
|
6
|
+
-- Workaround to select correct master slide. In spite of master slide can be selected by name,
|
7
|
+
-- name property is not limited to be unique.
|
8
|
+
-- So move the focus to second slide and force "make new slide" to use the exact master slide.
|
9
|
+
set TEMPLATE_SLIDE_INDEX to 2
|
10
|
+
move slide TEMPLATE_SLIDE_INDEX to before slide TEMPLATE_SLIDE_INDEX
|
11
|
+
|
12
|
+
set newSlide to make new slide
|
13
|
+
tell newSlide
|
14
|
+
set object text of default title item to first item of argv
|
15
|
+
set object text of default body item to second item of argv
|
16
|
+
end tell
|
17
|
+
end tell
|
18
|
+
end tell
|
19
|
+
end run
|
@@ -0,0 +1,15 @@
|
|
1
|
+
-- First argument - slides count
|
2
|
+
on run argv
|
3
|
+
tell application "Keynote"
|
4
|
+
set theSlides to slides of the front document
|
5
|
+
set n to first item of argv as number
|
6
|
+
|
7
|
+
repeat with theSlide in theSlides
|
8
|
+
if n > 2 then
|
9
|
+
delete slide n of the front document
|
10
|
+
end if
|
11
|
+
|
12
|
+
set n to n - 1
|
13
|
+
end repeat
|
14
|
+
end tell
|
15
|
+
end run
|
@@ -0,0 +1,17 @@
|
|
1
|
+
-- First argument - slides count
|
2
|
+
-- Second argument - code background path
|
3
|
+
|
4
|
+
on run argv
|
5
|
+
tell application "Keynote"
|
6
|
+
tell the front document
|
7
|
+
set theSlide to slide (first item of argv as number)
|
8
|
+
set theImage to second item of argv as POSIX file
|
9
|
+
set docWidth to its width
|
10
|
+
set docHeight to its height
|
11
|
+
|
12
|
+
tell theSlide
|
13
|
+
make new image with properties {opacity:80, file:theImage, width:docWidth - 180, position:{90, 240}}
|
14
|
+
end tell
|
15
|
+
end tell
|
16
|
+
end tell
|
17
|
+
end run
|
@@ -0,0 +1,28 @@
|
|
1
|
+
-- First argument - slides count
|
2
|
+
-- Second argument - POSIX path
|
3
|
+
on run argv
|
4
|
+
tell application "Keynote"
|
5
|
+
tell the front document
|
6
|
+
set TEMPLATE_SLIDE_INDEX to 2
|
7
|
+
|
8
|
+
set slideNumber to first item of argv as number
|
9
|
+
set theSlide to slide slideNumber
|
10
|
+
set theImage to second item of argv as POSIX file
|
11
|
+
set docWidth to its width
|
12
|
+
set docHeight to its height
|
13
|
+
|
14
|
+
-- Create temporary slide to fix the image size
|
15
|
+
tell slide TEMPLATE_SLIDE_INDEX
|
16
|
+
set imgFile to make new image with properties { file:theImage, width:docWidth / 3 }
|
17
|
+
tell imgFile
|
18
|
+
set imgWidth to its width
|
19
|
+
set imgHeight to its width
|
20
|
+
end tell
|
21
|
+
end tell
|
22
|
+
|
23
|
+
tell theSlide
|
24
|
+
make new image with properties {file:theImage, width:imgWidth, position:{ docWidth - imgWidth - 60, docHeight / 2 - imgHeight / 2 } }
|
25
|
+
end tell
|
26
|
+
end tell
|
27
|
+
end tell
|
28
|
+
end run
|
@@ -0,0 +1,14 @@
|
|
1
|
+
-- First argument - title
|
2
|
+
-- Second argument - sub
|
3
|
+
on run argv
|
4
|
+
tell application "Keynote"
|
5
|
+
set COVER_SLIDE_INDEX to 1
|
6
|
+
|
7
|
+
tell the front document
|
8
|
+
tell slide COVER_SLIDE_INDEX
|
9
|
+
set object text of default title item to first item of argv
|
10
|
+
set object text of default body item to second item of argv
|
11
|
+
end tell
|
12
|
+
end tell
|
13
|
+
end tell
|
14
|
+
end run
|
data/lib/md2key/converter.rb
CHANGED
@@ -25,9 +25,9 @@ module Md2key
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def generate_contents
|
28
|
-
Keynote.update_cover(@markdown.cover.title, @markdown.cover.lines.join(
|
28
|
+
Keynote.update_cover(@markdown.cover.title, @markdown.cover.lines.join("\n"))
|
29
29
|
@markdown.slides.each_with_index do |slide, index|
|
30
|
-
Keynote.create_slide(slide.title, slide.lines.join(
|
30
|
+
Keynote.create_slide(slide.title, slide.lines.join("\n"))
|
31
31
|
Keynote.insert_image(slide.image) if slide.image
|
32
32
|
Keynote.insert_code(slide.code) if slide.code
|
33
33
|
end
|
data/lib/md2key/keynote.rb
CHANGED
@@ -2,97 +2,35 @@ require 'unindent'
|
|
2
2
|
|
3
3
|
module Md2key
|
4
4
|
class Keynote
|
5
|
-
COVER_SLIDE_INDEX = 1
|
6
|
-
TEMPLATE_SLIDE_INDEX = 2
|
7
5
|
CODE_BACKGROUND_PATH = File.expand_path('../../assets/background.png', __dir__)
|
8
6
|
|
9
7
|
class << self
|
10
8
|
# You must provide a first slide as a cover slide.
|
11
9
|
def update_cover(title, sub)
|
12
|
-
|
13
|
-
tell the front document
|
14
|
-
tell slide #{COVER_SLIDE_INDEX}
|
15
|
-
set object text of default title item to "#{title}"
|
16
|
-
set object text of default body item to "#{sub}"
|
17
|
-
end tell
|
18
|
-
end tell
|
19
|
-
APPLE
|
10
|
+
execute_applescript(:void, :update_cover, title, sub)
|
20
11
|
end
|
21
12
|
|
22
13
|
def ensure_template_slide_availability
|
23
14
|
return if slides_count >= 2
|
24
|
-
|
25
|
-
tell_keynote(<<-APPLE.unindent)
|
26
|
-
tell the front document
|
27
|
-
make new slide
|
28
|
-
end
|
29
|
-
APPLE
|
15
|
+
execute_applescript(:void, :ensure_template_slide_availability)
|
30
16
|
end
|
31
17
|
|
32
18
|
# All slides after a second slide are unnecessary and deleted.
|
33
19
|
def delete_extra_slides
|
34
|
-
|
35
|
-
set theSlides to slides of the front document
|
36
|
-
set n to #{slides_count}
|
37
|
-
|
38
|
-
repeat with theSlide in theSlides
|
39
|
-
if n > 2 then
|
40
|
-
delete slide n of the front document
|
41
|
-
end if
|
42
|
-
|
43
|
-
set n to n - 1
|
44
|
-
end repeat
|
45
|
-
APPLE
|
20
|
+
execute_applescript(:void, :delete_extra_slides, slides_count)
|
46
21
|
end
|
47
22
|
|
48
23
|
def delete_template_slide
|
49
|
-
|
50
|
-
tell the front document
|
51
|
-
delete slide #{TEMPLATE_SLIDE_INDEX}
|
52
|
-
end tell
|
53
|
-
APPLE
|
24
|
+
execute_applescript(:void, :delete_template_slide)
|
54
25
|
end
|
55
26
|
|
56
27
|
def create_slide(title, content)
|
57
|
-
|
58
|
-
tell the front document
|
59
|
-
-- Workaround to select correct master slide. In spite of master slide can be selected by name,
|
60
|
-
-- name property is not limited to be unique.
|
61
|
-
-- So move the focus to second slide and force "make new slide" to use the exact master slide.
|
62
|
-
#{move_to_slide(TEMPLATE_SLIDE_INDEX)}
|
63
|
-
|
64
|
-
set newSlide to make new slide
|
65
|
-
tell newSlide
|
66
|
-
set object text of default title item to "#{title}"
|
67
|
-
set object text of default body item to "#{content}"
|
68
|
-
end tell
|
69
|
-
end tell
|
70
|
-
APPLE
|
28
|
+
execute_applescript(:void, :create_slide, title, content)
|
71
29
|
end
|
72
30
|
|
73
31
|
# Insert image to the last slide
|
74
32
|
def insert_image(path)
|
75
|
-
|
76
|
-
tell the front document
|
77
|
-
set theSlide to slide #{slides_count}
|
78
|
-
set theImage to POSIX file "#{path}"
|
79
|
-
set docWidth to its width
|
80
|
-
set docHeight to its height
|
81
|
-
|
82
|
-
-- Create temporary slide to fix the image size
|
83
|
-
tell slide #{TEMPLATE_SLIDE_INDEX}
|
84
|
-
set imgFile to make new image with properties { file: theImage, width: docWidth / 3 }
|
85
|
-
tell imgFile
|
86
|
-
set imgWidth to its width
|
87
|
-
set imgHeight to its width
|
88
|
-
end tell
|
89
|
-
end tell
|
90
|
-
|
91
|
-
tell theSlide
|
92
|
-
make new image with properties { file: theImage, width: imgWidth, position: { docWidth - imgWidth - 60, docHeight / 2 - imgHeight / 2 } }
|
93
|
-
end tell
|
94
|
-
end tell
|
95
|
-
APPLE
|
33
|
+
execute_applescript(:void, :insert_image, slides_count, path)
|
96
34
|
end
|
97
35
|
|
98
36
|
def insert_code(code)
|
@@ -105,76 +43,34 @@ module Md2key
|
|
105
43
|
private
|
106
44
|
|
107
45
|
def insert_code_background
|
108
|
-
|
109
|
-
tell the front document
|
110
|
-
set theSlide to slide #{slides_count}
|
111
|
-
set theImage to POSIX file "#{CODE_BACKGROUND_PATH}"
|
112
|
-
set docWidth to its width
|
113
|
-
set docHeight to its height
|
114
|
-
|
115
|
-
tell theSlide
|
116
|
-
make new image with properties { opacity: 80, file: theImage, width: docWidth - 180, position: { 90, 240 } }
|
117
|
-
end tell
|
118
|
-
end tell
|
119
|
-
APPLE
|
46
|
+
execute_applescript(:void, :insert_code_background, slides_count, CODE_BACKGROUND_PATH)
|
120
47
|
end
|
121
48
|
|
122
49
|
def activate_last_slide
|
123
|
-
|
124
|
-
activate
|
125
|
-
|
126
|
-
tell the front document
|
127
|
-
#{move_to_slide(slides_count)}
|
128
|
-
end tell
|
129
|
-
APPLE
|
130
|
-
end
|
131
|
-
|
132
|
-
# Workaround to activate the slide of given index. `show slide [index]`
|
133
|
-
# didn't work...
|
134
|
-
def move_to_slide(index)
|
135
|
-
"move slide #{index} to before slide #{index}"
|
50
|
+
execute_applescript(:void, :activate_last_slide)
|
136
51
|
end
|
137
52
|
|
138
53
|
def paste_clipboard
|
139
|
-
execute_applescript(
|
140
|
-
tell application "Keynote"
|
141
|
-
tell application "System Events"
|
142
|
-
tell application process "Keynote"
|
143
|
-
keystroke "v" using { command down }
|
144
|
-
end tell
|
145
|
-
end tell
|
146
|
-
end tell
|
147
|
-
APPLE
|
54
|
+
execute_applescript(:void, :paste_clipboard)
|
148
55
|
end
|
149
56
|
|
150
57
|
def slides_count
|
151
|
-
|
152
|
-
set n to 0
|
153
|
-
set theSlides to slides of the front document
|
154
|
-
repeat with theSlide in theSlides
|
155
|
-
set n to n + 1
|
156
|
-
end repeat
|
157
|
-
do shell script "echo " & n
|
158
|
-
APPLE
|
58
|
+
execute_applescript(:int, :slides_count)
|
159
59
|
end
|
160
60
|
|
161
|
-
def
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
execute_applescript(lines.join("\n"))
|
61
|
+
def execute_applescript(type, script_name, *args)
|
62
|
+
path = script_path(script_name.to_s)
|
63
|
+
args.map! { |arg| "\"#{arg}\"" }
|
64
|
+
command = "osascript #{path} #{args.join(' ')}"
|
65
|
+
`#{command + ' > /dev/null'}` if type == :void
|
66
|
+
`#{command}}`.to_i if type == :int
|
168
67
|
end
|
169
68
|
|
170
|
-
def
|
171
|
-
|
172
|
-
|
173
|
-
file.close
|
174
|
-
`osascript #{file.path}`.strip
|
175
|
-
ensure
|
176
|
-
file.delete
|
69
|
+
def script_path(script_name)
|
70
|
+
applescripts_path = File.expand_path('applescripts', __dir__)
|
71
|
+
File.join(applescripts_path, "#{script_name}.applescript")
|
177
72
|
end
|
73
|
+
|
178
74
|
end
|
179
75
|
end
|
180
76
|
end
|
data/lib/md2key/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: md2key
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
@@ -124,6 +124,16 @@ files:
|
|
124
124
|
- assets/background.png
|
125
125
|
- bin/md2key
|
126
126
|
- lib/md2key.rb
|
127
|
+
- lib/md2key/applescripts/activate_last_slide.applescript
|
128
|
+
- lib/md2key/applescripts/create_slide.applescript
|
129
|
+
- lib/md2key/applescripts/delete_extra_slides.applescript
|
130
|
+
- lib/md2key/applescripts/delete_template_slide.applescript
|
131
|
+
- lib/md2key/applescripts/ensure_template_slide_availability.applescript
|
132
|
+
- lib/md2key/applescripts/insert_code_background.applescript
|
133
|
+
- lib/md2key/applescripts/insert_image.applescript
|
134
|
+
- lib/md2key/applescripts/paste_clipboard.applescript
|
135
|
+
- lib/md2key/applescripts/slides_count.applescript
|
136
|
+
- lib/md2key/applescripts/update_cover.applescript
|
127
137
|
- lib/md2key/cli.rb
|
128
138
|
- lib/md2key/code.rb
|
129
139
|
- lib/md2key/converter.rb
|