Pistos-ramaze 2009.04.08 → 2009.06.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/MANIFEST +37 -22
- data/{README.markdown → README.md} +5 -24
- data/Rakefile +33 -26
- data/benchmark/bench_templates/bench.rb +67 -0
- data/benchmark/bench_templates/view/large.erb +79 -0
- data/benchmark/bench_templates/view/large.haml +41 -0
- data/benchmark/bench_templates/view/large.xhtml +79 -0
- data/benchmark/bench_templates/view/small.erb +21 -0
- data/benchmark/bench_templates/view/small.haml +12 -0
- data/benchmark/bench_templates/view/small.xhtml +21 -0
- data/benchmark/run.rb +14 -21
- data/benchmark/suite/minimal.rb +3 -5
- data/benchmark/suite/no_informer.rb +0 -2
- data/benchmark/suite/no_sessions.rb +3 -4
- data/benchmark/suite/no_template.rb +1 -3
- data/benchmark/suite/simple.rb +1 -3
- data/benchmark/suite/template_erubis.rb +0 -2
- data/benchmark/suite/template_etanni.rb +8 -0
- data/benchmark/suite/template_ezamar.rb +1 -3
- data/benchmark/suite/template_haml.rb +0 -2
- data/benchmark/suite/template_liquid.rb +0 -2
- data/benchmark/suite/template_markaby.rb +0 -2
- data/benchmark/suite/template_nagoro.rb +1 -3
- data/benchmark/suite/template_redcloth.rb +0 -2
- data/benchmark/suite/template_tenjin.rb +0 -2
- data/bin/ramaze +11 -163
- data/doc/AUTHORS +15 -8
- data/doc/CHANGELOG +10094 -12262
- data/doc/meta/announcement.txt +93 -46
- data/doc/tutorial/todolist.html +22 -58
- data/doc/tutorial/todolist.txt +20 -39
- data/examples/app/auth/layout/{auth.nag → auth.xhtml} +0 -0
- data/examples/app/auth/view/{index.nag → index.xhtml} +0 -0
- data/examples/app/auth/view/{login.nag → login.xhtml} +0 -0
- data/examples/app/auth/view/{secret.nag → secret.xhtml} +0 -0
- data/examples/app/blog/app.rb +1 -1
- data/examples/app/blog/controller/comment.rb +1 -1
- data/examples/app/blog/controller/entry.rb +12 -3
- data/examples/app/blog/model/init.rb +5 -0
- data/examples/app/blog/model/tag.rb +2 -2
- data/examples/app/blog/view/entry/index.nag +3 -3
- data/examples/app/blog/view/feed.atom.nag +1 -1
- data/examples/app/blog/view/feed.rss.nag +1 -1
- data/examples/app/blog/view/index.nag +1 -1
- data/examples/app/blog/view/tag/index.nag +1 -1
- data/examples/app/chat/layout/{default.nag → default.xhtml} +0 -0
- data/examples/app/chat/view/{chat.nag → chat.xhtml} +0 -0
- data/examples/app/chat/view/{index.nag → index.xhtml} +0 -0
- data/examples/app/localization/locale/de.yaml +5 -0
- data/examples/app/localization/locale/en.yaml +5 -0
- data/examples/app/localization/locale/ja.yaml +5 -0
- data/examples/app/localization/start.rb +33 -20
- data/examples/app/wikore/spec/wikore.rb +4 -6
- data/examples/app/wikore/src/controller.rb +9 -11
- data/examples/app/wikore/src/model.rb +7 -10
- data/examples/app/wikore/start.rb +1 -1
- data/examples/app/wikore/{template → view}/index.xhtml +0 -0
- data/examples/helpers/cache.rb +6 -4
- data/examples/misc/css.rb +6 -12
- data/examples/misc/rapp.rb +28 -17
- data/lib/proto/app.rb +14 -0
- data/lib/proto/config.ru +8 -5
- data/lib/proto/controller/init.rb +3 -3
- data/lib/proto/spec/main.rb +9 -11
- data/lib/proto/start.rb +6 -10
- data/lib/ramaze.rb +8 -9
- data/lib/ramaze/app.rb +4 -3
- data/lib/ramaze/cache/localmemcache.rb +2 -2
- data/lib/ramaze/cache/memcache.rb +26 -1
- data/lib/ramaze/cache/sequel.rb +24 -9
- data/lib/ramaze/contrib/addressable_route.rb +56 -0
- data/lib/ramaze/contrib/email.rb +2 -0
- data/lib/ramaze/contrib/facebook/facebook.rb +4 -4
- data/lib/ramaze/contrib/sequel/create_join.rb +1 -0
- data/lib/ramaze/contrib/sequel/form_field.rb +4 -4
- data/lib/ramaze/contrib/sequel/image.rb +9 -11
- data/lib/ramaze/contrib/sequel/relation.rb +17 -3
- data/lib/ramaze/controller.rb +26 -18
- data/lib/ramaze/gestalt.rb +4 -1
- data/lib/ramaze/helper.rb +1 -0
- data/lib/ramaze/helper/auth.rb +0 -5
- data/lib/ramaze/helper/cache.rb +65 -25
- data/lib/ramaze/helper/form.rb +14 -2
- data/lib/ramaze/helper/formatting.rb +3 -1
- data/lib/ramaze/helper/gestalt.rb +32 -0
- data/lib/ramaze/helper/identity.rb +3 -3
- data/lib/ramaze/helper/layout.rb +97 -0
- data/lib/ramaze/helper/link.rb +6 -25
- data/lib/ramaze/helper/localize.rb +13 -3
- data/lib/ramaze/helper/paginate.rb +4 -2
- data/lib/ramaze/helper/ultraviolet.rb +2 -0
- data/lib/ramaze/helper/user.rb +3 -3
- data/lib/ramaze/log/rotatinginformer.rb +10 -10
- data/lib/ramaze/request.rb +3 -5
- data/lib/ramaze/setup.rb +22 -9
- data/lib/ramaze/spec.rb +8 -12
- data/lib/ramaze/spec/bacon.rb +34 -0
- data/lib/ramaze/spec/helper/template_examples.rb +15 -22
- data/lib/ramaze/tool/bin.rb +340 -0
- data/lib/ramaze/tool/project_creator.rb +1 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +6 -11
- data/lib/ramaze/view/erubis.rb +2 -2
- data/lib/ramaze/view/ezamar.rb +2 -2
- data/lib/ramaze/view/gestalt.rb +14 -0
- data/lib/ramaze/view/haml.rb +2 -1
- data/lib/ramaze/view/liquid.rb +45 -11
- data/lib/ramaze/view/maruku.rb +2 -1
- data/lib/ramaze/view/nagoro/render_partial.rb +9 -9
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/tenjin.rb +7 -4
- data/lib/vendor/etag.rb +4 -2
- data/lib/vendor/route_exceptions.rb +9 -15
- data/ramaze.gemspec +56 -9
- data/spec/contrib/addressable_route.rb +30 -0
- data/spec/contrib/rest.rb +2 -2
- data/spec/examples/caching.rb +5 -7
- data/spec/examples/css.rb +3 -3
- data/spec/examples/element.rb +4 -3
- data/spec/examples/hello.rb +3 -3
- data/spec/examples/helpers/httpdigest.rb +44 -69
- data/spec/examples/linking.rb +3 -3
- data/spec/examples/simple.rb +3 -3
- data/spec/examples/templates/template_erubis.rb +8 -4
- data/spec/examples/templates/template_ezamar.rb +9 -4
- data/spec/examples/templates/template_haml.rb +8 -4
- data/spec/examples/templates/template_liquid.rb +8 -4
- data/spec/examples/templates/template_markaby.rb +9 -5
- data/spec/examples/templates/template_nagoro.rb +9 -5
- data/spec/examples/templates/template_redcloth.rb +8 -4
- data/spec/examples/templates/template_remarkably.rb +8 -4
- data/spec/examples/templates/template_tenjin.rb +8 -4
- data/spec/helper.rb +1 -2
- data/spec/ramaze/action/render.rb +4 -1
- data/spec/ramaze/app.rb +5 -2
- data/spec/ramaze/bin/ramaze.rb +96 -0
- data/spec/ramaze/cache/localmemcache.rb +1 -1
- data/spec/ramaze/cache/memcache.rb +7 -1
- data/spec/ramaze/cache/sequel.rb +1 -1
- data/spec/ramaze/controller/actionless_templates.rb +2 -2
- data/spec/ramaze/controller/lonely_mapping.rb +18 -0
- data/spec/ramaze/controller/mapping.rb +4 -15
- data/spec/ramaze/controller/provide_inheritance.rb +5 -2
- data/spec/ramaze/controller/resolve.rb +2 -2
- data/spec/ramaze/controller/subclass.rb +2 -2
- data/spec/ramaze/controller/template_resolving.rb +2 -2
- data/spec/ramaze/dispatcher/directory.rb +5 -2
- data/spec/ramaze/dispatcher/file.rb +28 -26
- data/spec/ramaze/error.rb +3 -3
- data/spec/ramaze/files.rb +5 -2
- data/spec/ramaze/gestalt.rb +26 -17
- data/spec/ramaze/helper/auth.rb +30 -41
- data/spec/ramaze/helper/bench.rb +6 -2
- data/spec/ramaze/helper/cache.rb +45 -5
- data/spec/ramaze/helper/flash.rb +11 -15
- data/spec/ramaze/helper/form.rb +6 -3
- data/spec/ramaze/helper/formatting.rb +4 -1
- data/spec/ramaze/helper/gestalt.rb +4 -1
- data/spec/ramaze/helper/gravatar.rb +4 -1
- data/spec/ramaze/helper/httpdigest.rb +51 -66
- data/spec/ramaze/helper/layout.rb +79 -0
- data/spec/ramaze/helper/layout/default.xhtml +5 -0
- data/spec/ramaze/helper/link.rb +33 -12
- data/spec/ramaze/helper/localize.rb +9 -4
- data/spec/ramaze/helper/maruku.rb +5 -2
- data/spec/ramaze/helper/pager.rb +2 -2
- data/spec/ramaze/helper/paginate.rb +5 -2
- data/spec/ramaze/helper/request_accessor.rb +5 -2
- data/spec/ramaze/helper/sequel_form.rb +7 -2
- data/spec/ramaze/helper/simple_captcha.rb +10 -14
- data/spec/ramaze/helper/stack.rb +32 -40
- data/spec/ramaze/helper/user.rb +19 -14
- data/spec/ramaze/helper/xhtml.rb +4 -1
- data/spec/ramaze/log/informer.rb +1 -1
- data/spec/ramaze/log/logging.rb +4 -1
- data/spec/ramaze/log/syslog.rb +6 -6
- data/spec/ramaze/params.rb +5 -6
- data/spec/ramaze/request.rb +16 -1
- data/spec/ramaze/session/memcache.rb +66 -0
- data/spec/ramaze/struct.rb +4 -1
- data/spec/ramaze/view.rb +2 -2
- data/spec/ramaze/view/erubis.rb +2 -2
- data/spec/ramaze/view/ezamar.rb +2 -2
- data/spec/ramaze/view/gestalt.rb +94 -0
- data/spec/ramaze/view/gestalt/external.ges +8 -0
- data/spec/ramaze/view/haml.rb +2 -2
- data/spec/ramaze/view/liquid.rb +2 -2
- data/spec/ramaze/view/nagoro.rb +2 -2
- data/spec/ramaze/view/redcloth.rb +2 -2
- data/spec/ramaze/view/remarkably.rb +2 -2
- data/spec/ramaze/view/sass.rb +2 -2
- data/spec/ramaze/view/tagz.rb +2 -2
- data/spec/ramaze/view/tenjin.rb +2 -2
- data/spec/snippets/array/put_within.rb +30 -25
- data/spec/snippets/binding/locals.rb +4 -1
- data/spec/snippets/numeric/filesize_format.rb +4 -1
- data/spec/snippets/numeric/time.rb +5 -2
- data/spec/snippets/object/__dir__.rb +4 -1
- data/spec/snippets/ordered_set.rb +4 -1
- data/spec/snippets/ramaze/acquire.rb +4 -1
- data/spec/snippets/ramaze/dictionary.rb +4 -1
- data/spec/snippets/ramaze/struct.rb +4 -1
- data/spec/snippets/string/camel_case.rb +4 -1
- data/spec/snippets/string/color.rb +4 -1
- data/spec/snippets/string/snake_case.rb +4 -1
- data/spec/snippets/string/unindent.rb +4 -1
- data/spec/snippets/thread/into.rb +4 -1
- data/tasks/bacon.rake +5 -3
- data/tasks/changelog.rake +3 -1
- data/tasks/{gem_installer.rake → gem_setup.rake} +45 -22
- data/tasks/release.rake +12 -27
- data/tasks/setup.rake +6 -0
- data/tasks/todo.rake +2 -4
- metadata +205 -31
- data/CHANGELOG +0 -16546
- data/benchmark/suite/template_builder.rb +0 -12
- data/doc/tutorial/todolist.mkd +0 -787
- data/examples/helpers/provide.rb +0 -23
- data/lib/proto/view/page.xhtml +0 -27
- data/lib/ramaze/snippets/divide.rb +0 -22
- data/lib/ramaze/snippets/kernel/constant.rb +0 -41
- data/lib/ramaze/snippets/object/acquire.rb +0 -37
- data/lib/ramaze/snippets/string/each.rb +0 -19
- data/spec/ramaze/helper/partial.rb +0 -40
- data/spec/snippets/kernel/constant.rb +0 -23
- data/tasks/install_dependencies.rake +0 -6
@@ -65,20 +65,34 @@ module SequelRelation
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def belongs_to(model)
|
68
|
-
todo :
|
68
|
+
todo :many_to_one, singular_sym(model), :class => model
|
69
69
|
end
|
70
70
|
|
71
71
|
def has_many(model)
|
72
72
|
todo :create_join, model
|
73
|
-
todo :many_to_many, model
|
73
|
+
todo :many_to_many, plural_sym(model), :class => model
|
74
74
|
end
|
75
75
|
|
76
76
|
def has_one(model)
|
77
|
-
todo :
|
77
|
+
todo :many_to_one, singular_sym(model), :class => model
|
78
78
|
end
|
79
79
|
|
80
80
|
def todo(method, *args)
|
81
81
|
TODO[@left] << [method, *args]
|
82
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def plural_sym(obj)
|
87
|
+
basename(obj).pluralize.to_sym
|
88
|
+
end
|
89
|
+
|
90
|
+
def singular_sym(obj)
|
91
|
+
basename(obj).to_sym
|
92
|
+
end
|
93
|
+
|
94
|
+
def basename(obj)
|
95
|
+
obj.to_s.split('::').last.downcase
|
96
|
+
end
|
83
97
|
end
|
84
98
|
end
|
data/lib/ramaze/controller.rb
CHANGED
@@ -19,23 +19,41 @@ module Ramaze
|
|
19
19
|
|
20
20
|
def self.inherited(into)
|
21
21
|
Innate::Node.included(into)
|
22
|
+
into.helper(:layout)
|
22
23
|
CONTROLLER_LIST << into
|
23
24
|
into.trait :skip_node_map => true
|
24
25
|
end
|
25
26
|
|
26
27
|
def self.setup
|
27
|
-
|
28
|
+
case CONTROLLER_LIST.size
|
29
|
+
when 0
|
30
|
+
require 'ramaze/controller/default'
|
31
|
+
when 1
|
32
|
+
controller = CONTROLLER_LIST.to_a.first
|
33
|
+
|
34
|
+
begin
|
35
|
+
controller.mapping
|
36
|
+
rescue
|
37
|
+
controller.map '/'
|
38
|
+
end
|
28
39
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
controller.
|
40
|
+
controller.setup_procedure
|
41
|
+
else
|
42
|
+
CONTROLLER_LIST.each do |controller|
|
43
|
+
controller.setup_procedure
|
33
44
|
end
|
34
|
-
next if controller.trait[:skip_controller_map]
|
35
|
-
controller.map(generate_mapping(controller.name))
|
36
45
|
end
|
37
46
|
end
|
38
47
|
|
48
|
+
def self.setup_procedure
|
49
|
+
unless ancestral_trait[:provide_set]
|
50
|
+
engine(:Etanni)
|
51
|
+
trait(:provide_set => false)
|
52
|
+
end
|
53
|
+
|
54
|
+
map(generate_mapping(name)) unless trait[:skip_controller_map]
|
55
|
+
end
|
56
|
+
|
39
57
|
def self.engine(name)
|
40
58
|
provide(:html, name.to_sym)
|
41
59
|
end
|
@@ -50,7 +68,7 @@ module Ramaze
|
|
50
68
|
}
|
51
69
|
|
52
70
|
def self.generate_mapping(klass_name = self.name)
|
53
|
-
chunks = klass_name.split(/::/)
|
71
|
+
chunks = klass_name.to_s.split(/::/)
|
54
72
|
return if chunks.empty?
|
55
73
|
|
56
74
|
last = chunks.last
|
@@ -80,15 +98,5 @@ module Ramaze
|
|
80
98
|
return unless app = self.app
|
81
99
|
app.options
|
82
100
|
end
|
83
|
-
|
84
|
-
def self.template(*args)
|
85
|
-
Ramaze.deprecated('Controller::template', 'Controller::alias_view')
|
86
|
-
alias_view(*args)
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.view_root(*locations)
|
90
|
-
Ramaze.deprecated('Controller::view_root', 'Controller::map_views')
|
91
|
-
map_views(*locations)
|
92
|
-
end
|
93
101
|
end
|
94
102
|
end
|
data/lib/ramaze/gestalt.rb
CHANGED
@@ -84,6 +84,9 @@ module Ramaze
|
|
84
84
|
if args.size == 1 and args[0].kind_of? Hash
|
85
85
|
# args are just attributes, children in block...
|
86
86
|
_gestalt_build_tag name, args[0], &block
|
87
|
+
elsif args[1].kind_of? Hash
|
88
|
+
# args are text and attributes ie. a('mylink', :href => '/mylink')
|
89
|
+
_gestalt_build_tag(name, args[1], args[0], &block)
|
87
90
|
else
|
88
91
|
# no attributes, but text
|
89
92
|
_gestalt_build_tag name, {}, args, &block
|
@@ -95,7 +98,7 @@ module Ramaze
|
|
95
98
|
|
96
99
|
def _gestalt_build_tag(name, attr = {}, text = [])
|
97
100
|
@out << "<#{name}"
|
98
|
-
@out << attr.map{|k,v| %[ #{k}="#{_gestalt_escape_entities(v)}"] }.join
|
101
|
+
@out << attr.map{|(k,v)| %[ #{k}="#{_gestalt_escape_entities(v)}"] }.join
|
99
102
|
if text != [] or block_given?
|
100
103
|
@out << ">"
|
101
104
|
@out << _gestalt_escape_entities([text].join)
|
data/lib/ramaze/helper.rb
CHANGED
data/lib/ramaze/helper/auth.rb
CHANGED
@@ -43,11 +43,6 @@ module Ramaze
|
|
43
43
|
!!session[:logged_in]
|
44
44
|
end
|
45
45
|
|
46
|
-
def check_auth(user, pass)
|
47
|
-
Ramaze.deprecated('Helper::User#check_auth', 'Helper::User#auth_login')
|
48
|
-
auth_login(user, pass)
|
49
|
-
end
|
50
|
-
|
51
46
|
# @return
|
52
47
|
def auth_login(user, pass)
|
53
48
|
return unless user and pass
|
data/lib/ramaze/helper/cache.rb
CHANGED
@@ -16,7 +16,7 @@ module Ramaze
|
|
16
16
|
into.extend(SingletonMethods)
|
17
17
|
into.add_action_wrapper(6.0, :cache_wrap)
|
18
18
|
into.trait[:cache_action] ||= Set.new
|
19
|
-
Ramaze::Cache.add(:action, :
|
19
|
+
Ramaze::Cache.add(:action, :cache_helper_value)
|
20
20
|
end
|
21
21
|
|
22
22
|
# @param [Action] action The currently wrapped action
|
@@ -28,46 +28,86 @@ module Ramaze
|
|
28
28
|
cache = Innate::Cache.action
|
29
29
|
|
30
30
|
ancestral_trait[:cache_action].each do |cache_action|
|
31
|
-
temp
|
32
|
-
|
31
|
+
temp = cache_action.dup
|
32
|
+
block = temp.delete(:key)
|
33
|
+
ttl = temp.delete(:ttl)
|
33
34
|
|
34
35
|
if temp.all?{|key, value| action[key] == value }
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
cache_key = action.full_path
|
37
|
+
cache_key << "_#{action.instance.instance_eval(&block).to_s}" if block
|
38
|
+
|
39
|
+
if cached = cache[cache_key]
|
40
|
+
action.options[:content_type] = cached[:type]
|
39
41
|
else
|
40
|
-
|
42
|
+
cached = {
|
43
|
+
:body => catch(:respond) { yield },
|
44
|
+
:type => response['Content-Type']
|
45
|
+
}
|
46
|
+
|
47
|
+
if ttl
|
48
|
+
cache.store(cache_key, cached, :ttl => ttl)
|
49
|
+
else
|
50
|
+
cache.store(cache_key, cached)
|
51
|
+
end
|
41
52
|
end
|
53
|
+
|
54
|
+
return cached[:body]
|
42
55
|
end
|
43
56
|
end
|
44
57
|
|
45
58
|
yield
|
46
59
|
end
|
47
60
|
|
48
|
-
#
|
61
|
+
# This method is used to access Ramaze::Cache.cache_helper_value.
|
62
|
+
# It provides an easy way to cache long-running computations, gathering
|
63
|
+
# external resources like RSS feeds or DB queries that are the same for
|
64
|
+
# every user of an application.
|
65
|
+
# This method changes behaviour if a block is passed, which can be used
|
66
|
+
# to do lazy computation of the cached value conveniently when using a
|
67
|
+
# custom TTL or longer expressions that don't fit on one line with ||=.
|
68
|
+
#
|
69
|
+
# @usage Example to get the cache object directly
|
70
|
+
#
|
71
|
+
# count = cache_value[:count] ||= Article.count
|
72
|
+
#
|
73
|
+
# @usage Example with block
|
74
|
+
#
|
75
|
+
# count = cache_value(:count){ Article.count }
|
76
|
+
# count = cache_value(:count, :ttl => 60){ Article.count }
|
77
|
+
#
|
78
|
+
# @return [Object] The cache wrapper assigned for :cache_helper_value
|
49
79
|
# @see Innate::Cache
|
50
80
|
# @author manveru
|
51
|
-
def cache_value
|
52
|
-
Ramaze::Cache.
|
53
|
-
end
|
54
|
-
|
81
|
+
def cache_value(key = nil, options = {})
|
82
|
+
cache = Ramaze::Cache.cache_helper_value
|
55
83
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
84
|
+
if key and block_given?
|
85
|
+
if found = cache[key]
|
86
|
+
found
|
87
|
+
else
|
88
|
+
cache.store(key, yield, options)
|
89
|
+
end
|
90
|
+
else
|
91
|
+
cache
|
92
|
+
end
|
62
93
|
end
|
63
94
|
|
64
95
|
module SingletonMethods
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
96
|
+
# This method allows you to cache whole actions.
|
97
|
+
#
|
98
|
+
# @example Basic usage
|
99
|
+
#
|
100
|
+
# class Foo < Ramaze::Controller
|
101
|
+
# helper :cache
|
102
|
+
# cache_action :method => :bar
|
103
|
+
#
|
104
|
+
# def bar
|
105
|
+
# rand
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
def cache_action(hash, &block)
|
110
|
+
hash[:key] = block if block_given?
|
71
111
|
hash[:method] = hash[:method].to_s
|
72
112
|
trait[:cache_action] << hash
|
73
113
|
end
|
data/lib/ramaze/helper/form.rb
CHANGED
@@ -35,13 +35,25 @@ module Ramaze
|
|
35
35
|
Ramaze::Gestalt.build{ tr{ td(:colspan => 2){ input(hash) }}}
|
36
36
|
end
|
37
37
|
|
38
|
+
# @example usage, normal select drop-down
|
39
|
+
#
|
40
|
+
# form_select('Favourite colors', :colors, @colors, :selected => @color)
|
41
|
+
#
|
42
|
+
# @example usage for pre-selected value
|
43
|
+
#
|
44
|
+
# form_select('Favourite colors', :colors, @colors, :selected => @color)
|
45
|
+
#
|
46
|
+
# @example usage, allow selecting multiple
|
47
|
+
#
|
48
|
+
# form_select('Cups', :cups, @cups, :selected => @cup, :multiple => 5)
|
38
49
|
def form_select(label, name, values, hash = {})
|
39
50
|
name = name.to_sym
|
40
51
|
id = "form-#{name}"
|
52
|
+
multiple, size = hash.values_at(:multiple, :size)
|
41
53
|
|
42
54
|
s_args = {:name => name, :id => id}.merge(form_tabindex)
|
43
|
-
s_args[:multiple] = :multiple if
|
44
|
-
s_args[:size] =
|
55
|
+
s_args[:multiple] = :multiple if multiple
|
56
|
+
s_args[:size] = (size || multiple || 1).to_i
|
45
57
|
|
46
58
|
has_selected, selected = hash.key?(:selected), hash[:selected]
|
47
59
|
error = form_errors[name.to_s]
|
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
module Ramaze
|
5
5
|
module Helper::Formatting
|
6
|
+
module_function
|
7
|
+
|
6
8
|
FORMATTING_NUMBER_COUNTER = { 0 => 'no', 2 => 'two', 3 => 'three',
|
7
9
|
4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight',
|
8
10
|
9 => 'nine', 10 => 'ten' }
|
@@ -113,7 +115,7 @@ module Ramaze
|
|
113
115
|
[-\w]+ # subdomain or domain
|
114
116
|
(?:\.[-\w]+)* # remaining subdomains or domain
|
115
117
|
(?::\d+)? # port
|
116
|
-
(?:/(?:(?:[~\w\+@%-]|(?:[,.;:][^\s$]))
|
118
|
+
(?:/(?:(?:[~\w\+@%-]|(?:[,.;:][^\s$])))?)* # path
|
117
119
|
(?:\?[\w\+@%&=.;-]+)? # query string
|
118
120
|
(?:\#[\w\-]*)? # trailing anchor
|
119
121
|
)
|
@@ -3,6 +3,8 @@ require 'ramaze/gestalt'
|
|
3
3
|
module Ramaze
|
4
4
|
module Helper
|
5
5
|
module Gestalt
|
6
|
+
CACHE_G = {}
|
7
|
+
|
6
8
|
def gestalt(&block)
|
7
9
|
Ramaze::Gestalt.new(&block)
|
8
10
|
end
|
@@ -10,6 +12,36 @@ module Ramaze
|
|
10
12
|
def build(&block)
|
11
13
|
Ramaze::Gestalt.build(&block)
|
12
14
|
end
|
15
|
+
|
16
|
+
def g(meth = nil, view = nil)
|
17
|
+
meth ||= caller[0].slice(/`(.*)'?/).gsub(/[\`\']/, '')
|
18
|
+
view_name = (self.class.to_s.sub('Controller', '') + 'View').split('::')
|
19
|
+
view ||= view_name.inject(Object){ |ns, name| ns.const_get(name) }
|
20
|
+
|
21
|
+
gestalt_class = CACHE_G[view] ||= g_class
|
22
|
+
gestalt = gestalt_class.new
|
23
|
+
gestalt.extend(view)
|
24
|
+
instance_variables.each do |iv|
|
25
|
+
gestalt.instance_variable_set(iv, instance_variable_get(iv))
|
26
|
+
end
|
27
|
+
gestalt.__send__(meth)
|
28
|
+
gestalt.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def g_class
|
32
|
+
ancs = self.class.ancestors
|
33
|
+
helpers = Ramaze::Helper.constants.map{ |c| Ramaze::Helper.const_get(c)}
|
34
|
+
our_helpers = ancs & helpers
|
35
|
+
our_helpers.delete(Ramaze::Helper::Gestalt)
|
36
|
+
gestalt_class = Class.new(Ramaze::Gestalt){ include(*our_helpers) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def method_missing(sym, *args, &block)
|
40
|
+
@gestalt ||= gestalt
|
41
|
+
@gestalt.send(sym, *args, &block)
|
42
|
+
end
|
13
43
|
end
|
14
44
|
end
|
15
45
|
end
|
46
|
+
|
47
|
+
module Ramaze::Helper::Link; undef :a end
|
@@ -26,7 +26,7 @@ module Ramaze
|
|
26
26
|
# embedded into a page.
|
27
27
|
def openid_login_form(caption="login")
|
28
28
|
%{
|
29
|
-
<form method="GET" action="#{
|
29
|
+
<form method="GET" action="#{rs(:openid_begin)}">
|
30
30
|
Identity URL: <input type="text" name="url" />
|
31
31
|
<input type="submit" value="#{caption}"/>
|
32
32
|
</form>
|
@@ -62,7 +62,7 @@ module Ramaze
|
|
62
62
|
openid_request.return_to_args['did_pape'] = 'y'
|
63
63
|
|
64
64
|
root = "http://#{request.http_host}/"
|
65
|
-
return_to = request.domain(
|
65
|
+
return_to = request.domain(rs(:openid_complete)).to_s
|
66
66
|
immediate = false
|
67
67
|
|
68
68
|
if openid_request.send_redirect?(root, return_to, immediate)
|
@@ -75,7 +75,7 @@ module Ramaze
|
|
75
75
|
|
76
76
|
rescue OpenID::OpenIDError => ex
|
77
77
|
flash[:error] = "Discovery failed for #{url}: #{ex}"
|
78
|
-
raw_redirect
|
78
|
+
raw_redirect rs(:/)
|
79
79
|
end
|
80
80
|
|
81
81
|
# After having authenticated at the OpenID server browsers are redirected
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Ramaze
|
2
|
+
module Helper
|
3
|
+
|
4
|
+
# Provides wrapper methods for a higher-level approach than the core layout
|
5
|
+
# method. These are useful for simpler layout needs, particularly:
|
6
|
+
#
|
7
|
+
# * layout all actions
|
8
|
+
# * layout a whitelist of actions
|
9
|
+
# * layout all but a blacklist of actions
|
10
|
+
#
|
11
|
+
# As with the core layout method, the layout rules apply only to the
|
12
|
+
# controller on which they are applied. Furthermore, multiple layout
|
13
|
+
# definitions are not combined; only the last definition will be used.
|
14
|
+
#
|
15
|
+
# This helper is one of the default helpers, so no explicit helper call
|
16
|
+
# is necessary before using it in your controllers.
|
17
|
+
#
|
18
|
+
# Usage:
|
19
|
+
#
|
20
|
+
# class MainController < Controller
|
21
|
+
# # Apply the default layout (e.g. ./layout/default.xhtml) to all
|
22
|
+
# # three actions.
|
23
|
+
# set_layout 'default'
|
24
|
+
# def action1; end
|
25
|
+
# def action2; end
|
26
|
+
# def action3; end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# class MainController < Controller
|
30
|
+
# # These two layout definitions accomplish the same thing. The
|
31
|
+
# # first uses a whitelist, the second uses a blacklist.
|
32
|
+
# set_layout 'default' => [:laid_out1, :laid_out2]
|
33
|
+
# set_layout_except 'default' => [:not_laid_out1, :not_laid_out2]
|
34
|
+
#
|
35
|
+
# def laid_out1; end
|
36
|
+
# def laid_out2; end
|
37
|
+
#
|
38
|
+
# def not_laid_out1; end
|
39
|
+
# def not_laid_out2; end
|
40
|
+
# end
|
41
|
+
module Layout
|
42
|
+
def self.included(into)
|
43
|
+
into.extend SingletonMethods
|
44
|
+
end
|
45
|
+
|
46
|
+
module SingletonMethods
|
47
|
+
# @param [String Hash] Either a layout name, or a single-element Hash
|
48
|
+
# which maps a layout name to an Array containing a whitelist of
|
49
|
+
# action names
|
50
|
+
# @see set_layout_except Innate::Node::layout
|
51
|
+
# @author Pistos, manveru
|
52
|
+
# @example Use a layout named 'default' on all actions of the controller:
|
53
|
+
# set_layout 'default'
|
54
|
+
# @example Use a layout named 'default' on just the index and admin actions:
|
55
|
+
# set_layout 'default' => [ :index, :admin ]
|
56
|
+
def set_layout(hash_or_the_layout)
|
57
|
+
if hash_or_the_layout.respond_to?(:to_hash)
|
58
|
+
f = hash_or_the_layout.first
|
59
|
+
the_layout = f[0]
|
60
|
+
whitelist = f[1].map{|action| action.to_s }
|
61
|
+
else
|
62
|
+
the_layout = hash_or_the_layout
|
63
|
+
end
|
64
|
+
|
65
|
+
layout do |path, wish|
|
66
|
+
if whitelist.nil? || whitelist.include?(path.to_s)
|
67
|
+
the_layout
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param [String Hash] Either a layout name, or a single-element Hash
|
73
|
+
# which maps a layout name to an Array containing a blacklist of
|
74
|
+
# action names
|
75
|
+
# @see set_layout Innate::Node::layout
|
76
|
+
# @author Pistos, manveru
|
77
|
+
# @example Use a layout named 'default' on all actions except the user_data action:
|
78
|
+
# set_layout_except 'default' => [ :user_data ]
|
79
|
+
def set_layout_except(hash_or_the_layout)
|
80
|
+
if hash_or_the_layout.respond_to?(:to_hash)
|
81
|
+
f = hash_or_the_layout.to_hash.first
|
82
|
+
the_layout = f[0]
|
83
|
+
blacklist = f[1].map{|action| action.to_s }
|
84
|
+
else
|
85
|
+
the_layout = hash_or_the_layout
|
86
|
+
end
|
87
|
+
|
88
|
+
layout do |path, wish|
|
89
|
+
if blacklist.nil? || !blacklist.include?(path.to_s)
|
90
|
+
the_layout
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|