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,36 @@
1
+ module Rad
2
+ class Workspace < OpenObject
3
+ def params
4
+ self[:params] || Params.new
5
+ end
6
+
7
+ def params?
8
+ !!params
9
+ end
10
+
11
+ alias_method :set_without_params, :[]=
12
+ def []= k, v
13
+ if k.to_s == 'params'
14
+ self.params = v
15
+ else
16
+ set_without_params k, v
17
+ end
18
+ end
19
+
20
+ def params= v
21
+ if v.is_a? Params
22
+ set_without_params :params, v
23
+ else
24
+ set_without_params :params, Params.new(v)
25
+ end
26
+ end
27
+
28
+ def inspect
29
+ h = {}
30
+ each{|k, v| h[k] = v}
31
+ h['env'] = "..." if h.include? 'env'
32
+ h['request'] = "..." if h.include? 'request'
33
+ h.inspect
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ # Conveyor is the heart of Rad, it allows for Processors to process request and build responce.
2
+
3
+ require 'rad/environment'
4
+
5
+ [
6
+ # 'config',
7
+ 'params',
8
+ 'workspace',
9
+ 'processor',
10
+ 'conveyor',
11
+ 'conveyors',
12
+ 'processors/conveyor_logger',
13
+ ].each{|f| require "rad/conveyor/#{f}"}
14
+
15
+ Rad.metaclass_eval do
16
+ inject conveyors: :conveyors
17
+ end
18
+
19
+ #
20
+ # Initializations
21
+ #
22
+ rad do
23
+ register :workspace, scope: :cycle, depends_on: :environment
24
+ register :conveyors, depends_on: :environment do
25
+ Rad::Conveyors.new
26
+ end
27
+ end
28
+
29
+ Rad::Config::DEFAULTS[:show_exceptions] = false
@@ -0,0 +1,111 @@
1
+ module Rad
2
+ class Config < SafeHash
3
+ inherit ::OpenConstructor
4
+
5
+ DEFAULTS = {}
6
+ RUNTIME = {}
7
+
8
+ def initialize
9
+ super
10
+
11
+ DEFAULTS.each{|k, v| self[k] = v}
12
+ RUNTIME.each{|k, v| self[k] = v}
13
+ end
14
+
15
+ # trying to load both file_path and file_path.environment files if they are exists
16
+ def merge_config! file_path
17
+ # unless ::Micon.include? :config
18
+ # raise("this method should be called only after config already initialized (use app.after :config do ... end)!")
19
+ # end
20
+ raise("config file must have .yml extension (#{file_path})!") unless file_path.end_with? '.yml'
21
+ default_file_path = file_path.sub(/yml$/, "default.yml")
22
+ file_path_for_current_environment = file_path.sub(/yml$/, "#{environment!}.yml")
23
+ [
24
+ default_file_path,
25
+ file_path,
26
+ file_path_for_current_environment
27
+ ].each do |cfile|
28
+ if ::File.exist? cfile
29
+ data = ::YAML.load_file cfile
30
+ if data
31
+ data.must_be.a ::Hash
32
+ self.deep_merge! data
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ #
39
+ # runtime_dir
40
+ #
41
+ def runtime_dir= runtime_dir
42
+ if runtime_dir
43
+ self[:runtime_dir] = ::File.expand_path(runtime_dir)
44
+ else
45
+ self.delete 'runtime_dir'
46
+ end
47
+ end
48
+
49
+
50
+ #
51
+ # public_dir
52
+ #
53
+ def public_dir
54
+ runtime_dir? ? "#{runtime_dir}/public" : self[:public_dir]
55
+ end
56
+ def public_dir?; runtime_dir? end
57
+ def public_dir!
58
+ "#{runtime_dir!}/public"
59
+ end
60
+
61
+
62
+ #
63
+ # environment
64
+ #
65
+ def environment= env
66
+ env = env.to_s
67
+ env.must_be.in %w{production development test}
68
+ self['environment'] = env
69
+ end
70
+
71
+ def development?; environment == 'development' end
72
+ def production?; environment == 'production' end
73
+ def test?; environment == 'test' end
74
+
75
+ def development &block; block.call if development? end
76
+ def production &block; block.call if production? end
77
+ def test &block; block.call if test? end
78
+
79
+ #
80
+ # log_path
81
+ #
82
+ attr_writer :log_path
83
+ def log_path
84
+ @log_path ||= runtime_dir? ? "#{runtime_dir}/log/#{environment}.log" : ""
85
+ end
86
+
87
+
88
+ #
89
+ # log_level
90
+ #
91
+ attr_writer :log_level
92
+ def log_level
93
+ @log_level ||= production? ? :info : :debug
94
+ end
95
+
96
+
97
+ #
98
+ # session
99
+ #
100
+ # key: 'rack.session', domain: 'foo.com', path: '/', expire_after: 2592000, secret: 'change_me'
101
+ # attr_accessor :session
102
+ # def session?; !!session end
103
+
104
+
105
+ # class << self
106
+ # attr_accessor :command_line_config
107
+ #
108
+ # def defered_configs; @defered_configs ||= [] end
109
+ # end
110
+ end
111
+ end
@@ -0,0 +1,107 @@
1
+ # module Rad
2
+ # class DependencyResolver
3
+ # class Dependency
4
+ # attr_accessor :name, :block, :before, :after
5
+ #
6
+ # def initialize name, block
7
+ # @name, @block = name, block
8
+ # @before, @after = [], []
9
+ # end
10
+ #
11
+ # def inspect
12
+ # "#<#{name} #{before.inspect}, #{after.inspect}>"
13
+ # end
14
+ # end
15
+ #
16
+ # def dependencies; @dependencies ||= {} end
17
+ #
18
+ # #
19
+ # # Define dependency
20
+ # #
21
+ # def run name, options = {}, &block
22
+ # options = options.to_openobject
23
+ # # raise "Invalid usage, you must specify :after or :before!" unless options.before? or options.after?
24
+ # d = Dependency.new name, block
25
+ #
26
+ # if options.before?
27
+ # add_dependency d, :before, options.before.must_be.present
28
+ # elsif options.after?
29
+ # add_dependency d, :after, options.after.must_be.present
30
+ # else
31
+ # add_dependency d, nil, nil
32
+ # end
33
+ # end
34
+ #
35
+ #
36
+ # #
37
+ # # Call dependencies
38
+ # #
39
+ # def call name, &block
40
+ # return unless dep = dependencies[name]
41
+ #
42
+ # # before
43
+ # callees = []
44
+ # dep_lists = [dep.before]
45
+ # while !dep_lists.empty?
46
+ # dep_lists.each do |list|
47
+ # callees << list
48
+ # end
49
+ #
50
+ # dep_lists = next_level dep_lists, :before
51
+ # end
52
+ # call_all callees.reverse
53
+ #
54
+ # # call
55
+ # dep.block.call if dep.block
56
+ #
57
+ # # after
58
+ # dep_lists = [dep.after]
59
+ # while !dep_lists.empty?
60
+ # call_all dep_lists
61
+ #
62
+ # dep_lists = next_level dep_lists, :after
63
+ # end
64
+ # end
65
+ #
66
+ # protected
67
+ # def add_dependency dep, type, ref
68
+ # raise "Dependency '#{dep.name}' already defined!" if dependencies.include? dep.name
69
+ # dependencies[dep.name] = dep
70
+ #
71
+ # # add back reference
72
+ # if type
73
+ # catch :found do
74
+ # dep_lists = [dependencies.values]
75
+ # while !dep_lists.empty?
76
+ # dep_lists.each do |list|
77
+ # list.each do |d|
78
+ # if d.name == ref
79
+ # d.send(type) << dep
80
+ # throw :found
81
+ # end
82
+ # end
83
+ # end
84
+ #
85
+ # dep_lists = next_level dep_lists, type
86
+ # end
87
+ #
88
+ # raise "Dependency '#{ref}' referenced from '#{dep.name}' not found!"
89
+ # end
90
+ # end
91
+ # end
92
+ #
93
+ # def next_level dep_lists, type
94
+ # r = []
95
+ # dep_lists.each do |list|
96
+ # list.each do |d|
97
+ # r << d.send(type)
98
+ # end
99
+ # end
100
+ # r
101
+ # end
102
+ #
103
+ # def call_all list_of_lists
104
+ # list_of_lists.each{|list| list.each{|d| d.block.call if d.block}}
105
+ # end
106
+ # end
107
+ # end
@@ -0,0 +1,29 @@
1
+ module Rad
2
+ class Environment
3
+ inject logger: :logger, config: :config
4
+
5
+ class << self
6
+ inject logger: :logger, config: :config
7
+
8
+ # def initialize_runtime runtime_dir, environment = nil
9
+ # init_file_path = "#{runtime_dir}/init.rb"
10
+ # load init_file_path if File.exist? init_file_path
11
+ #
12
+ # Micon.after :config do |config|
13
+ # config.runtime_dir = runtime_dir
14
+ #
15
+ # config.merge_config! "#{runtime_dir}/config/config.yml"
16
+ # end
17
+ # end
18
+ #
19
+ # def initialize_plugin plugin_dir
20
+ # init_file_path = "#{plugin_dir}/init.rb"
21
+ # load init_file_path if File.exist? init_file_path
22
+ #
23
+ # Micon.after :config do |config|
24
+ # config.merge_config! "#{plugin_dir}/config/config.yml"
25
+ # end
26
+ # end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,55 @@
1
+ module Rad
2
+ module FilesHelper
3
+ def directories
4
+ $LOAD_PATH
5
+ end
6
+
7
+ def file_exist? path, directories = nil
8
+ find_files(path).size > 0
9
+ end
10
+
11
+ def find_files fname, directories = nil
12
+ directories ||= self.directories
13
+ FilesHelper.find_files fname, directories
14
+ end
15
+
16
+ def find_files_without_cache fname, directories = nil
17
+ # directories ||= self.directories
18
+ FilesHelper.find_files_without_cache fname, directories
19
+ end
20
+
21
+ def find_file fname, directories = nil
22
+ files = find_files(fname, directories)
23
+ raise "File '#{fname}' not found!" if files.size == 0
24
+ raise "Found multiple files for '#{fname}'" if files.size > 1
25
+ files.first
26
+ end
27
+
28
+ def find_files_by_pattern_without_cache pattern, directories = nil
29
+ directories ||= self.directories
30
+ patterns = directories.to_a.collect{|d| "#{d}#{pattern}"}
31
+ Dir.glob patterns
32
+ end
33
+ alias_method :find_files_by_pattern, :find_files_by_pattern_without_cache
34
+
35
+ def find_file_by_pattern pattern
36
+ files = find_files_by_pattern(pattern)
37
+ raise "File '#{pattern}' not found!" if files.size == 0
38
+ raise "Found multiple files for '#{pattern}'" if files.size > 1
39
+ files.first
40
+ end
41
+
42
+ class << self
43
+ # don't move this class method to module, because there will be then
44
+ # multiple cache for every object that includes it.
45
+ def find_files fname, directories = nil
46
+ fname.must =~ /\//
47
+ directories.must_be.present # || raise('directories ')= self.directories
48
+ files = directories.collect{|dir| "#{dir}#{fname}"}
49
+ files.select{|f| File.exist? f}
50
+ end
51
+ cache_method_with_params_in_production :find_files
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,21 @@
1
+ rad.register :logger do
2
+ if defined?(SILENCE_LOGGER)
3
+ logger = Logger.new nil
4
+ else
5
+ config = rad[:config]
6
+ if config and config.runtime_dir? and File.exist?("#{config.runtime_dir}/log")
7
+ logger = ActiveSupport::BufferedLogger.new rad.config.log_path
8
+ logger.level = ActiveSupport::BufferedLogger.const_get config.log_level.to_s.upcase
9
+ # logger.auto_flushing = false if config.production? and !config.stdout_logger(false)
10
+ elsif config and config.test?
11
+ logger = Logger.new nil
12
+ elsif config
13
+ logger = Logger.new STDOUT
14
+ logger.warn "No log folder!"
15
+ else
16
+ logger = Logger.new STDOUT
17
+ logger.warn "Config not initialized!"
18
+ end
19
+ end
20
+ logger
21
+ end
@@ -0,0 +1,55 @@
1
+ # Environment prepares and assembles your app ($LOAD_PATH, plugins and config files)
2
+
3
+ #
4
+ # Support
5
+ #
6
+ require 'rad/support'
7
+
8
+ # config
9
+ [
10
+ 'config',
11
+ ].each{|f| require "rad/environment/#{f}"}
12
+
13
+ module Rad
14
+ VERSION = '0.0.1'
15
+ end
16
+
17
+ # environment
18
+ [
19
+ 'logger',
20
+ 'environment',
21
+ 'files_helper'
22
+ ].each{|f| require "rad/environment/#{f}"}
23
+ Rad::Environment.inherit Rad::FilesHelper
24
+
25
+
26
+ #
27
+ # Runtime initialization
28
+ #
29
+ rad do
30
+ register :config do
31
+ Rad::Config.new
32
+ end
33
+
34
+ register :environment, depends_on: :config do
35
+ environment = Rad::Environment.new
36
+ logger.info " Rad #{Rad::VERSION} started in :#{config.environment!} mode (at #{Time.now.to_s})\n\n" unless config.test?
37
+ environment
38
+ end
39
+ end
40
+
41
+ #
42
+ # Handy mehtods
43
+ #
44
+ module Rad
45
+ class << self
46
+ inject(
47
+ config: :config,
48
+ environment: :environment,
49
+ logger: :logger,
50
+ workspace: :workspace
51
+ )
52
+
53
+ # delegate :initialize_runtime, :initialize_plugin, to: Environment
54
+ end
55
+ end
@@ -0,0 +1,42 @@
1
+ module Rad
2
+ class Flash < OpenObject
3
+ attr_accessor :previous_messages, :current_messages
4
+
5
+ def initialize format, previous_messages = {}
6
+ self.current_messages, self.previous_messages = {}, previous_messages
7
+ @keep = false
8
+ end
9
+
10
+ def [] key
11
+ key = key.to_s
12
+
13
+ if keep?
14
+ previous_messages[key]
15
+ else
16
+ current_messages[key] || previous_messages[key]
17
+ end
18
+ end
19
+
20
+ def []= key, value
21
+ current_messages[key.to_s] = value.to_s
22
+ end
23
+
24
+ def keep!
25
+ @keep = true
26
+ self
27
+ end
28
+
29
+ def keep?
30
+ !!@keep
31
+ end
32
+
33
+ def messages_for_next_request
34
+ if keep?
35
+ current_messages
36
+ else
37
+ {}
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,83 @@
1
+ module Rad
2
+ module BasicHtmlHelper
3
+ BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked autobuffer
4
+ autoplay controls loop selected hidden scoped async
5
+ defer reversed ismap seemless muted required
6
+ autofocus novalidate formnovalidate open).to_set
7
+ BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map {|attr| attr.to_sym })
8
+
9
+
10
+ #
11
+ # authenticity_token
12
+ #
13
+ def authenticity_token; workspace.request.session['authenticity_token'] end
14
+
15
+
16
+ #
17
+ # JavaScript & StyleSheets
18
+ #
19
+ def stylesheet_link_tag *stylesheets
20
+ Array(stylesheets).collect{|ssheet|
21
+ tag :link, '', href: "#{config && config.url_root!}#{ssheet}", media: "screen", rel: "stylesheet", type: "text/css"
22
+ }.join("\n")
23
+ end
24
+
25
+
26
+ #
27
+ # Assets
28
+ #
29
+ def image_tag src, opt = {}
30
+ opt[:src] = src
31
+ tag :img, '', opt
32
+ end
33
+
34
+
35
+ #
36
+ # Common HTML tags
37
+ #
38
+ def label_tag name, text, options = {}
39
+ tag :label, text, options.merge(for: name)
40
+ end
41
+
42
+
43
+ #
44
+ # Special
45
+ #
46
+ def tag name, content_or_options_with_block = nil, options = nil, escape = true, &block
47
+ if block_given?
48
+ options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
49
+ content = capture(&block)
50
+ concat "<#{name}#{tag_options(options)}>#{content}</#{name}>"
51
+ else
52
+ content = content_or_options_with_block
53
+ "<#{name}#{tag_options(options)}>#{content}</#{name}>"
54
+ end
55
+ end
56
+
57
+ # instance_methods(false).each do |m|
58
+ # alias_method "html_#{m}", m
59
+ # end
60
+
61
+ # Escape
62
+ def h obj; obj.to_s.html_escape end
63
+
64
+ protected
65
+
66
+ def tag_options options
67
+ return "" unless options
68
+ options.must_be.a Hash
69
+ unless options.blank?
70
+ attrs = []
71
+ options.each_pair do |key, value|
72
+ if BOOLEAN_ATTRIBUTES.include?(key)
73
+ attrs << %(#{key}="#{key}") if value
74
+ elsif !value.nil?
75
+ final_value = value.is_a?(Array) ? value.join(" ") : value
76
+ attrs << %(#{key}="#{final_value}")
77
+ end
78
+ end
79
+ " #{attrs.sort * ' '}" unless attrs.empty?
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,5 @@
1
+ module Rad
2
+ module FlashHelper
3
+ inject flash: :flash
4
+ end
5
+ end
@@ -0,0 +1,115 @@
1
+ module Rad
2
+ module FormHelper
3
+ #
4
+ # Form
5
+ #
6
+ def form_for *args, &block
7
+ model_helper, options = build_form_model_helper_and_form_options *args
8
+
9
+ form_tag options do
10
+ block.call model_helper if block
11
+ end
12
+ end
13
+
14
+ def build_form_model_helper_and_form_options model_name, model, options = {}
15
+ model_name.must_be.a String, Symbol
16
+ return ModelHelper.new(self, self, model_name, model, options), options
17
+ end
18
+
19
+ def form_tag options = {}, &block
20
+ options['method'] ||= options[:method] || 'post'
21
+ tag :form, options, &block
22
+ end
23
+
24
+
25
+ #
26
+ # Errors
27
+ #
28
+ # delegate :error_messages, :field_with_errors, to: :form_builder
29
+ def error_messages *errors
30
+ errors = errors.first if errors.size == 1 and errors.first.is_a? Array
31
+ html = errors.join("<br/>")
32
+ tag :div, html, class: :error_messages
33
+ end
34
+
35
+ def field_with_errors name, errors, options, field_html
36
+ html = tag :div, errors.join("<br/>"), class: :field_error_messages
37
+ html << tag(:span, field_html, class: :field_with_errors)
38
+ html
39
+ end
40
+
41
+
42
+ #
43
+ # Form fields
44
+ #
45
+ def check_box_tag name, checked = false, options = {}
46
+ options = {type: "checkbox", name: name, value: '1'}.update(options)
47
+ options[:checked] = "checked" if checked
48
+ tag_with_style :input, '', options
49
+ end
50
+
51
+ def field_set_tag legend = nil, options = {}, &block
52
+ content = ""
53
+ content << tag(:legend, legend) unless legend.blank?
54
+ content << capture(&block)
55
+ tag_with_style :fieldset, content, options
56
+ end
57
+
58
+ def file_field_tag name, options = {}
59
+ text_field_tag name, nil, options.update(type: "file")
60
+ end
61
+
62
+ def hidden_field_tag name, value = '', options = {}
63
+ text_field_tag(name, value, options.update(type: "hidden"))
64
+ end
65
+
66
+ def password_field_tag name, value = nil, options = {}
67
+ text_field_tag(name, value, options.update(type: "password"))
68
+ end
69
+
70
+ def radio_button_tag name, checked = false, options = {}
71
+ options = {type: "radio", name: name, value: '1'}.update(options)
72
+ options["checked"] = "checked" if checked
73
+ tag_with_style :input, '', options
74
+ end
75
+
76
+ def select_tag name, selected, values, options = {}
77
+ buff = "\n"
78
+ values.each do |n, v|
79
+ o = {}
80
+ o[:value] = v if v
81
+ o[:selected] = 'selected' if (v || n) == selected
82
+ buff << tag(:option, n, o)
83
+ buff << "\n"
84
+ end
85
+
86
+ tag_with_style :select, buff, {name: name}.update(options)
87
+ end
88
+
89
+ def text_field_tag name, value = '', options = {}
90
+ tag_with_style :input, '', {type: "text", name: name, value: value}.update(options)
91
+ end
92
+
93
+ def text_area_tag name, value = '', options = {}
94
+ tag_with_style :textarea, value, {name: name}.update(options)
95
+ end
96
+
97
+
98
+ #
99
+ # Other
100
+ #
101
+ def submit_tag value, options = {}
102
+ tag_with_style :input, '', {type: "submit", value: value}.update(options)
103
+ end
104
+
105
+ protected
106
+ def tag_with_style name, value, options, &block
107
+ # add special class to fix with CSS some problems with fields display
108
+ klass = options.delete(:class) || options.delete('class') || ""
109
+ klass << " #{options[:type] || options['type'] || name}_input"
110
+ options['class'] = klass
111
+
112
+ tag name, value, options, &block
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,5 @@
1
+ module Rad
2
+ module HtmlHelper
3
+ inherit BasicHtmlHelper, FormHelper, JavascriptHelper, FlashHelper
4
+ end
5
+ end