rad_core 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) hide show
  1. data/Rakefile +10 -0
  2. data/lib/rad/controller/abstract_controller/micelaneous.rb +31 -0
  3. data/lib/rad/controller/abstract_controller/render.rb +160 -0
  4. data/lib/rad/controller/abstract_controller/responder.rb +17 -0
  5. data/lib/rad/controller/abstract_controller.rb +64 -0
  6. data/lib/rad/controller/controller_context.rb +15 -0
  7. data/lib/rad/controller/http_controller.rb +48 -0
  8. data/lib/rad/controller/processors/controller_caller.rb +28 -0
  9. data/lib/rad/controller/processors/controller_error_handling.rb +51 -0
  10. data/lib/rad/controller/processors/controller_logger.rb +12 -0
  11. data/lib/rad/controller.rb +28 -0
  12. data/lib/rad/conveyor/conveyor.rb +74 -0
  13. data/lib/rad/conveyor/conveyors.rb +20 -0
  14. data/lib/rad/conveyor/params.rb +14 -0
  15. data/lib/rad/conveyor/processor.rb +68 -0
  16. data/lib/rad/conveyor/processors/conveyor_logger.rb +25 -0
  17. data/lib/rad/conveyor/workspace.rb +36 -0
  18. data/lib/rad/conveyor.rb +29 -0
  19. data/lib/rad/environment/config.rb +111 -0
  20. data/lib/rad/environment/dependency_resolver.rb +107 -0
  21. data/lib/rad/environment/environment.rb +29 -0
  22. data/lib/rad/environment/files_helper.rb +55 -0
  23. data/lib/rad/environment/logger.rb +21 -0
  24. data/lib/rad/environment.rb +55 -0
  25. data/lib/rad/html/flash.rb +42 -0
  26. data/lib/rad/html/helpers/basic_html_helper.rb +83 -0
  27. data/lib/rad/html/helpers/flash_helper.rb +5 -0
  28. data/lib/rad/html/helpers/form_helper.rb +115 -0
  29. data/lib/rad/html/helpers/html_helper.rb +5 -0
  30. data/lib/rad/html/helpers/javascript_helper.rb +18 -0
  31. data/lib/rad/html/helpers/model_helper.rb +135 -0
  32. data/lib/rad/html/include_into_controller.rb +0 -0
  33. data/lib/rad/html/processors/prepare_flash.rb +26 -0
  34. data/lib/rad/html/processors/scoped_params.rb +26 -0
  35. data/lib/rad/html.rb +26 -0
  36. data/lib/rad/http/http.rb +21 -0
  37. data/lib/rad/http/http_adapter.rb +36 -0
  38. data/lib/rad/http/middleware/static_files.rb +21 -0
  39. data/lib/rad/http/processors/evaluate_format.rb +22 -0
  40. data/lib/rad/http/processors/http_logger.rb +15 -0
  41. data/lib/rad/http/processors/http_writer.rb +30 -0
  42. data/lib/rad/http/processors/prepare_params.rb +22 -0
  43. data/lib/rad/http/support/rack/fixes.rb +36 -0
  44. data/lib/rad/http/support/rack/rack_adapter.rb +67 -0
  45. data/lib/rad/http/support/rack/request.rb +42 -0
  46. data/lib/rad/http/support/rack/response.rb +86 -0
  47. data/lib/rad/http.rb +48 -0
  48. data/lib/rad/integration/controller_micelaneous_helper.rb +19 -0
  49. data/lib/rad/integration/router/abstract_routing_helper.rb +22 -0
  50. data/lib/rad/integration/router/controller_routing_helper.rb +58 -0
  51. data/lib/rad/integration/router/view_routing_helper.rb +104 -0
  52. data/lib/rad/integration.rb +30 -0
  53. data/lib/rad/mail/letter.rb +30 -0
  54. data/lib/rad/mail/mail_controller.rb +31 -0
  55. data/lib/rad/mail/mailer.rb +23 -0
  56. data/lib/rad/mail/processors/letter_builder.rb +36 -0
  57. data/lib/rad/mail.rb +15 -0
  58. data/lib/rad/profiles/mail.rb +16 -0
  59. data/lib/rad/profiles/web.rb +68 -0
  60. data/lib/rad/profiles/web_require.rb +5 -0
  61. data/lib/rad/remote/processors/remote_caller.rb +54 -0
  62. data/lib/rad/remote/processors/remote_logger.rb +13 -0
  63. data/lib/rad/remote/remote.rb +15 -0
  64. data/lib/rad/remote.rb +9 -0
  65. data/lib/rad/router/core/configurator.rb +25 -0
  66. data/lib/rad/router/core/core_routing_helper.rb +41 -0
  67. data/lib/rad/router/core/default_format_processor.rb +12 -0
  68. data/lib/rad/router/core/processors/router.rb +29 -0
  69. data/lib/rad/router/core/router.rb +271 -0
  70. data/lib/rad/router/core/simple_router.rb +23 -0
  71. data/lib/rad/router/routers/abstract_router.rb +62 -0
  72. data/lib/rad/router/routers/alias_router.rb +113 -0
  73. data/lib/rad/router/routers/restful_router.rb +113 -0
  74. data/lib/rad/router.rb +29 -0
  75. data/lib/rad/spec/controller.rb +41 -0
  76. data/lib/rad/spec/environment.rb +51 -0
  77. data/lib/rad/spec/http.rb +93 -0
  78. data/lib/rad/spec/mail.rb +31 -0
  79. data/lib/rad/spec/remote.rb +9 -0
  80. data/lib/rad/spec/router.rb +18 -0
  81. data/lib/rad/spec/template.rb +12 -0
  82. data/lib/rad/spec/view.rb +10 -0
  83. data/lib/rad/spec/xhtml.rb +33 -0
  84. data/lib/rad/spec.rb +11 -0
  85. data/lib/rad/support/active_support/locales/en/actionpack.yml +154 -0
  86. data/lib/rad/support/active_support/locales/en/activesupport.yml +36 -0
  87. data/lib/rad/support/active_support/micelaneous.rb +2 -0
  88. data/lib/rad/support/active_support/time.rb +105 -0
  89. data/lib/rad/support/active_support.rb +49 -0
  90. data/lib/rad/support/addressable.rb +45 -0
  91. data/lib/rad/support/buffered_logger.rb +44 -0
  92. data/lib/rad/support/callbacks.rb +168 -0
  93. data/lib/rad/support/exception.rb +31 -0
  94. data/lib/rad/support/filters.rb +34 -0
  95. data/lib/rad/support/format.rb +17 -0
  96. data/lib/rad/support/hacks_and_fixes.rb +23 -0
  97. data/lib/rad/support/micon.rb +13 -0
  98. data/lib/rad/support/mime.rb +13 -0
  99. data/lib/rad/support/module.rb +48 -0
  100. data/lib/rad/support/rson.rb +53 -0
  101. data/lib/rad/support/ruby_ext_with_active_support.rb +4 -0
  102. data/lib/rad/support/string.rb +26 -0
  103. data/lib/rad/support.rb +63 -0
  104. data/lib/rad/template/support/tilt.rb +68 -0
  105. data/lib/rad/template/support/tilt_fixes.rb +17 -0
  106. data/lib/rad/template/template.rb +250 -0
  107. data/lib/rad/template/template_context.rb +62 -0
  108. data/lib/rad/template.rb +25 -0
  109. data/lib/rad_core/gems.rb +31 -0
  110. data/readme.md +33 -0
  111. data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
  112. data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +11 -0
  113. data/spec/controller/abstract_controller_spec.rb +132 -0
  114. data/spec/controller/controller_context_spec/views/ItemSpec/actions.erb +4 -0
  115. data/spec/controller/controller_context_spec/views/ItemSpec/show.erb +0 -0
  116. data/spec/controller/controller_context_spec/views/ItemSpec/update.erb +0 -0
  117. data/spec/controller/controller_context_spec/views/NamespaceSpec/ClassSpec/show.erb +0 -0
  118. data/spec/controller/controller_context_spec/views/PageSpec/actions.erb +3 -0
  119. data/spec/controller/controller_context_spec/views/PageSpec/show.erb +0 -0
  120. data/spec/controller/controller_context_spec/views/namespace_spec/class_spec/update.erb +0 -0
  121. data/spec/controller/controller_context_spec.rb +123 -0
  122. data/spec/controller/controller_helper_spec/views/HelperMethodSpec/action.erb +1 -0
  123. data/spec/controller/controller_helper_spec/views/HelperSpec/action.erb +1 -0
  124. data/spec/controller/controller_helper_spec.rb +53 -0
  125. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/action.erb +1 -0
  126. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/custom_template.erb +1 -0
  127. data/spec/controller/controller_render_spec/views/AnotherActionSpec/another_action.erb +1 -0
  128. data/spec/controller/controller_render_spec/views/AnotherLayout/action.erb +1 -0
  129. data/spec/controller/controller_render_spec/views/ForbidPartialAsActionSpec/_action.erb +1 -0
  130. data/spec/controller/controller_render_spec/views/FormatSpec/action.html.erb +1 -0
  131. data/spec/controller/controller_render_spec/views/FormatSpec/action.js.erb +1 -0
  132. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_with_layout.erb +1 -0
  133. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_without_layout.erb +1 -0
  134. data/spec/controller/controller_render_spec/views/LayoutSpec/action.erb +1 -0
  135. data/spec/controller/controller_render_spec/views/MultipleActions/actions.haml +7 -0
  136. data/spec/controller/controller_render_spec/views/layouts/admin.erb +1 -0
  137. data/spec/controller/controller_render_spec/views/layouts/app.html.erb +1 -0
  138. data/spec/controller/controller_render_spec/views/layouts/app.js.erb +1 -0
  139. data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/action.erb +1 -0
  140. data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/another_action.erb +1 -0
  141. data/spec/controller/controller_render_spec/views/some_template.erb +1 -0
  142. data/spec/controller/controller_render_spec/views/standalone.html.erb +1 -0
  143. data/spec/controller/controller_render_spec.rb +217 -0
  144. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/a.erb +1 -0
  145. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/b.erb +1 -0
  146. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/c.erb +1 -0
  147. data/spec/controller/error_handling_spec.rb +117 -0
  148. data/spec/controller/http_controller_spec.rb +130 -0
  149. data/spec/controller/spec_helper.rb +19 -0
  150. data/spec/conveyor/conveyor_spec.rb +124 -0
  151. data/spec/conveyor/spec_helper.rb +3 -0
  152. data/spec/environment/config_spec/config.default.yml +3 -0
  153. data/spec/environment/config_spec/config.development.yml +3 -0
  154. data/spec/environment/config_spec/config.yml +5 -0
  155. data/spec/environment/config_spec.rb +30 -0
  156. data/spec/environment/environment_spec/path1/file1 +0 -0
  157. data/spec/environment/environment_spec/path1/some_folder/some_file +0 -0
  158. data/spec/environment/environment_spec/path2/file2 +0 -0
  159. data/spec/environment/environment_spec/path2/some_folder/some_file +0 -0
  160. data/spec/environment/environment_spec.rb +65 -0
  161. data/spec/environment/logger_spec.rb +19 -0
  162. data/spec/environment/minimal_app_spec/app.rb +1 -0
  163. data/spec/environment/minimal_app_spec.rb +25 -0
  164. data/spec/environment/spec_helper.rb +1 -0
  165. data/spec/environment/standard_app_spec/app/lib/app/init.rb +3 -0
  166. data/spec/environment/standard_app_spec/plugin_a/lib/plugin_a/init.rb +1 -0
  167. data/spec/environment/standard_app_spec/plugin_b/lib/emptygit +0 -0
  168. data/spec/environment/standard_app_spec.rb +48 -0
  169. data/spec/html/basic_html_helper_spec.rb +29 -0
  170. data/spec/html/form_helper_spec.rb +63 -0
  171. data/spec/html/javascript_helper_spec.rb +15 -0
  172. data/spec/html/model_helper_spec.rb +81 -0
  173. data/spec/html/scoped_params_spec.rb +15 -0
  174. data/spec/html/spec_helper.rb +28 -0
  175. data/spec/http/http_spec/app/lib/app/init.rb +10 -0
  176. data/spec/http/http_spec/app/runtime/public/emptygit +0 -0
  177. data/spec/http/http_spec/plugin_a/lib/plugin_a/init.rb +0 -0
  178. data/spec/http/http_spec/plugin_b/lib/plugin_b/init.rb +5 -0
  179. data/spec/http/http_spec/plugin_b/static/emptygit +0 -0
  180. data/spec/http/http_spec.rb +51 -0
  181. data/spec/http/micelaneous_spec.rb +13 -0
  182. data/spec/http/spec_helper.rb +5 -0
  183. data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
  184. data/spec/integration/basic_spec.rb +79 -0
  185. data/spec/integration/controller_routing_helper_spec.rb +84 -0
  186. data/spec/integration/flash_spec.rb +206 -0
  187. data/spec/integration/spec_helper.rb +5 -0
  188. data/spec/integration/spec_helper_spec.rb +63 -0
  189. data/spec/integration/view_routing_helper_spec.rb +134 -0
  190. data/spec/mail/mail_controller_spec/views/body_template_spec/signup.erb +1 -0
  191. data/spec/mail/mail_controller_spec.rb +61 -0
  192. data/spec/mail/spec_helper.rb +7 -0
  193. data/spec/remote/remote_spec.rb +75 -0
  194. data/spec/remote/spec_helper.rb +17 -0
  195. data/spec/router/alias_router_spec.rb +98 -0
  196. data/spec/router/basic_spec.rb +111 -0
  197. data/spec/router/configurator_spec.rb +18 -0
  198. data/spec/router/integration_spec.rb +42 -0
  199. data/spec/router/persistent_params_spec.rb +65 -0
  200. data/spec/router/restful_router_spec.rb +120 -0
  201. data/spec/router/routing_helper_spec.rb +55 -0
  202. data/spec/router/spec_helper.rb +20 -0
  203. data/spec/support/callbacks_spec.rb +157 -0
  204. data/spec/support/filters_spec.rb +60 -0
  205. data/spec/support/spec_helper.rb +4 -0
  206. data/spec/template/spec_helper.rb +6 -0
  207. data/spec/template/template_spec/file.erb +1 -0
  208. data/spec/template/template_spec/views/basic/custom_context.erb +1 -0
  209. data/spec/template/template_spec/views/basic/extension.erb +1 -0
  210. data/spec/template/template_spec/views/basic/general.html.erb +5 -0
  211. data/spec/template/template_spec/views/basic/non_existing_format.html.erb +0 -0
  212. data/spec/template/template_spec/views/format/format.erb +1 -0
  213. data/spec/template/template_spec/views/format/format.html.erb +1 -0
  214. data/spec/template/template_spec/views/format/format.js.erb +1 -0
  215. data/spec/template/template_spec/views/format_for_partials/_form.html.erb +1 -0
  216. data/spec/template/template_spec/views/format_for_partials/dialog.js.erb +1 -0
  217. data/spec/template/template_spec/views/layout/basic/content.erb +1 -0
  218. data/spec/template/template_spec/views/layout/basic/layout.erb +1 -0
  219. data/spec/template/template_spec/views/layout/content_for/content.erb +3 -0
  220. data/spec/template/template_spec/views/layout/content_for/layout.erb +3 -0
  221. data/spec/template/template_spec/views/layout/format/content.html.erb +1 -0
  222. data/spec/template/template_spec/views/layout/format/content.js.erb +1 -0
  223. data/spec/template/template_spec/views/layout/format/layout.html.erb +1 -0
  224. data/spec/template/template_spec/views/layout/format/layout.js.erb +1 -0
  225. data/spec/template/template_spec/views/layout/nested_yield/a.erb +1 -0
  226. data/spec/template/template_spec/views/layout/nested_yield/layout.erb +1 -0
  227. data/spec/template/template_spec/views/layout/nested_yield/layout_b.erb +1 -0
  228. data/spec/template/template_spec/views/layout/same_context/a.erb +1 -0
  229. data/spec/template/template_spec/views/layout/same_context/b.erb +1 -0
  230. data/spec/template/template_spec/views/layout/same_context/layout.erb +1 -0
  231. data/spec/template/template_spec/views/nested/format/a.erb +1 -0
  232. data/spec/template/template_spec/views/nested/format/b.erb +1 -0
  233. data/spec/template/template_spec/views/nested/relative/a.erb +1 -0
  234. data/spec/template/template_spec/views/nested/relative/b.erb +1 -0
  235. data/spec/template/template_spec/views/nested/relative/c.erb +1 -0
  236. data/spec/template/template_spec/views/nested/shared/c.erb +1 -0
  237. data/spec/template/template_spec/views/nesting_format/_edit.html.erb +1 -0
  238. data/spec/template/template_spec/views/nesting_format/_form.html.erb +1 -0
  239. data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -0
  240. data/spec/template/template_spec/views/other/template.erb +1 -0
  241. data/spec/template/template_spec/views/prefixes/_underscored.erb +1 -0
  242. data/spec/template/template_spec/views/prefixes/without_prefix.erb +1 -0
  243. data/spec/template/template_spec.rb +204 -0
  244. data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -0
  245. data/spec/template/tilt_spec/views/concat_and_capture.haml +3 -0
  246. data/spec/template/tilt_spec/views/encoding/erb.erb +1 -0
  247. data/spec/template/tilt_spec/views/encoding/haml.haml +1 -0
  248. data/spec/template/tilt_spec/views/errors.erb +3 -0
  249. data/spec/template/tilt_spec/views/errors.haml +3 -0
  250. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_erb.erb +4 -0
  251. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_haml.haml +1 -0
  252. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_erb.erb +1 -0
  253. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_haml.haml +2 -0
  254. data/spec/template/tilt_spec/views/nested_capture_and_concat.haml +3 -0
  255. data/spec/template/tilt_spec/views/ugly.haml +3 -0
  256. data/spec/template/tilt_spec/views/yield.erb +1 -0
  257. data/spec/template/tilt_spec.rb +98 -0
  258. metadata +531 -0
@@ -0,0 +1,93 @@
1
+ require 'rad/spec/controller'
2
+
3
+ rspec do
4
+ def request
5
+ rad.workspace.request
6
+ end
7
+
8
+ def self.with_http
9
+ with_controller
10
+
11
+ before :all do
12
+ rad.before_scope :cycle do
13
+ if defined?(Rad::Processors) and defined?(Rad::Processors::PrepareParams)
14
+ rad.conveyors.web do |web|
15
+ web.definitions.delete_if{|pdef, args| pdef == Rad::Processors::PrepareParams}
16
+ web.build!
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ WCALL_OPTIONS = [:controller]
24
+ attr_writer :wcall_options
25
+ def wcall_options; @wcall_options ||= {} end
26
+
27
+ def set_wcall options
28
+ invalid_options = options.keys - WCALL_OPTIONS
29
+ raise "Unsupported options #{invalid_options}!" unless invalid_options.empty?
30
+
31
+ self.wcall_options = options
32
+ end
33
+
34
+ def set_controller controller_class
35
+ set_wcall controller: controller_class
36
+ end
37
+
38
+ def self.set_controller &block
39
+ block.must_be.defined
40
+ before(:each){set_controller block.call}
41
+ end
42
+
43
+ def wcall *args, &block
44
+ workspace_variables, params = parse_wcall_arguments *args
45
+ ccall nil, nil, params, workspace_variables, &block
46
+ end
47
+
48
+ def post_wcall *args, &block
49
+ params = args.extract_options!
50
+ raise "_method variable already set!" if params.include?(:_method) or params.include?('_method')
51
+ wcall(*(args << params.merge(_method: 'post')), &block)
52
+ end
53
+
54
+ protected
55
+ def parse_wcall_arguments *args
56
+ # parsing params
57
+ params = args.extract_options!
58
+ first = args.first
59
+
60
+ workspace_variables = {}
61
+ if args.size == 1 and first.is_a?(String) and first =~ /^\//
62
+ workspace_variables[:path] = first
63
+ elsif (first.is_a?(String) or first.is_a?(Symbol)) and args.size <= 2
64
+ workspace_variables[:path] = '/'
65
+ workspace_variables[:class] = wcall_options[:controller] || raise("not defined wcall controller (use set_wcall controller: SomeController)!")
66
+ workspace_variables[:method_name] = first
67
+ workspace_variables.merge! args[1] if args.size > 1
68
+ elsif first.is_a?(Class) and args.size <= 3
69
+ workspace_variables[:path] = '/'
70
+ workspace_variables[:class] = args[0]
71
+ workspace_variables[:method_name] = args[1]
72
+ workspace_variables.merge! args[2] if args.size > 2
73
+ else
74
+ raise "Invalid input!"
75
+ end
76
+
77
+ # preparing environment
78
+ workspace_variables[:env] ||= {}
79
+ workspace_variables[:env].reverse_merge! Rad::HTTPAdapter.mock_environment
80
+
81
+ # setting request method
82
+ if request_method = params.delete(:_method) || params.delete('_method')
83
+ request_method = request_method.to_s.upcase
84
+ raise "invalid request method :#{request}" unless %w(GET POST PUT DELETE).include? request_method.
85
+ raise "REQUEST_METHOD variable already set!" if workspace_variables[:env].include? 'REQUEST_METHOD'
86
+ workspace_variables[:env]['REQUEST_METHOD'] = request_method
87
+ end
88
+
89
+ workspace_variables[:request] = Rad::Request.new(workspace_variables[:env])
90
+
91
+ return workspace_variables, params
92
+ end
93
+ end
@@ -0,0 +1,31 @@
1
+ module Rad
2
+ module RSpecHelper
3
+ def sent_letters
4
+ Rad::RSpecHelper.sent_letters
5
+ end
6
+
7
+ class << self
8
+ attr_accessor :sent_letters
9
+ end
10
+ end
11
+ end
12
+
13
+ rspec do
14
+ def self.with_mail
15
+ Rad::Mailer.class_eval do
16
+ def deliver letter
17
+ Rad::RSpecHelper.sent_letters << letter
18
+ end
19
+ end
20
+
21
+ Mail.defaults do
22
+ delivery_method :test
23
+ end
24
+
25
+ rspec.include Rad::RSpecHelper
26
+
27
+ before :each do
28
+ Rad::RSpecHelper.sent_letters = []
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ require 'rad/spec/environment'
2
+
3
+ rspec do
4
+ def rcall klass, method, params = {}
5
+ rad.conveyors.services.call(
6
+ class: klass, method_name: method, params: Rad::Params.new(params)
7
+ )
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ require 'rad/router'
2
+
3
+ rspec do
4
+ def self.with_router
5
+ include Rad::CoreRoutingHelper
6
+ end
7
+ end
8
+
9
+ # Rad::Response.class_eval do
10
+ # def success?
11
+ # headers['Location'].blank?
12
+ # end
13
+ # end
14
+
15
+ rspec.define_matcher :redirect_to do |actual, expected|
16
+ (actual.headers['Location'] and actual.headers['Location'].include?(expected)) or
17
+ (actual.body and actual.body.include?('window.location') and actual.body.include?(expected))
18
+ end
@@ -0,0 +1,12 @@
1
+ rspec do
2
+ def self.with_view_path *args
3
+ list = if args.first.is_a? Array
4
+ args.first
5
+ else
6
+ args
7
+ end
8
+
9
+ before(:all){list.each{|path| Rad::Template.paths << path}}
10
+ after(:all){list.each{|path| Rad::Template.paths.delete path}}
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ raise 'not finished'
2
+
3
+ #
4
+ # Routes
5
+ #
6
+ rspec do
7
+ def default_path
8
+ rad.config.default_path!
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ class String
2
+ def to_xhtml css = nil
3
+ node = Nokogiri::HTML(self)
4
+ unless css
5
+ node
6
+ else
7
+ nodes = node.css(css)
8
+ raise "Elements for '#{css}' CSS query not found!" if nodes.size < 1
9
+ raise "Found more than one elment for '#{css}' CSS query!" if nodes.size > 1
10
+ nodes.first
11
+ end
12
+ end
13
+ end
14
+
15
+ require 'nokogiri'
16
+ ::Nokogiri::XML::Node.class_eval do
17
+ def should_be_fuzzy_equal_to attributes
18
+ node_attributes = {}
19
+
20
+ attributes.each do |k, v|
21
+ nv = if k.to_s == 'content'
22
+ self.content
23
+ else
24
+ self[k.to_s]
25
+ end
26
+ node_attributes[k] = nv
27
+ end
28
+
29
+ node_attributes.should == attributes
30
+ end
31
+
32
+
33
+ end
data/lib/rad/spec.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rspec_ext'
2
+
3
+ %w(
4
+ controller
5
+ environment
6
+ template
7
+ http
8
+ mail
9
+ remote
10
+ router
11
+ ).each{|f| require "rad/spec/#{f}"}
@@ -0,0 +1,154 @@
1
+ "en":
2
+ number:
3
+ # Used in number_with_delimiter()
4
+ # These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
5
+ format:
6
+ # Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
7
+ separator: "."
8
+ # Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three)
9
+ delimiter: ","
10
+ # Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
11
+ precision: 3
12
+ # If set to true, precision will mean the number of significant digits instead
13
+ # of the number of decimal digits (1234 with precision 2 becomes 1200, 1.23543 becomes 1.2)
14
+ significant: false
15
+ # If set, the zeros after the decimal separator will always be stripped (eg.: 1.200 will be 1.2)
16
+ strip_insignificant_zeros: false
17
+
18
+ # Used in number_to_currency()
19
+ currency:
20
+ format:
21
+ # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
22
+ format: "%u%n"
23
+ unit: "$"
24
+ # These five are to override number.format and are optional
25
+ separator: "."
26
+ delimiter: ","
27
+ precision: 2
28
+ significant: false
29
+ strip_insignificant_zeros: false
30
+
31
+ # Used in number_to_percentage()
32
+ percentage:
33
+ format:
34
+ # These five are to override number.format and are optional
35
+ # separator:
36
+ delimiter: ""
37
+ # precision:
38
+ # significant: false
39
+ # strip_insignificant_zeros: false
40
+
41
+ # Used in number_to_precision()
42
+ precision:
43
+ format:
44
+ # These five are to override number.format and are optional
45
+ # separator:
46
+ delimiter: ""
47
+ # precision:
48
+ # significant: false
49
+ # strip_insignificant_zeros: false
50
+
51
+ # Used in number_to_human_size() and number_to_human()
52
+ human:
53
+ format:
54
+ # These five are to override number.format and are optional
55
+ # separator:
56
+ delimiter: ""
57
+ precision: 3
58
+ significant: true
59
+ strip_insignificant_zeros: true
60
+ # Used in number_to_human_size()
61
+ storage_units:
62
+ # Storage units output formatting.
63
+ # %u is the storage unit, %n is the number (default: 2 MB)
64
+ format: "%n %u"
65
+ units:
66
+ byte:
67
+ one: "Byte"
68
+ other: "Bytes"
69
+ kb: "KB"
70
+ mb: "MB"
71
+ gb: "GB"
72
+ tb: "TB"
73
+ # Used in number_to_human()
74
+ decimal_units:
75
+ format: "%n %u"
76
+ # Decimal units output formatting
77
+ # By default we will only quantify some of the exponents
78
+ # but the commented ones might be defined or overridden
79
+ # by the user.
80
+ units:
81
+ # femto: Quadrillionth
82
+ # pico: Trillionth
83
+ # nano: Billionth
84
+ # micro: Millionth
85
+ # mili: Thousandth
86
+ # centi: Hundredth
87
+ # deci: Tenth
88
+ unit: ""
89
+ # ten:
90
+ # one: Ten
91
+ # other: Tens
92
+ # hundred: Hundred
93
+ thousand: Thousand
94
+ million: Million
95
+ billion: Billion
96
+ trillion: Trillion
97
+ quadrillion: Quadrillion
98
+
99
+ # Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
100
+ datetime:
101
+ distance_in_words:
102
+ half_a_minute: "half a minute"
103
+ less_than_x_seconds:
104
+ one: "less than 1 second"
105
+ other: "less than %{count} seconds"
106
+ x_seconds:
107
+ one: "1 second"
108
+ other: "%{count} seconds"
109
+ less_than_x_minutes:
110
+ one: "less than a minute"
111
+ other: "less than %{count} minutes"
112
+ x_minutes:
113
+ one: "1 minute"
114
+ other: "%{count} minutes"
115
+ about_x_hours:
116
+ one: "about 1 hour"
117
+ other: "about %{count} hours"
118
+ x_days:
119
+ one: "1 day"
120
+ other: "%{count} days"
121
+ about_x_months:
122
+ one: "about 1 month"
123
+ other: "about %{count} months"
124
+ x_months:
125
+ one: "1 month"
126
+ other: "%{count} months"
127
+ about_x_years:
128
+ one: "about 1 year"
129
+ other: "about %{count} years"
130
+ over_x_years:
131
+ one: "over 1 year"
132
+ other: "over %{count} years"
133
+ almost_x_years:
134
+ one: "almost 1 year"
135
+ other: "almost %{count} years"
136
+ prompts:
137
+ year: "Year"
138
+ month: "Month"
139
+ day: "Day"
140
+ hour: "Hour"
141
+ minute: "Minute"
142
+ second: "Seconds"
143
+
144
+ helpers:
145
+ select:
146
+ # Default value for :prompt => true in FormOptionsHelper
147
+ prompt: "Please select"
148
+
149
+ # Default translation keys for submit FormHelper
150
+ submit:
151
+ create: 'Create %{model}'
152
+ update: 'Update %{model}'
153
+ submit: 'Save %{model}'
154
+
@@ -0,0 +1,36 @@
1
+ en:
2
+ date:
3
+ formats:
4
+ # Use the strftime parameters for formats.
5
+ # When no format has been given, it uses default.
6
+ # You can provide other formats here if you like!
7
+ default: "%Y-%m-%d"
8
+ short: "%b %d"
9
+ long: "%B %d, %Y"
10
+
11
+ day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
12
+ abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
13
+
14
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
15
+ month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
16
+ abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
17
+ # Used in date_select and datetime_select.
18
+ order:
19
+ - :year
20
+ - :month
21
+ - :day
22
+
23
+ time:
24
+ formats:
25
+ default: "%a, %d %b %Y %H:%M:%S %z"
26
+ short: "%d %b %H:%M"
27
+ long: "%B %d, %Y %H:%M"
28
+ am: "am"
29
+ pm: "pm"
30
+
31
+ # Used in array.to_sentence.
32
+ support:
33
+ array:
34
+ words_connector: ", "
35
+ two_words_connector: " and "
36
+ last_word_connector: ", and "
@@ -0,0 +1,2 @@
1
+ # default time
2
+ Time::DATE_FORMATS[:default] = "%Y-%m-%d %H:%M:%S"
@@ -0,0 +1,105 @@
1
+ class Time
2
+ # Reports the approximate distance in time between two Time or Date objects or integers as seconds.
3
+ # Set <tt>include_seconds</tt> to true if you want more detailed approximations when distance < 1 min, 29 secs
4
+ # Distances are reported based on the following table:
5
+ #
6
+ # 0 <-> 29 secs # => less than a minute
7
+ # 30 secs <-> 1 min, 29 secs # => 1 minute
8
+ # 1 min, 30 secs <-> 44 mins, 29 secs # => [2..44] minutes
9
+ # 44 mins, 30 secs <-> 89 mins, 29 secs # => about 1 hour
10
+ # 89 mins, 29 secs <-> 23 hrs, 59 mins, 29 secs # => about [2..24] hours
11
+ # 23 hrs, 59 mins, 29 secs <-> 47 hrs, 59 mins, 29 secs # => 1 day
12
+ # 47 hrs, 59 mins, 29 secs <-> 29 days, 23 hrs, 59 mins, 29 secs # => [2..29] days
13
+ # 29 days, 23 hrs, 59 mins, 30 secs <-> 59 days, 23 hrs, 59 mins, 29 secs # => about 1 month
14
+ # 59 days, 23 hrs, 59 mins, 30 secs <-> 1 yr minus 1 sec # => [2..12] months
15
+ # 1 yr <-> 1 yr, 3 months # => about 1 year
16
+ # 1 yr, 3 months <-> 1 yr, 9 months # => over 1 year
17
+ # 1 yr, 9 months <-> 2 yr minus 1 sec # => almost 2 years
18
+ # 2 yrs <-> max time or date # => (same rules as 1 yr)
19
+ #
20
+ # With <tt>include_seconds</tt> = true and the difference < 1 minute 29 seconds:
21
+ # 0-4 secs # => less than 5 seconds
22
+ # 5-9 secs # => less than 10 seconds
23
+ # 10-19 secs # => less than 20 seconds
24
+ # 20-39 secs # => half a minute
25
+ # 40-59 secs # => less than a minute
26
+ # 60-89 secs # => 1 minute
27
+ #
28
+ # ==== Examples
29
+ # from_time = Time.now
30
+ # distance_of_time_in_words(from_time, from_time + 50.minutes) # => about 1 hour
31
+ # distance_of_time_in_words(from_time, 50.minutes.from_now) # => about 1 hour
32
+ # distance_of_time_in_words(from_time, from_time + 15.seconds) # => less than a minute
33
+ # distance_of_time_in_words(from_time, from_time + 15.seconds, true) # => less than 20 seconds
34
+ # distance_of_time_in_words(from_time, 3.years.from_now) # => about 3 years
35
+ # distance_of_time_in_words(from_time, from_time + 60.hours) # => about 3 days
36
+ # distance_of_time_in_words(from_time, from_time + 45.seconds, true) # => less than a minute
37
+ # distance_of_time_in_words(from_time, from_time - 45.seconds, true) # => less than a minute
38
+ # distance_of_time_in_words(from_time, 76.seconds.from_now) # => 1 minute
39
+ # distance_of_time_in_words(from_time, from_time + 1.year + 3.days) # => about 1 year
40
+ # distance_of_time_in_words(from_time, from_time + 3.years + 6.months) # => over 3 years
41
+ # distance_of_time_in_words(from_time, from_time + 4.years + 9.days + 30.minutes + 5.seconds) # => about 4 years
42
+ #
43
+ # to_time = Time.now + 6.years + 19.days
44
+ # distance_of_time_in_words(from_time, to_time, true) # => about 6 years
45
+ # distance_of_time_in_words(to_time, from_time, true) # => about 6 years
46
+ # distance_of_time_in_words(Time.now, Time.now) # => less than a minute
47
+ #
48
+ def distance_of_time_in_words(to_time = 0, include_seconds = false, options = {})
49
+ from_time = self
50
+
51
+ from_time = from_time.to_time if from_time.respond_to?(:to_time)
52
+ to_time = to_time.to_time if to_time.respond_to?(:to_time)
53
+ distance_in_minutes = (((to_time - from_time).abs)/60).round
54
+ distance_in_seconds = ((to_time - from_time).abs).round
55
+
56
+ I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
57
+ case distance_in_minutes
58
+ when 0..1
59
+ return distance_in_minutes == 0 ?
60
+ locale.t(:less_than_x_minutes, :count => 1) :
61
+ locale.t(:x_minutes, :count => distance_in_minutes) unless include_seconds
62
+
63
+ case distance_in_seconds
64
+ when 0..4 then locale.t :less_than_x_seconds, :count => 5
65
+ when 5..9 then locale.t :less_than_x_seconds, :count => 10
66
+ when 10..19 then locale.t :less_than_x_seconds, :count => 20
67
+ when 20..39 then locale.t :half_a_minute
68
+ when 40..59 then locale.t :less_than_x_minutes, :count => 1
69
+ else locale.t :x_minutes, :count => 1
70
+ end
71
+
72
+ when 2..44 then locale.t :x_minutes, :count => distance_in_minutes
73
+ when 45..89 then locale.t :about_x_hours, :count => 1
74
+ when 90..1439 then locale.t :about_x_hours, :count => (distance_in_minutes.to_f / 60.0).round
75
+ when 1440..2529 then locale.t :x_days, :count => 1
76
+ when 2530..43199 then locale.t :x_days, :count => (distance_in_minutes.to_f / 1440.0).round
77
+ when 43200..86399 then locale.t :about_x_months, :count => 1
78
+ when 86400..525599 then locale.t :x_months, :count => (distance_in_minutes.to_f / 43200.0).round
79
+ else
80
+ distance_in_years = distance_in_minutes / 525600
81
+ minute_offset_for_leap_year = (distance_in_years / 4) * 1440
82
+ remainder = ((distance_in_minutes - minute_offset_for_leap_year) % 525600)
83
+ if remainder < 131400
84
+ locale.t(:about_x_years, :count => distance_in_years)
85
+ elsif remainder < 394200
86
+ locale.t(:over_x_years, :count => distance_in_years)
87
+ else
88
+ locale.t(:almost_x_years, :count => distance_in_years + 1)
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ # Like distance_of_time_in_words, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>.
95
+ #
96
+ # ==== Examples
97
+ # time_ago_in_words(3.minutes.from_now) # => 3 minutes
98
+ # time_ago_in_words(Time.now - 15.hours) # => 15 hours
99
+ # time_ago_in_words(Time.now) # => less than a minute
100
+ #
101
+ # from_time = Time.now - 3.days - 14.minutes - 25.seconds # => 3 days
102
+ def time_ago_in_words(include_seconds = false)
103
+ distance_of_time_in_words(Time.now, include_seconds)
104
+ end
105
+ end
@@ -0,0 +1,49 @@
1
+ require 'active_support/all'
2
+
3
+ # gem 'activesupport' #, '= 2.3.5'
4
+ #
5
+ # # autoload :BacktraceCleaner, 'active_support/backtrace_cleaner'
6
+ # autoload :Base64, 'active_support/base64'
7
+ # # autoload :BasicObject, 'active_support/basic_object' we use our own implementation
8
+ #
9
+ # # autoload :BufferedLogger, 'active_support/buffered_logger'
10
+ # # autoload :Cache, 'active_support/cache'
11
+ # # autoload :Callbacks, 'active_support/callbacks'
12
+ # # autoload :Deprecation, 'active_support/deprecation'
13
+ # # autoload :Duration, 'active_support/duration'
14
+ # # autoload :Gzip, 'active_support/gzip'
15
+ # autoload :Inflector, 'active_support/inflector'
16
+ # # autoload :Memoizable, 'active_support/memoizable'
17
+ # # autoload :MessageEncryptor, 'active_support/message_encryptor'
18
+ # # autoload :MessageVerifier, 'active_support/message_verifier'
19
+ # # autoload :Multibyte, 'active_support/multibyte'
20
+ # # autoload :OptionMerger, 'active_support/option_merger'
21
+ # # autoload :OrderedHash, 'active_support/ordered_hash'
22
+ # # autoload :OrderedOptions, 'active_support/ordered_options'
23
+ # # autoload :Rescuable, 'active_support/rescuable'
24
+ # # autoload :SecureRandom, 'active_support/secure_random'
25
+ # # autoload :StringInquirer, 'active_support/string_inquirer'
26
+ # autoload :TimeWithZone, 'active_support/time_with_zone'
27
+ # autoload :TimeZone, 'active_support/values/time_zone'
28
+ # # autoload :XmlMini, 'active_support/xml_mini'
29
+ #
30
+ # # require 'active_support/vendor'
31
+ # require 'active_support/core_ext'
32
+ # # require 'active_support/dependencies'
33
+ # # require 'active_support/json'
34
+
35
+
36
+ #
37
+ # Hacks
38
+ #
39
+ %w(
40
+ micelaneous
41
+ time
42
+ ).each{|f| require "rad/support/active_support/#{f}"}
43
+
44
+
45
+ #
46
+ # Locales
47
+ #
48
+ support_dir = File.dirname __FILE__
49
+ I18n.load_path += Dir["#{support_dir}/active_support/locales/**/*.{rb,yml}"]
@@ -0,0 +1,45 @@
1
+ Addressable::URI.class_eval do
2
+ def request_uri
3
+ return nil if self.absolute? && self.scheme !~ /^https?$/
4
+ return (
5
+ (self.path != "" ? self.path : "/") +
6
+ (self.query ? "?#{self.query}" : "")
7
+ )
8
+ end
9
+
10
+ def self.normalize_host host
11
+ host.gsub(/^www\./, "")
12
+ end
13
+
14
+ def normalized_host
15
+ host ? host : host.gsub(/^www\./, '')
16
+ end
17
+
18
+ # Delete 'nil' keys
19
+ def query_values_with_skip_nil= options
20
+ to_delete = []
21
+ options.each{|k, v| to_delete << k if v.nil?}
22
+ to_delete.each{|k| options.delete k}
23
+
24
+ self.query_values_without_skip_nil = options
25
+ end
26
+ alias_method_chain :query_values=, :skip_nil
27
+
28
+
29
+ # Override original to fix:
30
+ # - extra '?' sign (/some_path?) if there's empty but not-nil query
31
+ def to_s
32
+ @uri_string ||= (begin
33
+ uri_string = ""
34
+ uri_string << "#{self.scheme}:" if self.scheme != nil
35
+ uri_string << "//#{self.authority}" if self.authority != nil
36
+ uri_string << self.path.to_s
37
+ uri_string << "?#{self.query}" unless self.query.blank?
38
+ uri_string << "##{self.fragment}" if self.fragment != nil
39
+ if uri_string.respond_to?(:force_encoding)
40
+ uri_string.force_encoding(Encoding::UTF_8)
41
+ end
42
+ uri_string
43
+ end)
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # In development mode log also to STDOUT
3
+ #
4
+ ActiveSupport::BufferedLogger.class_eval do
5
+
6
+ def flush_with_stdout
7
+ STDOUT.write(buffer.join) unless buffer.empty?
8
+ flush_without_stdout
9
+ end
10
+ rad.after :config do
11
+ if rad.include?(:config) and (rad.config.development? or rad.config.stdout_logger(false))
12
+ alias_method_chain :flush, :stdout
13
+ end
14
+ end
15
+
16
+
17
+ def info_with_format obj
18
+ info_without_format(obj_to_string(obj))
19
+ end
20
+ alias_method_chain :info, :format
21
+
22
+ def warn_with_format obj
23
+ warn_without_format("WARN: " + obj_to_string(obj))
24
+ end
25
+ alias_method_chain :warn, :format
26
+
27
+ def error_with_format obj
28
+ error_without_format("ERROR: " + obj_to_string(obj))
29
+ end
30
+ alias_method_chain :error, :format
31
+
32
+ protected
33
+ def obj_to_string obj
34
+ if obj.is_a? Exception
35
+ backtrace = (obj.backtrace && obj.backtrace.sfilter(Exception.common_filters)) || []
36
+ %{\
37
+ #{obj.message}
38
+ #{backtrace.join("\n ")}
39
+ }
40
+ else
41
+ obj.to_s
42
+ end
43
+ end
44
+ end