clone 1.0.0.alpha → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +1 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -1
- data/VERSION +1 -1
- data/bin/clone +7 -0
- data/clone.gemspec +4 -0
- data/docs/readme +16 -0
- data/docs/readme.txt +5 -0
- data/lib/clone.rb +13 -2
- data/lib/clone/config/config.rb +19 -0
- data/lib/clone/config/config.yml +22 -0
- data/lib/clone/config/default_config.yml +20 -0
- data/lib/clone/config/require.rb +3 -0
- data/lib/clone/config/version.rb +10 -0
- data/lib/clone/config/yml.rb +22 -0
- data/lib/clone/config/z_defaults.rb +28 -0
- data/lib/clone/generator/engine.rb +581 -0
- data/lib/clone/generator/terminal.rb +104 -0
- data/lib/clone/helpers/helper_methods.rb +251 -0
- data/lib/clone/helpers/local_methods.rb +150 -0
- data/lib/clone/helpers/require.rb +37 -0
- data/module/Marshal.4.8 +0 -0
- data/module/Marshal.4.8.Z +0 -0
- data/module/gems/commander-4.1.3/.gitignore +6 -0
- data/module/gems/commander-4.1.3/.travis.yml +11 -0
- data/module/gems/commander-4.1.3/DEVELOPMENT +15 -0
- data/module/gems/commander-4.1.3/Gemfile +3 -0
- data/module/gems/commander-4.1.3/History.rdoc +345 -0
- data/module/gems/commander-4.1.3/Manifest +38 -0
- data/module/gems/commander-4.1.3/README.rdoc +375 -0
- data/module/gems/commander-4.1.3/Rakefile +10 -0
- data/module/gems/commander-4.1.3/bin/commander +55 -0
- data/module/gems/commander-4.1.3/commander.gemspec +26 -0
- data/module/gems/commander-4.1.3/lib/commander.rb +32 -0
- data/module/gems/commander-4.1.3/lib/commander/blank.rb +8 -0
- data/module/gems/commander-4.1.3/lib/commander/command.rb +213 -0
- data/module/gems/commander-4.1.3/lib/commander/core_ext.rb +3 -0
- data/module/gems/commander-4.1.3/lib/commander/core_ext/array.rb +26 -0
- data/module/gems/commander-4.1.3/lib/commander/core_ext/object.rb +11 -0
- data/module/gems/commander-4.1.3/lib/commander/delegates.rb +13 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters.rb +8 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/base.rb +18 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal.rb +20 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/command_help.erb +35 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/help.erb +36 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact.rb +12 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/command_help.erb +27 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/help.erb +29 -0
- data/module/gems/commander-4.1.3/lib/commander/import.rb +10 -0
- data/module/gems/commander-4.1.3/lib/commander/platform.rb +8 -0
- data/module/gems/commander-4.1.3/lib/commander/runner.rb +411 -0
- data/module/gems/commander-4.1.3/lib/commander/user_interaction.rb +521 -0
- data/module/gems/commander-4.1.3/lib/commander/version.rb +3 -0
- data/module/gems/commander-4.1.3/spec/command_spec.rb +157 -0
- data/module/gems/commander-4.1.3/spec/core_ext/array_spec.rb +20 -0
- data/module/gems/commander-4.1.3/spec/core_ext/object_spec.rb +21 -0
- data/module/gems/commander-4.1.3/spec/help_formatters/terminal_spec.rb +67 -0
- data/module/gems/commander-4.1.3/spec/runner_spec.rb +526 -0
- data/module/gems/commander-4.1.3/spec/spec_helper.rb +59 -0
- data/module/gems/commander-4.1.3/spec/ui_spec.rb +30 -0
- data/module/gems/hello.rb +1 -0
- data/module/gems/highline-1.6.19/.gitignore +2 -0
- data/module/gems/highline-1.6.19/AUTHORS +3 -0
- data/module/gems/highline-1.6.19/CHANGELOG +346 -0
- data/module/gems/highline-1.6.19/COPYING +340 -0
- data/module/gems/highline-1.6.19/INSTALL +55 -0
- data/module/gems/highline-1.6.19/LICENSE +7 -0
- data/module/gems/highline-1.6.19/README.rdoc +63 -0
- data/module/gems/highline-1.6.19/Rakefile +50 -0
- data/module/gems/highline-1.6.19/TODO +6 -0
- data/module/gems/highline-1.6.19/examples/ansi_colors.rb +38 -0
- data/module/gems/highline-1.6.19/examples/asking_for_arrays.rb +18 -0
- data/module/gems/highline-1.6.19/examples/basic_usage.rb +75 -0
- data/module/gems/highline-1.6.19/examples/color_scheme.rb +32 -0
- data/module/gems/highline-1.6.19/examples/get_character.rb +12 -0
- data/module/gems/highline-1.6.19/examples/limit.rb +12 -0
- data/module/gems/highline-1.6.19/examples/menus.rb +65 -0
- data/module/gems/highline-1.6.19/examples/overwrite.rb +19 -0
- data/module/gems/highline-1.6.19/examples/page_and_wrap.rb +322 -0
- data/module/gems/highline-1.6.19/examples/password.rb +7 -0
- data/module/gems/highline-1.6.19/examples/repeat_entry.rb +21 -0
- data/module/gems/highline-1.6.19/examples/trapping_eof.rb +22 -0
- data/module/gems/highline-1.6.19/examples/using_readline.rb +17 -0
- data/module/gems/highline-1.6.19/highline.gemspec +37 -0
- data/module/gems/highline-1.6.19/lib/highline.rb +1012 -0
- data/module/gems/highline-1.6.19/lib/highline/color_scheme.rb +134 -0
- data/module/gems/highline-1.6.19/lib/highline/compatibility.rb +16 -0
- data/module/gems/highline-1.6.19/lib/highline/import.rb +41 -0
- data/module/gems/highline-1.6.19/lib/highline/menu.rb +398 -0
- data/module/gems/highline-1.6.19/lib/highline/question.rb +475 -0
- data/module/gems/highline-1.6.19/lib/highline/simulate.rb +48 -0
- data/module/gems/highline-1.6.19/lib/highline/string_extensions.rb +131 -0
- data/module/gems/highline-1.6.19/lib/highline/style.rb +181 -0
- data/module/gems/highline-1.6.19/lib/highline/system_extensions.rb +222 -0
- data/module/gems/highline-1.6.19/setup.rb +1360 -0
- data/module/gems/highline-1.6.19/site/.cvsignore +1 -0
- data/module/gems/highline-1.6.19/site/highline.css +65 -0
- data/module/gems/highline-1.6.19/site/images/logo.png +0 -0
- data/module/gems/highline-1.6.19/site/index.html +58 -0
- data/module/gems/highline-1.6.19/test/string_methods.rb +32 -0
- data/module/gems/highline-1.6.19/test/tc_color_scheme.rb +96 -0
- data/module/gems/highline-1.6.19/test/tc_highline.rb +1128 -0
- data/module/gems/highline-1.6.19/test/tc_import.rb +52 -0
- data/module/gems/highline-1.6.19/test/tc_menu.rb +439 -0
- data/module/gems/highline-1.6.19/test/tc_string_extension.rb +20 -0
- data/module/gems/highline-1.6.19/test/tc_string_highline.rb +38 -0
- data/module/gems/highline-1.6.19/test/tc_style.rb +567 -0
- data/module/gems/highline-1.6.19/test/ts_all.rb +16 -0
- data/module/latest_specs.4.8 +0 -0
- data/module/latest_specs.4.8.gz +0 -0
- data/module/prerelease_specs.4.8 +0 -0
- data/module/prerelease_specs.4.8.gz +0 -0
- data/module/specs.4.8 +0 -0
- data/module/specs.4.8.gz +0 -0
- data/samples/blather/restlike/Gemfile +4 -0
- data/samples/blather/restlike/cmd.yml +1 -0
- data/samples/blather/restlike/lib/blather.rb +9 -0
- data/samples/blather/restlike/lib/blather/dsl/api.rb +78 -0
- data/samples/blather/restlike/lib/blather/dsl/call.rb +13 -0
- data/samples/blather/restlike/lib/blather/dsl/client.rb +58 -0
- data/samples/blather/restlike/lib/blather/dsl/config.rb +11 -0
- data/samples/blather/restlike/lib/blather/dsl/extraDSL.rb +163 -0
- data/samples/blather/restlike/lib/blather/meta/require.rb +8 -0
- data/samples/blather/restlike/lib/blather/meta/xmpp.yml +5 -0
- data/samples/blather/restlike/lib/blather/vendors/xmpp_default.rb +27 -0
- data/samples/blather/restlike/readme +2 -0
- data/samples/grape/init/Gemfile +2 -0
- data/samples/grape/init/cmd.yml +3 -0
- data/samples/grape/init/config.ru +2 -0
- data/samples/grape/init/docs/grape/documentation.txt +939 -0
- data/samples/grape/init/docs/grape/generate_rest_routes.rb +37 -0
- data/samples/grape/init/docs/grape/ls_routes.rb +31 -0
- data/samples/grape/init/lib/grape.rb +4 -0
- data/samples/grape/init/lib/grape/meta/subclasses.rb +20 -0
- data/samples/grape/init/lib/grape/xpath/app.rb +30 -0
- data/samples/grape/init/lib/grape/xpath/ruotes.rb +6 -0
- data/samples/grape/init/readme +1 -0
- data/samples/grape/readme +29 -0
- data/samples/grape/vendor/lib/grape/vendors/v1/rest.rb +57 -0
- data/samples/mongoid/cmd.yml +1 -0
- data/samples/mongoid/init/Gemfile +3 -0
- data/samples/mongoid/init/cmd.yml +2 -0
- data/samples/mongoid/init/docs/mongoid/ModelsRelations.rb +11 -0
- data/samples/mongoid/init/docs/mongoid/documents.xls +0 -0
- data/samples/mongoid/init/docs/mongoid/generate_modelsToDocs.rb +25 -0
- data/samples/mongoid/init/docs/mongoid/modelsToDocs.rb +25 -0
- data/samples/mongoid/init/docs/mongoid/relations.txt +1354 -0
- data/samples/mongoid/init/lib/mongoid.rb +44 -0
- data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_CRUD.rb +446 -0
- data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_MP.rb +517 -0
- data/samples/mongoid/init/lib/mongoid/dsl/init.rb +37 -0
- data/samples/mongoid/init/lib/mongoid/dsl/params.rb +67 -0
- data/samples/mongoid/init/lib/mongoid/meta/banned.rb +147 -0
- data/samples/mongoid/init/lib/mongoid/meta/control.yml +13 -0
- data/samples/mongoid/init/lib/mongoid/meta/mongoid.yml +6 -0
- data/samples/mongoid/init/lib/mongoid/meta/mpatch.rb +14 -0
- data/samples/mongoid/model/lib/mongoid/models/model.rb +28 -0
- data/samples/mongoid/readme +33 -0
- data/samples/rack/init/Gemfile +10 -0
- data/samples/rack/init/cmd.yml +2 -0
- data/samples/rack/init/config.ru +1 -0
- data/samples/rack/init/docs/rack/rake introducing.txt +60 -0
- data/samples/rack/init/docs/rack/webservers/Thin +43 -0
- data/samples/rack/init/docs/rack/webservers/ebb +72 -0
- data/samples/rack/init/docs/rack/webservers/fcgi +103 -0
- data/samples/rack/init/docs/rack/webservers/mongrel +74 -0
- data/samples/rack/init/docs/rack/webservers/passenger +37 -0
- data/samples/rack/init/docs/rack/webservers/scgi +188 -0
- data/samples/rack/init/lib/rack.rb +1 -0
- data/samples/rack/init/lib/rack/meta/webserver/thin.rb +45 -0
- data/samples/rack/init/lib/rack/meta/webserver/thin.yml +6 -0
- data/samples/rack/init/server.rb +0 -0
- data/samples/rack/readme +13 -0
- data/samples/rest_client/init/Gemfile +5 -0
- data/samples/rest_client/init/boot.rb +2 -0
- data/samples/rest_client/init/cmd.yml +1 -0
- data/samples/rest_client/init/config/rest_client/defaults.rb +16 -0
- data/samples/rest_client/init/docs/rest_client/simple overlook +251 -0
- data/samples/rest_client/init/test/rest_client/rest_dsl.rb +5 -0
- data/samples/rest_client/readme +7 -0
- data/samples/scripts/lines_counter/lines_number.rb +32 -0
- data/samples/scripts/lines_counter/readme +5 -0
- data/samples/scripts/readme +1 -0
- metadata +197 -7
- data/lib/clone/cms.rb +0 -56
- data/lib/clone/ext.rb +0 -77
- data/sample/test.rb +0 -30
@@ -0,0 +1,55 @@
|
|
1
|
+
= Installing HighLine
|
2
|
+
|
3
|
+
RubyGems is the preferred easy install method for HighLine. However, you can
|
4
|
+
install HighLine manually as described below.
|
5
|
+
|
6
|
+
== Installing the Gem
|
7
|
+
|
8
|
+
HighLine is intended to be installed via the
|
9
|
+
RubyGems[http://rubyforge.org/projects/rubygems/] system. To get the latest
|
10
|
+
version, simply enter the following into your command prompt:
|
11
|
+
|
12
|
+
$ sudo gem install highline
|
13
|
+
|
14
|
+
You must have RubyGems[http://rubyforge.org/projects/rubygems/] installed for
|
15
|
+
the above to work.
|
16
|
+
|
17
|
+
If you want to build the gem locally, make sure you have
|
18
|
+
Rake[http://rubyforge.org/projects/rake/] installed then run the following
|
19
|
+
command:
|
20
|
+
|
21
|
+
$ rake package
|
22
|
+
|
23
|
+
== Installing Manually
|
24
|
+
|
25
|
+
Download the latest version of HighLine from the
|
26
|
+
{RubyForge project page}[http://rubyforge.org/frs/?group_id=683]. Navigate to
|
27
|
+
the root project directory and enter:
|
28
|
+
|
29
|
+
$ sudo ruby setup.rb
|
30
|
+
|
31
|
+
== Installing HighLine on JRuby
|
32
|
+
|
33
|
+
If you are using HighLine on JRuby, many features will not work properly
|
34
|
+
without a working ncurses installation. First, ensure that you have
|
35
|
+
ncurses installed and then install the ffi-ncurses gem.
|
36
|
+
|
37
|
+
If ffi-ncurses fails to find your ncurses library, you may need to set the
|
38
|
+
RUBY_FFI_NCURSES envirionment variable, i.e:
|
39
|
+
|
40
|
+
RUBY_FFI_NCURSES_LIB=ncursesw ruby examples/hello.rb
|
41
|
+
|
42
|
+
For details, see the ffi-ncurses documentation at:
|
43
|
+
http://github.com/seanohalpin/ffi-ncurses
|
44
|
+
|
45
|
+
== Using termios
|
46
|
+
|
47
|
+
While not a requirement, HighLine will take advantage of the termios library if
|
48
|
+
installed (on Unix). This slightly improves HighLine's character reading
|
49
|
+
capabilities and thus is recommended for all Unix users.
|
50
|
+
|
51
|
+
If using the HighLine gem, you should be able to add termios as easily as:
|
52
|
+
|
53
|
+
$ sudo gem install termios
|
54
|
+
|
55
|
+
For manual installs, consult the termios documentation.
|
@@ -0,0 +1,7 @@
|
|
1
|
+
= License Terms
|
2
|
+
|
3
|
+
Distributed under the user's choice of the {GPL Version 2}[http://www.gnu.org/licenses/old-licenses/gpl-2.0.html] (see COPYING for details) or the
|
4
|
+
{Ruby software license}[http://www.ruby-lang.org/en/LICENSE.txt] by
|
5
|
+
James Edward Gray II and Greg Brown.
|
6
|
+
|
7
|
+
Please email James[mailto:james@grayproductions.net] with any questions.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
= Read Me
|
2
|
+
|
3
|
+
by James Edward Gray II
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
Welcome to HighLine.
|
8
|
+
|
9
|
+
HighLine was designed to ease the tedious tasks of doing console input and
|
10
|
+
output with low-level methods like gets() and puts(). HighLine provides a
|
11
|
+
robust system for requesting data from a user, without needing to code all the
|
12
|
+
error checking and validation rules and without needing to convert the typed
|
13
|
+
Strings into what your program really needs. Just tell HighLine what you're
|
14
|
+
after, and let it do all the work.
|
15
|
+
|
16
|
+
== Documentation
|
17
|
+
|
18
|
+
See HighLine and HighLine::Question for documentation.
|
19
|
+
|
20
|
+
== Examples
|
21
|
+
|
22
|
+
Basic usage:
|
23
|
+
|
24
|
+
ask("Company? ") { |q| q.default = "none" }
|
25
|
+
|
26
|
+
Validation:
|
27
|
+
|
28
|
+
ask("Age? ", Integer) { |q| q.in = 0..105 }
|
29
|
+
ask("Name? (last, first) ") { |q| q.validate = /\A\w+, ?\w+\Z/ }
|
30
|
+
|
31
|
+
Type conversion for answers:
|
32
|
+
|
33
|
+
ask("Birthday? ", Date)
|
34
|
+
ask("Interests? (comma sep list) ", lambda { |str| str.split(/,\s*/) })
|
35
|
+
|
36
|
+
Reading passwords:
|
37
|
+
|
38
|
+
ask("Enter your password: ") { |q| q.echo = false }
|
39
|
+
ask("Enter your password: ") { |q| q.echo = "x" }
|
40
|
+
|
41
|
+
ERb based output (with HighLine's ANSI color tools):
|
42
|
+
|
43
|
+
say("This should be <%= color('bold', BOLD) %>!")
|
44
|
+
|
45
|
+
Menus:
|
46
|
+
|
47
|
+
choose do |menu|
|
48
|
+
menu.prompt = "Please choose your favorite programming language? "
|
49
|
+
|
50
|
+
menu.choice(:ruby) { say("Good choice!") }
|
51
|
+
menu.choices(:python, :perl) { say("Not from around here, are you?") }
|
52
|
+
end
|
53
|
+
|
54
|
+
For more examples see the examples/ directory of this project.
|
55
|
+
|
56
|
+
== Installing
|
57
|
+
|
58
|
+
See the INSTALL file for instructions.
|
59
|
+
|
60
|
+
== Questions and/or Comments
|
61
|
+
|
62
|
+
Feel free to email {James Edward Gray II}[mailto:james@grayproductions.net] or
|
63
|
+
{Gregory Brown}[mailto:gregory.t.brown@gmail.com] with any questions.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "rdoc/task"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rubygems/package_task"
|
4
|
+
|
5
|
+
require "rubygems"
|
6
|
+
|
7
|
+
task :default => [:meta]
|
8
|
+
|
9
|
+
Rake::TestTask.new do |test|
|
10
|
+
test.libs << "test"
|
11
|
+
test.test_files = [ "test/ts_all.rb"]
|
12
|
+
test.verbose = true
|
13
|
+
test.ruby_opts << "-w"
|
14
|
+
end
|
15
|
+
|
16
|
+
Rake::RDocTask.new do |rdoc|
|
17
|
+
rdoc.rdoc_files.include( "README.rdoc", "INSTALL",
|
18
|
+
"TODO", "CHANGELOG",
|
19
|
+
"AUTHORS", "COPYING",
|
20
|
+
"LICENSE", "lib/" )
|
21
|
+
rdoc.main = "README.rdoc"
|
22
|
+
rdoc.rdoc_dir = "doc/html"
|
23
|
+
rdoc.title = "HighLine Documentation"
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Upload current documentation to Rubyforge"
|
27
|
+
task :upload_docs => [:rdoc] do
|
28
|
+
sh "scp -r doc/html/* " +
|
29
|
+
"bbazzarrakk@rubyforge.org:/var/www/gforge-projects/highline/doc/"
|
30
|
+
sh "scp -r site/* " +
|
31
|
+
"bbazzarrakk@rubyforge.org:/var/www/gforge-projects/highline/"
|
32
|
+
end
|
33
|
+
|
34
|
+
load(File.join(File.dirname(__FILE__), "highline.gemspec"))
|
35
|
+
Gem::PackageTask.new(SPEC) do |package|
|
36
|
+
# do nothing: I just need a gem but this block is required
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Show library's code statistics"
|
40
|
+
task :stats do
|
41
|
+
require 'code_statistics'
|
42
|
+
CodeStatistics.new( ["HighLine", "lib"],
|
43
|
+
["Functionals", "examples"],
|
44
|
+
["Units", "test"] ).to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Add new files to Subversion"
|
48
|
+
task :add_to_svn do
|
49
|
+
sh %Q{svn status | ruby -nae 'system "svn add \#{$F[1]}" if $F[0] == "?"' }
|
50
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# ansi_colors.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2005-05-03.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "rubygems"
|
9
|
+
require "highline/import"
|
10
|
+
|
11
|
+
# Supported color sequences.
|
12
|
+
colors = %w{black red green yellow blue magenta cyan white}
|
13
|
+
|
14
|
+
# Using color() with symbols.
|
15
|
+
colors.each_with_index do |c, i|
|
16
|
+
say("This should be <%= color('#{c}', :#{c}) %>!")
|
17
|
+
if i == 0
|
18
|
+
say( "This should be " +
|
19
|
+
"<%= color('white on #{c}', :white, :on_#{c}) %>!")
|
20
|
+
else
|
21
|
+
say( "This should be " +
|
22
|
+
"<%= color( '#{colors[i - 1]} on #{c}',
|
23
|
+
:#{colors[i - 1]}, :on_#{c} ) %>!")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Using color with constants.
|
28
|
+
say("This should be <%= color('bold', BOLD) %>!")
|
29
|
+
say("This should be <%= color('underlined', UNDERLINE) %>!")
|
30
|
+
|
31
|
+
# Using constants only.
|
32
|
+
say("This might even <%= BLINK %>blink<%= CLEAR %>!")
|
33
|
+
|
34
|
+
# It even works with list wrapping.
|
35
|
+
erb_digits = %w{Zero One Two Three Four} +
|
36
|
+
["<%= color('Five', :blue) %%>"] +
|
37
|
+
%w{Six Seven Eight Nine}
|
38
|
+
say("<%= list(#{erb_digits.inspect}, :columns_down, 3) %>")
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# asking_for_arrays.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2005-07-05.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "rubygems"
|
9
|
+
require "highline/import"
|
10
|
+
require "pp"
|
11
|
+
|
12
|
+
grades = ask( "Enter test scores (or a blank line to quit):",
|
13
|
+
lambda { |ans| ans =~ /^-?\d+$/ ? Integer(ans) : ans} ) do |q|
|
14
|
+
q.gather = ""
|
15
|
+
end
|
16
|
+
|
17
|
+
say("Grades:")
|
18
|
+
pp grades
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# basic_usage.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2005-04-28.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "rubygems"
|
9
|
+
require "highline/import"
|
10
|
+
require "yaml"
|
11
|
+
|
12
|
+
contacts = [ ]
|
13
|
+
|
14
|
+
class NameClass
|
15
|
+
def self.parse( string )
|
16
|
+
if string =~ /^\s*(\w+),\s*(\w+)\s*$/
|
17
|
+
self.new($2, $1)
|
18
|
+
else
|
19
|
+
raise ArgumentError, "Invalid name format."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(first, last)
|
24
|
+
@first, @last = first, last
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :first, :last
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
entry = Hash.new
|
32
|
+
|
33
|
+
# basic output
|
34
|
+
say("Enter a contact:")
|
35
|
+
|
36
|
+
# basic input
|
37
|
+
entry[:name] = ask("Name? (last, first) ", NameClass) do |q|
|
38
|
+
q.validate = /\A\w+, ?\w+\Z/
|
39
|
+
end
|
40
|
+
entry[:company] = ask("Company? ") { |q| q.default = "none" }
|
41
|
+
entry[:address] = ask("Address? ")
|
42
|
+
entry[:city] = ask("City? ")
|
43
|
+
entry[:state] = ask("State? ") do |q|
|
44
|
+
q.case = :up
|
45
|
+
q.validate = /\A[A-Z]{2}\Z/
|
46
|
+
end
|
47
|
+
entry[:zip] = ask("Zip? ") do |q|
|
48
|
+
q.validate = /\A\d{5}(?:-?\d{4})?\Z/
|
49
|
+
end
|
50
|
+
entry[:phone] = ask( "Phone? ",
|
51
|
+
lambda { |p| p.delete("^0-9").
|
52
|
+
sub(/\A(\d{3})/, '(\1) ').
|
53
|
+
sub(/(\d{4})\Z/, '-\1') } ) do |q|
|
54
|
+
q.validate = lambda { |p| p.delete("^0-9").length == 10 }
|
55
|
+
q.responses[:not_valid] = "Enter a phone numer with area code."
|
56
|
+
end
|
57
|
+
entry[:age] = ask("Age? ", Integer) { |q| q.in = 0..105 }
|
58
|
+
entry[:birthday] = ask("Birthday? ", Date)
|
59
|
+
entry[:interests] = ask( "Interests? (comma separated list) ",
|
60
|
+
lambda { |str| str.split(/,\s*/) } )
|
61
|
+
entry[:description] = ask("Enter a description for this contact.") do |q|
|
62
|
+
q.whitespace = :strip_and_collapse
|
63
|
+
end
|
64
|
+
|
65
|
+
contacts << entry
|
66
|
+
# shortcut for yes and no questions
|
67
|
+
end while agree("Enter another contact? ", true)
|
68
|
+
|
69
|
+
if agree("Save these contacts? ", true)
|
70
|
+
file_name = ask("Enter a file name: ") do |q|
|
71
|
+
q.validate = /\A\w+\Z/
|
72
|
+
q.confirm = true
|
73
|
+
end
|
74
|
+
File.open("#{file_name}.yaml", "w") { |file| YAML.dump(contacts, file) }
|
75
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
# color_scheme.rb
|
4
|
+
#
|
5
|
+
# Created by Jeremy Hinegardner on 2007-01-24
|
6
|
+
# Copyright 2007 Jeremy Hinegardner. All rights reserved
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'highline/import'
|
10
|
+
|
11
|
+
# Create a color scheme, naming color patterns with symbol names.
|
12
|
+
ft = HighLine::ColorScheme.new do |cs|
|
13
|
+
cs[:headline] = [ :bold, :yellow, :on_black ]
|
14
|
+
cs[:horizontal_line] = [ :bold, :white, :on_blue]
|
15
|
+
cs[:even_row] = [ :green ]
|
16
|
+
cs[:odd_row] = [ :magenta ]
|
17
|
+
end
|
18
|
+
|
19
|
+
# Assign that color scheme to HighLine...
|
20
|
+
HighLine.color_scheme = ft
|
21
|
+
|
22
|
+
# ...and use it.
|
23
|
+
say("<%= color('Headline', :headline) %>")
|
24
|
+
say("<%= color('-'*20, :horizontal_line) %>")
|
25
|
+
|
26
|
+
# Setup a toggle for rows.
|
27
|
+
i = true
|
28
|
+
("A".."D").each do |row|
|
29
|
+
row_color = i ? :even_row : :odd_row
|
30
|
+
say("<%= color('#{row}', '#{row_color}') %>")
|
31
|
+
i = !i
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
# limit.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2008-11-12.
|
6
|
+
# Copyright 2008 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "rubygems"
|
9
|
+
require "highline/import"
|
10
|
+
|
11
|
+
text = ask("Enter text (max 10 chars): ") { |q| q.limit = 10 }
|
12
|
+
puts "You entered: #{text}!"
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "highline/import"
|
5
|
+
|
6
|
+
# The old way, using ask() and say()...
|
7
|
+
choices = %w{ruby python perl}
|
8
|
+
say("This is the old way using ask() and say()...")
|
9
|
+
say("Please choose your favorite programming language:")
|
10
|
+
say(choices.map { |c| " #{c}\n" }.join)
|
11
|
+
|
12
|
+
case ask("? ", choices)
|
13
|
+
when "ruby"
|
14
|
+
say("Good choice!")
|
15
|
+
else
|
16
|
+
say("Not from around here, are you?")
|
17
|
+
end
|
18
|
+
|
19
|
+
# The new and improved choose()...
|
20
|
+
say("\nThis is the new mode (default)...")
|
21
|
+
choose do |menu|
|
22
|
+
menu.prompt = "Please choose your favorite programming language? "
|
23
|
+
|
24
|
+
menu.choice :ruby do say("Good choice!") end
|
25
|
+
menu.choices(:python, :perl) do say("Not from around here, are you?") end
|
26
|
+
end
|
27
|
+
|
28
|
+
say("\nThis is letter indexing...")
|
29
|
+
choose do |menu|
|
30
|
+
menu.index = :letter
|
31
|
+
menu.index_suffix = ") "
|
32
|
+
|
33
|
+
menu.prompt = "Please choose your favorite programming language? "
|
34
|
+
|
35
|
+
menu.choice :ruby do say("Good choice!") end
|
36
|
+
menu.choices(:python, :perl) do say("Not from around here, are you?") end
|
37
|
+
end
|
38
|
+
|
39
|
+
say("\nThis is with a different layout...")
|
40
|
+
choose do |menu|
|
41
|
+
menu.layout = :one_line
|
42
|
+
|
43
|
+
menu.header = "Languages"
|
44
|
+
menu.prompt = "Favorite? "
|
45
|
+
|
46
|
+
menu.choice :ruby do say("Good choice!") end
|
47
|
+
menu.choices(:python, :perl) do say("Not from around here, are you?") end
|
48
|
+
end
|
49
|
+
|
50
|
+
say("\nYou can even build shells...")
|
51
|
+
loop do
|
52
|
+
choose do |menu|
|
53
|
+
menu.layout = :menu_only
|
54
|
+
|
55
|
+
menu.shell = true
|
56
|
+
|
57
|
+
menu.choice(:load, "Load a file.") do |command, details|
|
58
|
+
say("Loading file with options: #{details}...")
|
59
|
+
end
|
60
|
+
menu.choice(:save, "Save a file.") do |command, details|
|
61
|
+
say("Saving file with options: #{details}...")
|
62
|
+
end
|
63
|
+
menu.choice(:quit, "Exit program.") { exit }
|
64
|
+
end
|
65
|
+
end
|