rabbit 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/doc/_layouts/skeleton.html +1 -0
  3. data/doc/css/rabbit.css +2 -1
  4. data/doc/css/syntax.scss +67 -0
  5. data/doc/en/development.rd +31 -0
  6. data/doc/en/index.rd +0 -4
  7. data/doc/en/news.rd +55 -0
  8. data/doc/en/sample/markdown/rabbit.md +250 -246
  9. data/doc/en/usage/rabbit.rd +16 -0
  10. data/doc/ja/development.rd +30 -0
  11. data/doc/ja/index.rd +0 -5
  12. data/doc/ja/news.rd +55 -0
  13. data/doc/ja/sample/markdown/rabbit.md +251 -247
  14. data/doc/ja/usage/rabbit.rd +16 -1
  15. data/lib/rabbit/command/rabbit.rb +5 -1
  16. data/lib/rabbit/element/index-slide.rb +1 -1
  17. data/lib/rabbit/element/text-renderer.rb +7 -7
  18. data/lib/rabbit/gtk.rb +17 -10
  19. data/lib/rabbit/image/svg.rb +25 -23
  20. data/lib/rabbit/info-window.rb +1 -0
  21. data/lib/rabbit/parser/ext/rouge.rb +126 -0
  22. data/lib/rabbit/parser/markdown/converter.rb +4 -4
  23. data/lib/rabbit/parser/rd/ext/block-verbatim.rb +13 -1
  24. data/lib/rabbit/parser/rd/rt/rt2rabbit-lib.rb +3 -3
  25. data/lib/rabbit/parser/wiki/output.rb +9 -3
  26. data/lib/rabbit/progress.rb +16 -8
  27. data/lib/rabbit/renderer/display/drawing-area-base.rb +8 -8
  28. data/lib/rabbit/renderer/display/drawing-area-primitive.rb +3 -3
  29. data/lib/rabbit/renderer/display/graffiti.rb +39 -39
  30. data/lib/rabbit/renderer/display/progress.rb +3 -2
  31. data/lib/rabbit/renderer/display/search.rb +1 -1
  32. data/lib/rabbit/renderer/kernel.rb +1 -1
  33. data/lib/rabbit/search-window.rb +2 -2
  34. data/lib/rabbit/source/memory.rb +4 -0
  35. data/lib/rabbit/theme/background-image-toolkit/background-image-toolkit.rb +1 -1
  36. data/lib/rabbit/theme/color-circle-title-slide/color-circle-title-slide.rb +1 -1
  37. data/lib/rabbit/theme/default-block-quote/default-block-quote.rb +1 -1
  38. data/lib/rabbit/theme/image-slide-number/image-slide-number.rb +13 -2
  39. data/lib/rabbit/theme/lightning-talk-toolkit/lightning-talk-toolkit.rb +2 -2
  40. data/lib/rabbit/theme/slide-number/slide-number.rb +1 -1
  41. data/lib/rabbit/theme/syntax-highlighting/syntax-highlighting.rb +3 -0
  42. data/lib/rabbit/theme/table/table.rb +1 -1
  43. data/lib/rabbit/theme/title-on-image-toolkit/title-on-image-toolkit.rb +1 -1
  44. data/lib/rabbit/utils.rb +1 -1
  45. data/lib/rabbit/version.rb +2 -2
  46. data/po/en/rabbit.edit.po +107 -107
  47. data/po/fr/rabbit.edit.po +107 -107
  48. data/po/ja/rabbit.edit.po +107 -107
  49. data/rabbit.gemspec +3 -2
  50. data/sample/rabbit-en.rd +12 -0
  51. data/sample/rabbit.rd +12 -0
  52. data/test/parser/test-markdown.rb +9 -57
  53. metadata +20 -4
@@ -15,7 +15,22 @@ Rabbitはコマンドラインから起動する方法とコマンドランチ
15
15
 
16
16
  % rabbit XXX.rd
17
17
 
18
- 例えば、sample/rabbit-implementation.rdを使うには、トップの
18
+ 例えば、XXX.rd の内容はこのようになっています。
19
+
20
+ = タイトル
21
+
22
+ :author
23
+ 発表者名
24
+
25
+ = 1ページ目
26
+
27
+ ここは内容
28
+
29
+ = 2ページ目
30
+
31
+ おしまい
32
+
33
+ sample/rabbit-implementation.rdを使うには、トップの
19
34
  ディレクトリで以下のようにします。
20
35
 
21
36
  % rabbit sample/rabbit-implementation.rd
@@ -64,7 +64,11 @@ module Rabbit
64
64
  @logger.error($!)
65
65
  end
66
66
  end
67
- application.run.zero?
67
+ exit_code = application.run
68
+ application.windows.each(&:destroy)
69
+ application.unref
70
+
71
+ exit_code.zero?
68
72
  end
69
73
 
70
74
  private
@@ -154,7 +154,7 @@ module Rabbit
154
154
  text = %Q[<span size="#{text_size}">#{text}</span>]
155
155
  @layout, _, _ = canvas.make_layout(text)
156
156
  @layout.set_width(width * Pango::SCALE)
157
- @layout.set_alignment(Pango::Layout::ALIGN_CENTER)
157
+ @layout.set_alignment(Pango::Alignment::CENTER)
158
158
  end
159
159
  canvas.draw_pixbuf(@pixbuf, x, y)
160
160
  canvas.draw_rectangle(false, x, y, width, height)
@@ -22,7 +22,7 @@ module Rabbit
22
22
 
23
23
  def align=(new_value)
24
24
  if new_value.is_a?(String)
25
- new_value = Pango::Layout.const_get("ALIGN_#{new_value.to_s.upcase}")
25
+ new_value = Pango::Alignment.const_get(new_value.to_s.upcase)
26
26
  end
27
27
  dirty! if @align != new_value
28
28
  @align = new_value
@@ -78,11 +78,11 @@ module Rabbit
78
78
  end
79
79
 
80
80
  def do_horizontal_centering(canvas, x, y, w, h)
81
- self.align = Pango::Layout::ALIGN_CENTER
81
+ self.align = Pango::Alignment::CENTER
82
82
  end
83
83
 
84
84
  def reset_horizontal_centering(canvas, x, y, w, h)
85
- self.align = default_align if @align == Pango::Layout::ALIGN_CENTER
85
+ self.align = default_align if @align == Pango::Alignment::CENTER
86
86
  end
87
87
 
88
88
  def markuped_text
@@ -197,8 +197,8 @@ module Rabbit
197
197
  setup_layout(layout, w)
198
198
  width, height = layout.pixel_size
199
199
  if layout.width != -1 and
200
- (layout.alignment == Pango::Layout::ALIGN_CENTER or
201
- layout.alignment == Pango::Layout::ALIGN_RIGHT)
200
+ (layout.alignment == Pango::Alignment::CENTER or
201
+ layout.alignment == Pango::Alignment::RIGHT)
202
202
  width = layout.width / Pango::SCALE
203
203
  end
204
204
  @width, @height = width, height
@@ -242,11 +242,11 @@ module Rabbit
242
242
  end
243
243
 
244
244
  def default_wrap_mode
245
- Pango::Layout::WRAP_WORD_CHAR
245
+ Pango::WrapMode::WORD_CHAR
246
246
  end
247
247
 
248
248
  def default_align
249
- Pango::Layout::ALIGN_LEFT
249
+ Pango::Alignment::LEFT
250
250
  end
251
251
 
252
252
  def default_justify
@@ -37,6 +37,16 @@ module Cairo
37
37
  end
38
38
  end
39
39
 
40
+ module Pango
41
+ unless const_defined?(:WrapMode)
42
+ WrapMode = Layout::WrapMode
43
+ end
44
+
45
+ unless const_defined?(:Alignment)
46
+ Alignment = Layout::Alignment
47
+ end
48
+ end
49
+
40
50
  module Gdk
41
51
  class Event
42
52
  STOP = true unless const_defined?(:STOP)
@@ -104,33 +114,30 @@ module Gtk
104
114
 
105
115
  unless const_defined?(:Application)
106
116
  class Application < Gio::Application
117
+ attr_reader :windows
107
118
  def initialize(id, flags)
108
119
  super
109
120
  signal_connect_after("activate") do
110
- Gtk.main if ApplicationWindow.n_instances > 0
121
+ Gtk.main unless @windows.empty?
111
122
  end
123
+ @windows = []
112
124
  end
113
125
  end
114
126
  end
115
127
 
116
128
  unless const_defined?(:ApplicationWindow)
117
129
  class ApplicationWindow
118
- @@n_instances = 0
119
-
120
130
  class << self
121
131
  def new(application)
122
132
  window = Window.new
123
- @@n_instances += 1
133
+ application.windows << window
124
134
  window.signal_connect("destroy") do
125
- @@n_instances -= 1
126
- Gtk.main_quit if @@n_instances.zero?
135
+ windows = application.windows
136
+ windows.delete(window)
137
+ Gtk.main_quit if windows.empty?
127
138
  end
128
139
  window
129
140
  end
130
-
131
- def n_instances
132
- @@n_instances
133
- end
134
141
  end
135
142
  end
136
143
  end
@@ -1,10 +1,29 @@
1
+ # Copyright (C) 2004-2017 Kouhei Sutou <kou@cozmixng.org>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "rsvg2"
2
18
 
3
19
  require "rabbit/image/base"
4
20
 
21
+ unless Object.const_defined?(:Rsvg)
22
+ Rsvg = RSVG
23
+ end
24
+
5
25
  module Rabbit
6
26
  module ImageManipulable
7
-
8
27
  class SVG < Base
9
28
 
10
29
  unshift_loader(self)
@@ -34,23 +53,16 @@ module Rabbit
34
53
  end
35
54
 
36
55
  def pixbuf
37
- @pixbuf ||= to_pixbuf(width, height)
56
+ @handle.pixbuf
38
57
  end
39
58
 
40
59
  private
41
60
  def update_size
42
- @handle = nil
43
61
  rsvg_environment do |name|
44
- if RSVG::Handle.respond_to?(:new_from_file)
45
- @handle = RSVG::Handle.new_from_file(name)
46
- dim = @handle.dimensions
47
- @width = dim.width
48
- @height = dim.height
49
- else
50
- @pixbuf = RSVG.pixbuf_from_file(name)
51
- @width = @pixbuf.width
52
- @height = @pixbuf.height
53
- end
62
+ @handle = Rsvg::Handle.new(:path => name)
63
+ dim = @handle.dimensions
64
+ @width = dim.width
65
+ @height = dim.height
54
66
  end
55
67
  end
56
68
 
@@ -65,16 +77,6 @@ module Rabbit
65
77
  yield(name)
66
78
  end
67
79
  end
68
-
69
- def to_pixbuf(w=nil, h=nil)
70
- rsvg_environment do |name|
71
- if w or h
72
- RSVG.pixbuf_from_file_at_size(name, w || width, h || height)
73
- else
74
- RSVG.pixbuf_from_file(name)
75
- end
76
- end
77
- end
78
80
  end
79
81
  end
80
82
  end
@@ -301,6 +301,7 @@ module Rabbit
301
301
  @canvas.source_force_modified(true) do |original_source|
302
302
  source.source = original_source.read
303
303
  source.base = original_source.base
304
+ source.extension = original_source.extension
304
305
  end
305
306
  canvas.parse(source)
306
307
  end
@@ -0,0 +1,126 @@
1
+ # Copyright (C) 2017 Kouhei Sutou <kou@cozmixng.org>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
17
+ require "rouge"
18
+
19
+ require "rabbit/utils"
20
+ require "rabbit/parser/ext/escape"
21
+
22
+ module Rabbit
23
+ module Parser
24
+ module Ext
25
+ module Rouge
26
+ include GetText
27
+
28
+ module_function
29
+ def highlight(lang, text, logger)
30
+ lexer = ::Rouge::Lexer.find(lang).new
31
+ formatter = RabbitFormatter.new
32
+ block = Element::SyntaxHighlightingBlock.new
33
+ text_container = Element::TextContainer.new
34
+ formatter.format(lexer.lex(text.strip)) do |element|
35
+ text_container << element
36
+ end
37
+ block << text_container
38
+ block
39
+ end
40
+
41
+ class RabbitFormatter < ::Rouge::Formatter
42
+ tag "rabbit"
43
+
44
+ include Element
45
+
46
+ def stream(tokens)
47
+ tokens.each do |token, value|
48
+ escaped_text = Escape.escape_meta_character(value)
49
+ text_element = SyntaxHighlightingText.new(Text.new(escaped_text))
50
+ tag_name = compute_tag_name(token)
51
+ if Utils.syntax_highlighting_debug?
52
+ p [tag_name, token.qualname, value]
53
+ end
54
+ yield(CustomTag.new("syntax-#{tag_name}", text_element))
55
+ end
56
+ end
57
+
58
+ private
59
+ def compute_tag_name(token)
60
+ group = token.token_chain.first.name
61
+ case group
62
+ when :Keyword
63
+ case token.name
64
+ when :Constant
65
+ tag_namenize(token.name)
66
+ else
67
+ tag_namenize(group)
68
+ end
69
+ when :Name
70
+ case token.name
71
+ when :Namespace
72
+ "include"
73
+ else
74
+ case token.parent.name
75
+ when :Variable
76
+ "#{tag_namenize(token.name)}_variable"
77
+ else
78
+ tag_namenize(token.name)
79
+ end
80
+ end
81
+ when :Literal
82
+ if match_token?("Literal.String", token)
83
+ case token.name
84
+ when :Symbol
85
+ tag_namenize(token.name)
86
+ else
87
+ "string"
88
+ end
89
+ elsif match_token?("Literal.Number", token)
90
+ if match_token?("Literal.Number.Float", token)
91
+ "float"
92
+ elsif match_token?("Literal.Number.Integer", token)
93
+ "integer"
94
+ else
95
+ tag_namenize(token.name)
96
+ end
97
+ else
98
+ tag_namenize(token.name)
99
+ end
100
+ when :Generic
101
+ tag_name = tag_namenize(token.name)
102
+ case tag_name
103
+ when "deleted"
104
+ "delete"
105
+ when "inserted"
106
+ "insert"
107
+ else
108
+ tag_name
109
+ end
110
+ else
111
+ tag_namenize(group)
112
+ end
113
+ end
114
+
115
+ def tag_namenize(name)
116
+ name.to_s.downcase
117
+ end
118
+
119
+ def match_token?(name, token)
120
+ ::Rouge::Token[name].matches?(token)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012-2016 Kouhei Sutou <kou@cozmixng.org>
1
+ # Copyright (C) 2012-2017 Kouhei Sutou <kou@cozmixng.org>
2
2
  #
3
3
  # This program is free software; you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -19,10 +19,10 @@ require "English"
19
19
  require "rabbit/gettext"
20
20
  require "rabbit/parser/pause-support"
21
21
  require "rabbit/parser/ext/blockdiag"
22
- require "rabbit/parser/ext/coderay"
23
22
  require "rabbit/parser/ext/escape"
24
23
  require "rabbit/parser/ext/inline"
25
24
  require "rabbit/parser/ext/image"
25
+ require "rabbit/parser/ext/rouge"
26
26
  require "rabbit/parser/ext/tex"
27
27
 
28
28
  module Rabbit
@@ -282,7 +282,7 @@ module Rabbit
282
282
  if @in_table_header
283
283
  header = TableHeader.new(convert_container(element))
284
284
  def header.default_align
285
- Pango::Layout::ALIGN_CENTER
285
+ Pango::Alignment::CENTER
286
286
  end
287
287
  header
288
288
  else
@@ -334,7 +334,7 @@ module Rabbit
334
334
  end
335
335
  else
336
336
  logger = @canvas.logger
337
- Ext::CodeRay.highlight(language, content, logger)
337
+ Ext::Rouge.highlight(language, content, logger)
338
338
  end
339
339
  end
340
340
 
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2004-2015 Kouhei Sutou <kou@cozmixng.org>
1
+ # Copyright (C) 2004-2017 Kouhei Sutou <kou@cozmixng.org>
2
2
  #
3
3
  # This program is free software; you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@ require "rabbit/parser/ext/aafigure"
28
28
  require "rabbit/parser/ext/blockdiag"
29
29
  require "rabbit/parser/ext/coderay"
30
30
  require "rabbit/parser/ext/emacs"
31
+ require "rabbit/parser/ext/rouge"
31
32
 
32
33
  module Rabbit
33
34
  module Parser
@@ -189,6 +190,17 @@ module Rabbit
189
190
  text = Text.new(src)
190
191
  PreformattedBlock.new(PreformattedText.new(text))
191
192
  end
193
+
194
+ def ext_block_verb_rouge(label, source, content, visitor)
195
+ return nil unless /\Arouge (\w+)\z/i =~ label
196
+ lang = $1.downcase.untaint
197
+
198
+ src, prop = parse_source(source)
199
+ logger = visitor.logger
200
+
201
+ result = Parser::Ext::Rouge.highlight(lang, src, logger)
202
+ result || default_ext_block_verbatim(label, src, src, visitor)
203
+ end
192
204
  end
193
205
  end
194
206
  end
@@ -71,15 +71,15 @@ module Rabbit
71
71
  case align
72
72
  when :center
73
73
  def target.default_align
74
- Pango::Layout::ALIGN_CENTER
74
+ Pango::Alignment::CENTER
75
75
  end
76
76
  when :right
77
77
  def target.default_align
78
- Pango::Layout::ALIGN_RIGHT
78
+ Pango::Alignment::RIGHT
79
79
  end
80
80
  else
81
81
  def target.default_align
82
- Pango::Layout::ALIGN_LEFT
82
+ Pango::Alignment::LEFT
83
83
  end
84
84
  end
85
85
  target.align = target.default_align