waves-stable 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/app/Rakefile +72 -0
- data/app/bin/waves-console +4 -0
- data/app/bin/waves-server +4 -0
- data/app/configurations/development.rb.erb +31 -0
- data/app/configurations/mapping.rb.erb +14 -0
- data/app/configurations/production.rb.erb +31 -0
- data/app/controllers/.gitignore +0 -0
- data/app/doc/.gitignore +0 -0
- data/app/helpers/.gitignore +0 -0
- data/app/lib/application.rb.erb +5 -0
- data/app/lib/tasks/.gitignore +0 -0
- data/app/log/.gitignore +0 -0
- data/app/models/.gitignore +0 -0
- data/app/public/css/.gitignore +0 -0
- data/app/public/flash/.gitignore +0 -0
- data/app/public/images/.gitignore +0 -0
- data/app/public/javascript/.gitignore +0 -0
- data/app/schema/migrations/.gitignore +0 -0
- data/app/startup.rb +5 -0
- data/app/templates/errors/not_found_404.mab +2 -0
- data/app/templates/errors/server_error_500.mab +2 -0
- data/app/templates/layouts/default.mab +14 -0
- data/app/tmp/sessions/.gitignore +0 -0
- data/app/views/.gitignore +0 -0
- data/bin/waves +84 -0
- data/bin/waves-console +4 -0
- data/bin/waves-server +4 -0
- data/doc/HISTORY +44 -0
- data/doc/LICENSE +22 -0
- data/lib/commands/waves-console.rb +21 -0
- data/lib/commands/waves-server.rb +55 -0
- data/lib/controllers/base.rb +11 -0
- data/lib/controllers/mixin.rb +165 -0
- data/lib/dispatchers/base.rb +67 -0
- data/lib/dispatchers/default.rb +81 -0
- data/lib/foundations/default.rb +27 -0
- data/lib/foundations/simple.rb +30 -0
- data/lib/helpers/asset_helper.rb +67 -0
- data/lib/helpers/common.rb +66 -0
- data/lib/helpers/default.rb +13 -0
- data/lib/helpers/form.rb +40 -0
- data/lib/helpers/formatting.rb +30 -0
- data/lib/helpers/model.rb +33 -0
- data/lib/helpers/number_helper.rb +25 -0
- data/lib/helpers/tag_helper.rb +58 -0
- data/lib/helpers/url_helper.rb +77 -0
- data/lib/helpers/view.rb +24 -0
- data/lib/layers/default_errors.rb +26 -0
- data/lib/layers/inflect/english.rb +24 -0
- data/lib/layers/inflect/english/rules.rb +88 -0
- data/lib/layers/inflect/english/string.rb +24 -0
- data/lib/layers/mvc.rb +54 -0
- data/lib/layers/orm/active_record.rb +92 -0
- data/lib/layers/orm/active_record/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/active_record/tasks/generate.rb +28 -0
- data/lib/layers/orm/active_record/tasks/schema.rb +22 -0
- data/lib/layers/orm/data_mapper.rb +38 -0
- data/lib/layers/orm/filebase.rb +22 -0
- data/lib/layers/orm/migration.rb +79 -0
- data/lib/layers/orm/sequel.rb +86 -0
- data/lib/layers/orm/sequel/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/sequel/tasks/generate.rb +28 -0
- data/lib/layers/orm/sequel/tasks/schema.rb +16 -0
- data/lib/layers/simple.rb +32 -0
- data/lib/layers/simple_errors.rb +23 -0
- data/lib/mapping/mapping.rb +289 -0
- data/lib/mapping/pretty_urls.rb +96 -0
- data/lib/renderers/erubis.rb +63 -0
- data/lib/renderers/haml.rb +45 -0
- data/lib/renderers/markaby.rb +33 -0
- data/lib/renderers/mixin.rb +50 -0
- data/lib/runtime/application.rb +69 -0
- data/lib/runtime/blackboard.rb +57 -0
- data/lib/runtime/configuration.rb +185 -0
- data/lib/runtime/console.rb +20 -0
- data/lib/runtime/debugger.rb +9 -0
- data/lib/runtime/logger.rb +59 -0
- data/lib/runtime/mime_types.rb +22 -0
- data/lib/runtime/request.rb +78 -0
- data/lib/runtime/response.rb +40 -0
- data/lib/runtime/response_mixin.rb +38 -0
- data/lib/runtime/response_proxy.rb +30 -0
- data/lib/runtime/server.rb +107 -0
- data/lib/runtime/session.rb +66 -0
- data/lib/tasks/cluster.rb +26 -0
- data/lib/tasks/gem.rb +31 -0
- data/lib/tasks/generate.rb +80 -0
- data/lib/utilities/hash.rb +31 -0
- data/lib/utilities/inflect.rb +110 -0
- data/lib/utilities/integer.rb +24 -0
- data/lib/utilities/module.rb +21 -0
- data/lib/utilities/object.rb +25 -0
- data/lib/utilities/proc.rb +16 -0
- data/lib/utilities/string.rb +49 -0
- data/lib/utilities/symbol.rb +10 -0
- data/lib/utilities/tempfile.rb +9 -0
- data/lib/views/base.rb +9 -0
- data/lib/views/mixin.rb +110 -0
- data/lib/waves.rb +84 -0
- data/samples/blog/Rakefile +14 -0
- data/samples/blog/bin/waves-console +3 -0
- data/samples/blog/bin/waves-server +3 -0
- data/samples/blog/configurations/development.rb +31 -0
- data/samples/blog/configurations/mapping.rb +23 -0
- data/samples/blog/configurations/production.rb +30 -0
- data/samples/blog/doc/EMTPY +0 -0
- data/samples/blog/lib/application.rb +5 -0
- data/samples/blog/models/comment.rb +14 -0
- data/samples/blog/models/entry.rb +14 -0
- data/samples/blog/public/css/site.css +2 -0
- data/samples/blog/public/javascript/site.js +13 -0
- data/samples/blog/schema/migrations/001_initial_schema.rb +17 -0
- data/samples/blog/schema/migrations/002_add_comments.rb +18 -0
- data/samples/blog/schema/migrations/templates/empty.rb.erb +9 -0
- data/samples/blog/startup.rb +6 -0
- data/samples/blog/templates/comment/add.mab +10 -0
- data/samples/blog/templates/comment/list.mab +6 -0
- data/samples/blog/templates/entry/editor.mab +13 -0
- data/samples/blog/templates/entry/list.mab +11 -0
- data/samples/blog/templates/entry/show.mab +9 -0
- data/samples/blog/templates/entry/summary.mab +5 -0
- data/samples/blog/templates/errors/not_found_404.mab +2 -0
- data/samples/blog/templates/errors/server_error_500.mab +2 -0
- data/samples/blog/templates/layouts/default.mab +17 -0
- data/verify/app_generation/helpers.rb +24 -0
- data/verify/app_generation/startup.rb +39 -0
- data/verify/blackboard/blackboard_verify.rb +92 -0
- data/verify/blackboard/helpers.rb +5 -0
- data/verify/configurations/attributes.rb +37 -0
- data/verify/configurations/helpers.rb +1 -0
- data/verify/configurations/rack_integration.rb +29 -0
- data/verify/controllers/base.rb +37 -0
- data/verify/controllers/helpers.rb +13 -0
- data/verify/controllers/interface.rb +51 -0
- data/verify/core/helpers.rb +3 -0
- data/verify/core/utilities.rb +177 -0
- data/verify/foundations/default.rb +86 -0
- data/verify/foundations/default_application/Rakefile +14 -0
- data/verify/foundations/default_application/bin/waves-console +3 -0
- data/verify/foundations/default_application/bin/waves-server +3 -0
- data/verify/foundations/default_application/configurations/development.rb +26 -0
- data/verify/foundations/default_application/configurations/mapping.rb +14 -0
- data/verify/foundations/default_application/configurations/production.rb +30 -0
- data/verify/foundations/default_application/controllers/default.rb +15 -0
- data/verify/foundations/default_application/controllers/loaded.rb +15 -0
- data/verify/foundations/default_application/defaultapplication.db +0 -0
- data/verify/foundations/default_application/helpers/loaded.rb +10 -0
- data/verify/foundations/default_application/lib/application.rb +5 -0
- data/verify/foundations/default_application/models/default.rb +13 -0
- data/verify/foundations/default_application/models/loaded.rb +13 -0
- data/verify/foundations/default_application/schema/migrations/templates/empty.rb.erb +9 -0
- data/verify/foundations/default_application/startup.rb +7 -0
- data/verify/foundations/default_application/templates/errors/not_found_404.mab +2 -0
- data/verify/foundations/default_application/templates/errors/server_error_500.mab +2 -0
- data/verify/foundations/default_application/templates/layouts/default.mab +14 -0
- data/verify/foundations/default_application/views/default.rb +7 -0
- data/verify/foundations/default_application/views/loaded.rb +15 -0
- data/verify/foundations/helpers.rb +1 -0
- data/verify/foundations/simple.rb +25 -0
- data/verify/helpers.rb +76 -0
- data/verify/layers/data_mapper/association_verify.rb +87 -0
- data/verify/layers/default_errors.rb +29 -0
- data/verify/layers/helpers.rb +1 -0
- data/verify/layers/migration.rb +33 -0
- data/verify/layers/sequel/model.rb +41 -0
- data/verify/mapping/always.rb +19 -0
- data/verify/mapping/filters.rb +65 -0
- data/verify/mapping/handle.rb +24 -0
- data/verify/mapping/helpers.rb +7 -0
- data/verify/mapping/matches.rb +27 -0
- data/verify/mapping/named.rb +29 -0
- data/verify/mapping/options.rb +17 -0
- data/verify/mapping/path.rb +40 -0
- data/verify/mapping/response_proxy.rb +50 -0
- data/verify/mapping/threaded.rb +25 -0
- data/verify/requests/helpers.rb +16 -0
- data/verify/requests/request.rb +73 -0
- data/verify/requests/response.rb +59 -0
- data/verify/requests/session.rb +54 -0
- data/verify/views/helpers.rb +1 -0
- data/verify/views/rendering.rb +34 -0
- data/verify/views/templates/foo.erb +0 -0
- data/verify/views/templates/moo.erb +0 -0
- data/verify/views/templates/moo.mab +0 -0
- metadata +439 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
module Waves
|
2
|
+
|
3
|
+
# Helper methods can be defined for any view template by simply defining them within the default Helper module in <tt>helpers/default.rb</tt> of the generated application. Helpers specific to a particular View class can be explicitly defined by creating a helper module that corresponds to the View class. For examples, for the +User+ View class, you would define a helper module in <tt>user.rb</tt> named +User+.
|
4
|
+
#
|
5
|
+
# The default helper class initially includes a wide-variety of helpers, including helpers for layouts, Textile formatting, rendering forms, and nested views, as well as helpers for accessing the request and response objects. More helpers will be added in future releases, but in many cases, there is no need to include all of them in your application.
|
6
|
+
module Helpers
|
7
|
+
|
8
|
+
# Common helpers are helpers that are needed for just about any Web page. For example,
|
9
|
+
# each page will likely have a layout and a doctype.
|
10
|
+
|
11
|
+
module Common
|
12
|
+
|
13
|
+
DOCTYPES = {
|
14
|
+
:html3 => "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n",
|
15
|
+
:html4_transitional =>
|
16
|
+
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " <<
|
17
|
+
"\"http://www.w3.org/TR/html4/loose.dtd\">\n",
|
18
|
+
:html4_strict =>
|
19
|
+
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" " <<
|
20
|
+
"\"http://www.w3.org/TR/html4/strict.dtd\">\n",
|
21
|
+
:html4_frameset =>
|
22
|
+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" " <<
|
23
|
+
"\"http://www.w3.org/TR/html4/frameset.dtd\">\n",
|
24
|
+
:xhtml1_transitional =>
|
25
|
+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " <<
|
26
|
+
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n",
|
27
|
+
:xhtml1_strict =>
|
28
|
+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " <<
|
29
|
+
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n",
|
30
|
+
:xhtml1_frameset =>
|
31
|
+
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" " <<
|
32
|
+
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n",
|
33
|
+
:xhtml2 => "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
|
34
|
+
}
|
35
|
+
|
36
|
+
# Invokes a layout view (i.e., a view from the layouts template directory), using
|
37
|
+
# the assigns parameter to define instance variables for the view. The block is
|
38
|
+
# evaluated and also passed into the view as the +layout_content+ instance variable.
|
39
|
+
#
|
40
|
+
# You can define a layout just by creating a template and then calling the
|
41
|
+
# +layout_content+ accessor when you want to embed the caller's content.
|
42
|
+
#
|
43
|
+
# == Example
|
44
|
+
#
|
45
|
+
# doctype :html4_transitional
|
46
|
+
# html do
|
47
|
+
# title @title # passed as an assigns parameter
|
48
|
+
# end
|
49
|
+
# body do
|
50
|
+
# layout_content
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
def layout( name, assigns = {}, &block )
|
54
|
+
assigns[ :layout_content ] = capture(&block)
|
55
|
+
self << Waves.application.views[:layouts].process( request ) do
|
56
|
+
send( name, assigns )
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# The doctype method simply generates a valid DOCTYPE declaration for your page.
|
61
|
+
# Valid options are defined in the +DOCTYPES+ constant.
|
62
|
+
def doctype(type) ; self << DOCTYPES[type||:html4_strict] ; end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Waves
|
2
|
+
module Helpers
|
3
|
+
module Default
|
4
|
+
attr_reader :request, :content
|
5
|
+
include Waves::ResponseMixin
|
6
|
+
include Waves::Helpers::Common
|
7
|
+
include Waves::Helpers::Formatting
|
8
|
+
include Waves::Helpers::Model
|
9
|
+
include Waves::Helpers::View
|
10
|
+
include Waves::Helpers::Form
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/helpers/form.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Waves
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
# Form helpers are used in generating forms. Since Markaby already provides Ruby
|
6
|
+
# methods for basic form generation, the focus of this helper is on providing templates
|
7
|
+
# to handle things that go beyond the basics. You must define a form template
|
8
|
+
# directory with templates for each type of form element you wish to use. The names
|
9
|
+
# of the template should match the +type+ option provided in the property method.
|
10
|
+
#
|
11
|
+
# For example, this code:
|
12
|
+
#
|
13
|
+
# property :name => 'blog.title', :type => :text, :value => @blog.title
|
14
|
+
#
|
15
|
+
# will invoke the +text+ form view (the template in +templates/form/text.mab+),
|
16
|
+
# passing in the name ('blog.title') and the value (@blog.title) as instance variables.
|
17
|
+
#
|
18
|
+
# These helpers are Markaby only.
|
19
|
+
module Form
|
20
|
+
|
21
|
+
# This method really is a place-holder for common wrappers around groups of
|
22
|
+
# properties. You will usually want to override this. As is, it simply places
|
23
|
+
# a DIV element with class 'properties' around the block.
|
24
|
+
def properties(&block)
|
25
|
+
div.properties do
|
26
|
+
yield
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Invokes the form view for the +type+ given in the option.
|
31
|
+
def property( options )
|
32
|
+
self << view( :form, options[:type], options )
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'redcloth'
|
2
|
+
module Waves
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
# Formatting helpers are used to convert specialized content, like Markaby or
|
6
|
+
# Textile, into valid HTML. It also provides common escaping functions.
|
7
|
+
module Formatting
|
8
|
+
|
9
|
+
# Escape a string as HTML content.
|
10
|
+
def escape_html(s); Rack::Utils.escape_html(s); end
|
11
|
+
|
12
|
+
# Escape a URI, converting quotes and spaces and so on.
|
13
|
+
def escape_uri(s); Rack::Utils.escape(s); end
|
14
|
+
|
15
|
+
# Treat content as Markaby and evaluate (only works within a Markaby template).
|
16
|
+
# Used to pull Markaby content from a file or database into a Markaby template.
|
17
|
+
def markaby( content ); self << eval( content ); end
|
18
|
+
|
19
|
+
# Treat content as Textile.
|
20
|
+
def textile( content )
|
21
|
+
return if content.nil? or content.empty?
|
22
|
+
( ::RedCloth::TEXTILE_TAGS << [ 96.chr, '&8216;'] ).each do |pat,ent|
|
23
|
+
content.gsub!( pat, ent.gsub('&','&#') )
|
24
|
+
end
|
25
|
+
self << ::RedCloth.new( content ).to_html
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Waves
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
# Model helpers allow you to directly access a model from within a view.
|
5
|
+
# This is useful when creating things like select boxes that need data
|
6
|
+
# from anther model. For example, a Markaby select box for authors might look like:
|
7
|
+
#
|
8
|
+
# select do
|
9
|
+
# all(:user).each do |user|
|
10
|
+
# option user.full_name, :value => user.id
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# You could also use these within a view class to keep model-based logic out
|
15
|
+
# of the templates themselves. For example, in the view class you might define
|
16
|
+
# a method called +authors+ that returns an array of name / id pairs. This could
|
17
|
+
# then be called from the template instead of the model helper.
|
18
|
+
#
|
19
|
+
module Model
|
20
|
+
|
21
|
+
# Just like model.all. Returns all the instances of that model.
|
22
|
+
def all( model )
|
23
|
+
Waves.application.models[ model ].all( domain )
|
24
|
+
end
|
25
|
+
|
26
|
+
# Finds a specific instance using the name field
|
27
|
+
def find( model, name )
|
28
|
+
Waves.application.models[ model ][ :name => name ] rescue nil
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Waves
|
2
|
+
module Helpers
|
3
|
+
module NumberHelper
|
4
|
+
|
5
|
+
# Formats a +number+ with grouped thousands using +delimiter+. You
|
6
|
+
# can customize the format in the +options+ hash.
|
7
|
+
# * <tt>:delimiter</tt> - Sets the thousands delimiter, defaults to ","
|
8
|
+
# * <tt>:separator</tt> - Sets the separator between the units, defaults to "."
|
9
|
+
#
|
10
|
+
# number_with_delimiter(12345678) => 12,345,678
|
11
|
+
# number_with_delimiter(12345678.05) => 12,345,678.05
|
12
|
+
# number_with_delimiter(12345678, :delimiter => ".") => 12.345.678
|
13
|
+
def number_with_delimiter(number, delimiter=",", separator=".")
|
14
|
+
begin
|
15
|
+
parts = number.to_s.split(separator)
|
16
|
+
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
|
17
|
+
parts.join separator
|
18
|
+
rescue
|
19
|
+
number
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Waves
|
2
|
+
module Helpers
|
3
|
+
module TagHelper
|
4
|
+
|
5
|
+
ESCAPE_TABLE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
|
6
|
+
def h(value)
|
7
|
+
value.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] }
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns an empty HTML tag of type +name+ which by default is XHTML
|
11
|
+
# compliant. Setting +open+ to true will create an open tag compatible
|
12
|
+
# with HTML 4.0 and below. Add HTML attributes by passing an attributes
|
13
|
+
# hash to +options+. For attributes with no value like (disabled and
|
14
|
+
# readonly), give it a value of true in the +options+ hash. You can use
|
15
|
+
# symbols or strings for the attribute names.
|
16
|
+
#
|
17
|
+
# tag("br")
|
18
|
+
# # => <br />
|
19
|
+
# tag("br", nil, true)
|
20
|
+
# # => <br>
|
21
|
+
# tag("input", { :type => 'text', :disabled => true })
|
22
|
+
# # => <input type="text" disabled="disabled" />
|
23
|
+
def tag(name, options = nil, open = false)
|
24
|
+
"<#{name}#{tag_options(options) if options}" + (open ? ">" : " />")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the escaped +html+ without affecting existing escaped entities.
|
28
|
+
#
|
29
|
+
# escape_once("1 > 2 & 3")
|
30
|
+
# # => "1 < 2 & 3"
|
31
|
+
def escape_once(html)
|
32
|
+
fix_double_escape(h(html.to_s))
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def tag_options(options)
|
38
|
+
cleaned_options = convert_booleans(options.stringify_keys.reject {|key, value| value.nil?})
|
39
|
+
' ' + cleaned_options.map {|key, value| %(#{key}="#{escape_once(value)}")}.sort * ' ' unless cleaned_options.empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def convert_booleans(options)
|
43
|
+
%w( disabled readonly multiple ).each { |a| boolean_attribute(options, a) }
|
44
|
+
options
|
45
|
+
end
|
46
|
+
|
47
|
+
def boolean_attribute(options, attribute)
|
48
|
+
options[attribute] ? options[attribute] = attribute : options.delete(attribute)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Fix double-escaped entities, such as &amp;, &#123;, etc.
|
52
|
+
def fix_double_escape(escaped)
|
53
|
+
escaped.gsub(/&([a-z]+|(#\d+));/i) { "&#{$1};" }
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Waves
|
2
|
+
module Helpers
|
3
|
+
module UrlHelper
|
4
|
+
|
5
|
+
# Returns the URL for the set of +options+ provided. This takes the
|
6
|
+
# same options as url_for in action controller. For a list, see the
|
7
|
+
# documentation for ActionController::Base#url_for. Note that it'll
|
8
|
+
# set :only_path => true so you'll get the relative /controller/action
|
9
|
+
# instead of the fully qualified http://example.com/controller/action.
|
10
|
+
#
|
11
|
+
# When called from a view, url_for returns an HTML escaped url. If you
|
12
|
+
# need an unescaped url, pass :escape => false in the +options+.
|
13
|
+
def url_for(options = {}, *parameters_for_method_reference)
|
14
|
+
if options.kind_of? Hash
|
15
|
+
options = { :only_path => true }.update(options.symbolize_keys)
|
16
|
+
escape = options.key?(:escape) ? options.delete(:escape) : true
|
17
|
+
else
|
18
|
+
escape = true
|
19
|
+
end
|
20
|
+
|
21
|
+
url = options[:url] #@controller.send(:url_for, options, *parameters_for_method_reference)
|
22
|
+
escape ? html_escape(url) : url
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Creates a link tag of the given +name+ using a URL created by the set
|
27
|
+
# of +options+. See the valid options in the documentation for
|
28
|
+
# ActionController::Base#url_for. It's also possible to pass a string instead
|
29
|
+
# of an options hash to get a link tag that uses the value of the string as the
|
30
|
+
# href for the link. If nil is passed as a name, the link itself will become
|
31
|
+
# the name.
|
32
|
+
#
|
33
|
+
# The +html_options+ will accept a hash of html attributes for the link tag.
|
34
|
+
# It also accepts 3 modifiers that specialize the link behavior.
|
35
|
+
#
|
36
|
+
# * <tt>:confirm => 'question?'</tt>: This will add a JavaScript confirm
|
37
|
+
# prompt with the question specified. If the user accepts, the link is
|
38
|
+
# processed normally, otherwise no action is taken.
|
39
|
+
# * <tt>:popup => true || array of window options</tt>: This will force the
|
40
|
+
# link to open in a popup window. By passing true, a default browser window
|
41
|
+
# will be opened with the URL. You can also specify an array of options
|
42
|
+
# that are passed-thru to JavaScripts window.open method.
|
43
|
+
# * <tt>:method => symbol of HTTP verb</tt>: This modifier will dynamically
|
44
|
+
# create an HTML form and immediately submit the form for processing using
|
45
|
+
# the HTTP verb specified. Useful for having links perform a POST operation
|
46
|
+
# in dangerous actions like deleting a record (which search bots can follow
|
47
|
+
# while spidering your site). Supported verbs are :post, :delete and :put.
|
48
|
+
# Note that if the user has JavaScript disabled, the request will fall back
|
49
|
+
# to using GET. If you are relying on the POST behavior, your should check
|
50
|
+
# for it in your controllers action by using the request objects methods
|
51
|
+
# for post?, delete? or put?.
|
52
|
+
#
|
53
|
+
# You can mix and match the +html_options+ with the exception of
|
54
|
+
# :popup and :method which will raise an ActionView::ActionViewError
|
55
|
+
# exception.
|
56
|
+
#
|
57
|
+
# link_to "Visit Other Site", "http://www.rubyonrails.org/", :confirm => "Are you sure?"
|
58
|
+
# link_to "Help", { :action => "help" }, :popup => true
|
59
|
+
# link_to "View Image", { :action => "view" }, :popup => ['new_window_name', 'height=300,width=600']
|
60
|
+
# link_to "Delete Image", { :action => "delete", :id => @image.id }, :confirm => "Are you sure?", :method => :delete
|
61
|
+
def link_to(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
62
|
+
if html_options
|
63
|
+
html_options = html_options.stringify_keys
|
64
|
+
# convert_options_to_javascript!(html_options)
|
65
|
+
tag_options = tag_options(html_options)
|
66
|
+
else
|
67
|
+
tag_options = nil
|
68
|
+
end
|
69
|
+
|
70
|
+
url = options.is_a?(String) ? options : self.url_for(options, *parameters_for_method_reference)
|
71
|
+
"<a href=\"#{url}\"#{tag_options}>#{name || url}</a>"
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/helpers/view.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Waves
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
# View helpers are intended to help reuse views from within other views.
|
5
|
+
# Both the +layout+ method in the common helpers and the +property+ method
|
6
|
+
# of the form helpers are specialized instance of this.
|
7
|
+
#
|
8
|
+
# The star of our show here is the +view+ method. This takes a model, view,
|
9
|
+
# and assigns hash (which are converted into instance variables in the target
|
10
|
+
# view) and returns the result of evaluating the view as content in the current
|
11
|
+
# template.
|
12
|
+
module View
|
13
|
+
|
14
|
+
# Invokes the view for the given model, passing the assigns as instance variables.
|
15
|
+
def view( model, view, assigns = {} )
|
16
|
+
self << Waves.application.views[ model ].process( request ) do
|
17
|
+
send( view, assigns )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Waves
|
2
|
+
module Layers
|
3
|
+
|
4
|
+
# Configures Waves to use the templates in app/templates/errors for exception handling
|
5
|
+
module DefaultErrors
|
6
|
+
|
7
|
+
def self.included( app )
|
8
|
+
|
9
|
+
app.auto_eval :Configurations do
|
10
|
+
auto_eval :Mapping do
|
11
|
+
extend Waves::Mapping
|
12
|
+
handle(Waves::Dispatchers::NotFoundError) do
|
13
|
+
html = Waves.application.views[:errors].process( request ) do
|
14
|
+
not_found_404( :error => Waves::Dispatchers::NotFoundError )
|
15
|
+
end
|
16
|
+
response.status = '404'
|
17
|
+
response.content_type = 'text/html'
|
18
|
+
response.body = html
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'layers/inflect/english/rules'
|
2
|
+
require 'layers/inflect/english/string'
|
3
|
+
module Waves
|
4
|
+
module Layers
|
5
|
+
module Inflect
|
6
|
+
module English
|
7
|
+
|
8
|
+
def self.included(app)
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
String.class_eval do
|
13
|
+
include Waves::Layers::Inflect::English::StringMethods
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Waves
|
2
|
+
module Layers
|
3
|
+
module Inflect
|
4
|
+
module English
|
5
|
+
# Extends Waves::Inflect::InflectorMethods
|
6
|
+
module Rules
|
7
|
+
|
8
|
+
extend Waves::Inflect::InflectorMethods
|
9
|
+
|
10
|
+
# One argument means singular and plural are the same.
|
11
|
+
word 'equipment'
|
12
|
+
word 'information'
|
13
|
+
word 'money'
|
14
|
+
word 'species'
|
15
|
+
word 'series'
|
16
|
+
word 'fish'
|
17
|
+
word 'sheep'
|
18
|
+
word 'moose'
|
19
|
+
word 'hovercraft'
|
20
|
+
|
21
|
+
# Two arguments defines a singular and plural exception.
|
22
|
+
word 'Swiss' , 'Swiss'
|
23
|
+
word 'life' , 'lives'
|
24
|
+
word 'wife' , 'wives'
|
25
|
+
word 'cactus' , 'cacti'
|
26
|
+
word 'goose' , 'geese'
|
27
|
+
word 'criterion' , 'criteria'
|
28
|
+
word 'alias' , 'aliases'
|
29
|
+
word 'status' , 'statuses'
|
30
|
+
word 'axis' , 'axes'
|
31
|
+
word 'crisis' , 'crises'
|
32
|
+
word 'testis' , 'testes'
|
33
|
+
word 'child' , 'children'
|
34
|
+
word 'person' , 'people'
|
35
|
+
word 'potato' , 'potatoes'
|
36
|
+
word 'tomato' , 'tomatoes'
|
37
|
+
word 'buffalo' , 'buffaloes'
|
38
|
+
word 'torpedo' , 'torpedoes'
|
39
|
+
word 'quiz' , 'quizes'
|
40
|
+
word 'matrix' , 'matrices'
|
41
|
+
word 'vertex' , 'vetices'
|
42
|
+
word 'index' , 'indices'
|
43
|
+
word 'ox' , 'oxen'
|
44
|
+
word 'mouse' , 'mice'
|
45
|
+
word 'louse' , 'lice'
|
46
|
+
word 'thesis' , 'theses'
|
47
|
+
word 'thief' , 'thieves'
|
48
|
+
word 'analysis' , 'analyses'
|
49
|
+
|
50
|
+
# One-way singularization exception (convert plural to singular).
|
51
|
+
singular_word 'cactus', 'cacti'
|
52
|
+
|
53
|
+
# General rules.
|
54
|
+
rule 'hive' , 'hives'
|
55
|
+
rule 'rf' , 'rves'
|
56
|
+
rule 'af' , 'aves'
|
57
|
+
rule 'ero' , 'eroes'
|
58
|
+
rule 'man' , 'men'
|
59
|
+
rule 'ch' , 'ches'
|
60
|
+
rule 'sh' , 'shes'
|
61
|
+
rule 'ss' , 'sses'
|
62
|
+
rule 'ta' , 'tum'
|
63
|
+
rule 'ia' , 'ium'
|
64
|
+
rule 'ra' , 'rum'
|
65
|
+
rule 'ay' , 'ays'
|
66
|
+
rule 'ey' , 'eys'
|
67
|
+
rule 'oy' , 'oys'
|
68
|
+
rule 'uy' , 'uys'
|
69
|
+
rule 'y' , 'ies'
|
70
|
+
rule 'x' , 'xes'
|
71
|
+
rule 'lf' , 'lves'
|
72
|
+
rule 'us' , 'uses'
|
73
|
+
rule '' , 's'
|
74
|
+
|
75
|
+
# One-way singular rules.
|
76
|
+
singular_rule 'of' , 'ofs' # proof
|
77
|
+
singular_rule 'o' , 'oes' # hero, heroes
|
78
|
+
singular_rule 'f' , 'ves'
|
79
|
+
|
80
|
+
# One-way plural rules.
|
81
|
+
plural_rule 'fe' , 'ves' # safe, wife
|
82
|
+
plural_rule 's' , 'ses'
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|