textbringer-presentation 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8fbd83312deed81be377ea000c09123de2d4167
4
+ data.tar.gz: 80fd6afd4af01c4510c36e3472a61db96b99029c
5
+ SHA512:
6
+ metadata.gz: e8212da996b2084c7705548c4b703ba68c912dd475420a376afd6335900027b72de4855f6bd9d343fa0c50d1310fedaf257041b4223d493ca91ee6ba01cce457
7
+ data.tar.gz: 7edbf87cf52e911d1f9620713a3ba8cb64fe26b06973a421394c964b6a8b7f8340fa0675662f6f5e175b05a9dc1dc27f23348f45ab5b6515e2e16138f90d68c6
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in textbringer-presentation.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Shugo Maeda
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # textbringer-presentation
2
+
3
+ Presentation mode for Textbringer.
4
+
5
+ ## Installation
6
+
7
+ $ gem install textbringer-presentation
8
+
9
+ ## Usage
10
+
11
+ 1. Write presentation slides in Markdown.
12
+ 2. Type `M-x presentation` to start the presentation.
13
+
14
+ ## Development
15
+
16
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
17
+
18
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
19
+
20
+ ## Contributing
21
+
22
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shugo/textbringer-presentation.
23
+
24
+
25
+ ## License
26
+
27
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
28
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "textbringer/presentation"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ CONFIG[:presentation_top_margin] = 1
5
+ CONFIG[:presentation_left_margin] = 2
6
+ CONFIG[:presentation_image_left_margin] = 2
7
+ CONFIG[:presentation_image_background] = "black"
8
+ CONFIG[:presentation_code_top_margin] = 1
9
+ CONFIG[:presentation_code_left_margin] = 2
10
+
11
+ if Window.has_colors?
12
+ Face.define :presentation_title, foreground: "magenta", bold: true
13
+ end
14
+
15
+ class PresentationMode < FundamentalMode
16
+ define_generic_command :forward_slide
17
+ define_generic_command :backward_slide
18
+ define_generic_command :quit_presentation
19
+ define_generic_command :show_current_slide
20
+
21
+ PRESENTATION_MODE_MAP = Keymap.new
22
+ PRESENTATION_MODE_MAP.define_key(:right, :forward_slide_command)
23
+ PRESENTATION_MODE_MAP.define_key(:left, :backward_slide_command)
24
+ PRESENTATION_MODE_MAP.define_key("q", :quit_presentation_command)
25
+ PRESENTATION_MODE_MAP.define_key("\C-l", :show_current_slide_command)
26
+
27
+ define_syntax :presentation_title, /\A\s*.+/
28
+ define_syntax :keyword, /\*\*.*?\*\*/
29
+
30
+ def initialize(buffer)
31
+ super(buffer)
32
+ buffer.keymap = PRESENTATION_MODE_MAP
33
+ show_current_slide
34
+ end
35
+
36
+ def show_current_slide
37
+ Window.delete_other_windows
38
+ Window.redraw
39
+ @buffer.read_only = false
40
+ begin
41
+ @buffer.clear
42
+ slide_list = buffer[:slide_list]
43
+ slide = slide_list.current
44
+ if slide
45
+ @buffer.insert("\n" * @buffer[:presentation_top_margin])
46
+ left_margin = " " * @buffer[:presentation_left_margin]
47
+ @buffer.insert("#{left_margin}#{slide.title}\n\n")
48
+ body = slide.body
49
+ img_re = /!\[.*?\]\((.*\.(?:jpg|png))\)/
50
+ img = body.slice(img_re, 1)
51
+ code_re = /^```([a-z]+)?\n(.*?)^```$/m
52
+ lang, code = body.scan(code_re)[0]
53
+ s = body.sub(img_re, "").sub(code_re, "").strip.
54
+ gsub(/^/, left_margin)
55
+ @buffer.insert(s)
56
+ beginning_of_buffer
57
+ if img
58
+ show_image(img, s)
59
+ end
60
+ if code
61
+ show_code(code, lang)
62
+ end
63
+ show_slide_number(slide_list)
64
+ end
65
+ ensure
66
+ @buffer.read_only = true
67
+ end
68
+ end
69
+
70
+ def forward_slide
71
+ @buffer[:slide_list].forward_slide
72
+ show_current_slide
73
+ end
74
+
75
+ def backward_slide
76
+ @buffer[:slide_list].backward_slide
77
+ show_current_slide
78
+ end
79
+
80
+ def quit_presentation
81
+ Window.delete_other_windows
82
+ buffer = Buffer["*Code*"]
83
+ if buffer
84
+ buffer.kill
85
+ end
86
+ kill_buffer(@buffer)
87
+ Window.redraw
88
+ end
89
+
90
+ private
91
+
92
+ def show_image(img, body)
93
+ Window.redisplay
94
+ wininfo = `xwininfo -id $WINDOWID`
95
+ width = wininfo.slice(/Width: (\d+)/, 1).to_i
96
+ height = wininfo.slice(/Height: (\d+)/, 1).to_i
97
+ lines = Window.lines
98
+ columns = Window.columns
99
+ y = @buffer[:presentation_top_margin] +
100
+ (/\A\s*\z/.match(body) ? 3 : body.count("\n") + 5)
101
+ left_margin = @buffer[:presentation_image_left_margin]
102
+ img_width = width * (columns - left_margin * 2) / columns
103
+ img_height = height * (lines - y - 2) / lines
104
+ STDOUT.printf("\e[%d;%dH", y, left_margin + 1)
105
+ img_size = "#{img_width}x#{img_height}"
106
+ img_bg = @buffer[:presentation_image_background]
107
+ STDOUT.print(`convert -resize #{img_size} -gravity center -background '#{img_bg}' -extent #{img_size} '#{img}' - | img2sixel`)
108
+ STDOUT.flush
109
+ end
110
+
111
+ def show_code(code, lang)
112
+ Window.current.split
113
+ Window.current.shrink_if_larger_than_buffer
114
+ Window.other_window
115
+ buffer = Buffer.find_or_new("*Code*")
116
+ buffer.clear
117
+ switch_to_buffer(buffer)
118
+ if lang
119
+ send(lang.downcase + "_mode")
120
+ else
121
+ fundamental_mode
122
+ end
123
+ insert("\n" * @buffer[:presentation_code_top_margin])
124
+ left_margin = " " * @buffer[:presentation_code_left_margin]
125
+ insert(code.gsub(/^/, left_margin))
126
+ beginning_of_buffer
127
+ Window.other_window
128
+ end
129
+
130
+ def show_slide_number(slide_list)
131
+ slide = slide_list.current
132
+ msg = "#{slide.number}/#{slide_list.size}"
133
+ message(msg, log: false)
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "presentation/version"
4
+ require_relative "presentation/slide_list"
5
+ require_relative "modes/presentation_mode"
6
+
7
+ module Textbringer
8
+ module Presentation
9
+ end
10
+
11
+ include Commands
12
+
13
+ define_command(:presentation) do
14
+ slide_list = Presentation::SlideList.new(Buffer.current.to_s)
15
+ buffer = Buffer.find_or_new("*Presentaion*", undo_limit: 0)
16
+ switch_to_buffer(buffer)
17
+ buffer[:slide_list] = slide_list
18
+ presentation_mode
19
+ end
20
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module Presentation
5
+ class Slide
6
+ attr_reader :number, :title, :body
7
+
8
+ def initialize(number, title, body)
9
+ @number = number
10
+ @title = title
11
+ @body = body
12
+ end
13
+ end
14
+
15
+ class SlideList
16
+ def initialize(s)
17
+ @list = s.scan(/^#+ *(.*?)\n(.*?)(?:(?=^#)|\z)/m).map.with_index {
18
+ |(title, body), i|
19
+ Slide.new(i + 1, title.strip, body.strip)
20
+ }
21
+ @index = 0
22
+ end
23
+
24
+ def size
25
+ @list.size
26
+ end
27
+
28
+ def current
29
+ @list[@index]
30
+ end
31
+
32
+ def forward_slide
33
+ if @index < @list.size - 1
34
+ @index += 1
35
+ end
36
+ end
37
+
38
+ def backward_slide
39
+ if @index > 0
40
+ @index -= 1
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module Presentation
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require_relative "textbringer/presentation"
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'textbringer/presentation/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "textbringer-presentation"
8
+ spec.version = Textbringer::Presentation::VERSION
9
+ spec.authors = ["Shugo Maeda"]
10
+ spec.email = ["shugo@ruby-lang.org"]
11
+
12
+ spec.summary = "Presentation mode for Textbringer."
13
+ spec.description = "Presentation mode for Textbringer."
14
+ spec.homepage = "https://github.com/shugo/textbringer"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "textbringer"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 12.0"
28
+ spec.add_development_dependency "test-unit"
29
+ spec.add_development_dependency "simplecov"
30
+ spec.add_development_dependency "codecov"
31
+ spec.add_development_dependency "bundler-audit"
32
+ spec.add_development_dependency "guard"
33
+ spec.add_development_dependency "guard-shell"
34
+ spec.add_development_dependency "ripper-tags"
35
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: textbringer-presentation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shugo Maeda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: textbringer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
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: simplecov
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: codecov
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: bundler-audit
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: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-shell
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: ripper-tags
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Presentation mode for Textbringer.
154
+ email:
155
+ - shugo@ruby-lang.org
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - Gemfile
162
+ - LICENSE.txt
163
+ - README.md
164
+ - Rakefile
165
+ - bin/console
166
+ - bin/setup
167
+ - lib/textbringer/modes/presentation_mode.rb
168
+ - lib/textbringer/presentation.rb
169
+ - lib/textbringer/presentation/slide_list.rb
170
+ - lib/textbringer/presentation/version.rb
171
+ - lib/textbringer_plugin.rb
172
+ - textbringer-presentation.gemspec
173
+ homepage: https://github.com/shugo/textbringer
174
+ licenses:
175
+ - MIT
176
+ metadata: {}
177
+ post_install_message:
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubyforge_project:
193
+ rubygems_version: 2.6.10
194
+ signing_key:
195
+ specification_version: 4
196
+ summary: Presentation mode for Textbringer.
197
+ test_files: []
198
+ has_rdoc: