md2key 0.3.3 → 0.4.0

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: cd515b14ad74d002e0ae91bc868149359f04dc5b
4
- data.tar.gz: c45239e78b4c18217d2b7214508f91f04016de7e
3
+ metadata.gz: 5cb41f4bf6d0e31b689ac2d30b05c4e9d70c4ded
4
+ data.tar.gz: badaf24c7b6bda22c26d32832142050d3a58661a
5
5
  SHA512:
6
- metadata.gz: 092762b159e56c5019b328119be0d1536bbbf525f8d95b7aa4567a916b6099728cf111820ab22e496b9612ab7414184bdc2dd58f898879f9a0aa5404918c0dd7
7
- data.tar.gz: 879b241ded9e1b00a3e6aa985675ca7ed0416e57e3d7d182c8601bcca8509cc59f1d2a53451a7a07dae1fd23e94e2cc750b039f15cb19803a840d58489873708
6
+ metadata.gz: e3a084189e758af94942187ff63d7f4d683b6ea8244ef26ef2693cd36bb54aed4df5af5093d2e8c09478964ac4ebdb80e6187497a64049d1c9fa4a06cc1fd55e
7
+ data.tar.gz: 58d9ac418c913b0ce95e65a4044033d42d4f84ce2d6725307290b991a82a326261fa7de7666191973fe3db615068ab7233c1d8630d6afd17c5e6c2c577ef5d66
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.4.0
2
+
3
+ - Support sintax-highlighted source code insert
4
+
1
5
  # v0.3.3
2
6
 
3
7
  - Don't pull the Keynote window in the front
data/README.md CHANGED
@@ -41,6 +41,22 @@ You can separate slides with `---` just for readability.
41
41
  ![](/Applications/Keynote.app/Contents/Resources/keynote.help/Contents/Resources/GlobalArt/AppLanding_KeynoteP4.png)
42
42
  ```
43
43
 
44
+ ### Insert source code
45
+
46
+ <img src='https://i.gyazo.com/7ff36be267652ab567191a6d5cae1d0f.png' width='60%'>
47
+
48
+ <pre>
49
+ # ActiveRecord::Precount
50
+
51
+ ```rb
52
+ Tweet.all.precount(:favorites).each do |tweet|
53
+ p tweet.favorites.count
54
+ end
55
+ # SELECT `tweets`.* FROM `tweets`
56
+ # SELECT COUNT(`favorites`.`tweet_id`), `favorites`.`tweet_id` FROM `favorites` ...
57
+ ```
58
+ </pre>
59
+
44
60
  ## License
45
61
 
46
62
  MIT License
Binary file
@@ -0,0 +1,4 @@
1
+ module Md2key
2
+ class Code < Struct.new(:source, :extension)
3
+ end
4
+ end
@@ -29,6 +29,7 @@ module Md2key
29
29
  @markdown.slides.each_with_index do |slide, index|
30
30
  Keynote.create_slide(slide.title, slide.lines.join('\n'))
31
31
  Keynote.insert_image(slide.image) if slide.image
32
+ Keynote.insert_code(slide.code) if slide.code
32
33
  end
33
34
  end
34
35
  end
@@ -0,0 +1,29 @@
1
+ module Md2key
2
+ class Highlight
3
+ class << self
4
+ def pbcopy_highlighted_code(code)
5
+ ensure_highlight_availability
6
+
7
+ file = Tempfile.new(["code", ".#{code.extension}"])
8
+ file.write(code.source)
9
+ file.close
10
+
11
+ IO.popen(['highlight', '-O', 'rtf', '-K', '28', '-s', 'rdark', '-k', 'Monaco', file.path], 'r+') do |highlight|
12
+ IO.popen('pbcopy', 'w+') do |pbcopy|
13
+ pbcopy.write(highlight.read)
14
+ end
15
+ end
16
+ ensure
17
+ file.delete
18
+ end
19
+
20
+ private
21
+
22
+ def ensure_highlight_availability
23
+ return if system('which -s highlight')
24
+
25
+ abort "`highlight` is not available. Try `brew install highlight`."
26
+ end
27
+ end
28
+ end
29
+ end
@@ -4,6 +4,7 @@ module Md2key
4
4
  class Keynote
5
5
  COVER_SLIDE_INDEX = 1
6
6
  TEMPLATE_SLIDE_INDEX = 2
7
+ CODE_BACKGROUND_PATH = File.expand_path('../../assets/background.png', __dir__)
7
8
 
8
9
  class << self
9
10
  # You must provide a first slide as a cover slide.
@@ -58,7 +59,7 @@ module Md2key
58
59
  -- Workaround to select correct master slide. In spite of master slide can be selected by name,
59
60
  -- name property is not limited to be unique.
60
61
  -- So move the focus to second slide and force "make new slide" to use the exact master slide.
61
- move slide #{TEMPLATE_SLIDE_INDEX} to before slide #{TEMPLATE_SLIDE_INDEX}
62
+ #{move_to_slide(TEMPLATE_SLIDE_INDEX)}
62
63
 
63
64
  set newSlide to make new slide
64
65
  tell newSlide
@@ -78,6 +79,7 @@ module Md2key
78
79
  set docWidth to its width
79
80
  set docHeight to its height
80
81
 
82
+ -- Create temporary slide to fix the image size
81
83
  tell slide #{TEMPLATE_SLIDE_INDEX}
82
84
  set imgFile to make new image with properties { file: theImage, width: docWidth / 3 }
83
85
  tell imgFile
@@ -87,14 +89,64 @@ module Md2key
87
89
  end tell
88
90
 
89
91
  tell theSlide
90
- make new image with properties { file: theImage, width: imgWidth, position: { docWidth - imgWidth - 60, docHeight / 2 - imgHeight / 2} }
92
+ make new image with properties { file: theImage, width: imgWidth, position: { docWidth - imgWidth - 60, docHeight / 2 - imgHeight / 2 } }
91
93
  end tell
92
94
  end tell
93
95
  APPLE
94
96
  end
95
97
 
98
+ def insert_code(code)
99
+ Highlight.pbcopy_highlighted_code(code)
100
+ insert_code_background
101
+ activate_last_slide
102
+ paste_clipboard
103
+ end
104
+
96
105
  private
97
106
 
107
+ def insert_code_background
108
+ tell_keynote(<<-APPLE.unindent)
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
120
+ end
121
+
122
+ def activate_last_slide
123
+ tell_keynote(<<-APPLE.unindent)
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}"
136
+ end
137
+
138
+ def paste_clipboard
139
+ execute_applescript(<<-APPLE.unindent)
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
148
+ end
149
+
98
150
  def slides_count
99
151
  tell_keynote(<<-APPLE.unindent).to_i
100
152
  set n to 0
@@ -56,6 +56,11 @@ module Md2key
56
56
  end
57
57
  slide.lines << child.text
58
58
  end
59
+ when 'pre'
60
+ node.children.each do |child|
61
+ next if !child.is_a?(Oga::XML::Element) || child.name != 'code'
62
+ slide.code = Code.new(child.text, child.attribute('class').value)
63
+ end
59
64
  when 'hr'
60
65
  # noop
61
66
  end
@@ -87,7 +92,10 @@ module Md2key
87
92
  end
88
93
 
89
94
  def to_xhtml(markdown)
90
- redcarpet = Redcarpet::Markdown.new(Redcarpet::Render::XHTML)
95
+ redcarpet = Redcarpet::Markdown.new(
96
+ Redcarpet::Render::XHTML,
97
+ fenced_code_blocks: true,
98
+ )
91
99
  redcarpet.render(markdown)
92
100
  end
93
101
  end
data/lib/md2key/slide.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Md2key
2
- class Slide < Struct.new(:title, :lines, :image)
2
+ class Slide < Struct.new(:title, :lines, :image, :code)
3
3
  def initialize(*)
4
4
  super
5
5
  self.lines ||= []
@@ -1,3 +1,3 @@
1
1
  module Md2key
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/md2key.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'md2key/code'
1
2
  require 'md2key/slide'
2
3
  require 'md2key/markdown'
4
+ require 'md2key/highlight'
3
5
  require 'md2key/keynote'
4
6
  require 'md2key/converter'
5
7
  require 'md2key/cli'
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.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
@@ -121,10 +121,13 @@ files:
121
121
  - Gemfile
122
122
  - README.md
123
123
  - Rakefile
124
+ - assets/background.png
124
125
  - bin/md2key
125
126
  - lib/md2key.rb
126
127
  - lib/md2key/cli.rb
128
+ - lib/md2key/code.rb
127
129
  - lib/md2key/converter.rb
130
+ - lib/md2key/highlight.rb
128
131
  - lib/md2key/keynote.rb
129
132
  - lib/md2key/markdown.rb
130
133
  - lib/md2key/slide.rb