wee-pm 0.1

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,204 @@
1
+ require 'rdoc/markup/simple_markup'
2
+ require 'rdoc/markup/simple_markup/to_html'
3
+
4
+ class ExtendedHtml < SM::ToHtml
5
+ # We're invoked with a potential external hyperlink.
6
+ # [mailto:] just gets inserted.
7
+ # [http:] links are checked to see if they
8
+ # reference an image. If so, that image gets inserted
9
+ # using an <img> tag. Otherwise a conventional <a href>
10
+ # is used.
11
+
12
+ attr_accessor :block_processor
13
+
14
+ def handle_special_HYPERLINK(special)
15
+ url = special.text
16
+ if url =~ /([A-Za-z]+):(.*)/
17
+ type = $1
18
+ path = $2
19
+ else
20
+ # www.
21
+ type = "http"
22
+ path = url
23
+ url = "http://#{url}"
24
+ end
25
+
26
+ img_attrs = {}
27
+ if type == "http" && url =~ /\.(gif|png|jpg|jpeg|bmp)((;.*)?)$/ #((;\w+[=][^;]*)*)
28
+ if $2.nil? or $2.empty?
29
+ attr_size = 0
30
+ else
31
+ attr_size = $~.offset(2)[1] - $~.offset(2)[0]
32
+ m = $2.to_s[1..-1]
33
+ m.split(";").each {|a|
34
+ k, v = a.split("=", 2)
35
+ img_attrs[k] = v
36
+ }
37
+ end
38
+
39
+ s = img_attrs.keys.grep(/^\d+x\d+$/)
40
+ width, height = s.first.split("x", 2) if s.size == 1
41
+ width = img_attrs['w'] || img_attrs['width'] || width
42
+ height = img_attrs['h'] || img_attrs['height'] || height
43
+
44
+ attrs = ""
45
+ attrs << 'width="' + width + '" ' if width
46
+ attrs << 'height="' + height + '" ' if height
47
+ attrs << 'style="float: left;padding-right: 40px;" ' if img_attrs['floating'] == 'left'
48
+
49
+ src =
50
+ if path[0,2] == "./"
51
+ path[2..(-1-attr_size)]
52
+ elsif path[0,2] == "//"
53
+ "http:" + path[0..(-1-attr_size)]
54
+ else
55
+ "http://" + path[0..(-1-attr_size)]
56
+ end
57
+ %{<a href="#{src}"><img src="#{src}" #{ attrs } border="0"></a>}
58
+ else
59
+ "<a href=\"#{url}\">#{url.sub(%r{^\w+:/*}, '')}</a>"
60
+ end
61
+ end
62
+
63
+ def handle_special_RUBYTALK(special)
64
+ if special.text =~ /^ruby-talk:(\d+)$/
65
+ num = $1.to_i
66
+ %(<a href="http://rubytalk.com/cgi-bin/scat.rb/ruby/ruby-talk/#{ num }">ruby-talk:#{ num }</a>)
67
+ else
68
+ raise
69
+ end
70
+ end
71
+
72
+ # Here's a hypedlink where the label is different to the URL
73
+ # <label>[url]
74
+ #
75
+
76
+ def handle_special_TIDYLINK(special)
77
+ text = special.text
78
+ unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
79
+ return text
80
+ end
81
+ label = $1
82
+ url = $2
83
+
84
+ if url !~ /\w+?:/
85
+ if url =~ /\./
86
+ url = "http://#{url}"
87
+ #else
88
+ #return find_wiki_word(url, label)
89
+ end
90
+ end
91
+
92
+ "<a href=\"#{url}\">#{label}</a>"
93
+ end
94
+
95
+ def accept_verbatim(am, fragment)
96
+ lines = fragment.txt.split("\n")
97
+
98
+ # remove leading whitespace
99
+ margin = if lines.first =~ /^(\s+)/ then $1.size else 0 end
100
+ if lines.all? {|l| l[0, margin].strip.empty? }
101
+ lines.map!{|l| l[margin..-1]}
102
+ end
103
+
104
+ first_line = lines.first.strip
105
+
106
+ case first_line
107
+ when /^\!\!([^:]*)(:(.*))?$/
108
+ processor, option = $1, $3
109
+ @res << @block_processor.call(processor, option, lines[1..-1].join("\n"))
110
+ else
111
+ @res << annotate("<pre>")
112
+ output = CGI.escapeHTML(lines.join("\n"))
113
+
114
+ # strip whitespaces on the right
115
+ if pos = (output =~ /\s*\z/)
116
+ output = output[0,pos]
117
+ end
118
+
119
+ @res << output
120
+ @res << annotate("</pre>") << "\n"
121
+ end
122
+ end
123
+
124
+ end
125
+
126
+ class ExtendedMarkup < SM::SimpleMarkup
127
+ def initialize
128
+ super
129
+ # and links of the form <text>[<url>] or {text with spaces}[<url>]
130
+ add_special(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
131
+
132
+ # and external references
133
+ add_special(/((link:|http:|mailto:|ftp:|www\.)\S+\w\/?)/, :HYPERLINK)
134
+
135
+ add_special(/(ruby-talk:\d+)/, :RUBYTALK)
136
+ end
137
+ end
138
+
139
+ class SlidesHtml < ExtendedHtml
140
+ attr_accessor :show_number_of_overlays
141
+ attr_accessor :count
142
+
143
+ def start_accepting
144
+ super
145
+ @overlays_shown = 0
146
+ @nesting = 0
147
+ @done = false
148
+ end
149
+
150
+ def end_accepting
151
+ if @count
152
+ @overlays_shown
153
+ else
154
+ super
155
+ end
156
+ end
157
+
158
+ def accept_paragraph(am, fragment)
159
+ return if @done; overlay_added
160
+ return if @count
161
+ super
162
+ end
163
+
164
+ def accept_verbatim(am, fragment)
165
+ return if @done; overlay_added
166
+ return if @count
167
+ super
168
+ end
169
+
170
+ def accept_rule(am, fragment)
171
+ return if @done; overlay_added
172
+ super
173
+ end
174
+
175
+ def accept_list_start(am, fragment)
176
+ return if @done; @nesting += 1
177
+ super
178
+ end
179
+
180
+ def accept_list_end(am, fragment)
181
+ return if @done and @nesting == 0; @nesting -= 1
182
+ super
183
+ end
184
+
185
+ def accept_list_item(am, fragment)
186
+ return if @done; overlay_added
187
+ super
188
+ end
189
+
190
+ def accept_heading(am, fragment)
191
+ return if @done; overlay_added
192
+ super
193
+ end
194
+
195
+ private
196
+
197
+ def overlay_added
198
+ @overlays_shown += 1
199
+ return if @show_number_of_overlays.nil?
200
+ @done = true if @overlays_shown >= @show_number_of_overlays
201
+ end
202
+ end
203
+
204
+ class SlidesMarkup < ExtendedMarkup; end
@@ -0,0 +1,40 @@
1
+ require 'enumerator'
2
+
3
+ def remove_leading_and_trailing_empty_lines(str)
4
+ remove_trailing_empty_lines(remove_leading_empty_lines(str))
5
+ end
6
+
7
+ def remove_trailing_empty_lines(str)
8
+ str = str.chomp + "\n"
9
+ str = remove_leading_empty_lines(str.to_enum(:each_line).to_a.reverse.join(""))
10
+ str.to_enum(:each_line).to_a.reverse.join("")
11
+ end
12
+
13
+ def remove_leading_empty_lines(str)
14
+ first_non_empty_line_seen = false
15
+ res = ""
16
+ str.each_line {|l|
17
+ if first_non_empty_line_seen
18
+ res << l
19
+ else
20
+ unless l.strip.empty?
21
+ first_non_empty_line_seen = true
22
+ res << l
23
+ end
24
+ end
25
+ }
26
+ res
27
+ end
28
+
29
+ if __FILE__ == $0
30
+ require 'test/unit'
31
+
32
+ class TC < Test::Unit::TestCase
33
+ def test_leading_trailing
34
+ str = " \n \n test \n \n"
35
+ r = remove_leading_and_trailing_empty_lines(str)
36
+ assert_equal " test \n", r
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = "wee-pm"
5
+ s.version = "0.1"
6
+ s.summary = "A web-based presentation maker and viewer using Wee"
7
+ s.files = Dir['**/*']
8
+ s.bindir = 'bin'
9
+ s.executables = ['wee-pm', 'wee-pm-pdf']
10
+ s.default_executable = 'wee-pm'
11
+ s.add_dependency('wee', '>= 0.10.0')
12
+ s.requirements << 'vim (for colorizing source code)'
13
+ s.requirements << 'html2ps (for creating Postscript output)'
14
+ s.requirements << 'ps2pdf (for creating PDF output)'
15
+
16
+ s.author = "Michael Neumann"
17
+ s.email = "mneumann@ntecs.de"
18
+ s.homepage = "http://rubyforge.org/projects/wee"
19
+ s.rubyforge_project = "wee"
20
+ end
21
+
22
+ if __FILE__ == $0
23
+ Gem::manage_gems
24
+ Gem::Builder.new(spec).build
25
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: wee-pm
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.1"
7
+ date: 2007-09-01 00:00:00 +02:00
8
+ summary: A web-based presentation maker and viewer using Wee
9
+ require_paths:
10
+ - lib
11
+ email: mneumann@ntecs.de
12
+ homepage: http://rubyforge.org/projects/wee
13
+ rubyforge_project: wee
14
+ description:
15
+ autorequire:
16
+ default_executable: wee-pm
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Michael Neumann
31
+ files:
32
+ - README
33
+ - bin
34
+ - bin/wee-pm
35
+ - bin/wee-pm-pdf
36
+ - TODO
37
+ - wee-pm.gemspec
38
+ - lib
39
+ - lib/wee-pm
40
+ - lib/wee-pm/slideshtml.rb
41
+ - lib/wee-pm/utils.rb
42
+ - lib/wee-pm/colorize_filter.rb
43
+ - lib/wee-pm/converter.rb
44
+ - lib/wee-pm/presentation.rb
45
+ - lib/wee-pm/presentation_maker.rb
46
+ - lib/wee-pm/colorize.rb
47
+ test_files: []
48
+
49
+ rdoc_options: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ executables:
54
+ - wee-pm
55
+ - wee-pm-pdf
56
+ extensions: []
57
+
58
+ requirements:
59
+ - vim (for colorizing source code)
60
+ - html2ps (for creating Postscript output)
61
+ - ps2pdf (for creating PDF output)
62
+ dependencies:
63
+ - !ruby/object:Gem::Dependency
64
+ name: wee
65
+ version_requirement:
66
+ version_requirements: !ruby/object:Gem::Version::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 0.10.0
71
+ version: