compages 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. data/.project +18 -0
  2. data/README +180 -0
  3. data/Rakefile +10 -0
  4. data/app/controllers/application.rb +4 -0
  5. data/app/controllers/contents_controller.rb +116 -0
  6. data/app/controllers/pages_controller.rb +59 -0
  7. data/app/controllers/render_controller.rb +24 -0
  8. data/app/helpers/application_helper.rb +6 -0
  9. data/app/helpers/contents_helper.rb +5 -0
  10. data/app/helpers/pages_helper.rb +5 -0
  11. data/app/helpers/render_helper.rb +2 -0
  12. data/app/models/content.rb +26 -0
  13. data/app/models/meta_data.rb +3 -0
  14. data/app/models/page.rb +106 -0
  15. data/app/models/page_element.rb +9 -0
  16. data/app/views/contents/_content_preview.rhtml +1 -0
  17. data/app/views/contents/_contents_list.rhtml +3 -0
  18. data/app/views/contents/_show_library.rhtml +60 -0
  19. data/app/views/contents/_write_now.rhtml +42 -0
  20. data/app/views/layouts/pages.rhtml +24 -0
  21. data/app/views/layouts/render.rhtml +11 -0
  22. data/app/views/pages/_change_theme.rhtml +0 -0
  23. data/app/views/pages/_edit_menu.rhtml +62 -0
  24. data/app/views/pages/_page_listed.rhtml +13 -0
  25. data/app/views/pages/_select_theme.rhtml +4 -0
  26. data/app/views/pages/edit.rhtml +35 -0
  27. data/app/views/pages/index.rhtml +45 -0
  28. data/app/views/pages/list.rhtml +41 -0
  29. data/app/views/pages/list_a.rhtml +40 -0
  30. data/app/views/pages/welcome.rhtml +27 -0
  31. data/app/views/render/_blank.rhtml +3 -0
  32. data/app/views/render/show.rhtml +1 -0
  33. data/bin/compages +14 -0
  34. data/config/boot.rb +44 -0
  35. data/config/database.yml.home +35 -0
  36. data/config/environment.rb +53 -0
  37. data/config/environments/development.rb +21 -0
  38. data/config/environments/production.rb +18 -0
  39. data/config/environments/test.rb +19 -0
  40. data/config/routes.rb +32 -0
  41. data/db/Copia di schema.rb +48 -0
  42. data/db/migrate/001_create_pages.rb +12 -0
  43. data/db/migrate/002_create_contents.rb +12 -0
  44. data/db/migrate/003_create_meta_datas.rb +14 -0
  45. data/db/migrate/004_create_page_elements.rb +17 -0
  46. data/db/migrate/005_add_urlnames.rb +15 -0
  47. data/db/migrate/006_add_sessions.rb +15 -0
  48. data/db/schema.mysql.sql +65 -0
  49. data/db/schema.postgresql.sql +65 -0
  50. data/db/schema.rb +49 -0
  51. data/db/schema.sqlite.sql +65 -0
  52. data/db/schema.sqlserver.sql +71 -0
  53. data/db/schema_version +1 -0
  54. data/doc/ER-model/v1.dia +0 -0
  55. data/doc/ER-model/v2.dia +0 -0
  56. data/doc/ER-model/v3.dia +0 -0
  57. data/doc/README_FOR_APP +2 -0
  58. data/doc/esempi/doc-vir/ecds.htm +2362 -0
  59. data/doc/esempi/doc-vir/ecds_files/search.gif +0 -0
  60. data/doc/esempi/doc-vir/ecds_files/upld.gif +0 -0
  61. data/doc/esempi/doc-vir/ecds_files/upld.jpg +0 -0
  62. data/installer/apache13.conf.example.template +33 -0
  63. data/installer/apache20.conf.example.template +40 -0
  64. data/installer/lighttpd.conf.example.template +6 -0
  65. data/installer/rails_installer_defaults.yml +5 -0
  66. data/lib/redcloth.rb +1130 -0
  67. data/lib/render_engine.rb +94 -0
  68. data/lib/tasks/release.rake +46 -0
  69. data/public/.htaccess +41 -0
  70. data/public/404.html +8 -0
  71. data/public/500.html +8 -0
  72. data/public/_index.html +277 -0
  73. data/public/favicon.ico +0 -0
  74. data/public/images/body_bg.gif +0 -0
  75. data/public/images/body_bg_short.gif +0 -0
  76. data/public/images/ie_shadow.png +0 -0
  77. data/public/images/journal_reflex.gif +0 -0
  78. data/public/images/journal_shadow.gif +0 -0
  79. data/public/images/logo_journal_small.bmp +0 -0
  80. data/public/images/logo_journal_small.png +0 -0
  81. data/public/images/page_edit_shadow.png +0 -0
  82. data/public/images/restore_bar.png +0 -0
  83. data/public/images/spinner.gif +0 -0
  84. data/public/javascripts/application.js +23 -0
  85. data/public/javascripts/controls.js +815 -0
  86. data/public/javascripts/dragdrop.js +913 -0
  87. data/public/javascripts/effects.js +958 -0
  88. data/public/javascripts/lowpro.js +307 -0
  89. data/public/javascripts/prototype.js +2006 -0
  90. data/public/robots.txt +1 -0
  91. data/public/stylesheets/compages.css +196 -0
  92. data/public/stylesheets/editing.css +180 -0
  93. data/public/stylesheets/editing_ie_filth.css +36 -0
  94. data/public/themes/Doc_basic/_script.js +342 -0
  95. data/public/themes/Doc_basic/images/Thumbs.db +0 -0
  96. data/public/themes/Doc_basic/images/search.gif +0 -0
  97. data/public/themes/Doc_basic/images/upld.gif +0 -0
  98. data/public/themes/Doc_basic/images/upld.jpg +0 -0
  99. data/public/themes/Doc_basic/index.html +114 -0
  100. data/public/themes/Doc_basic/style.css +1743 -0
  101. data/public/themes/color7boxes/default2.css +42 -0
  102. data/public/themes/color7boxes/index.html +40 -0
  103. data/public/themes/prova/index.html +12 -0
  104. data/public/zDoc/images/search.gif +0 -0
  105. data/public/zDoc/images/upld.gif +0 -0
  106. data/public/zDoc/images/upld.jpg +0 -0
  107. data/public/zDoc/index.html +176 -0
  108. data/public/zDoc/script.js +342 -0
  109. data/public/zDoc/style.css +1741 -0
  110. data/script/about +3 -0
  111. data/script/breakpointer +3 -0
  112. data/script/console +3 -0
  113. data/script/destroy +3 -0
  114. data/script/generate +3 -0
  115. data/script/performance/benchmarker +3 -0
  116. data/script/performance/profiler +3 -0
  117. data/script/plugin +3 -0
  118. data/script/process/reaper +3 -0
  119. data/script/process/spawner +3 -0
  120. data/script/runner +3 -0
  121. data/script/server +3 -0
  122. data/test/fixtures/contents.yml +5 -0
  123. data/test/fixtures/meta_datas.yml +5 -0
  124. data/test/fixtures/page_elements.yml +5 -0
  125. data/test/fixtures/pages.yml +5 -0
  126. data/test/functional/contents_controller_test.rb +18 -0
  127. data/test/functional/pages_controller_test.rb +18 -0
  128. data/test/functional/render_controller_test.rb +18 -0
  129. data/test/test_helper.rb +28 -0
  130. data/test/unit/content_test.rb +10 -0
  131. data/test/unit/meta_data_test.rb +10 -0
  132. data/test/unit/page_element_test.rb +10 -0
  133. data/test/unit/page_test.rb +10 -0
  134. data/tmp/sessions/ruby_sess.0ced4c30e36477ab +0 -0
  135. data/tmp/sessions/ruby_sess.20fbe26671422e70 +0 -0
  136. data/tmp/sessions/ruby_sess.2c72521f3a7e2ba9 +0 -0
  137. data/tmp/sessions/ruby_sess.4107a69d982a2eb7 +0 -0
  138. data/tmp/sessions/ruby_sess.573ded9c7fdd9035 +0 -0
  139. data/tmp/sessions/ruby_sess.5a9767815bb96258 +0 -0
  140. data/tmp/sessions/ruby_sess.85d723b794005388 +0 -0
  141. data/tmp/sessions/ruby_sess.875b3b3e3529afdb +0 -0
  142. data/tmp/sessions/ruby_sess.936766f3a397c88b +0 -0
  143. data/tmp/sessions/ruby_sess.984e2e4c9a2e7891 +0 -0
  144. data/tmp/sessions/ruby_sess.a1faebd7448bc45d +0 -0
  145. data/tmp/sessions/ruby_sess.a415768c7635bc15 +0 -0
  146. data/tmp/sessions/ruby_sess.b2dadcbe6c1b0add +0 -0
  147. data/tmp/sessions/ruby_sess.ca9100beb103a428 +0 -0
  148. data/tmp/sessions/ruby_sess.d649c800a046efde +0 -0
  149. data/tmp/sessions/ruby_sess.db73bbfafd5a537c +0 -0
  150. data/tmp/sessions/ruby_sess.e32487b847524df1 +0 -0
  151. data/tmp/sessions/ruby_sess.f4e45d67828cc437 +0 -0
  152. data/tmp/sessions/ruby_sess.f5a3f064f2f7a26f +0 -0
  153. data/tmp/sessions/ruby_sess.ff0c47b35f238cda +0 -0
  154. data/vendor/plugins/acts_as_urlnameable.tar.gz +0 -0
  155. data/vendor/plugins/acts_as_urlnameable/LICENSE +19 -0
  156. data/vendor/plugins/acts_as_urlnameable/README +193 -0
  157. data/vendor/plugins/acts_as_urlnameable/Rakefile +25 -0
  158. data/vendor/plugins/acts_as_urlnameable/TODO +5 -0
  159. data/vendor/plugins/acts_as_urlnameable/db/00x_add_urlnames_table.rb +15 -0
  160. data/vendor/plugins/acts_as_urlnameable/db/urlnames_table.sql +7 -0
  161. data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/ClassMethods.html +167 -0
  162. data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/InstanceMethods.html +213 -0
  163. data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/SingletonMethods.html +189 -0
  164. data/vendor/plugins/acts_as_urlnameable/doc/created.rid +1 -0
  165. data/vendor/plugins/acts_as_urlnameable/doc/files/LICENSE.html +129 -0
  166. data/vendor/plugins/acts_as_urlnameable/doc/files/README.html +333 -0
  167. data/vendor/plugins/acts_as_urlnameable/doc/files/TODO.html +121 -0
  168. data/vendor/plugins/acts_as_urlnameable/doc/files/lib/acts_as_urlnameable_rb.html +101 -0
  169. data/vendor/plugins/acts_as_urlnameable/doc/fr_class_index.html +29 -0
  170. data/vendor/plugins/acts_as_urlnameable/doc/fr_file_index.html +30 -0
  171. data/vendor/plugins/acts_as_urlnameable/doc/fr_method_index.html +34 -0
  172. data/vendor/plugins/acts_as_urlnameable/doc/index.html +24 -0
  173. data/vendor/plugins/acts_as_urlnameable/doc/rdoc-style.css +208 -0
  174. data/vendor/plugins/acts_as_urlnameable/init.rb +3 -0
  175. data/vendor/plugins/acts_as_urlnameable/lib/acts_as_urlnameable.rb +159 -0
  176. data/vendor/plugins/acts_as_urlnameable/lib/urlname.rb +3 -0
  177. data/vendor/plugins/acts_as_urlnameable/test/acts_as_urlnameable_test.rb +233 -0
  178. data/vendor/plugins/acts_as_urlnameable/test/connection.rb +8 -0
  179. data/vendor/plugins/acts_as_urlnameable/test/fixtures/article.rb +13 -0
  180. data/vendor/plugins/acts_as_urlnameable/test/fixtures/articles.yml +62 -0
  181. data/vendor/plugins/acts_as_urlnameable/test/fixtures/page.rb +14 -0
  182. data/vendor/plugins/acts_as_urlnameable/test/fixtures/pages.yml +35 -0
  183. data/vendor/plugins/acts_as_urlnameable/test/fixtures/people.yml +9 -0
  184. data/vendor/plugins/acts_as_urlnameable/test/fixtures/person.rb +26 -0
  185. data/vendor/plugins/acts_as_urlnameable/test/fixtures/schema.rb +24 -0
  186. data/vendor/plugins/acts_as_urlnameable/test/fixtures/section.rb +5 -0
  187. data/vendor/plugins/acts_as_urlnameable/test/fixtures/sections.yml +9 -0
  188. data/vendor/plugins/acts_as_urlnameable/test/fixtures/urlnames.yml +153 -0
  189. data/vendor/plugins/acts_as_urlnameable/test/test_helper.rb +42 -0
  190. data/vendor/plugins/gems/README +30 -0
  191. data/vendor/plugins/gems/init.rb +9 -0
  192. data/vendor/plugins/gems/tasks/gems_tasks.rake +32 -0
  193. data/vendor/plugins/unobtrusive_javascript/CHANGELOG +72 -0
  194. data/vendor/plugins/unobtrusive_javascript/README +73 -0
  195. data/vendor/plugins/unobtrusive_javascript/Rakefile +33 -0
  196. data/vendor/plugins/unobtrusive_javascript/about.yml +6 -0
  197. data/vendor/plugins/unobtrusive_javascript/assets/javascripts/lowpro.js +307 -0
  198. data/vendor/plugins/unobtrusive_javascript/init.rb +21 -0
  199. data/vendor/plugins/unobtrusive_javascript/install.rb +1 -0
  200. data/vendor/plugins/unobtrusive_javascript/lib/actionview_helpers_patches.rb +17 -0
  201. data/vendor/plugins/unobtrusive_javascript/lib/asset_tag_helper_patches.rb +33 -0
  202. data/vendor/plugins/unobtrusive_javascript/lib/behaviour_caching.rb +70 -0
  203. data/vendor/plugins/unobtrusive_javascript/lib/controllers/unobtrusive_javascript_controller.rb +52 -0
  204. data/vendor/plugins/unobtrusive_javascript/lib/prototype_helper_patches.rb +72 -0
  205. data/vendor/plugins/unobtrusive_javascript/lib/scriptaculous_helper_patches.rb +62 -0
  206. data/vendor/plugins/unobtrusive_javascript/lib/tag_helper_patches.rb +37 -0
  207. data/vendor/plugins/unobtrusive_javascript/lib/ujs.rb +32 -0
  208. data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_helper.rb +62 -0
  209. data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script.rb +54 -0
  210. data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script_converter.rb +23 -0
  211. data/vendor/plugins/unobtrusive_javascript/lib/ujs/controller_methods.rb +55 -0
  212. data/vendor/plugins/unobtrusive_javascript/lib/ujs/helpers.rb +152 -0
  213. data/vendor/plugins/unobtrusive_javascript/lib/ujs/javascript_proxies.rb +57 -0
  214. data/vendor/plugins/unobtrusive_javascript/tasks/unobtrusive_javascript_tasks.rake +15 -0
  215. data/vendor/plugins/unobtrusive_javascript/test/asset_tag_helper_patches_test.rb +32 -0
  216. data/vendor/plugins/unobtrusive_javascript/test/behaviour_helper_test.rb +180 -0
  217. data/vendor/plugins/unobtrusive_javascript/test/behaviour_script_converter_test.rb +72 -0
  218. data/vendor/plugins/unobtrusive_javascript/test/behaviour_script_test.rb +98 -0
  219. data/vendor/plugins/unobtrusive_javascript/test/config/environment.rb +8 -0
  220. data/vendor/plugins/unobtrusive_javascript/test/config/routes.rb +4 -0
  221. data/vendor/plugins/unobtrusive_javascript/test/config/schema.rb +3 -0
  222. data/vendor/plugins/unobtrusive_javascript/test/controller_methods_test.rb +48 -0
  223. data/vendor/plugins/unobtrusive_javascript/test/helpers_test.rb +186 -0
  224. data/vendor/plugins/unobtrusive_javascript/test/javascript_proxies_test.rb +3 -0
  225. data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/boot.rb +26 -0
  226. data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_controller.rb +11 -0
  227. data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_mailer.rb +4 -0
  228. data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/active_record.rb +27 -0
  229. data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/rails.rb +31 -0
  230. data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/ptk.rb +148 -0
  231. data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/suite/difference.rb +23 -0
  232. data/vendor/plugins/unobtrusive_javascript/test/lib/stubs/controller_stub.rb +10 -0
  233. data/vendor/plugins/unobtrusive_javascript/test/ptk_helper.rb +29 -0
  234. data/vendor/plugins/unobtrusive_javascript/test/tag_helper_patches_test.rb +59 -0
  235. data/vendor/plugins/unobtrusive_javascript/test/test_helper.rb +25 -0
  236. data/vendor/plugins/unobtrusive_javascript/test/unobtrusive_javascript_controller_test.rb +95 -0
  237. data/vendor/plugins/unobtrusive_javascript/uninstall.rb +1 -0
  238. data/vendor/redcloth/bin/redcloth +3 -0
  239. data/vendor/redcloth/doc/CHANGELOG +160 -0
  240. data/vendor/redcloth/doc/COPYING +25 -0
  241. data/vendor/redcloth/doc/README +106 -0
  242. data/vendor/redcloth/doc/REFERENCE +216 -0
  243. data/vendor/redcloth/doc/make.rb +359 -0
  244. data/vendor/redcloth/lib/redcloth.rb +1130 -0
  245. data/vendor/redcloth/run-tests.rb +28 -0
  246. data/vendor/redcloth/setup.rb +1376 -0
  247. data/vendor/redcloth/tests/code.yml +105 -0
  248. data/vendor/redcloth/tests/hard_breaks.yml +26 -0
  249. data/vendor/redcloth/tests/images.yml +171 -0
  250. data/vendor/redcloth/tests/instiki.yml +39 -0
  251. data/vendor/redcloth/tests/links.yml +155 -0
  252. data/vendor/redcloth/tests/lists.yml +77 -0
  253. data/vendor/redcloth/tests/markdown.yml +218 -0
  254. data/vendor/redcloth/tests/poignant.yml +64 -0
  255. data/vendor/redcloth/tests/table.yml +198 -0
  256. data/vendor/redcloth/tests/textism.yml +406 -0
  257. metadata +432 -0
@@ -0,0 +1,33 @@
1
+ module ActionView::Helpers::AssetTagHelper
2
+ alias_method :rails_javascript_include_tag, :javascript_include_tag
3
+
4
+ # Adds a new option to Rails' built-in <tt>javascript_include_tag</tt>
5
+ # helper - <tt>:unobtrusive</tt>. Works in the same way as <tt>:defaults</tt> - specifying
6
+ # <tt>:unobtrusive</tt> will make sure the necessary javascript
7
+ # libraries and behaviours file +script+ tags are loaded. Will happily
8
+ # work along side <tt>:defaults</tt>.
9
+ #
10
+ # <%= javascript_include_tag :defaults, :unobtrusive %>
11
+ #
12
+ # This replaces the old +unobtrusive_javascript_files+ helper.
13
+ def javascript_include_tag(*sources)
14
+ if sources.delete :unobtrusive
15
+ sources = sources.concat(
16
+ ['lowpro', behaviours_url]
17
+ ).uniq
18
+ end
19
+ rails_javascript_include_tag(*sources)
20
+ end
21
+
22
+ protected
23
+ def behaviours_url
24
+ action_path = case @controller.request.path
25
+ when '', '/'
26
+ '/index'
27
+ else
28
+ @controller.request.path
29
+ end
30
+ "/behaviours#{action_path}.js"
31
+ end
32
+ end
33
+
@@ -0,0 +1,70 @@
1
+ module UJS
2
+ module BehaviourCaching
3
+
4
+ def self.included(base)
5
+ base.extend ControllerClassMethods
6
+ end
7
+
8
+ attr_accessor :cache_behaviours
9
+
10
+ module ControllerClassMethods
11
+
12
+ # Also file caching of the behaviour for hidden actions. This actually
13
+ # write the javascript file into the public directory (or given cache dir)
14
+ # in the same style as page caching. Which means requests for the behaviour
15
+ # will not hit the application at all. Use this for reasonably static behaviours.
16
+ #
17
+ # NB. If you use caches_page or caches_action your behaviours will automatically ne
18
+ # cached in this way. expire_page and expire_action also automatically expire the
19
+ # cached behaviour.
20
+ #
21
+ # caches_behaviour :index, :register
22
+ #
23
+ # See expire_behaviour to expire cached behaviours.
24
+ def caches_behaviour(*actions)
25
+ actions.each do |action|
26
+ class_eval "prepend_before_filter { |c| c.cache_behaviours = (c.action_name == '#{action}') }"
27
+ end
28
+ end
29
+
30
+ alias_method :caches_behavior, :caches_behaviour
31
+
32
+ def caches_page(*actions)
33
+ caches_behaviour(*actions)
34
+ super
35
+ end
36
+
37
+ def caches_action(*actions)
38
+ caches_behaviour(*actions)
39
+ super
40
+ end
41
+
42
+ end
43
+
44
+ # Expires the behaviours for the given url options.
45
+ #
46
+ # expire_behaviour :action => 'index'
47
+ def expire_behaviour(options={})
48
+ self.class.expire_page "/behaviour#{url_for(options)}.js"
49
+ end
50
+
51
+ alias_method :expire_behavior, :expire_behaviour
52
+
53
+ def expire_page(options={})
54
+ expire_behaviour(options)
55
+ super
56
+ end
57
+
58
+ def expire_action(options={})
59
+ if options[:action].is_a?(Array)
60
+ options[:action].dup.each do |action|
61
+ expire_behaviour(options.merge({ :action => action }))
62
+ end
63
+ else
64
+ expire_behaviour(options)
65
+ end
66
+ super
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,52 @@
1
+ require 'digest/md5'
2
+
3
+ class UnobtrusiveJavascriptController < ActionController::Base
4
+ skip_before_filter :initialise_js_behaviours
5
+ skip_after_filter :store_js_behaviours
6
+
7
+ after_filter :perform_any_caching
8
+ after_filter :reset_js_behaviours
9
+
10
+ # Renders the external javascript behaviours file
11
+ # with the appropriate content-type.
12
+ def generate
13
+ headers['Content-Type'] = 'text/javascript'
14
+
15
+ if js_behaviours
16
+ generate_etag
17
+ modified? ? render_script : render_304
18
+ else
19
+ render :text => "", :layout => false
20
+ end
21
+ end
22
+
23
+ protected
24
+
25
+ def perform_any_caching
26
+ if behaviour_caching_enabled?
27
+ self.class.cache_page js_behaviours.to_s, request.path
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def generate_etag
34
+ headers['ETag'] = Digest::MD5.hexdigest(js_behaviours.to_s)
35
+ end
36
+
37
+ def modified?
38
+ request.env['HTTP_IF_NONE_MATCH'] != headers['ETag']
39
+ end
40
+
41
+ def render_script
42
+ render :text => js_behaviours.to_s, :layout => false
43
+ end
44
+
45
+ def render_304
46
+ render :nothing => true, :status => 304
47
+ end
48
+
49
+ def behaviour_caching_enabled?
50
+ js_behaviours && js_behaviours.cache?
51
+ end
52
+ end
@@ -0,0 +1,72 @@
1
+ module ActionView::Helpers::PrototypeHelper
2
+
3
+ class JavaScriptRef
4
+ def initialize(ref); @ref = ref; end
5
+ def to_json; @ref; end
6
+ end
7
+
8
+ def javascript_variable(name)
9
+ JavaScriptRef.new(name)
10
+ end
11
+
12
+ def build_observer(klass, name, options={})
13
+ set_default_external!(options)
14
+ javascript = build_observer_js(klass, name, options)
15
+
16
+ unless options.delete :external
17
+ javascript_tag(javascript)
18
+ else
19
+ @controller.apply_behaviour("##{name}", javascript)
20
+ return ''
21
+ end
22
+ end
23
+
24
+ def build_observer_js(klass, name, options)
25
+ if options[:with] && !options[:with].include?("=")
26
+ options[:with] = "'#{options[:with]}=' + value"
27
+ else
28
+ options[:with] ||= 'value' if options[:update]
29
+ end
30
+
31
+ callback = options[:function] || remote_function(options)
32
+ javascript = "new #{klass}(#{name.to_json}, "
33
+ javascript << "#{options[:frequency]}, " if options[:frequency]
34
+ javascript << "function(element, value) {"
35
+ javascript << "#{callback}}"
36
+ javascript << ", '#{options[:on]}'" if options[:on]
37
+ javascript << ")"
38
+ javascript
39
+ end
40
+
41
+ def remote_function(options)
42
+ javascript_options = options_for_ajax(options)
43
+
44
+ update = ''
45
+ if options[:update] and options[:update].is_a?Hash
46
+ update = []
47
+ update << "success:'#{options[:update][:success]}'" if options[:update][:success]
48
+ update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
49
+ update = '{' + update.join(',') + '}'
50
+ elsif options[:update]
51
+ update << "'#{options[:update]}'"
52
+ end
53
+
54
+ function = update.empty? ?
55
+ "new Ajax.Request(" :
56
+ "new Ajax.Updater(#{update}, "
57
+
58
+ url_options = options[:url]
59
+ url_options = url_options.merge(:escape => false) if url_options.is_a? Hash
60
+ url = url_options.is_a?(JavaScriptRef) ? url_options.to_json : "'#{url_for(url_options)}'"
61
+ function << "#{url}"
62
+ function << ", #{javascript_options})"
63
+
64
+ function = "#{options[:before]}; #{function}" if options[:before]
65
+ function = "#{function}; #{options[:after]}" if options[:after]
66
+ function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
67
+ function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
68
+
69
+ return function
70
+ end
71
+
72
+ end
@@ -0,0 +1,62 @@
1
+ module ActionView::Helpers::ScriptaculousHelper
2
+ def draggable_element(element_id, options={})
3
+ set_default_external!(options)
4
+ external = options.delete :external
5
+ prepare_script(element_id, draggable_element_js(element_id, options).chop!, external)
6
+ end
7
+
8
+ def draggable_element_js(element_id, options = {}) #:nodoc:
9
+ %(new Draggable(#{element_id.to_json}, #{options_for_javascript(options)});)
10
+ end
11
+
12
+ def drop_recieving_element(element_id, options={})
13
+ set_default_external!(options)
14
+ external = options.delete :external
15
+ prepare_script(element_id, drop_receiving_element_js(element_id, options).chop!, external)
16
+ end
17
+
18
+ def drop_receiving_element_js(element_id, options = {}) #:nodoc:
19
+ options[:with] ||= "'id=' + encodeURIComponent(element.id)"
20
+ options[:onDrop] ||= "function(element){" + remote_function(options) + "}"
21
+ options.delete_if { |key, value| ActionView::Helpers::PrototypeHelper::AJAX_OPTIONS.include?(key) }
22
+
23
+ options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
24
+ options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass]
25
+
26
+ %(Droppables.add(#{element_id.to_json}, #{options_for_javascript(options)});)
27
+ end
28
+
29
+ def sortable_element(element_id, options={})
30
+ set_default_external!(options)
31
+ external = options.delete :external
32
+ prepare_script(element_id, sortable_element_js(element_id, options).chop!, external)
33
+ end
34
+
35
+ def sortable_element_js(element_id, options = {}) #:nodoc:
36
+ options[:with] ||= "Sortable.serialize(#{element_id.to_json})"
37
+ options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
38
+ options.delete_if { |key, value| ActionView::Helpers::PrototypeHelper::AJAX_OPTIONS.include?(key) }
39
+
40
+ [:tag, :overlap, :constraint, :handle].each do |option|
41
+ options[option] = "'#{options[option]}'" if options[option]
42
+ end
43
+
44
+ options[:containment] = array_or_string_for_javascript(options[:containment]) if options[:containment]
45
+ options[:only] = array_or_string_for_javascript(options[:only]) if options[:only]
46
+
47
+ %(Sortable.create(#{element_id.to_json}, #{options_for_javascript(options)});)
48
+ end
49
+
50
+ protected
51
+
52
+ def prepare_script(element_id, js, external=true)
53
+ unless external
54
+ javascript_tag(js)
55
+ else
56
+ @controller.apply_behaviour "##{element_id}", js
57
+ return ''
58
+ end
59
+ end
60
+
61
+ end
62
+
@@ -0,0 +1,37 @@
1
+ module ActionView::Helpers::TagHelper
2
+ include UJS::Helpers
3
+
4
+ JAVASCRIPT_EVENTS = %w(click mouseup mousedown dblclick mousemove mouseover mouseout submit change keypress keyup keydown load)
5
+
6
+ alias_method :rails_tag_options, :tag_options
7
+
8
+ protected
9
+ # Patch to the built-in Rails tag_options method. Looks for any
10
+ # javascript event handlers, extracts them and registers them
11
+ # as unobtrusive behaviours.
12
+ #
13
+ # This behaviour affects any built-in Rails helpers that generate
14
+ # HTML. Event extraction behaviour can be bypassed by passing in
15
+ # <tt>:inline => true</tt> as part of a helper's HTML options hash.
16
+ def tag_options(opts)
17
+ set_default_external!(opts)
18
+ if opts[:external]
19
+ JAVASCRIPT_EVENTS.each do |event|
20
+ unless opts["on#{event}"].blank?
21
+ opts['id'] = generate_html_id unless opts['id']
22
+ apply_behaviour("##{opts['id']}:#{event}", opts["on#{event}"]) unless opts["on#{event}"].nil?
23
+ opts.delete("on#{event}")
24
+ end
25
+ end
26
+ opts.delete(:external)
27
+ end
28
+ rails_tag_options(opts)
29
+ end
30
+
31
+ # Generate a unique id to be used as the HTML +id+ attribute.
32
+ def generate_html_id
33
+ @tag_counter ||= 0
34
+ @tag_counter = @tag_counter.next
35
+ "#{UJS::Settings.generated_id_prefix}#{@tag_counter}"
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ module UJS
2
+ PLUGIN_NAME = 'unobtrusive_javascript'
3
+ PLUGIN_PATH = "#{RAILS_ROOT}/vendor/plugins/#{PLUGIN_NAME}"
4
+ PLUGIN_ASSET_PATH = "#{PLUGIN_PATH}/assets"
5
+ PLUGIN_CONTROLLER_PATH = "#{PLUGIN_PATH}/lib/controllers"
6
+
7
+ class Settings
8
+ # All elements with attached behaviours that do not
9
+ # have an HTML +id+ attribute will have one
10
+ # generated automatically, using the form _prefix_x_,
11
+ # where the default prefix is "uj_element_" and x is an
12
+ # automatically incremented number. You can set the
13
+ # generated prefix to anything you like by setting it in your
14
+ # environment.rb file:
15
+ #
16
+ # UJS::Settings.generated_id_prefix = "my_prefix_"
17
+ cattr_accessor :generated_id_prefix
18
+ @@generated_id_prefix = "uj_element_"
19
+ end
20
+
21
+ class << self
22
+ # Adds routes to your application necessary for the plugin to function correctly.
23
+ # Simply add the following inside your Routes.draw block in routes.rb:
24
+ # UJS::routes
25
+ # This is now *mandatory*.
26
+ def routes
27
+ ActionController::Routing::Routes.add_route "/behaviours/*page_path", :controller => "unobtrusive_javascript", :action => "generate"
28
+ end
29
+
30
+ alias_method :use_fake_script_links, :routes
31
+ end
32
+ end
@@ -0,0 +1,62 @@
1
+ module UJS
2
+ # The helper methods in this module can all be passed as arguments to apply_behaviour and allow
3
+ # you to reproduce common functionailty such as drag and drop and sorting in a simple way. Think
4
+ # of them as the apply_javascript equivilent to the Scriptaculous helpers.
5
+ #
6
+ # Usage:
7
+ #
8
+ # apply_behaviour '.products', make_draggable
9
+ # apply_behaviour '.help', make_remote_link( :action => 'showhelp' )
10
+ # apply_behaviour '.todolist', make_sortable
11
+ #
12
+ module BehaviourHelper
13
+
14
+ # Make a link send an Ajax request. options identical to linkt_to_remote except that
15
+ # :url defaults to the href attribute of the link.
16
+ def make_remote_link(options={})
17
+ options[:url] ||= javascript_variable('this.href');
18
+ "this.observe('click', function(event) {\n#{remote_function(options)};\nreturn false;\n});"
19
+ end
20
+
21
+ # Make a form submit via an Ajax request. options identical remote_form except that
22
+ # :url defaults to the action attribute of the form.
23
+ def make_remote_form(options={})
24
+ options[:url] ||= javascript_variable('this.action');
25
+ options[:with] ||= 'Form.serialize(this)'
26
+ "this.observe('submit', function(event) {\n#{remote_function(options)};\nreturn false;\n});"
27
+ end
28
+
29
+ # Observe a form or form field (specified with the type argument) using the given options
30
+ # which are the same as observe_form and observe_field.
31
+ def make_observed(type, options={})
32
+ obs = (type.to_s == 'form') ? 'Form' : 'Form.Element'
33
+ if options[:frequency] && options[:frequency] > 0
34
+ build_observer_js("#{obs}.Observer", javascript_variable('this'), options)
35
+ else
36
+ build_observer_js("#{obs}.EventObserver", javascript_variable('this'), options)
37
+ end
38
+ end
39
+
40
+ # Makes the children of the element sortable.
41
+ def make_sortable(options={})
42
+ sortable_element_js(javascript_variable('this'), options)
43
+ end
44
+
45
+ # Makes the element draggable.
46
+ def make_draggable(options={})
47
+ draggable_element_js(javascript_variable('this'), options)
48
+ end
49
+
50
+ # Makes the element a drop target.
51
+ def make_drop_receiving(options={})
52
+ drop_receiving_element_js(javascript_variable('this'), options)
53
+ end
54
+
55
+ def make_autocomplete # :nodoc:
56
+ end
57
+
58
+ def make_in_place_editor # :nodoc:
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,54 @@
1
+ class UJS::BehaviourScript
2
+ attr_reader :rules
3
+ attr_writer :reapply_after_ajax
4
+
5
+ def initialize(cache=false, reapply_after_ajax=true)
6
+ @rules, @cache, @reapply_after_ajax = [], cache, reapply_after_ajax
7
+ end
8
+
9
+ def add_rule(selector, javascript, cancel_default=false)
10
+ javascript = javascript << cancel_default_js if cancel_default
11
+ @rules << [selector, javascript]
12
+ end
13
+
14
+ def cache?
15
+ @cache
16
+ end
17
+
18
+ def enable_cache
19
+ @cache = true
20
+ end
21
+
22
+ def reapply_after_ajax?
23
+ @reapply_after_ajax
24
+ end
25
+
26
+ # Renders behaviour block and option JavaScript.
27
+ def to_s
28
+ (@rules && !@rules.empty?) ? "Event.addBehavior({\n#{rule_js}\n});" + option_js : ''
29
+ end
30
+
31
+ # Uses behaviour script converter to conver to a hash for session storage
32
+ def to_hash
33
+ UJS::BehaviourScriptConverter.convert_to_hash(self)
34
+ end
35
+
36
+ protected
37
+ # Renders a collection of behaviour rules in javascript format
38
+ def rule_js
39
+ @rules.uniq.collect { |sel, js| behaviour_rule(sel, js) }.join(",\n")
40
+ end
41
+
42
+ # Renders behaviour rule javascript for the behaviours file
43
+ def behaviour_rule(selector, behaviour)
44
+ "\"#{selector}\": function(event) {\n#{behaviour}\n}"
45
+ end
46
+
47
+ def option_js
48
+ reapply_after_ajax? ? '' : "\nEvent.addBehavior.reapplyAfterAjax = false;"
49
+ end
50
+
51
+ def cancel_default_js
52
+ " return false;"
53
+ end
54
+ end