rdialog 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.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ +++ 0.1.0 2007-04-27
2
+
3
+ + 1 major enhancement:
4
+ + Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,15 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/rdialog.rb
6
+ lib/rdialog/version.rb
7
+ scripts/txt2html
8
+ setup.rb
9
+ test/test_helper.rb
10
+ test/test_rdialog.rb
11
+ website/index.html
12
+ website/index.txt
13
+ website/javascripts/rounded_corners_lite.inc.js
14
+ website/stylesheets/screen.css
15
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,3 @@
1
+ README for rdialog
2
+ ==================
3
+
data/Rakefile ADDED
@@ -0,0 +1,89 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+ include FileUtils
12
+ require File.join(File.dirname(__FILE__), 'lib', 'rdialog', 'version')
13
+
14
+ AUTHOR = 'Aleks Clarks' # can also be an array of Authors
15
+ EMAIL = "aleks.clark@gmail.com"
16
+ DESCRIPTION = "A gem providing a ruby interface to the n-curses dialog generator dialog"
17
+ GEM_NAME = 'rdialog' # what ppl will type to install your gem
18
+ RUBYFORGE_PROJECT = 'rdialog' # The unix name for your project
19
+ HOMEPATH = "http://rdialog.rubyforge.org"
20
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
21
+
22
+ NAME = "rdialog"
23
+ REV = "" # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
24
+ VERS = Rdialog::VERSION::STRING
25
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
26
+ RDOC_OPTS = ['--quiet', '--title', 'rdialog documentation',
27
+ "--opname", "index.html",
28
+ "--line-numbers",
29
+ "--main", "README",
30
+ "--inline-source"]
31
+
32
+ class Hoe
33
+ def extra_deps
34
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
35
+ end
36
+ end
37
+
38
+ # Generate all the Rake tasks
39
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
40
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
41
+ p.author = AUTHOR
42
+ p.description = DESCRIPTION
43
+ p.email = EMAIL
44
+ p.summary = DESCRIPTION
45
+ p.url = HOMEPATH
46
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
47
+ p.test_globs = ["test/**/test_*.rb"]
48
+ p.clean_globs = CLEAN #An array of file patterns to delete on clean.
49
+
50
+ # == Optional
51
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
52
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
53
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
54
+ end
55
+
56
+
57
+ desc 'Generate website files'
58
+ task :website_generate do
59
+ Dir['website/**/*.txt'].each do |txt|
60
+ sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
61
+ end
62
+ end
63
+
64
+ desc 'Upload website files to rubyforge'
65
+ task :website_upload do
66
+ config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
67
+ host = "#{config["username"]}@rubyforge.org"
68
+ remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
69
+ # remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ local_dir = 'website'
71
+ sh %{rsync -av #{local_dir}/ #{host}:#{remote_dir}}
72
+ end
73
+
74
+ desc 'Generate and upload website files'
75
+ task :website => [:website_generate, :website_upload]
76
+
77
+ desc 'Release the website and new gem version'
78
+ task :deploy => [:check_version, :website, :release]
79
+
80
+ task :check_version do
81
+ unless ENV['VERSION']
82
+ puts 'Must pass a VERSION=x.y.z release version'
83
+ exit
84
+ end
85
+ unless ENV['VERSION'] == VERS
86
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
87
+ exit
88
+ end
89
+ end
@@ -0,0 +1,9 @@
1
+ module Rdialog #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/rdialog.rb ADDED
@@ -0,0 +1,297 @@
1
+
2
+ # vim:ts=4:sw=4:
3
+ # = rdialog - A dialog gem for Ruby
4
+ #
5
+ # Homepage:: http://built-it.net/ruby/rdialog/
6
+ # Author:: Aleks Clark (http://built-it.net)
7
+ # Copyright:: (cc) 2004 Aleks Clark
8
+ # License:: BSD
9
+ #
10
+ # class RDialog::Dialog.new( array, str, array)
11
+
12
+ require 'tempfile'
13
+ require 'date'
14
+ class RDialog
15
+ #
16
+ # All accessors are boolean unless otherwise noted.
17
+ #
18
+
19
+ #
20
+ # This gives you some control over the box dimensions when
21
+ # using auto sizing (specifying 0 for height and width).
22
+ # It represents width / height. The default is 9,
23
+ # which means 9 characters wide to every 1 line high.
24
+ #
25
+ attr_accessor :aspect
26
+
27
+ #
28
+ # Specifies a backtitle string to be displayed on the backdrop,
29
+ # at the top of the screen.
30
+ #
31
+ attr_accessor :backtitle
32
+
33
+ #
34
+ # Sound the audible alarm each time the screen is refreshed.
35
+ #
36
+ attr_accessor :beep
37
+
38
+ #
39
+ # Specify the position of the upper left corner of a dialog box
40
+ # on the screen, as an array containing two integers.
41
+ #
42
+ attr_accessor :begin
43
+
44
+ #
45
+ # Interpret embedded newlines in the dialog text as a newline
46
+ # on the screen. Otherwise, dialog will only wrap lines where
47
+ # needed to fit inside the text box. Even though you can control
48
+ # line breaks with this, dialog will still wrap any lines that are
49
+ # too long for the width of the box. Without cr-wrap, the layout
50
+ # of your text may be formatted to look nice in the source code of
51
+ # your script without affecting the way it will look in the dialog.
52
+ #
53
+ attr_accessor :crwrap
54
+
55
+ #
56
+ # Interpret the tags data for checklist, radiolist and menuboxes
57
+ # adding a column which is displayed in the bottom line of the
58
+ # screen, for the currently selected item.
59
+ #
60
+ attr_accessor :itemhelp
61
+
62
+ #
63
+ # Suppress the "Cancel" button in checklist, inputbox and menubox
64
+ # modes. A script can still test if the user pressed the ESC key to
65
+ # cancel to quit.
66
+ #
67
+ attr_accessor :nocancel
68
+
69
+ #
70
+ # Draw a shadow to the right and bottom of each dialog box.
71
+ #
72
+ attr_accessor :shadow
73
+
74
+ #
75
+ # Sleep (delay) for the given integer of seconds after processing
76
+ # a dialog box.
77
+ #
78
+ attr_accessor :sleep
79
+
80
+ #
81
+ # Convert each tab character to one or more spaces.
82
+ # Otherwise, tabs are rendered according to the curses library's
83
+ # interpretation.
84
+ #
85
+ attr_accessor :tabcorrect
86
+
87
+ #
88
+ # Specify the number(int) of spaces that a tab character occupies
89
+ # if the tabcorrect option is set true. The default is 8.
90
+ #
91
+ attr_accessor :tablen
92
+
93
+ #
94
+ # Title string to be displayed at the top of the dialog box.
95
+ #
96
+ attr_accessor :title
97
+
98
+ #
99
+ # Alternate path to dialog. If this is not set, environment path
100
+ # is used.
101
+ attr_accessor :path_to_dialog
102
+
103
+ # TODO
104
+ #print maxsize method
105
+ #print size method
106
+ #print version method
107
+
108
+
109
+ def initialize()
110
+ end
111
+
112
+ def calendar(text="Select a Date", height=2, width=2, day=Date.today.mday(), month=Date.today.mon(), year=Date.today.year())
113
+
114
+ tmp = Tempfile.new('tmp')
115
+
116
+ command = option_string() + "--calendar \"" + text.to_s +
117
+ "\" " + height.to_i.to_s + " " + width.to_i.to_s + " " +
118
+ day.to_i.to_s + " " + month.to_i.to_s + " " + year.to_i.to_s +
119
+ " 2> " + tmp.path
120
+ success = system(command)
121
+ if success
122
+ date = Date::civil(*tmp.readline.split('/').collect {|i| i.to_i}.reverse)
123
+ tmp.close!
124
+ return date
125
+ else
126
+ tmp.close!
127
+ return success
128
+ end
129
+
130
+ end
131
+
132
+ def checklist(text, items, height=0, width=0, listheight=0)
133
+
134
+ tmp = Tempfile.new('tmp')
135
+
136
+ itemlist = String.new
137
+
138
+ for item in items
139
+ if item[2]
140
+ item[2] = "on"
141
+ else
142
+ item[2] = "off"
143
+ end
144
+ itemlist += "\"" + item[0].to_s + "\" \"" + item[1].to_s +
145
+ "\" " + item[2] + " "
146
+
147
+ if @itemhelp
148
+ itemlist += "\"" + item[3].to_s + "\" "
149
+ end
150
+ end
151
+
152
+ command = option_string() + "--checklist \"" + text.to_s +
153
+ "\" " + height.to_i.to_s + " " + width.to_i.to_s +
154
+ " " + listheight.to_i.to_s + " " + itemlist + "2> " +
155
+ tmp.path
156
+ puts command
157
+ success = system(command)
158
+ puts success
159
+ if success
160
+ selected_string = tmp.readline
161
+ tmp.close!
162
+ selected_string.slice!(0)
163
+ selected_string.chomp!("\"")
164
+ selected_array = selected_string.split('" "')
165
+ for item in selected_array
166
+ item.delete!("\\")
167
+ end
168
+
169
+ return selected_array
170
+ else
171
+ tmp.close!
172
+ return success
173
+ end
174
+
175
+ end
176
+
177
+ def radiolist(text, items, height=0, width=0, listheight=0)
178
+
179
+ tmp = Tempfile.new('tmp')
180
+
181
+ itemlist = String.new
182
+
183
+ for item in items
184
+ if item[2]
185
+ item[2] = "on"
186
+ else
187
+ item[2] = "off"
188
+ end
189
+ itemlist += "\"" + item[0].to_s + "\" \"" + item[1].to_s +
190
+ "\" " + item[2] + " "
191
+
192
+ if @itemhelp
193
+ itemlist += "\"" + item[3].to_s + "\" "
194
+ end
195
+ end
196
+
197
+ command = option_string() + "--radiolist \"" + text.to_s +
198
+ "\" " + height.to_i.to_s + " " + width.to_i.to_s +
199
+ " " + listheight.to_i.to_s + " " + itemlist + "2> " +
200
+ tmp.path
201
+ success = system(command)
202
+
203
+ if success
204
+ selected_string = tmp.readline
205
+ tmp.close!
206
+ return selected_string
207
+ else
208
+ tmp.close!
209
+ return success
210
+ end
211
+
212
+ end
213
+
214
+ def inputbox(text="Please enter some text", height=0, width=0, init="")
215
+ tmp = Tempfile.new('tmp')
216
+
217
+ command = option_string() + "--inputbox \"" + text.to_s +
218
+ "\" " + height.to_i.to_s + " " + width.to_i.to_s + " "
219
+
220
+ unless init.empty?
221
+ command += init.to_s + " "
222
+ end
223
+
224
+ command += "2> " + tmp.path
225
+
226
+ success = system(command)
227
+
228
+ if success
229
+ selected_string = tmp.readline
230
+ tmp.close!
231
+ return selected_string
232
+ else
233
+ tmp.close!
234
+ return success
235
+ end
236
+ end
237
+
238
+ private
239
+
240
+ def option_string()
241
+ unless @path_to_dialog
242
+ ostring = "dialog "
243
+ else
244
+ ostring = @path_to_dialog + " "
245
+ end
246
+ if @aspect
247
+ ostring += "--aspect " + aspect + " "
248
+ end
249
+
250
+ if @beep
251
+ ostring += "--beep "
252
+ end
253
+
254
+ if @boxbegin
255
+ ostring += "--begin " + @boxbegin[0] + @boxbegin[1] + " "
256
+ end
257
+
258
+ if @backtitle
259
+ ostring += "--backtitle \"" + @backtitle + "\" "
260
+ end
261
+
262
+ if @itemhelp
263
+ ostring += "--item-help "
264
+ end
265
+
266
+ unless @shadow == nil
267
+ if @shadow == true
268
+ ostring += "--shadow "
269
+ else
270
+ ostring += "--no-shadow "
271
+ end
272
+ end
273
+
274
+ if @sleep
275
+ ostring += "--sleep " + @sleep.to_i + " "
276
+ end
277
+
278
+ if @tabcorrect
279
+ ostring += "--tab-correct "
280
+ end
281
+
282
+ if @tablen
283
+ ostring += "--tab-len " + @tablen.to_i + " "
284
+ end
285
+
286
+ if @title
287
+ ostring += "--title " + @title.to_s + " "
288
+ end
289
+
290
+ return ostring
291
+
292
+ end
293
+ end
294
+
295
+
296
+
297
+ #Dir[File.join(File.dirname(__FILE__), 'rdialog/**/*.rb')].sort.each { |lib| require lib }
data/scripts/txt2html ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require File.dirname(__FILE__) + '/../lib/rdialog/version.rb'
8
+
9
+ version = Rdialog::VERSION::STRING
10
+ download = 'http://rubyforge.org/projects/rdialog'
11
+
12
+ class Fixnum
13
+ def ordinal
14
+ # teens
15
+ return 'th' if (10..19).include?(self % 100)
16
+ # others
17
+ case self % 10
18
+ when 1: return 'st'
19
+ when 2: return 'nd'
20
+ when 3: return 'rd'
21
+ else return 'th'
22
+ end
23
+ end
24
+ end
25
+
26
+ class Time
27
+ def pretty
28
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
+ end
30
+ end
31
+
32
+ def convert_syntax(syntax, source)
33
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
+ end
35
+
36
+ if ARGV.length >= 1
37
+ src, template = ARGV
38
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
+
40
+ else
41
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
+ exit!
43
+ end
44
+
45
+ template = ERB.new(File.open(template).read)
46
+
47
+ title = nil
48
+ body = nil
49
+ File.open(src) do |fsrc|
50
+ title_text = fsrc.readline
51
+ body_text = fsrc.read
52
+ syntax_items = []
53
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
+ ident = syntax_items.length
55
+ element, syntax, source = $1, $2, $3
56
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
+ "syntax-temp-#{ident}"
58
+ }
59
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
+ body = RedCloth.new(body_text).to_html
61
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
+ end
63
+ stat = File.stat(src)
64
+ created = stat.ctime
65
+ modified = stat.mtime
66
+
67
+ $stdout << template.result(binding)