-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validations ValidationOfPresence lets you ensure a parameter is present. CGI url_for helper lets you construct escaped parameters programmatically. url_for('index.cgi', :q => 'bar') => 'index.cgi?test=bar' Made URI completion more consistent Fixed CGI header duplication Templating Better error handling
- Loading branch information
Aphyr
committed
Mar 30, 2008
1 parent
2e3aba8
commit a92910b
Showing
11 changed files
with
222 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/doc/ | ||
/pkg/ | ||
doc/ | ||
pkg/ | ||
~* | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Array | ||
# Convert an array to a nice sentence. Method is called on each element of the array, and should return a string. | ||
def to_sentence(method = :to_s) | ||
case size | ||
when 0 | ||
'' | ||
when 1 | ||
first.send method | ||
when 2 | ||
first.send(method) + ' and ' + last.send(method) | ||
else | ||
sentence = self[1..-2].inject(first.send(method)) do |sentence, element| | ||
sentence += ', ' + element.send(method) | ||
end | ||
sentence + ', and ' + last.send(method) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class CGI | ||
HTTP_PORT = 80 | ||
HTTPS_PORT = 443 | ||
|
||
# Returns a full uri for a given uri fragment. | ||
# full_uri_for 'foo.cgi' => 'http://localhost/dir/foo.cgi' | ||
# full_uri_for '/images/' => 'http://localhost/images/' | ||
def full_uri_for(fragment) | ||
case fragment | ||
when /^http:\/\// | ||
# The fragment is a complete URI | ||
fragment | ||
when /^\// | ||
# The fragment is relative to the root of this host | ||
host_uri + fragment | ||
else | ||
# The fragment is relative to this directory | ||
relative_uri + fragment | ||
end | ||
end | ||
|
||
# Try to guess the uri for the host alone (http://host/) | ||
def host_uri | ||
uri = '' | ||
case server_port | ||
when HTTP_PORT | ||
uri << 'http://' + server_name | ||
when HTTPS_PORT | ||
uri << 'https://' + server_name | ||
else | ||
uri << 'https://' + server_name + ':' + server_port | ||
end | ||
uri << '/' | ||
end | ||
|
||
# Try to guess the relative path for this request. (http://host/directory/) | ||
def relative_uri | ||
uri.sub(/[^\/]*$/, '') | ||
end | ||
|
||
# Try to guess the full uri for this script (http://host/directory/script.cgi) | ||
def uri | ||
host_uri.chop + script_name | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Provides support methods for string manipulation | ||
|
||
class String | ||
# Converts dashes, underscores, and spaces to camelcase | ||
# | ||
# "foo_bar_baz".camelcase => "FooBarBaz" | ||
# "FooBarBaz".camelcase(false) => "fooBarBaz" | ||
def camelcase(first_letter_capitalized = true) | ||
# Convert separators | ||
camelcase = gsub(/[ _-]([^ _-])/) do |match| | ||
$1.upcase | ||
end | ||
|
||
# Convert first letter | ||
if first_letter_capitalized | ||
camelcase[0..0].upcase + camelcase[1..-1] | ||
else | ||
camelcase[0..0].downcase + camelcase[1..-1] | ||
end | ||
end | ||
|
||
# Removes module and class prefixes | ||
# | ||
# "Foo::Bar::Baz".demodulize => "Baz" | ||
def demodulize | ||
self[/([^:]+)$/] | ||
end | ||
|
||
# Splits the string into module and class components | ||
# | ||
# "Foo::Bar::Baz".module_split => ["Foo", "Bar", "Baz"] | ||
def module_split | ||
self.split /::/ | ||
end | ||
|
||
# Converts the string into a conventional path. | ||
def module_path | ||
File.join(module_split.map {|e| e.underscore }) | ||
end | ||
|
||
# Converts dashes, spaces, and capitals to underscore separators. | ||
# | ||
# "FooBar-Baz Whee".underscore => 'foo_bar_baz_whee' | ||
def underscore(force_lower_case = true) | ||
# Convert separators | ||
underscore = gsub(/[ -]/, '_') | ||
|
||
# Convert capitals | ||
underscore.gsub!(/(.)([A-Z])/) do |match| | ||
$1 + '_' + $2 | ||
end | ||
|
||
# Drop double underscores | ||
underscore.gsub!(/_+/, '_') | ||
|
||
if force_lower_case | ||
underscore.downcase | ||
else | ||
underscore | ||
end | ||
end | ||
end |
Binary file not shown.