waw 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENCE.rdoc +25 -0
- data/README.rdoc +32 -0
- data/bin/waw +32 -0
- data/bin/waw-profile +26 -0
- data/bin/waw-start +26 -0
- data/bin/wspec +33 -0
- data/layouts/empty/Rakefile +14 -0
- data/layouts/empty/config.ru +5 -0
- data/layouts/empty/config/commons.cfg +31 -0
- data/layouts/empty/config/devel.cfg +21 -0
- data/layouts/empty/ignore +7 -0
- data/layouts/empty/logs/dontforgetme +0 -0
- data/layouts/empty/resources/messages.rs +1 -0
- data/layouts/empty/test/wspec/site_respond.wspec +3 -0
- data/layouts/empty/test/wspec/test_all.rb +13 -0
- data/layouts/empty/waw.deploy +1 -0
- data/layouts/empty/waw.routing +6 -0
- data/layouts/static/dependencies +1 -0
- data/layouts/static/public/.wawaccess +18 -0
- data/layouts/static/public/css/style.css +0 -0
- data/layouts/static/public/images/dontforgetme +0 -0
- data/layouts/static/public/js/project.js +0 -0
- data/layouts/static/public/pages/.wawaccess +30 -0
- data/layouts/static/public/pages/404.wtpl +1 -0
- data/layouts/static/public/pages/index.wtpl +5 -0
- data/layouts/static/public/templates/.wawaccess +9 -0
- data/layouts/static/public/templates/layout.wtpl +17 -0
- data/layouts/static/test/wspec/static_pages_are_served.wspec +21 -0
- data/layouts/static/waw.routing +8 -0
- data/lib/waw.rb +99 -0
- data/lib/waw/commands/command.rb +115 -0
- data/lib/waw/commands/profile_command.rb +66 -0
- data/lib/waw/commands/start_command.rb +59 -0
- data/lib/waw/config.rb +110 -0
- data/lib/waw/controller.rb +25 -0
- data/lib/waw/controllers/action/action.rb +91 -0
- data/lib/waw/controllers/action/action_utils.rb +30 -0
- data/lib/waw/controllers/action/js_generation.rb +116 -0
- data/lib/waw/controllers/action_controller.rb +133 -0
- data/lib/waw/controllers/error/backtrace.rb +54 -0
- data/lib/waw/controllers/error_handler.rb +62 -0
- data/lib/waw/controllers/json_controller.rb +31 -0
- data/lib/waw/controllers/no_cache.rb +22 -0
- data/lib/waw/controllers/static/match.rb +80 -0
- data/lib/waw/controllers/static/waw_access.rb +235 -0
- data/lib/waw/controllers/static/waw_access_dsl.rb +48 -0
- data/lib/waw/controllers/static_controller.rb +37 -0
- data/lib/waw/default_config.cfg +14 -0
- data/lib/waw/environment_utils.rb +57 -0
- data/lib/waw/errors.rb +4 -0
- data/lib/waw/ext.rb +3 -0
- data/lib/waw/ext/core.rb +4 -0
- data/lib/waw/ext/core/hash.rb +47 -0
- data/lib/waw/ext/core/logger.rb +10 -0
- data/lib/waw/ext/core/module.rb +20 -0
- data/lib/waw/ext/core/object.rb +29 -0
- data/lib/waw/ext/rack.rb +19 -0
- data/lib/waw/ext/rack/builder.rb +43 -0
- data/lib/waw/ext/rack/delegator.rb +51 -0
- data/lib/waw/ext/rack/urlmap.rb +55 -0
- data/lib/waw/ext/wlang.rb +1 -0
- data/lib/waw/ext/wlang/hosted_language.rb +21 -0
- data/lib/waw/fullstate.rb +8 -0
- data/lib/waw/fullstate/on_class.rb +37 -0
- data/lib/waw/fullstate/on_instance.rb +27 -0
- data/lib/waw/fullstate/variable.rb +36 -0
- data/lib/waw/kern.rb +6 -0
- data/lib/waw/kern/app.rb +48 -0
- data/lib/waw/kern/empty/waw.deploy +0 -0
- data/lib/waw/kern/empty/waw.routing +1 -0
- data/lib/waw/kern/freezed_state.rb +32 -0
- data/lib/waw/kern/hooks.rb +53 -0
- data/lib/waw/kern/lifecycle.rb +248 -0
- data/lib/waw/kern/living_state.rb +87 -0
- data/lib/waw/kern/utils.rb +27 -0
- data/lib/waw/resource_collection.rb +100 -0
- data/lib/waw/restart.rb +32 -0
- data/lib/waw/routing.rb +43 -0
- data/lib/waw/routing/action_routing.rb +78 -0
- data/lib/waw/routing/dsl.rb +45 -0
- data/lib/waw/routing/feedback.rb +23 -0
- data/lib/waw/routing/form_validation_feedback.rb +36 -0
- data/lib/waw/routing/javascript.rb +17 -0
- data/lib/waw/routing/redirect.rb +26 -0
- data/lib/waw/routing/refresh.rb +17 -0
- data/lib/waw/routing/routing_rule.rb +16 -0
- data/lib/waw/scope_utils.rb +69 -0
- data/lib/waw/session.rb +51 -0
- data/lib/waw/testing.rb +1 -0
- data/lib/waw/tools/mail.rb +4 -0
- data/lib/waw/tools/mail/mail.rb +119 -0
- data/lib/waw/tools/mail/mail_agent.rb +123 -0
- data/lib/waw/tools/mail/mailbox.rb +62 -0
- data/lib/waw/tools/mail/template.rb +38 -0
- data/lib/waw/utils/dsl_helper.rb +116 -0
- data/lib/waw/validation.rb +175 -0
- data/lib/waw/validation/and_validator.rb +27 -0
- data/lib/waw/validation/array_validations.rb +38 -0
- data/lib/waw/validation/boolean_validator.rb +32 -0
- data/lib/waw/validation/comparison_validations.rb +45 -0
- data/lib/waw/validation/date_validator.rb +31 -0
- data/lib/waw/validation/default_validator.rb +30 -0
- data/lib/waw/validation/dsl_ruby_extensions.rb +11 -0
- data/lib/waw/validation/errors.rb +17 -0
- data/lib/waw/validation/ext.rb +3 -0
- data/lib/waw/validation/file_validator.rb +30 -0
- data/lib/waw/validation/float_validator.rb +19 -0
- data/lib/waw/validation/helpers.rb +67 -0
- data/lib/waw/validation/integer_validator.rb +16 -0
- data/lib/waw/validation/isin_validator.rb +24 -0
- data/lib/waw/validation/mandatory_validator.rb +17 -0
- data/lib/waw/validation/missing_validator.rb +17 -0
- data/lib/waw/validation/not_validator.rb +20 -0
- data/lib/waw/validation/or_validator.rb +34 -0
- data/lib/waw/validation/regexp_validator.rb +29 -0
- data/lib/waw/validation/same_validator.rb +16 -0
- data/lib/waw/validation/signature.rb +157 -0
- data/lib/waw/validation/size_validations.rb +44 -0
- data/lib/waw/validation/string_validator.rb +15 -0
- data/lib/waw/validation/validator.rb +48 -0
- data/lib/waw/wawgen.rb +2 -0
- data/lib/waw/wawgen/create.rb +166 -0
- data/lib/waw/wawgen/project.rb +25 -0
- data/lib/waw/wspec.rb +5 -0
- data/lib/waw/wspec/browser.rb +240 -0
- data/lib/waw/wspec/dsl.rb +201 -0
- data/lib/waw/wspec/html_analysis.rb +136 -0
- data/lib/waw/wspec/html_analysis/tag.rb +56 -0
- data/lib/waw/wspec/runner.rb +70 -0
- data/lib/waw/wspec/scenario.rb +35 -0
- data/lib/waw/wspec/suite.rb +54 -0
- data/test/bricks/error_handler/config/test.cfg +2 -0
- data/test/bricks/error_handler/logs/webapp.log +1411 -0
- data/test/bricks/error_handler/test/error_handler.wspec +16 -0
- data/test/bricks/error_handler/waw.deploy +1 -0
- data/test/bricks/error_handler/waw.routing +27 -0
- data/test/integration/waw_create_integration_test.rb +24 -0
- data/test/spec/assumptions_spec.rb +30 -0
- data/test/spec/controllers/action_controller_spec.rb +14 -0
- data/test/spec/controllers/static/waw_access_spec.rb +112 -0
- data/test/spec/environment_utils_spec.rb +15 -0
- data/test/spec/ext/core/hash_spec.rb +58 -0
- data/test/spec/fixtures.rb +41 -0
- data/test/spec/fixtures/action/config/default.cfg +2 -0
- data/test/spec/fixtures/action/lib/action_controller_test.rb +12 -0
- data/test/spec/fixtures/action/waw.deploy +1 -0
- data/test/spec/fixtures/action/waw.routing +6 -0
- data/test/spec/fixtures/empty/waw.deploy +0 -0
- data/test/spec/fixtures/empty/waw.routing +0 -0
- data/test/spec/fullstate/on_class_spec.rb +59 -0
- data/test/spec/fullstate/on_instance_spec.rb +59 -0
- data/test/spec/fullstate/session_spec.rb +43 -0
- data/test/spec/fullstate/variable_spec.rb +55 -0
- data/test/spec/resource_collection_spec.rb +50 -0
- data/test/spec/test_all.rb +9 -0
- data/test/spec/tools/mail/mail_agent_spec.rb +116 -0
- data/test/spec/tools/mail/mail_spec.rb +56 -0
- data/test/spec/tools/mail/mailbox_spec.rb +57 -0
- data/test/spec/tools/mail/template_spec.rb +47 -0
- data/test/spec/validation/array_validation_spec.rb +63 -0
- data/test/spec/validation/array_validator_spec.rb +17 -0
- data/test/spec/validation/date_validation_spec.rb +35 -0
- data/test/spec/validation/default_validation_spec.rb +37 -0
- data/test/spec/validation/disjuctive_validation_spec.rb +33 -0
- data/test/spec/validation/errors_spec.rb +37 -0
- data/test/spec/validation/file_validator_spec.rb +34 -0
- data/test/spec/validation/mail_validation_spec.rb +51 -0
- data/test/spec/validation/missing_validation_spec.rb +43 -0
- data/test/spec/validation/same_validation_spec.rb +24 -0
- data/test/spec/validation/signature_intuition_spec.rb +37 -0
- data/test/spec/validation/signature_spec.rb +164 -0
- data/test/spec/validation/validation_spec.rb +28 -0
- data/test/spec/wspec/html_analysis/tag_spec.rb +38 -0
- data/test/spec/wspec/html_analysis_spec.rb +170 -0
- data/test/unit/test_all.rb +8 -0
- data/test/unit/waw/app_test.rb +126 -0
- data/test/unit/waw/app_test/config/commons.cfg +2 -0
- data/test/unit/waw/app_test/config/devel.cfg +1 -0
- data/test/unit/waw/config_test.rb +54 -0
- data/test/unit/waw/controllers/action_controller_test.rb +76 -0
- data/test/unit/waw/controllers/action_test.rb +35 -0
- data/test/unit/waw/controllers/example_action_controller_test.rb +24 -0
- data/test/unit/waw/controllers/multiple_action_controller_test.rb +78 -0
- data/test/unit/waw/controllers/static/example/css/example.css +1 -0
- data/test/unit/waw/controllers/static/example/index.html +1 -0
- data/test/unit/waw/controllers/static/example/js/example.js +1 -0
- data/test/unit/waw/controllers/static/example/pages/hello.wtpl +1 -0
- data/test/unit/waw/controllers/static/waw_access_test.rb +76 -0
- data/test/unit/waw/ext/rack_test.rb +74 -0
- data/test/unit/waw/resource_collection_test.rb +49 -0
- data/test/unit/waw/resources.txt +4 -0
- data/test/unit/waw/routing/routing_test.rb +26 -0
- data/test/unit/waw/utils/dsl_helper_test.rb +79 -0
- data/test/unit/waw/utils/dsl_helper_test_extensions1.rb +4 -0
- data/test/unit/waw/validation/signature_test.rb +193 -0
- data/test/unit/waw/validation_test.rb +319 -0
- data/test/unit/waw/wspec/html_analysis_test.html +81 -0
- data/test/unit/waw/wspec/html_analysis_test.rb +26 -0
- metadata +272 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
module Waw
|
2
|
+
module Kern
|
3
|
+
#
|
4
|
+
# Utilities of the waw kernel
|
5
|
+
#
|
6
|
+
module Utils
|
7
|
+
|
8
|
+
#
|
9
|
+
# Finds the root of the waw application by traversing the file system
|
10
|
+
# up from _from_ until a waw.deploy file can be found. Returns the
|
11
|
+
# root_folder that contains the waw.deploy file.
|
12
|
+
#
|
13
|
+
# This method raises a WawError if the waw.deploy file cannot be found.
|
14
|
+
#
|
15
|
+
def find_web_root(from)
|
16
|
+
web_root = File.expand_path(from)
|
17
|
+
from = File.dirname(from) if File.file?(from)
|
18
|
+
until File.exists?(File.join(web_root, 'waw.deploy')) or File.exists?(File.join(web_root, 'wawdeploy'))
|
19
|
+
web_root = File.expand_path(File.join(web_root, '..'))
|
20
|
+
raise WawError, "Unable to find waw.deploy file from folder #{from}" if web_root == '/'
|
21
|
+
end
|
22
|
+
web_root
|
23
|
+
end
|
24
|
+
|
25
|
+
end # module Utils
|
26
|
+
end # module Kern
|
27
|
+
end # module Waw
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Waw
|
2
|
+
# Localized resources
|
3
|
+
class ResourceCollection
|
4
|
+
|
5
|
+
# DSL for resources
|
6
|
+
class DSL
|
7
|
+
|
8
|
+
# Creates a DSL instance
|
9
|
+
def initialize(resources)
|
10
|
+
@resources = resources
|
11
|
+
end
|
12
|
+
|
13
|
+
# Adds a resource to the collection
|
14
|
+
def method_missing(name, *args, &block)
|
15
|
+
if args.length==0 and block.nil?
|
16
|
+
@resources.send(name)
|
17
|
+
elsif args.length==1 and block.nil?
|
18
|
+
@resources.send(:add_resource, name, args[0])
|
19
|
+
elsif args.length==0 and block
|
20
|
+
@resources.send(:add_resource, name, nil, &block)
|
21
|
+
elsif block
|
22
|
+
raise ArgumentError, "Bad resources usage on #{name} #{args.inspect} #{block.inspect}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end # class Resources
|
27
|
+
|
28
|
+
# Resource name
|
29
|
+
attr_reader :__name
|
30
|
+
|
31
|
+
# Creates a resource collection
|
32
|
+
def initialize(name = "unnamed")
|
33
|
+
@resources = {}
|
34
|
+
@__name = name
|
35
|
+
end
|
36
|
+
|
37
|
+
# Yields the block with each resource key,value pair
|
38
|
+
def each
|
39
|
+
@resources.each_pair {|k, v| yield(k, v)}
|
40
|
+
end
|
41
|
+
alias :each_pair :each
|
42
|
+
|
43
|
+
# Returns the resource installed under name
|
44
|
+
def [](name)
|
45
|
+
@resources[name]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Checks if a resource exists
|
49
|
+
def has_resource?(name)
|
50
|
+
@resources.has_key?(name)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Add a resource
|
54
|
+
def add_resource(name, value, &block)
|
55
|
+
if not(value.nil?) and block.nil?
|
56
|
+
@resources[name.to_s.to_sym] = value
|
57
|
+
self.instance_eval <<-EOF
|
58
|
+
def #{name}
|
59
|
+
@resources[:#{name}]
|
60
|
+
end
|
61
|
+
EOF
|
62
|
+
elsif value.nil? and not(block.nil?)
|
63
|
+
@resources[name.to_s.to_sym] = block
|
64
|
+
self.instance_eval <<-EOF
|
65
|
+
def #{name}
|
66
|
+
@resources[:#{name}].call(self)
|
67
|
+
end
|
68
|
+
EOF
|
69
|
+
else
|
70
|
+
raise ArgumentError, "ResourceCollection.add_resource expects one argument or a block"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Logs a friendly message and returns nil
|
75
|
+
def method_missing(name, *args)
|
76
|
+
if args.size==1
|
77
|
+
args[0]
|
78
|
+
elsif args.size==0
|
79
|
+
Waw.logger.warn("No such resource #{name} on #{@__name}, (#{caller[0]})")
|
80
|
+
nil
|
81
|
+
else
|
82
|
+
super
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Parses some resource string
|
87
|
+
def self.parse_resources(str, name = "unnamed")
|
88
|
+
r = ResourceCollection.new(name)
|
89
|
+
DSL.new(r).instance_eval str
|
90
|
+
r
|
91
|
+
end
|
92
|
+
|
93
|
+
# Parses a resource file
|
94
|
+
def self.parse_resource_file(f, name=File.basename(f, '.rs'))
|
95
|
+
parse_resources File.read(f), name
|
96
|
+
end
|
97
|
+
|
98
|
+
private :add_resource
|
99
|
+
end # class ResourceCollection
|
100
|
+
end # module Waw
|
data/lib/waw/restart.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Waw
|
2
|
+
class Restart
|
3
|
+
include ::Rack::Delegator
|
4
|
+
|
5
|
+
# Default options
|
6
|
+
DEFAULT_OPTIONS = { :when => :always }
|
7
|
+
|
8
|
+
# Creates a restarter instance
|
9
|
+
def initialize(app, opts = {}, lock = Mutex.new)
|
10
|
+
@options = DEFAULT_OPTIONS.merge(opts)
|
11
|
+
@app = app
|
12
|
+
@lock = lock
|
13
|
+
end
|
14
|
+
|
15
|
+
# Should I need to restart?
|
16
|
+
def restart?
|
17
|
+
@options[:when] == :always
|
18
|
+
end
|
19
|
+
|
20
|
+
# Handle the call
|
21
|
+
def call(env)
|
22
|
+
if restart?
|
23
|
+
@lock.synchronize do
|
24
|
+
root_folder = Waw.root_folder
|
25
|
+
Waw.reload
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@app.call(env)
|
29
|
+
end
|
30
|
+
|
31
|
+
end # class Restart
|
32
|
+
end # module Waw
|
data/lib/waw/routing.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'waw/routing/dsl'
|
2
|
+
require 'waw/routing/action_routing'
|
3
|
+
require 'waw/routing/routing_rule'
|
4
|
+
require 'waw/routing/feedback'
|
5
|
+
require 'waw/routing/form_validation_feedback'
|
6
|
+
require 'waw/routing/refresh'
|
7
|
+
require 'waw/routing/redirect'
|
8
|
+
require 'waw/routing/javascript'
|
9
|
+
module Waw
|
10
|
+
module Routing
|
11
|
+
module Methods
|
12
|
+
|
13
|
+
# Checks if a service response matches some expected pattern
|
14
|
+
def matches?(what, json_response = self)
|
15
|
+
raise ArgumentError, "Array expected as json_response (#{json_response.inspect} found)" unless Array===json_response
|
16
|
+
json_response = json_response.dup
|
17
|
+
what.split('/').each do |elm|
|
18
|
+
return false if json_response.empty?
|
19
|
+
case part = json_response.shift
|
20
|
+
when String, Symbol
|
21
|
+
if elm == '*'
|
22
|
+
# always ok here
|
23
|
+
else
|
24
|
+
return false unless part.to_s==elm.to_s
|
25
|
+
end
|
26
|
+
when Array
|
27
|
+
if elm == '*'
|
28
|
+
return false if part.empty?
|
29
|
+
else
|
30
|
+
return false unless part.any?{|e| e.to_s == elm.to_s} or (elm=='*')
|
31
|
+
end
|
32
|
+
else
|
33
|
+
raise ArgumentError, "Unexpected part in json_response #{part}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
true
|
37
|
+
end
|
38
|
+
alias :=~ :matches?
|
39
|
+
|
40
|
+
end # module Methods
|
41
|
+
extend Methods
|
42
|
+
end # module Routing
|
43
|
+
end # module Waw
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Waw
|
2
|
+
module Routing
|
3
|
+
|
4
|
+
#
|
5
|
+
# Routing rules installed on an action
|
6
|
+
#
|
7
|
+
class ActionRouting
|
8
|
+
|
9
|
+
# Creates an empty routing table. If a block is given, executes it
|
10
|
+
# as a Routing DSL
|
11
|
+
def initialize(&block)
|
12
|
+
@rules = {}
|
13
|
+
DSL.new(self).instance_eval(&block) if block
|
14
|
+
end
|
15
|
+
|
16
|
+
# Add some routing rules
|
17
|
+
def add_rules(action_results, exec)
|
18
|
+
action_results.each {|actr| @rules[actr] = exec}
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_js_if_then_else(table, key, level = 0, align = 0)
|
22
|
+
case table
|
23
|
+
when Hash
|
24
|
+
if table.size==1 and table.has_key?('*')
|
25
|
+
generate_js_if_then_else(table['*'], key, level, align)
|
26
|
+
else
|
27
|
+
first, buffer, space = true, "", " "
|
28
|
+
|
29
|
+
# normal table
|
30
|
+
table.each do |key, n|
|
31
|
+
next if key=='*'
|
32
|
+
code = "#{first ? space*align : ' else '}if (data[#{level}] == '#{key}') {\n" +
|
33
|
+
"#{generate_js_if_then_else(n, key, level+1, align+2)}\n" +
|
34
|
+
" "*align + "}"
|
35
|
+
first = false
|
36
|
+
buffer << code
|
37
|
+
end
|
38
|
+
|
39
|
+
if table.has_key?('*')
|
40
|
+
buffer << " else {\n"
|
41
|
+
buffer << generate_js_if_then_else(table['*'], key, level, align+1)
|
42
|
+
buffer << " "*align + "}"
|
43
|
+
end
|
44
|
+
|
45
|
+
buffer
|
46
|
+
end
|
47
|
+
when RoutingRule
|
48
|
+
table.generate_js_code(key, align)
|
49
|
+
else
|
50
|
+
raise "Unexpected table #{table}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Generates the javascript routing
|
55
|
+
def generate_js_routing(action, align=0)
|
56
|
+
# Build the if-then-else table
|
57
|
+
table = Hash.new {|h, k| h[k] = Hash.new}
|
58
|
+
@rules.each do |pattern, rule|
|
59
|
+
elements = pattern.split('/')
|
60
|
+
raise "Unsupport action-routing pattern #{pattern}" if elements.size==0 or elements.size>2
|
61
|
+
elements << '*' if elements.size == 1
|
62
|
+
table[elements[0]][elements[1]] = rule
|
63
|
+
end
|
64
|
+
|
65
|
+
# Build the javascript code now
|
66
|
+
generate_js_if_then_else(table, "", 0, align)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Applies this action routing on a browser
|
70
|
+
def apply_on_browser(result, browser)
|
71
|
+
@rules.each_pair do |pattern, rule|
|
72
|
+
rule.apply_on_browser(result, browser) if Waw::Routing.matches?(pattern, result)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end # class ActionRouting
|
77
|
+
end # module Routing
|
78
|
+
end # module Waw
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Waw
|
2
|
+
module Routing
|
3
|
+
# The DSL for routing blocks
|
4
|
+
class DSL
|
5
|
+
|
6
|
+
# Creates a DSL instance for some routing instance
|
7
|
+
def initialize(routing)
|
8
|
+
@routing = routing
|
9
|
+
end
|
10
|
+
|
11
|
+
# Evaluates the block as routing execution and installs it
|
12
|
+
# under all provided action results
|
13
|
+
def upon(*action_results)
|
14
|
+
raise ArgumentError, "Missing routing block on upon", caller unless block_given?
|
15
|
+
@routing.add_rules(action_results, yield)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Feedback routing execution
|
19
|
+
def feedback(*args)
|
20
|
+
Waw::Routing::Feedback.new(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Form validation feedback routing execution
|
24
|
+
def form_validation_feedback(*args)
|
25
|
+
Waw::Routing::FormValidationFeedback.new(*args)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Refresh routing execution
|
29
|
+
def refresh(*args)
|
30
|
+
Waw::Routing::Refresh.new(*args)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Redirect routing execution
|
34
|
+
def redirect(*args)
|
35
|
+
Waw::Routing::Redirect.new(*args)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Javascript routing execution
|
39
|
+
def javascript(*args)
|
40
|
+
Waw::Routing::Javascript.new(*args)
|
41
|
+
end
|
42
|
+
|
43
|
+
end # class DSL
|
44
|
+
end # module Routing
|
45
|
+
end # module Waw
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Waw
|
2
|
+
module Routing
|
3
|
+
# Feedback routing
|
4
|
+
class Feedback < RoutingRule
|
5
|
+
|
6
|
+
# Creates a feedback instance
|
7
|
+
def initialize(opts = {})
|
8
|
+
@opts = opts
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate_js_code(result, align=0)
|
12
|
+
selector = @opts[:css_selector] || '.feedback'
|
13
|
+
buffer = ""
|
14
|
+
buffer << " "*align + "$(form + ' input').hide();\n" if @opts[:hide_input]
|
15
|
+
buffer << " "*align + "$(form + ' #{selector}').show();\n"
|
16
|
+
message = @opts[:message] ? "'#{@opts[:message]}'" : 'data[1][0]'
|
17
|
+
buffer << " "*align + "$(form + ' #{selector}').html(messages[#{message}]);"
|
18
|
+
buffer
|
19
|
+
end
|
20
|
+
|
21
|
+
end # class Feedback
|
22
|
+
end # module Routing
|
23
|
+
end # module Waw
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Waw
|
2
|
+
module Routing
|
3
|
+
# FormValidationFeedback routing
|
4
|
+
class FormValidationFeedback < RoutingRule
|
5
|
+
|
6
|
+
def initialize(opts = {})
|
7
|
+
@options = opts
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_js_code(result, align=0)
|
11
|
+
buffer = ""
|
12
|
+
buffer << " "*align + "str = '';\n"
|
13
|
+
buffer << " "*align + "str += '<ul>';\n"
|
14
|
+
buffer << " "*align + "for (var k in data[1]) {\n"
|
15
|
+
buffer << " "*(align+2) + "str += '<li>' + messages[data[1][k]] + '</li>';\n"
|
16
|
+
buffer << " "*align + "}\n"
|
17
|
+
buffer << " "*align + "str += '</ul>';\n"
|
18
|
+
buffer << " "*align + "$(form + ' .feedback').show();\n"
|
19
|
+
buffer << " "*align + "$(form + ' .feedback').html(str);\n"
|
20
|
+
if @options[:scroll]
|
21
|
+
where = case @options[:scroll]
|
22
|
+
when :top
|
23
|
+
'0'
|
24
|
+
when :form
|
25
|
+
"$(form).offset().top"
|
26
|
+
when :feedback
|
27
|
+
"$(form + ' .feedback').offset().top"
|
28
|
+
end
|
29
|
+
buffer << "$('html, body').animate( { scrollTop: #{where} }, 'slow' );\n"
|
30
|
+
end
|
31
|
+
buffer
|
32
|
+
end
|
33
|
+
|
34
|
+
end # class FormValidationFeedback
|
35
|
+
end # module Routing
|
36
|
+
end # module Waw
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Waw
|
2
|
+
module Routing
|
3
|
+
# Javascript routing
|
4
|
+
class Javascript < RoutingRule
|
5
|
+
|
6
|
+
# Creates a javascript instance
|
7
|
+
def initialize(code)
|
8
|
+
@code = code
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate_js_code(result, align=0)
|
12
|
+
@code
|
13
|
+
end
|
14
|
+
|
15
|
+
end # class Javascript
|
16
|
+
end # module Routing
|
17
|
+
end # module Waw
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Waw
|
2
|
+
module Routing
|
3
|
+
# Redirect routing
|
4
|
+
class Redirect < RoutingRule
|
5
|
+
|
6
|
+
# Creates a redirection rule instance
|
7
|
+
def initialize(opts = {})
|
8
|
+
@opts = opts
|
9
|
+
end
|
10
|
+
|
11
|
+
# Forces the browser to refresh
|
12
|
+
def apply_on_browser(result, browser)
|
13
|
+
browser.location = @opts[:url]
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_js_code(result, align=0)
|
17
|
+
if @opts[:url]
|
18
|
+
" "*align + "window.location = \"#{@opts[:url]}\";"
|
19
|
+
else
|
20
|
+
" "*align + "window.location = data[1];"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end # class Redirect
|
25
|
+
end # module Routing
|
26
|
+
end # module Waw
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Waw
|
2
|
+
module Routing
|
3
|
+
# Refresh routing
|
4
|
+
class Refresh < RoutingRule
|
5
|
+
|
6
|
+
# Forces the browser to refresh
|
7
|
+
def apply_on_browser(result, browser)
|
8
|
+
browser.refresh
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate_js_code(result, align=0)
|
12
|
+
" "*align + "location.reload(true);"
|
13
|
+
end
|
14
|
+
|
15
|
+
end # class Refresh
|
16
|
+
end # module Routing
|
17
|
+
end # module Waw
|