alfa 0.0.1.pre → 0.0.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/assets/css/960gs/960.css +653 -0
- data/assets/css/960gs/960_12_col.css +357 -0
- data/assets/css/960gs/960_12_col_rtl.css +357 -0
- data/assets/css/960gs/960_16_col.css +446 -0
- data/assets/css/960gs/960_16_col_rtl.css +446 -0
- data/assets/css/960gs/960_24_col.css +621 -0
- data/assets/css/960gs/960_24_col_rtl.css +621 -0
- data/assets/css/960gs/960_rtl.css +653 -0
- data/assets/css/960gs/demo.css +55 -0
- data/assets/css/960gs/min/960.css +1 -0
- data/assets/css/960gs/min/960_12_col.css +1 -0
- data/assets/css/960gs/min/960_12_col_rtl.css +1 -0
- data/assets/css/960gs/min/960_16_col.css +1 -0
- data/assets/css/960gs/min/960_16_col_rtl.css +1 -0
- data/assets/css/960gs/min/960_24_col.css +1 -0
- data/assets/css/960gs/min/960_24_col_rtl.css +1 -0
- data/assets/css/960gs/min/960_rtl.css +1 -0
- data/assets/css/960gs/min/reset.css +1 -0
- data/assets/css/960gs/min/reset_rtl.css +1 -0
- data/assets/css/960gs/min/text.css +1 -0
- data/assets/css/960gs/min/text_rtl.css +1 -0
- data/assets/css/960gs/reset.css +211 -0
- data/assets/css/960gs/reset_rtl.css +211 -0
- data/assets/css/960gs/text.css +86 -0
- data/assets/css/960gs/text_rtl.css +86 -0
- data/assets/js/jquery/jquery-1.3.2.js +4376 -0
- data/assets/js/jquery/jquery-1.3.2.min.js +19 -0
- data/assets/js/jquery/jquery-1.4.2.js +6240 -0
- data/assets/js/jquery/jquery-1.4.2.min.js +154 -0
- data/assets/js/jquery/jquery-1.4.4.js +7179 -0
- data/assets/js/jquery/jquery-1.4.4.min.js +167 -0
- data/assets/js/jquery/jquery-1.8.2.js +9440 -0
- data/assets/js/jquery/jquery-1.8.2.min.js +2 -0
- data/assets/js/jquery/jquery-latest.js +2 -0
- data/assets/js/jquery/plugins/corner.js +178 -0
- data/assets/js/jquery/plugins/corner_12x.js +503 -0
- data/assets/js/jquery/plugins/datepick/calendar-green.gif +0 -0
- data/assets/js/jquery/plugins/datepick/calendar.gif +0 -0
- data/assets/js/jquery/plugins/datepick/datepickBasics.html +34 -0
- data/assets/js/jquery/plugins/datepick/flora.datepick.css +221 -0
- data/assets/js/jquery/plugins/datepick/humanity.datepick.css +192 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-ar.js +27 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-az.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-bg.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-ca.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-cs.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-da.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-de.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-el.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-eo.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-es.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-et.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-fa.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-fi.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-fr.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-he.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-hr.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-hu.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-hy.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-id.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-is.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-it.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-ja.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-ko.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-lt.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-lv.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-ms.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-nl.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-no.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-pl.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-pt-BR.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-ro.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-ru.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-sk.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-sl.js +27 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-sq.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-sr-SR.js +25 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-sr.js +25 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-sv.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-th.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-tr.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-uk.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-validation.js +141 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-validation.min.js +8 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-validation.pack.js +8 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-zh-CN.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick-zh-TW.js +26 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick.css +216 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick.ent +76 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick.js +1974 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick.min.js +8 -0
- data/assets/js/jquery/plugins/datepick/jquery.datepick.pack.js +8 -0
- data/assets/js/jquery/plugins/datepick/redmond.datepick.css +204 -0
- data/assets/js/jquery/plugins/datepick/smoothness.datepick.css +205 -0
- data/assets/js/jquery/plugins/fancybox/blank.gif +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_close.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_loading.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_nav_left.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_nav_right.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_shadow_e.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_shadow_n.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_shadow_ne.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_shadow_nw.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_shadow_s.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_shadow_se.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_shadow_sw.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_shadow_w.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_title_left.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_title_main.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_title_over.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancy_title_right.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancybox-x.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancybox-y.png +0 -0
- data/assets/js/jquery/plugins/fancybox/fancybox.png +0 -0
- data/assets/js/jquery/plugins/fancybox/jquery.easing-1.3.pack.js +72 -0
- data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.2.css +359 -0
- data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.2.js +1136 -0
- data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.2.pack.js +46 -0
- data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.4.css +359 -0
- data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.4.js +1156 -0
- data/assets/js/jquery/plugins/fancybox/jquery.fancybox-1.3.4.pack.js +46 -0
- data/assets/js/jquery/plugins/fancybox/jquery.mousewheel-3.0.4.pack.js +14 -0
- data/assets/js/jquery/plugins/jquery.cookie.js +96 -0
- data/assets/js/jquery/plugins/jquery.easing.1.3.js +205 -0
- data/assets/js/jquery/plugins/jquery.flash.js +288 -0
- data/assets/js/jquery/plugins/jquery.flash.min.js +1 -0
- data/assets/js/jquery/plugins/jquery.ifixpng.js +137 -0
- data/assets/js/jquery/plugins/jquery.mousewheel.js +84 -0
- data/assets/js/jquery/plugins/jquery.mousewheel.min.js +12 -0
- data/assets/js/jquery/plugins/jquery.numberformatter-1.2.2.js +486 -0
- data/assets/js/jquery/plugins/jquery.sifr.js +224 -0
- data/assets/js/jquery/plugins/jquery.sifr.min.js +1 -0
- data/assets/js/jquery/plugins/jquery.swfobject.js +1 -0
- data/assets/js/jquery/plugins/jquery.timers-1.1.2.js +147 -0
- data/assets/js/jquery/plugins/simplegallery.js +167 -0
- data/assets/js/jquery/ui/external/jquery.bgiframe-2.1.2.js +39 -0
- data/assets/js/jquery/ui/external/jquery.cookie.js +89 -0
- data/assets/js/jquery/ui/external/jquery.metadata.js +122 -0
- data/assets/js/jquery/ui/external/qunit.css +153 -0
- data/assets/js/jquery/ui/external/qunit.js +1261 -0
- data/assets/js/jquery/ui/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/assets/js/jquery/ui/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/assets/js/jquery/ui/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/assets/js/jquery/ui/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/assets/js/jquery/ui/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/assets/js/jquery/ui/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/assets/js/jquery/ui/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/assets/js/jquery/ui/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/assets/js/jquery/ui/images/ui-icons_222222_256x240.png +0 -0
- data/assets/js/jquery/ui/images/ui-icons_2e83ff_256x240.png +0 -0
- data/assets/js/jquery/ui/images/ui-icons_454545_256x240.png +0 -0
- data/assets/js/jquery/ui/images/ui-icons_888888_256x240.png +0 -0
- data/assets/js/jquery/ui/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/assets/js/jquery/ui/jquery-ui-latest.min.js +778 -0
- data/assets/js/jquery/ui/themes/base/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-icons_222222_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-icons_2e83ff_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-icons_454545_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-icons_888888_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/base/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.accordion.css +19 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.all.css +11 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.autocomplete.css +53 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.base.css +11 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.button.css +38 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.core.css +41 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.datepicker.css +68 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.dialog.css +21 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.progressbar.css +11 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.resizable.css +20 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.selectable.css +10 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.slider.css +24 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.tabs.css +18 -0
- data/assets/js/jquery/ui/themes/base/jquery.ui.theme.css +252 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery-ui-1.8.6.custom.css +572 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.accordion.css +19 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.all.css +11 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.autocomplete.css +53 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.base.css +11 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.button.css +38 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.core.css +41 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.datepicker.css +68 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.dialog.css +21 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.progressbar.css +11 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.resizable.css +20 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.selectable.css +10 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.slider.css +24 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.tabs.css +18 -0
- data/assets/js/jquery/ui/themes/smoothness/jquery.ui.theme.css +254 -0
- data/bin/alfa +15 -0
- data/lib/alfa/application.rb +36 -0
- data/lib/alfa/cli_application.rb +11 -3
- data/lib/alfa/commands/new.rb +4 -0
- data/lib/alfa/config.rb +11 -0
- data/lib/alfa/controller.rb +1 -1
- data/lib/alfa/database/mysql.rb +60 -8
- data/lib/alfa/database.rb +2 -1
- data/lib/alfa/logger.rb +38 -0
- data/lib/alfa/models/base.rb +1 -1
- data/lib/alfa/models/base_sql.rb +1 -1
- data/lib/alfa/models/dummy.rb +1 -1
- data/lib/alfa/models/mysql.rb +36 -26
- data/lib/alfa/models.rb +1 -1
- data/lib/alfa/query_logger.rb +29 -0
- data/lib/alfa/router.rb +155 -0
- data/lib/alfa/support.rb +58 -2
- data/lib/alfa/tfile.rb +97 -0
- data/lib/alfa/web_application.rb +106 -85
- data/lib/alfa.rb +1 -1
- data/lib/ruty/bugfix.rb +21 -0
- data/lib/ruty/tags/resources.rb +45 -2
- data/lib/ruty/upgrade.rb +61 -0
- data/test/data/test_router/config/routes.rb +4 -0
- data/test/test_alfa.rb +1 -52
- data/test/test_router.rb +132 -0
- data/test/test_support.rb +26 -0
- data/test/test_tfile.rb +186 -0
- metadata +259 -100
data/lib/alfa/web_application.rb
CHANGED
@@ -1,121 +1,142 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
require 'alfa/support'
|
2
3
|
require 'alfa/exceptions'
|
4
|
+
require 'alfa/application'
|
5
|
+
require 'alfa/tfile'
|
6
|
+
require 'alfa/controller'
|
7
|
+
require 'alfa/router'
|
3
8
|
require 'ruty'
|
9
|
+
require 'ruty/bugfix'
|
10
|
+
require 'ruty/upgrade'
|
4
11
|
require 'ruty/tags/resources'
|
5
12
|
|
6
13
|
Encoding.default_external='utf-8'
|
7
14
|
Encoding.default_internal='utf-8'
|
8
15
|
|
9
16
|
module Alfa
|
10
|
-
class WebApplication
|
17
|
+
class WebApplication < Alfa::Application
|
11
18
|
|
12
|
-
|
13
|
-
|
14
|
-
@env = env
|
15
|
-
begin
|
16
|
-
response_code = 200
|
17
|
-
route, params = self.find_route
|
18
|
-
c_sym = route[:options].has_key?(:controller) ? route[:options][:controller] : params[:controller]
|
19
|
-
a_sym = route[:options].has_key?(:action) ? route[:options][:action] : params[:action]
|
20
|
-
l_sym = route[:options].has_key?(:layout) ? route[:options][:layout] : :default
|
21
|
-
controller = self.invoke_controller(c_sym)
|
22
|
-
raise Alfa::RouteException404 unless controller.public_methods.include?(a_sym)
|
23
|
-
controller.__send__(a_sym)
|
24
|
-
data = controller._instance_variables_hash
|
25
|
-
Ruty::Tags::RequireStyle.clean_cache
|
26
|
-
content = self.render_template(File.join(c_sym.to_s, a_sym.to_s + '.tpl'), data)
|
27
|
-
body = self.render_layout(l_sym.to_s + '.tpl', {body: content})
|
28
|
-
rescue Alfa::RouteException404
|
29
|
-
response_code = 404
|
30
|
-
body = 'Url not found'
|
31
|
-
rescue Exception => e
|
32
|
-
response_code = 500
|
33
|
-
body = 'Error occured: ' + e.message + ' at ' + e.backtrace.first
|
34
|
-
end
|
35
|
-
headers = {
|
36
|
-
"Content-Type" => 'text/html; charset=utf-8',
|
37
|
-
}
|
38
|
-
[response_code, headers, [body]]
|
39
|
-
end
|
40
|
-
|
41
|
-
# set routes
|
42
|
-
def self.routes &block
|
43
|
-
@routes = []
|
44
|
-
class_eval &block
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
def self.route rule, options = {}
|
49
|
-
@routes << {:rule => rule, :options => options}
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
19
|
+
@namespaces_stack = []
|
20
|
+
@bputs = []
|
53
21
|
|
54
|
-
def self.
|
55
|
-
|
56
|
-
|
57
|
-
is_success, params = self.route_match? route[:rule], url
|
58
|
-
return route, params if is_success
|
22
|
+
def self.inherited subclass
|
23
|
+
instance_variables.each do |var|
|
24
|
+
subclass.instance_variable_set(var, instance_variable_get(var))
|
59
25
|
end
|
60
|
-
raise Alfa::RouteException404
|
61
26
|
end
|
62
27
|
|
28
|
+
def self.init!
|
29
|
+
Alfa::Router.set_apps_dir File.join(PROJECT_ROOT, 'apps')
|
30
|
+
require File.join(PROJECT_ROOT, 'config/routes')
|
31
|
+
super
|
32
|
+
end
|
63
33
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
34
|
+
# main rack routine
|
35
|
+
def self.call env
|
36
|
+
start_time = Time.now
|
37
|
+
response_code = nil # required for store context inside @logger.portion
|
38
|
+
headers = {} # required for store context inside @logger.portion
|
39
|
+
body = nil # required for store context inside @logger.portion
|
40
|
+
@logger.portion do |l|
|
41
|
+
@config[:db].each_value { |db| db.loggers = [l] }
|
42
|
+
@env = env
|
43
|
+
@bputs = []
|
44
|
+
headers = {"Content-Type" => 'text/html; charset=utf-8'}
|
45
|
+
t_sym = :default
|
46
|
+
begin
|
47
|
+
l.info "#{env['REQUEST_METHOD']} #{env['REQUEST_URI']} #{env['SERVER_PROTOCOL']} from #{env['REMOTE_ADDR']} at #{DateTime.now}"
|
48
|
+
#l.info " HTTP_HOST: #{env['HTTP_HOST']}"
|
49
|
+
#@logger.info " HTTP_ACCEPT: #{env['HTTP_ACCEPT']}"
|
50
|
+
#@logger.info " HTTP_ACCEPT_LANGUAGE: #{env['HTTP_ACCEPT_LANGUAGE']}"
|
51
|
+
#@logger.info " PATH_INFO: #{env['PATH_INFO']}"
|
52
|
+
response_code = 200
|
53
|
+
route, params = self.routes.find_route @env['PATH_INFO']
|
54
|
+
t_sym = route[:options].has_key?(:type) ? route[:options][:type] : :default
|
55
|
+
if t_sym == :asset
|
56
|
+
body = File.read(File.expand_path('../../../assets/' + params[:path], __FILE__))
|
57
|
+
case File.extname(params[:path]).downcase
|
58
|
+
when '.js'
|
59
|
+
headers = {'Content-Type' => 'application/javascript; charset=utf-8'}
|
60
|
+
when '.css'
|
61
|
+
headers = {'Content-Type' => 'text/css; charset=utf-8'}
|
62
|
+
else
|
63
|
+
end
|
79
64
|
else
|
80
|
-
|
81
|
-
|
65
|
+
app_sym = route[:options].has_key?(:app) ? route[:options][:app] : params[:app]
|
66
|
+
c_sym = route[:options].has_key?(:controller) ? route[:options][:controller] : params[:controller]
|
67
|
+
a_sym = route[:options].has_key?(:action) ? route[:options][:action] : params[:action]
|
68
|
+
l_sym = route[:options].has_key?(:layout) ? route[:options][:layout] : :default
|
69
|
+
controller = self.invoke_controller(app_sym, c_sym)
|
70
|
+
raise Alfa::RouteException404 unless controller.public_methods.include?(a_sym)
|
71
|
+
controller.__send__(a_sym)
|
72
|
+
data = controller._instance_variables_hash
|
73
|
+
Ruty::Tags::RequireStyle.clean_cache
|
74
|
+
content = self.render_template(app_sym.to_s, File.join(c_sym.to_s, a_sym.to_s + '.tpl'), data)
|
75
|
+
body = self.render_layout(app_sym.to_s, l_sym.to_s + '.tpl', {body: content})
|
76
|
+
headers = {"Content-Type" => 'text/html; charset=utf-8'}
|
82
77
|
end
|
78
|
+
rescue Alfa::RouteException404 => e
|
79
|
+
response_code = 404
|
80
|
+
body = 'Url not found<br>urls map:<br>'
|
81
|
+
body += self.routes.instance_variable_get(:@routes).inspect
|
82
|
+
l.info "404: Url not found (#{e.message})"
|
83
|
+
rescue Exception => e
|
84
|
+
response_code = 500
|
85
|
+
body = "Error occured: #{e.message} at #{e.backtrace.first}<br>Full backtrace:<br>#{e.backtrace.join("<br>")}"
|
83
86
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
return false, {}
|
87
|
+
if t_sym == :default
|
88
|
+
#debug_info = '<hr>Queries:<br>' + @logger.logs.map { |log|
|
89
|
+
# r = "#{log[:num]}: #{log[:query]} | #{log[:status]}"
|
90
|
+
# r += ", error: #{log[:error]}" if log[:status] == :fail
|
91
|
+
# r += ", logger hash: #{log[:logger_hash]}"
|
92
|
+
# r
|
93
|
+
#}.join('<br>')
|
94
|
+
debug_info = "<hr>rack env: #{env.inspect}"
|
93
95
|
end
|
96
|
+
l.info "RESPONSE: #{response_code} (#{sprintf('%.4f', Time.now - start_time)} sec)"
|
97
|
+
l << "\n"
|
94
98
|
end
|
99
|
+
@log_file.flush
|
100
|
+
#@logger = nil
|
101
|
+
return [response_code, headers, [body, @bputs.join('<br>')]]
|
102
|
+
end
|
103
|
+
|
104
|
+
# router
|
105
|
+
def self.routes
|
106
|
+
@router ||= Alfa::Router
|
95
107
|
end
|
96
108
|
|
97
109
|
|
98
|
-
def self.
|
110
|
+
def self.bputs arg
|
111
|
+
@bputs << "#{arg}\n"
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
# private section
|
116
|
+
|
117
|
+
def self.invoke_controller application, controller
|
99
118
|
@controllers ||= {}
|
100
|
-
|
101
|
-
|
102
|
-
@controllers[controller] ||= Kernel.const_get(Alfa::Support.capitalize_name(controller)+'Controller').new
|
103
|
-
@controllers[controller]
|
119
|
+
require File.join(PROJECT_ROOT, 'apps', application.to_s, 'controllers', controller.to_s)
|
120
|
+
@controllers[[application, controller]] ||= Kernel.const_get(Alfa::Support.capitalize_name(controller)+'Controller').new
|
104
121
|
end
|
105
122
|
|
106
|
-
def self.render_template template, data = {}
|
107
|
-
t = self.loader.get_template File.join('
|
123
|
+
def self.render_template app, template, data = {}
|
124
|
+
t = self.loader.get_template File.join(app, 'templates', template)
|
108
125
|
t.render data
|
109
126
|
end
|
110
127
|
|
111
|
-
def self.render_layout layout, data = {}
|
112
|
-
t = self.loader.get_template File.join('layouts', layout)
|
128
|
+
def self.render_layout app, layout, data = {}
|
129
|
+
t = self.loader.get_template File.join(app, 'layouts', layout)
|
113
130
|
t.render data
|
114
131
|
end
|
115
132
|
|
116
133
|
def self.loader
|
117
|
-
@loader ||= Ruty::Loaders::Filesystem.new(:dirname => File.join(PROJECT_ROOT, '
|
134
|
+
@loader ||= Ruty::Loaders::Filesystem.new(:dirname => File.join(PROJECT_ROOT, 'apps'))
|
118
135
|
end
|
119
136
|
|
120
137
|
end
|
121
|
-
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def bputs arg
|
141
|
+
Alfa::WebApplication.bputs arg
|
142
|
+
end
|
data/lib/alfa.rb
CHANGED
data/lib/ruty/bugfix.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Ruty
|
2
|
+
class Parser
|
3
|
+
# tokenize the sourcecode and return an array of tokens
|
4
|
+
def tokenize
|
5
|
+
result = Datastructure::TokenStream.new
|
6
|
+
@source.scan(TAG_REGEX).each do |match|
|
7
|
+
result << [:text, match[0]] if match[0] and not match[0].empty?
|
8
|
+
if data = match[1]
|
9
|
+
result << [:block, data.strip]
|
10
|
+
elsif data = match[2]
|
11
|
+
result << [:var, data.strip]
|
12
|
+
elsif data = match[3]
|
13
|
+
result << [:comment, data.strip]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
rest = $~ ? @source[$~.end(0)..-1] : @source
|
17
|
+
result << [:text, rest] if not rest.empty?
|
18
|
+
result.close
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/ruty/tags/resources.rb
CHANGED
@@ -5,13 +5,15 @@ class Ruty::Tags::RequireStyle < Ruty::Tag
|
|
5
5
|
def initialize parser, argstring
|
6
6
|
@@styles << argstring unless @@styles.include? argstring
|
7
7
|
end
|
8
|
+
def self.add path
|
9
|
+
@@styles << path unless @@styles.include? path
|
10
|
+
end
|
8
11
|
def self.clean_cache
|
9
12
|
@@styles = []
|
10
13
|
end
|
11
14
|
Ruty::Tags.register(self, :require_style)
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
17
|
class Ruty::Tags::Styles < Ruty::Tag
|
16
18
|
def initialize parser, argstring
|
17
19
|
end
|
@@ -23,11 +25,46 @@ class Ruty::Tags::Styles < Ruty::Tag
|
|
23
25
|
Ruty::Tags.register(self, :styles)
|
24
26
|
end
|
25
27
|
|
28
|
+
class Ruty::Tags::Require960gs < Ruty::Tag
|
29
|
+
@@styles = []
|
30
|
+
def initialize parser, argstring
|
31
|
+
Ruty::Tags::RequireStyle.add '/~assets/css/960gs/960.css'
|
32
|
+
end
|
33
|
+
Ruty::Tags.register(self, :require_960gs)
|
34
|
+
end
|
35
|
+
|
36
|
+
class Ruty::Tags::Require960gs24 < Ruty::Tag
|
37
|
+
@@styles = []
|
38
|
+
def initialize parser, argstring
|
39
|
+
case argstring
|
40
|
+
when 'text'
|
41
|
+
Ruty::Tags::RequireStyle.add '/~assets/css/960gs/text.css'
|
42
|
+
when 'reset'
|
43
|
+
Ruty::Tags::RequireStyle.add '/~assets/css/960gs/reset.css'
|
44
|
+
when 'full'
|
45
|
+
Ruty::Tags::RequireStyle.add '/~assets/css/960gs/reset.css'
|
46
|
+
Ruty::Tags::RequireStyle.add '/~assets/css/960gs/text.css'
|
47
|
+
else
|
48
|
+
end
|
49
|
+
Ruty::Tags::RequireStyle.add '/~assets/css/960gs/960_24_col.css'
|
50
|
+
end
|
51
|
+
Ruty::Tags.register(self, :require_960gs24)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
26
55
|
# SCRIPTS
|
27
56
|
|
28
57
|
# Require external script that must be included at bottom of page.
|
29
58
|
class Ruty::Tags::RequireScript < Ruty::Tag
|
59
|
+
@@scripts = []
|
30
60
|
def initialize parser, argstring
|
61
|
+
Ruty::Tags::RequireScript.add argstring
|
62
|
+
end
|
63
|
+
def self.add path
|
64
|
+
@@scripts << path unless @@scripts.include? path
|
65
|
+
end
|
66
|
+
def self.clean_cache
|
67
|
+
@@scripts = []
|
31
68
|
end
|
32
69
|
Ruty::Tags.register(self, :require_script)
|
33
70
|
end
|
@@ -43,6 +80,11 @@ end
|
|
43
80
|
class Ruty::Tags::Scripts < Ruty::Tag
|
44
81
|
def initialize parser, argstring
|
45
82
|
end
|
83
|
+
def render_node context, stream
|
84
|
+
Ruty::Tags::RequireScript.class_variable_get(:@@scripts).each do |file|
|
85
|
+
stream << "<script src=\"#{file}\"></script>\n"
|
86
|
+
end
|
87
|
+
end
|
46
88
|
Ruty::Tags.register(self, :scripts)
|
47
89
|
end
|
48
90
|
|
@@ -63,6 +105,7 @@ end
|
|
63
105
|
# Shortcut for jquery (required bottom)
|
64
106
|
class Ruty::Tags::RequireJquery < Ruty::Tag
|
65
107
|
def initialize parser, argstring
|
108
|
+
Ruty::Tags::RequireScript.add '/~assets/js/jquery/jquery-latest.js'
|
66
109
|
end
|
67
110
|
Ruty::Tags.register(self, :require_jquery)
|
68
111
|
end
|
@@ -72,4 +115,4 @@ class Ruty::Tags::RequireJqueryPlugin < Ruty::Tag
|
|
72
115
|
def initialize parser, argstring
|
73
116
|
end
|
74
117
|
Ruty::Tags.register(self, :require_jquery_plugin)
|
75
|
-
end
|
118
|
+
end
|
data/lib/ruty/upgrade.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# escape variables by default
|
2
|
+
# {{ variable }} transforms to {{ variable|escape }}
|
3
|
+
# {{ variable|raw }} transforms to {{ variable }}
|
4
|
+
module Ruty
|
5
|
+
class ParserController
|
6
|
+
|
7
|
+
# parse everything until the block returns true
|
8
|
+
def parse_until &block
|
9
|
+
result = Datastructure::NodeStream.new(self)
|
10
|
+
while not @tokenstream.eos?
|
11
|
+
token, value = @tokenstream.next
|
12
|
+
|
13
|
+
# text tokens are returned just if the arn't empty
|
14
|
+
if token == :text
|
15
|
+
@first = false if @first and not value.strip.empty?
|
16
|
+
result << Datastructure::TextNode.new(value) \
|
17
|
+
if not value.empty?
|
18
|
+
|
19
|
+
# variables leave the parser just if they have just
|
20
|
+
# one name and some optional filters on it.
|
21
|
+
elsif token == :var
|
22
|
+
@first = false
|
23
|
+
names = []
|
24
|
+
filters = []
|
25
|
+
Parser::parse_arguments(value).each do |arg|
|
26
|
+
if arg.is_a?(Array)
|
27
|
+
filters << arg
|
28
|
+
else
|
29
|
+
names << arg
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
filters << [:escape] if (filters & [[:raw], [:escape]]).empty?
|
34
|
+
filters -= [[:raw]]
|
35
|
+
|
36
|
+
fail('Invalid syntax for variable node') if names.size != 1
|
37
|
+
result << Datastructure::VariableNode.new(names[0], filters)
|
38
|
+
|
39
|
+
# blocks are a bit more complicated. first they can act as
|
40
|
+
# needle tokens for other blocks, on the other hand blocks
|
41
|
+
# can have their own subprogram
|
42
|
+
elsif token == :block
|
43
|
+
p = value.split(/\s+/, 2)
|
44
|
+
name = p[0].to_sym
|
45
|
+
args = p[1] || ''
|
46
|
+
if block.call(name, args)
|
47
|
+
@first = false
|
48
|
+
return result.to_nodelist
|
49
|
+
end
|
50
|
+
|
51
|
+
tag = Tags[name]
|
52
|
+
fail("Unknown tag #{name.inspect}") if tag.nil?
|
53
|
+
result << tag.new(self, args)
|
54
|
+
@first = false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
result.to_nodelist
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/test/test_alfa.rb
CHANGED
@@ -1,57 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'alfa'
|
3
3
|
|
4
|
-
class DB1 < Alfa::Database::MySQL; end
|
5
|
-
class DB2 < Alfa::Database::MySQL; end
|
6
|
-
|
7
4
|
class AlfaTest < Test::Unit::TestCase
|
8
|
-
def test_route_match
|
9
|
-
# string rules, positive cases
|
10
|
-
assert_equal([true, {}], Alfa::WebApplication.route_match?('/', '/'))
|
11
|
-
assert_equal([true, {action: 'foo'}], Alfa::WebApplication.route_match?('/:action', '/foo'))
|
12
|
-
assert_equal([true, {action: 'foo'}], Alfa::WebApplication.route_match?('/:action/', '/foo/'))
|
13
|
-
assert_equal([true, {controller: 'foo', action: 'bar'}], Alfa::WebApplication.route_match?('/:controller/:action', '/foo/bar'))
|
14
|
-
assert_equal([true, {}], Alfa::WebApplication.route_match?('/foo/bar', '/foo/bar'))
|
15
|
-
assert_equal([true, {}], Alfa::WebApplication.route_match?('/*/bar', '/foo/bar'))
|
16
|
-
assert_equal([true, {action: 'bar'}], Alfa::WebApplication.route_match?('/*/:action', '/foo/bar'))
|
17
|
-
assert_equal([true, {}], Alfa::WebApplication.route_match?('/**', '/foo/bar'))
|
18
|
-
assert_equal([true, {controller: 'foo'}], Alfa::WebApplication.route_match?('/:controller/**', '/foo/bar/baz'))
|
19
|
-
|
20
|
-
# string rules, negative cases
|
21
|
-
assert_equal([false, {action: 'foo'}], Alfa::WebApplication.route_match?('/:action', '/foo/'))
|
22
|
-
assert_equal([false, {action: 'foo'}], Alfa::WebApplication.route_match?('/:action/', '/foo'))
|
23
|
-
assert_equal([false, {}], Alfa::WebApplication.route_match?('/foo/bar/', '/foo/bar'))
|
24
|
-
assert_equal([false, {}], Alfa::WebApplication.route_match?('/*', '/foo/bar'))
|
25
|
-
assert_equal([false, {}], Alfa::WebApplication.route_match?('/*/', '/foo/bar'))
|
26
|
-
assert_equal([false, {}], Alfa::WebApplication.route_match?('/*', '/foo/bar/'))
|
27
|
-
assert_equal([false, {}], Alfa::WebApplication.route_match?('/**/', '/foo/bar'))
|
28
|
-
assert_equal([false, {}], Alfa::WebApplication.route_match?('/**', '/foo/bar/'))
|
29
|
-
|
30
|
-
# regexp rules, positive cases
|
31
|
-
rule = Regexp.new('^/(?<controller>[^/]+)/(?<action>[^/]+)?$')
|
32
|
-
assert_equal([true, {controller: 'default', action: 'index'}], Alfa::WebApplication.route_match?(rule, '/default/index'))
|
33
|
-
|
34
|
-
# regexp rules, negative cases
|
35
|
-
rule = Regexp.new('^/(?<controller>[^/]+)/(?<action>[^/]+)?$')
|
36
|
-
assert_equal([false, {}], Alfa::WebApplication.route_match?(rule, '/'))
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
def test_capitalize_name
|
41
|
-
assert_equal('Foo', Alfa::Support.capitalize_name(:foo))
|
42
|
-
assert_equal('Foo', Alfa::Support.capitalize_name('foo'))
|
43
|
-
assert_equal('Foo', Alfa::Support.capitalize_name('FOO'))
|
44
|
-
assert_equal('Foo', Alfa::Support.capitalize_name('Foo'))
|
45
|
-
assert_equal('FooBar', Alfa::Support.capitalize_name(:foo_bar))
|
46
|
-
assert_equal('FooBar', Alfa::Support.capitalize_name('foo_bar'))
|
47
|
-
assert_equal('FooBar', Alfa::Support.capitalize_name(:foo__bar))
|
48
|
-
assert_equal('BarBaz', Alfa::Support.capitalize_name('foo/bar_baz'))
|
49
|
-
end
|
50
5
|
|
51
|
-
|
52
|
-
DB1.host = 'localhost'
|
53
|
-
DB2.host = 'otherhost'
|
54
|
-
assert_equal('localhost', DB1.host)
|
55
|
-
assert_equal('otherhost', DB2.host)
|
56
|
-
end
|
57
|
-
end
|
6
|
+
end
|
data/test/test_router.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'alfa/router'
|
3
|
+
|
4
|
+
class AlfaRouterTest < Test::Unit::TestCase
|
5
|
+
def test_01 # route_match
|
6
|
+
# string rules, positive cases
|
7
|
+
assert_equal([true, {}], Alfa::Router.route_match?('/', '/'))
|
8
|
+
assert_equal([true, {action: 'foo'}], Alfa::Router.route_match?('/:action', '/foo'))
|
9
|
+
assert_equal([true, {action: 'foo'}], Alfa::Router.route_match?('/:action/', '/foo/'))
|
10
|
+
assert_equal([true, {controller: 'foo', action: 'bar'}], Alfa::Router.route_match?('/:controller/:action', '/foo/bar'))
|
11
|
+
assert_equal([true, {}], Alfa::Router.route_match?('/foo/bar', '/foo/bar'))
|
12
|
+
assert_equal([true, {}], Alfa::Router.route_match?('/*/bar', '/foo/bar'))
|
13
|
+
assert_equal([true, {action: 'bar'}], Alfa::Router.route_match?('/*/:action', '/foo/bar'))
|
14
|
+
assert_equal([true, {}], Alfa::Router.route_match?('/**', '/foo/bar'))
|
15
|
+
assert_equal([true, {controller: 'foo'}], Alfa::Router.route_match?('/:controller/**', '/foo/bar/baz'))
|
16
|
+
assert_equal([true, {path: 'js/jquery/jquery-latest.js', type: :asset}], Alfa::Router.route_match?('/~assets/:path**', '/~assets/js/jquery/jquery-latest.js'))
|
17
|
+
assert_equal([true, {}], Alfa::Router.route_match?('/hello.html', '/hello.html'))
|
18
|
+
|
19
|
+
# string rules, negative cases
|
20
|
+
assert_equal([false, {action: 'foo'}], Alfa::Router.route_match?('/:action', '/foo/'))
|
21
|
+
assert_equal([false, {action: 'foo'}], Alfa::Router.route_match?('/:action/', '/foo'))
|
22
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/foo/bar/', '/foo/bar'))
|
23
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/*', '/foo/bar'))
|
24
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/*/', '/foo/bar'))
|
25
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/*', '/foo/bar/'))
|
26
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/**/', '/foo/bar'))
|
27
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/**', '/foo/bar/'))
|
28
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/~assets/:path**', '/~assets/js/jquery/non-exists-file.js'))
|
29
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/~assets/:path**', '/~assets/js/jquery/'))
|
30
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/~assets/:path**', '/~assets/js/jquery'))
|
31
|
+
assert_equal([false, {}], Alfa::Router.route_match?('/hello.html', '/~assets/js/jquery/jquery-latest.js'))
|
32
|
+
|
33
|
+
# regexp rules, positive cases
|
34
|
+
rule = Regexp.new('^/(?<controller>[^/]+)/(?<action>[^/]+)?$')
|
35
|
+
assert_equal([true, {controller: 'default', action: 'index'}], Alfa::Router.route_match?(rule, '/default/index'))
|
36
|
+
|
37
|
+
# regexp rules, negative cases
|
38
|
+
rule = Regexp.new('^/(?<controller>[^/]+)/(?<action>[^/]+)?$')
|
39
|
+
assert_equal([false, {}], Alfa::Router.route_match?(rule, '/'))
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def test_02 # app_match
|
44
|
+
# positive cases
|
45
|
+
assert_equal(true, Alfa::Router.app_match?('/foo/', '/foo/'))
|
46
|
+
assert_equal(true, Alfa::Router.app_match?('/foo', '/foo/'))
|
47
|
+
assert_equal(true, Alfa::Router.app_match?('/foo/', '/foo/bar'))
|
48
|
+
assert_equal(true, Alfa::Router.app_match?('/foo/bar/', '/foo/bar/'))
|
49
|
+
|
50
|
+
# negative cases
|
51
|
+
assert_equal(false, Alfa::Router.app_match?('/foo/', '/bar/'))
|
52
|
+
assert_equal(false, Alfa::Router.app_match?('/foo', '/bar/'))
|
53
|
+
assert_equal(false, Alfa::Router.app_match?('/foo/', '/bar/bar'))
|
54
|
+
assert_equal(false, Alfa::Router.app_match?('/foo/bar/', '/bar/bar'))
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def prepare_router
|
59
|
+
Alfa::Router.draw do
|
60
|
+
route '/hello.html'
|
61
|
+
mount '/admin/', :admin
|
62
|
+
Alfa::Router.context :app => :admin do
|
63
|
+
Alfa::Router.draw do
|
64
|
+
route '/', :controller => :main, :action => :index, :layout => :admin
|
65
|
+
route '/:controller', :action => :index
|
66
|
+
end
|
67
|
+
end
|
68
|
+
mount '/', :frontend
|
69
|
+
Alfa::Router.context :app => :frontend do
|
70
|
+
Alfa::Router.draw do
|
71
|
+
route '/', :controller => :main, :action => :index, :layout => :index
|
72
|
+
route '/:action', :controller => :main, :layout => :internal
|
73
|
+
route '/:controller/:action', :layout => :internal
|
74
|
+
route '/:controller/:action/:id', :layout => :internal
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Checks right order of draw and mounted rules
|
81
|
+
def test_03 # Router's internal routes struct
|
82
|
+
prepare_router
|
83
|
+
assert_equal(
|
84
|
+
[
|
85
|
+
{:rule=>"/~assets/:path**", :options=>{:type=>:asset}},
|
86
|
+
{:rule=>"/hello.html", :options=>{}},
|
87
|
+
{:context=>{:app=>{:path=>"/admin/", :app=>:admin, :options=>{}}},
|
88
|
+
:routes=>[
|
89
|
+
{:rule=>"/", :options=>{:controller=>:main, :action=>:index, :layout=>:admin}},
|
90
|
+
{:rule=>"/:controller", :options=>{:action=>:index}}
|
91
|
+
]},
|
92
|
+
{:context=>{:app=>{:path=>"/", :app=>:frontend, :options=>{}}},
|
93
|
+
:routes=>[
|
94
|
+
{:rule=>"/", :options=>{:controller=>:main, :action=>:index, :layout=>:index}},
|
95
|
+
{:rule=>"/:action", :options=>{:controller=>:main, :layout=>:internal}},
|
96
|
+
{:rule=>"/:controller/:action", :options=>{:layout=>:internal}},
|
97
|
+
{:rule=>"/:controller/:action/:id", :options=>{:layout=>:internal}},
|
98
|
+
]},
|
99
|
+
],
|
100
|
+
Alfa::Router.instance_variable_get(:@routes)
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
def test_04 # mount
|
106
|
+
prepare_router
|
107
|
+
#puts Alfa::Router.instance_variable_get(:@routes)
|
108
|
+
assert_equal([{rule: '/hello.html', options: {}}, {}], Alfa::Router.find_route('/hello.html'))
|
109
|
+
assert_equal([{rule: '/', options: {app: :frontend, controller: :main, action: :index, layout: :index}}, {}], Alfa::Router.find_route('/'))
|
110
|
+
assert_equal([{rule: '/:action', options: {app: :frontend, controller: :main, layout: :internal}}, {action: 'foo'}], Alfa::Router.find_route('/foo'))
|
111
|
+
assert_equal([{rule: '/:controller/:action', options: {app: :frontend, layout: :internal}}, {controller: 'foo', action: 'bar'}], Alfa::Router.find_route('/foo/bar'))
|
112
|
+
assert_equal([{rule: '/:controller/:action/:id', options: {app: :frontend, layout: :internal}}, {controller: 'foo', action: 'bar', id: '8'}], Alfa::Router.find_route('/foo/bar/8'))
|
113
|
+
assert_equal([{rule: '/', options: {app: :admin, controller: :main, action: :index, layout: :admin}}, {}], Alfa::Router.find_route('/admin/'))
|
114
|
+
assert_equal([{rule: '/:controller', options: {app: :admin, action: :index}}, {controller: 'foo'}], Alfa::Router.find_route('/admin/foo'))
|
115
|
+
assert_raise Alfa::RouteException404 do
|
116
|
+
Alfa::Router.find_route('/admin/foo/bar')
|
117
|
+
end
|
118
|
+
assert_equal([{rule: '/~assets/:path**', options: {type: :asset}}, {path: 'js/jquery/jquery-latest.js', type: :asset}], Alfa::Router.find_route('/~assets/js/jquery/jquery-latest.js'))
|
119
|
+
#assert_equal([{rule: '/:controller/:action/:id', options: {app: :backend, layout: :internal}}, {controller: 'foo', action: 'bar', id: '8'}], Alfa::Router.find_route('/foo/bar/8'))
|
120
|
+
end
|
121
|
+
|
122
|
+
# this test loads routes.rb files from data/test_router directory to simulate real project skeletron
|
123
|
+
def test_05 # load_from_files
|
124
|
+
assert_equal([{rule: '/', options: {app: :frontend, controller: :main, action: :index, layout: :index}}, {}], Alfa::Router.find_route('/'))
|
125
|
+
assert_equal([{rule: '/:action', options: {app: :frontend, controller: :main, layout: :internal}}, {action: 'foo'}], Alfa::Router.find_route('/foo'))
|
126
|
+
assert_equal([{rule: '/:controller/:action', options: {app: :frontend, layout: :internal}}, {controller: 'foo', action: 'bar'}], Alfa::Router.find_route('/foo/bar'))
|
127
|
+
assert_equal([{rule: '/:controller/:action/:id', options: {app: :frontend, layout: :internal}}, {controller: 'foo', action: 'bar', id: '8'}], Alfa::Router.find_route('/foo/bar/8'))
|
128
|
+
assert_equal([{rule: '/', options: {app: :admin, controller: :main, action: :index, layout: :admin}}, {}], Alfa::Router.find_route('/admin/'))
|
129
|
+
assert_equal([{rule: '/:controller', options: {app: :admin, action: :index}}, {controller: 'foo'}], Alfa::Router.find_route('/admin/foo'))
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'alfa/support'
|
3
|
+
require 'alfa/database/mysql'
|
4
|
+
|
5
|
+
class DB1 < Alfa::Database::MySQL; end
|
6
|
+
class DB2 < Alfa::Database::MySQL; end
|
7
|
+
|
8
|
+
class AlfaSupportTest < Test::Unit::TestCase
|
9
|
+
def test_capitalize_name
|
10
|
+
assert_equal('Foo', Alfa::Support.capitalize_name(:foo))
|
11
|
+
assert_equal('Foo', Alfa::Support.capitalize_name('foo'))
|
12
|
+
assert_equal('Foo', Alfa::Support.capitalize_name('FOO'))
|
13
|
+
assert_equal('Foo', Alfa::Support.capitalize_name('Foo'))
|
14
|
+
assert_equal('FooBar', Alfa::Support.capitalize_name(:foo_bar))
|
15
|
+
assert_equal('FooBar', Alfa::Support.capitalize_name('foo_bar'))
|
16
|
+
assert_equal('FooBar', Alfa::Support.capitalize_name(:foo__bar))
|
17
|
+
assert_equal('BarBaz', Alfa::Support.capitalize_name('foo/bar_baz'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_inheritance
|
21
|
+
DB1.host = 'localhost'
|
22
|
+
DB2.host = 'otherhost'
|
23
|
+
assert_equal('localhost', DB1.host)
|
24
|
+
assert_equal('otherhost', DB2.host)
|
25
|
+
end
|
26
|
+
end
|