pppt 0.0.2 → 0.0.3

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: bc9f51b1ed7b46d7ab5f597729c1a7e5ccb98397
4
- data.tar.gz: 263d333d274808b9f39437ed588393f90524ecf8
3
+ metadata.gz: f90ebf9bce01e79f124e7a2c2d58561bf22fbaab
4
+ data.tar.gz: baa9af08d7443cb4444a5777024533a3c8d6a56a
5
5
  SHA512:
6
- metadata.gz: 398d1a04e6557876d4a9483b101a94f884e92c881da6d319ba3023ff4861990b6f8454bc3250d30f5f89c3d694249ea9b1acee3f274413698f22bd0db3c202e2
7
- data.tar.gz: 30b82ea7e50ba994078712f33506e51598912f3681eeba6ed403e116e838ac79abe36bc219c63021baea39a4b0054cfaf4360cb76ccac3e98920a3fe639f3c3a
6
+ metadata.gz: 621a0b993e1716cdd36e639652bb8940da46a10c2ad73d12612ddabdc0e8770634e374c2206e06146be2d9d1164d19fa481e1f8c1e48b133eb9d42a42701e9c0
7
+ data.tar.gz: a5cfc7ec844c9a36c536bf979c2b9fb9712ecce83a2f8d5d4a00a0d131c19c68cc73da16691e722e62752a0242b47ad0d90bf919a8bcf38cdb7e0ab22bebfdb2
data/exe/pppt CHANGED
@@ -14,7 +14,7 @@ class App < Thor
14
14
  end
15
15
 
16
16
  data = YAML.load(open(file))
17
- ::Presentation.new(data).run
17
+ ::Pppt::Presentation.new(data).run
18
18
  end
19
19
 
20
20
  desc 'init', 'create presentation template'
@@ -1,4 +1,4 @@
1
- class Helpers
1
+ class Pppt::Helpers
2
2
  def self.truncate_screen_width(str, width, suffix = '...')
3
3
  i = 0
4
4
  str.each_char.inject(0) do |c, x|
@@ -12,7 +12,7 @@ class Helpers
12
12
 
13
13
  def self.split_screen_width(str, width = 40)
14
14
  s = i = r = 0
15
- str.each_char.inject([]) do |res, c|
15
+ str.each_char.each_with_object([]) do |c, res|
16
16
  i += c.ascii_only? ? 1 : 2
17
17
  r += 1
18
18
  next res if i < width
@@ -27,4 +27,10 @@ class Helpers
27
27
  hankaku_len = str.each_char.count(&:ascii_only?)
28
28
  hankaku_len + (str.size - hankaku_len) * 2
29
29
  end
30
+
31
+ def self.format_page_number(page)
32
+ index = page['page'] || '-'
33
+ title = page['action'] || (page['title'] && " - #{page['title']}") || page['h1'] || page['h2'] || page['h3'] || (page['body'] && " #{Helpers.truncate_screen_width(page['body'].join(''), 15)}")
34
+ format('%02s %s', index, title)
35
+ end
30
36
  end
@@ -5,9 +5,9 @@ require 'pppt/presentation_pages'
5
5
  require 'pppt/presentation_window'
6
6
  include Curses
7
7
 
8
- class Presentation
8
+ class Pppt::Presentation
9
9
  def initialize(pages)
10
- @window = PresentationWindow.new(pages)
10
+ @window = Pppt::PresentationWindow.new(pages)
11
11
  @prev_ch = nil
12
12
  Curses.stdscr.keypad(true)
13
13
  Curses.noecho
@@ -1,4 +1,4 @@
1
- class PresentationPages
1
+ class Pppt::PresentationPages
2
2
  attr_reader :data, :size
3
3
  def initialize(pages)
4
4
  @data = pages
@@ -1,6 +1,6 @@
1
- class PresentationWindow
1
+ class Pppt::PresentationWindow
2
2
  def initialize(data)
3
- @pages = PresentationPages.new(data)
3
+ @pages = Pppt::PresentationPages.new(data)
4
4
  @current = 0
5
5
  @max = @pages.size
6
6
  init_screen
@@ -40,8 +40,8 @@ class PresentationWindow
40
40
  w.addstr(' ' * w.maxx)
41
41
  w.setpos(vindex, 3)
42
42
  w.standout if i == current
43
- page_string = page_to_string(page)
44
- w.addstr(page_string + (' ' * (w.maxx - Helpers.screen_width(page_string) - 4)))
43
+ page_number_string = Pppt::Helpers.format_page_number(page)
44
+ w.addstr(page_number_string + (' ' * (w.maxx - Pppt::Helpers.screen_width(page_number_string) - 4)))
45
45
  vindex += 1
46
46
  w.standend if i == current
47
47
  break if i >= start_point + height
@@ -85,17 +85,10 @@ class PresentationWindow
85
85
  w.addstr(Time.now.strftime('%H:%M:%S'))
86
86
  end
87
87
 
88
- # 目次ページでのページ番号の整形
89
- def page_to_string(page)
90
- index = page['page'] || '-'
91
- title = page['action'] || (page['title'] && " - #{page['title']}") || page['h1'] || page['h2'] || page['h3'] || (page['body'] && " #{Helpers.truncate_screen_width(page['body'].join(''), 15)}")
92
- format('%02s %s', index, title)
93
- end
94
-
95
88
  # ページコンテンツを表示する
96
89
  def write_element(w, k, v)
97
90
  len = 1
98
- len = Helpers.screen_width(v) if v.is_a? String
91
+ len = Pppt::Helpers.screen_width(v) if v.is_a? String
99
92
  width = w.maxx - 1
100
93
  pad = ' ' * ((width - len) / 2)
101
94
  case k
@@ -134,7 +127,7 @@ class PresentationWindow
134
127
  v.split("\n").each do |x|
135
128
  x.chomp!
136
129
  w.setpos((w.maxy / 2) - 2 + vindex, 0)
137
- len = Helpers.screen_width(x)
130
+ len = Pppt::Helpers.screen_width(x)
138
131
  pad = ' ' * ((width - len) / 2)
139
132
  w.addstr("#{pad}#{x}#{pad}")
140
133
  vindex += 1
@@ -152,7 +145,7 @@ class PresentationWindow
152
145
  vindex = 5
153
146
  w.setpos(vindex, 2)
154
147
  v.each do |line|
155
- vindex = render_line(w, line, vindex, 1)
148
+ vindex = render_body_text(w, line, vindex)
156
149
  end
157
150
  when 'page'
158
151
  w.setpos(w.maxy - 2, 0)
@@ -160,18 +153,18 @@ class PresentationWindow
160
153
  end
161
154
  end
162
155
 
163
- def render_line(w, lines, vindex, level)
156
+ def render_body_text(w, lines, vindex, level = 1)
164
157
  width = w.maxx - 4
165
158
  vi = vindex + 1
166
159
  if lines.is_a? Array
167
160
  lines.each do |sub_line|
168
- vi = render_line(w, sub_line, vi, level + 1)
161
+ vi = render_body_text(w, sub_line, vi, level + 1)
169
162
  end
170
163
  else
171
164
  sp = ['*', '-', '>'][level - 1]
172
165
  indent = ' ' * (level * 2)
173
166
  lines.split("\n").each do |x|
174
- Helpers.split_screen_width(x, width - (4 + 4 * level)).each do |xl|
167
+ Pppt::Helpers.split_screen_width(x, width - (4 + 4 * level)).each do |xl|
175
168
  w.setpos(vi, 2)
176
169
  w.addstr("#{indent}#{sp} #{xl}")
177
170
  sp = ' '
@@ -1,3 +1,3 @@
1
1
  module Pppt
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pppt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ma2saka