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.
Files changed (227) hide show
  1. data/.gitignore +3 -0
  2. data/MANIFEST +37 -22
  3. data/{README.markdown → README.md} +5 -24
  4. data/Rakefile +33 -26
  5. data/benchmark/bench_templates/bench.rb +67 -0
  6. data/benchmark/bench_templates/view/large.erb +79 -0
  7. data/benchmark/bench_templates/view/large.haml +41 -0
  8. data/benchmark/bench_templates/view/large.xhtml +79 -0
  9. data/benchmark/bench_templates/view/small.erb +21 -0
  10. data/benchmark/bench_templates/view/small.haml +12 -0
  11. data/benchmark/bench_templates/view/small.xhtml +21 -0
  12. data/benchmark/run.rb +14 -21
  13. data/benchmark/suite/minimal.rb +3 -5
  14. data/benchmark/suite/no_informer.rb +0 -2
  15. data/benchmark/suite/no_sessions.rb +3 -4
  16. data/benchmark/suite/no_template.rb +1 -3
  17. data/benchmark/suite/simple.rb +1 -3
  18. data/benchmark/suite/template_erubis.rb +0 -2
  19. data/benchmark/suite/template_etanni.rb +8 -0
  20. data/benchmark/suite/template_ezamar.rb +1 -3
  21. data/benchmark/suite/template_haml.rb +0 -2
  22. data/benchmark/suite/template_liquid.rb +0 -2
  23. data/benchmark/suite/template_markaby.rb +0 -2
  24. data/benchmark/suite/template_nagoro.rb +1 -3
  25. data/benchmark/suite/template_redcloth.rb +0 -2
  26. data/benchmark/suite/template_tenjin.rb +0 -2
  27. data/bin/ramaze +11 -163
  28. data/doc/AUTHORS +15 -8
  29. data/doc/CHANGELOG +10094 -12262
  30. data/doc/meta/announcement.txt +93 -46
  31. data/doc/tutorial/todolist.html +22 -58
  32. data/doc/tutorial/todolist.txt +20 -39
  33. data/examples/app/auth/layout/{auth.nag → auth.xhtml} +0 -0
  34. data/examples/app/auth/view/{index.nag → index.xhtml} +0 -0
  35. data/examples/app/auth/view/{login.nag → login.xhtml} +0 -0
  36. data/examples/app/auth/view/{secret.nag → secret.xhtml} +0 -0
  37. data/examples/app/blog/app.rb +1 -1
  38. data/examples/app/blog/controller/comment.rb +1 -1
  39. data/examples/app/blog/controller/entry.rb +12 -3
  40. data/examples/app/blog/model/init.rb +5 -0
  41. data/examples/app/blog/model/tag.rb +2 -2
  42. data/examples/app/blog/view/entry/index.nag +3 -3
  43. data/examples/app/blog/view/feed.atom.nag +1 -1
  44. data/examples/app/blog/view/feed.rss.nag +1 -1
  45. data/examples/app/blog/view/index.nag +1 -1
  46. data/examples/app/blog/view/tag/index.nag +1 -1
  47. data/examples/app/chat/layout/{default.nag → default.xhtml} +0 -0
  48. data/examples/app/chat/view/{chat.nag → chat.xhtml} +0 -0
  49. data/examples/app/chat/view/{index.nag → index.xhtml} +0 -0
  50. data/examples/app/localization/locale/de.yaml +5 -0
  51. data/examples/app/localization/locale/en.yaml +5 -0
  52. data/examples/app/localization/locale/ja.yaml +5 -0
  53. data/examples/app/localization/start.rb +33 -20
  54. data/examples/app/wikore/spec/wikore.rb +4 -6
  55. data/examples/app/wikore/src/controller.rb +9 -11
  56. data/examples/app/wikore/src/model.rb +7 -10
  57. data/examples/app/wikore/start.rb +1 -1
  58. data/examples/app/wikore/{template → view}/index.xhtml +0 -0
  59. data/examples/helpers/cache.rb +6 -4
  60. data/examples/misc/css.rb +6 -12
  61. data/examples/misc/rapp.rb +28 -17
  62. data/lib/proto/app.rb +14 -0
  63. data/lib/proto/config.ru +8 -5
  64. data/lib/proto/controller/init.rb +3 -3
  65. data/lib/proto/spec/main.rb +9 -11
  66. data/lib/proto/start.rb +6 -10
  67. data/lib/ramaze.rb +8 -9
  68. data/lib/ramaze/app.rb +4 -3
  69. data/lib/ramaze/cache/localmemcache.rb +2 -2
  70. data/lib/ramaze/cache/memcache.rb +26 -1
  71. data/lib/ramaze/cache/sequel.rb +24 -9
  72. data/lib/ramaze/contrib/addressable_route.rb +56 -0
  73. data/lib/ramaze/contrib/email.rb +2 -0
  74. data/lib/ramaze/contrib/facebook/facebook.rb +4 -4
  75. data/lib/ramaze/contrib/sequel/create_join.rb +1 -0
  76. data/lib/ramaze/contrib/sequel/form_field.rb +4 -4
  77. data/lib/ramaze/contrib/sequel/image.rb +9 -11
  78. data/lib/ramaze/contrib/sequel/relation.rb +17 -3
  79. data/lib/ramaze/controller.rb +26 -18
  80. data/lib/ramaze/gestalt.rb +4 -1
  81. data/lib/ramaze/helper.rb +1 -0
  82. data/lib/ramaze/helper/auth.rb +0 -5
  83. data/lib/ramaze/helper/cache.rb +65 -25
  84. data/lib/ramaze/helper/form.rb +14 -2
  85. data/lib/ramaze/helper/formatting.rb +3 -1
  86. data/lib/ramaze/helper/gestalt.rb +32 -0
  87. data/lib/ramaze/helper/identity.rb +3 -3
  88. data/lib/ramaze/helper/layout.rb +97 -0
  89. data/lib/ramaze/helper/link.rb +6 -25
  90. data/lib/ramaze/helper/localize.rb +13 -3
  91. data/lib/ramaze/helper/paginate.rb +4 -2
  92. data/lib/ramaze/helper/ultraviolet.rb +2 -0
  93. data/lib/ramaze/helper/user.rb +3 -3
  94. data/lib/ramaze/log/rotatinginformer.rb +10 -10
  95. data/lib/ramaze/request.rb +3 -5
  96. data/lib/ramaze/setup.rb +22 -9
  97. data/lib/ramaze/spec.rb +8 -12
  98. data/lib/ramaze/spec/bacon.rb +34 -0
  99. data/lib/ramaze/spec/helper/template_examples.rb +15 -22
  100. data/lib/ramaze/tool/bin.rb +340 -0
  101. data/lib/ramaze/tool/project_creator.rb +1 -1
  102. data/lib/ramaze/version.rb +1 -1
  103. data/lib/ramaze/view.rb +6 -11
  104. data/lib/ramaze/view/erubis.rb +2 -2
  105. data/lib/ramaze/view/ezamar.rb +2 -2
  106. data/lib/ramaze/view/gestalt.rb +14 -0
  107. data/lib/ramaze/view/haml.rb +2 -1
  108. data/lib/ramaze/view/liquid.rb +45 -11
  109. data/lib/ramaze/view/maruku.rb +2 -1
  110. data/lib/ramaze/view/nagoro/render_partial.rb +9 -9
  111. data/lib/ramaze/view/sass.rb +1 -1
  112. data/lib/ramaze/view/tenjin.rb +7 -4
  113. data/lib/vendor/etag.rb +4 -2
  114. data/lib/vendor/route_exceptions.rb +9 -15
  115. data/ramaze.gemspec +56 -9
  116. data/spec/contrib/addressable_route.rb +30 -0
  117. data/spec/contrib/rest.rb +2 -2
  118. data/spec/examples/caching.rb +5 -7
  119. data/spec/examples/css.rb +3 -3
  120. data/spec/examples/element.rb +4 -3
  121. data/spec/examples/hello.rb +3 -3
  122. data/spec/examples/helpers/httpdigest.rb +44 -69
  123. data/spec/examples/linking.rb +3 -3
  124. data/spec/examples/simple.rb +3 -3
  125. data/spec/examples/templates/template_erubis.rb +8 -4
  126. data/spec/examples/templates/template_ezamar.rb +9 -4
  127. data/spec/examples/templates/template_haml.rb +8 -4
  128. data/spec/examples/templates/template_liquid.rb +8 -4
  129. data/spec/examples/templates/template_markaby.rb +9 -5
  130. data/spec/examples/templates/template_nagoro.rb +9 -5
  131. data/spec/examples/templates/template_redcloth.rb +8 -4
  132. data/spec/examples/templates/template_remarkably.rb +8 -4
  133. data/spec/examples/templates/template_tenjin.rb +8 -4
  134. data/spec/helper.rb +1 -2
  135. data/spec/ramaze/action/render.rb +4 -1
  136. data/spec/ramaze/app.rb +5 -2
  137. data/spec/ramaze/bin/ramaze.rb +96 -0
  138. data/spec/ramaze/cache/localmemcache.rb +1 -1
  139. data/spec/ramaze/cache/memcache.rb +7 -1
  140. data/spec/ramaze/cache/sequel.rb +1 -1
  141. data/spec/ramaze/controller/actionless_templates.rb +2 -2
  142. data/spec/ramaze/controller/lonely_mapping.rb +18 -0
  143. data/spec/ramaze/controller/mapping.rb +4 -15
  144. data/spec/ramaze/controller/provide_inheritance.rb +5 -2
  145. data/spec/ramaze/controller/resolve.rb +2 -2
  146. data/spec/ramaze/controller/subclass.rb +2 -2
  147. data/spec/ramaze/controller/template_resolving.rb +2 -2
  148. data/spec/ramaze/dispatcher/directory.rb +5 -2
  149. data/spec/ramaze/dispatcher/file.rb +28 -26
  150. data/spec/ramaze/error.rb +3 -3
  151. data/spec/ramaze/files.rb +5 -2
  152. data/spec/ramaze/gestalt.rb +26 -17
  153. data/spec/ramaze/helper/auth.rb +30 -41
  154. data/spec/ramaze/helper/bench.rb +6 -2
  155. data/spec/ramaze/helper/cache.rb +45 -5
  156. data/spec/ramaze/helper/flash.rb +11 -15
  157. data/spec/ramaze/helper/form.rb +6 -3
  158. data/spec/ramaze/helper/formatting.rb +4 -1
  159. data/spec/ramaze/helper/gestalt.rb +4 -1
  160. data/spec/ramaze/helper/gravatar.rb +4 -1
  161. data/spec/ramaze/helper/httpdigest.rb +51 -66
  162. data/spec/ramaze/helper/layout.rb +79 -0
  163. data/spec/ramaze/helper/layout/default.xhtml +5 -0
  164. data/spec/ramaze/helper/link.rb +33 -12
  165. data/spec/ramaze/helper/localize.rb +9 -4
  166. data/spec/ramaze/helper/maruku.rb +5 -2
  167. data/spec/ramaze/helper/pager.rb +2 -2
  168. data/spec/ramaze/helper/paginate.rb +5 -2
  169. data/spec/ramaze/helper/request_accessor.rb +5 -2
  170. data/spec/ramaze/helper/sequel_form.rb +7 -2
  171. data/spec/ramaze/helper/simple_captcha.rb +10 -14
  172. data/spec/ramaze/helper/stack.rb +32 -40
  173. data/spec/ramaze/helper/user.rb +19 -14
  174. data/spec/ramaze/helper/xhtml.rb +4 -1
  175. data/spec/ramaze/log/informer.rb +1 -1
  176. data/spec/ramaze/log/logging.rb +4 -1
  177. data/spec/ramaze/log/syslog.rb +6 -6
  178. data/spec/ramaze/params.rb +5 -6
  179. data/spec/ramaze/request.rb +16 -1
  180. data/spec/ramaze/session/memcache.rb +66 -0
  181. data/spec/ramaze/struct.rb +4 -1
  182. data/spec/ramaze/view.rb +2 -2
  183. data/spec/ramaze/view/erubis.rb +2 -2
  184. data/spec/ramaze/view/ezamar.rb +2 -2
  185. data/spec/ramaze/view/gestalt.rb +94 -0
  186. data/spec/ramaze/view/gestalt/external.ges +8 -0
  187. data/spec/ramaze/view/haml.rb +2 -2
  188. data/spec/ramaze/view/liquid.rb +2 -2
  189. data/spec/ramaze/view/nagoro.rb +2 -2
  190. data/spec/ramaze/view/redcloth.rb +2 -2
  191. data/spec/ramaze/view/remarkably.rb +2 -2
  192. data/spec/ramaze/view/sass.rb +2 -2
  193. data/spec/ramaze/view/tagz.rb +2 -2
  194. data/spec/ramaze/view/tenjin.rb +2 -2
  195. data/spec/snippets/array/put_within.rb +30 -25
  196. data/spec/snippets/binding/locals.rb +4 -1
  197. data/spec/snippets/numeric/filesize_format.rb +4 -1
  198. data/spec/snippets/numeric/time.rb +5 -2
  199. data/spec/snippets/object/__dir__.rb +4 -1
  200. data/spec/snippets/ordered_set.rb +4 -1
  201. data/spec/snippets/ramaze/acquire.rb +4 -1
  202. data/spec/snippets/ramaze/dictionary.rb +4 -1
  203. data/spec/snippets/ramaze/struct.rb +4 -1
  204. data/spec/snippets/string/camel_case.rb +4 -1
  205. data/spec/snippets/string/color.rb +4 -1
  206. data/spec/snippets/string/snake_case.rb +4 -1
  207. data/spec/snippets/string/unindent.rb +4 -1
  208. data/spec/snippets/thread/into.rb +4 -1
  209. data/tasks/bacon.rake +5 -3
  210. data/tasks/changelog.rake +3 -1
  211. data/tasks/{gem_installer.rake → gem_setup.rake} +45 -22
  212. data/tasks/release.rake +12 -27
  213. data/tasks/setup.rake +6 -0
  214. data/tasks/todo.rake +2 -4
  215. metadata +205 -31
  216. data/CHANGELOG +0 -16546
  217. data/benchmark/suite/template_builder.rb +0 -12
  218. data/doc/tutorial/todolist.mkd +0 -787
  219. data/examples/helpers/provide.rb +0 -23
  220. data/lib/proto/view/page.xhtml +0 -27
  221. data/lib/ramaze/snippets/divide.rb +0 -22
  222. data/lib/ramaze/snippets/kernel/constant.rb +0 -41
  223. data/lib/ramaze/snippets/object/acquire.rb +0 -37
  224. data/lib/ramaze/snippets/string/each.rb +0 -19
  225. data/spec/ramaze/helper/partial.rb +0 -40
  226. data/spec/snippets/kernel/constant.rb +0 -23
  227. 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 :belongs_to, model.to_s.downcase.to_sym
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.to_s.downcase.pluralize.to_sym
73
+ todo :many_to_many, plural_sym(model), :class => model
74
74
  end
75
75
 
76
76
  def has_one(model)
77
- todo :belongs_to, model.to_s.downcase.to_sym
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
@@ -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
- require 'ramaze/controller/default' if CONTROLLER_LIST.empty?
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
- CONTROLLER_LIST.each do |controller|
30
- unless controller.ancestral_trait[:provide_set]
31
- controller.engine(:Etanni)
32
- controller.trait(:provide_set => false)
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
@@ -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)
@@ -9,4 +9,5 @@ module Ramaze
9
9
 
10
10
  require 'ramaze/helper/flash'
11
11
  require 'ramaze/helper/link'
12
+ require 'ramaze/helper/layout'
12
13
  end
@@ -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
@@ -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, :action_value)
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 = cache_action.dup
32
- ttl = temp.delete(:ttl)
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
- if cached = cache[temp]
36
- return cached
37
- elsif ttl
38
- return cache.store(temp, yield, :ttl => ttl)
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
- return cache.store(temp, yield)
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
- # @return [Object] The cache wrapper assigned for :action_value
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.action_value
53
- end
54
-
81
+ def cache_value(key = nil, options = {})
82
+ cache = Ramaze::Cache.cache_helper_value
55
83
 
56
- # @deprecated Use the #cache_value method instead
57
- # @author manveru
58
- def value_cache
59
- Ramaze::deprecated('Innate::Helper::Cache#value_cache',
60
- 'Innate::Helper::Cache#cache_value')
61
- cache_value
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
- def cache(name, hash = {})
66
- Ramaze.deprecated('Helper::Cache::cache', 'Helper::Cache::cache_action')
67
- cache_action(hash.merge(:method => name))
68
- end
69
-
70
- def cache_action(hash)
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
@@ -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 hash[:multiple]
44
- s_args[:size] = hash[:size] || 1
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$]))+)?)* # path
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="#{Rs(:openid_begin)}">
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(Rs(:openid_complete)).to_s
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 Rs(:/)
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