compages 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,23 @@
1
+ class UJS::BehaviourScriptConverter
2
+ def initialize(script)
3
+ @script = script
4
+ end
5
+
6
+ # Converts a BehaviourScript object into a custom hash format
7
+ def self.convert_to_hash(script)
8
+ self.new(script).to_hash
9
+ end
10
+
11
+ # Converts a hash-converted BehaviourScript back to a BehaviourScript again
12
+ def self.convert_from_hash(script_hash)
13
+ script = UJS::BehaviourScript.new(script_hash[:options][:cache], script_hash[:options][:reapply_after_ajax])
14
+ script_hash[:rules].each { |r| script.add_rule(r[0], r[1]) }
15
+ script
16
+ end
17
+
18
+ # Convert behaviour script to a hash
19
+ def to_hash
20
+ { :options => { :cache => @script.cache?, :reapply_after_ajax => @script.reapply_after_ajax? },
21
+ :rules => @script.rules }
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ module UJS::ControllerMethods
2
+ def self.included(base)
3
+ base.class_eval do
4
+ before_filter :store_controller_for_helpers
5
+ before_filter :initialise_js_behaviours
6
+ after_filter :store_js_behaviours
7
+ end
8
+ end
9
+
10
+ # Lets you register javascript behaviours from within
11
+ # the controller. For a description of the different options
12
+ # available, see UJS::Helpers#apply_behaviour (note:
13
+ # this function does not take a block like the view helper version)
14
+ def apply_behaviour(selector, behaviour, opts={})
15
+ opts.reverse_merge!(:prevent_default => false)
16
+ @js_behaviours.add_rule(selector, behaviour, opts[:prevent_default])
17
+ end
18
+
19
+ def cache_behaviours
20
+ @js_behaviours.enable_cache
21
+ end
22
+
23
+ def reapply_behaviours_after_ajax=(val)
24
+ @js_behaviours.reapply_after_ajax = val
25
+ end
26
+
27
+ # Make American and English spellings both work for apply_behaviour
28
+ alias_method :apply_behavior, :apply_behaviour
29
+
30
+ protected
31
+ # Initialises the javascript behaviours
32
+ def initialise_js_behaviours
33
+ @js_behaviours = UJS::BehaviourScript.new(@cache_behaviours)
34
+ end
35
+
36
+ # Clears the array of registered javascript behaviours
37
+ def reset_js_behaviours
38
+ session[:js_behaviours] = nil
39
+ end
40
+
41
+ # Returns a BehaviourScript from the behaviours serialized to the session
42
+ def js_behaviours
43
+ return nil if session[:js_behaviours].nil?
44
+ UJS::BehaviourScriptConverter.convert_from_hash(session[:js_behaviours])
45
+ end
46
+
47
+ # Stores all registered javascript behaviours in the session as a hash
48
+ def store_js_behaviours
49
+ session[:js_behaviours] = @js_behaviours.to_hash
50
+ end
51
+
52
+ def store_controller_for_helpers
53
+ ActionView::Helpers.current_controller = self
54
+ end
55
+ end
@@ -0,0 +1,152 @@
1
+ require File.dirname(__FILE__) + '/behaviour_helper'
2
+ require File.dirname(__FILE__) + '/javascript_proxies'
3
+
4
+ module UJS::Helpers
5
+ include UJS::BehaviourHelper
6
+ include UJS::JavascriptProxies
7
+
8
+ # This is the core functionality of the plugin;
9
+ # it allows you to attach javascript behaviour to your page
10
+ # elements in an unobtrusive fashion. It takes three options:
11
+ # * +selector+ - CSS selector and event. For a full overview of
12
+ # the selector syntax, see the event:Selectors website.
13
+ # http://encytemedia.com/event-selectors
14
+ # * +behaviour+ - The javascript that you want to attach to the element
15
+ # and event specified by +selector+ as a string of javascript.
16
+ # * +opts+ - A hash of additional options.
17
+ #
18
+ # Attaching a behaviour to an element on your page is as simple as
19
+ # specifying the element and the event you want the behaviour attached
20
+ # to, using the CSS selector format, and passing in a string of javascript:
21
+ #
22
+ # <% apply_behaviour "#coollink:click", "alert('Hello World')" %>
23
+ #
24
+ # You can also make use of any of the built-in Rails helpers that
25
+ # generate Javascript:
26
+ #
27
+ # <% apply_behaviour "#coolink:click", visual_effect(:highlight, "coollink") %>
28
+ #
29
+ # You will have access to two javascript variables inside your javascript string:
30
+ # * +this+: returns a reference to the HTML element that the behaviour was attached to
31
+ # * +event+: the event the behaviour was attached to:
32
+ #
33
+ # <% apply_behaviour "#coollink:click", "alert('You clicked ' this.id); Event.stop(event)" %>
34
+ #
35
+ # The following options can be set using the opts hash:
36
+ #
37
+ # * <tt>:external</tt> - If true, the behaviour will be attached to the external behaviour file.
38
+ # If false, it will be rendered directly in the page inside +script+ tags. Defaults to true.
39
+ #
40
+ # When setting <tt>:external</tt> to false, you <em>must</em> call the register_js_behaviour from
41
+ # within ERb <em>output</em> blocks. If <tt>:external</tt> is true, you can use either output or non-output blocks.
42
+ #
43
+ # If you set :prevent_default to true the default action of the event is stopped (similar to calling event.stop).
44
+ # This is very useful for hijacking links in order to provide some other behaviour.
45
+ #
46
+ # You can also pass a block to the function instead of a string of javascript -
47
+ # the block will be passed in a JavascriptGenerator object (+page+), the element (optional)
48
+ # and the event (optional). You can use the Javascript generator
49
+ # to write your attached behaviour using Ruby:
50
+ #
51
+ # <% apply_behaviour "#coollink:click" do |page, element, event|
52
+ # page.alert("Hi there, I'm going to fade away...")
53
+ # page.visual_effect :fade, element
54
+ # end %>
55
+ def apply_behaviour(selector, *args, &block) #:yields: page, element, event
56
+ opts = args.last.is_a?(Hash) ? args.pop : {}
57
+ set_default_external!(opts)
58
+ behaviour = normalise_behaviour_string(args.first || '')
59
+
60
+ if block_given?
61
+ generator = new_javascript_generator
62
+ args = [generator, element_proxy(generator), event_proxy(generator)][0..block.arity-1]
63
+ @template.instance_exec(*args, &block)
64
+ behaviour = generator.to_s
65
+ end
66
+
67
+ if !opts[:external]
68
+ render_inline_behaviour_block(selector, behaviour, opts)
69
+ else
70
+ @controller.apply_behaviour(selector, behaviour, opts) and return ''
71
+ end
72
+ end
73
+
74
+ # Allow you to apply multiple behaviours with block syntax.
75
+ #
76
+ # apply_behaviours do
77
+ # on 'a:click', 'alert("boo")'
78
+ # on 'abbr:mouseover', 'showAbbr(this)'
79
+ # end
80
+ def apply_behaviours(&block)
81
+ mapper = BehaviourMapper.new(self).instance_eval &block
82
+ mapper.to_s
83
+ end
84
+
85
+ # Make sure American and English spellings both work
86
+ alias_method :apply_behavior, :apply_behaviour
87
+ alias_method :apply_behaviors, :apply_behaviours
88
+
89
+ protected
90
+ # A convenient mapper class for applying
91
+ # multiple behaviours at once.
92
+ class BehaviourMapper
93
+ def initialize(base)
94
+ @base = base
95
+ @output = ''
96
+ end
97
+
98
+ def on(*args, &block)
99
+ @output << @base.apply_behaviour(*args, &block)
100
+ end
101
+
102
+ # delegate all other method calls to the view
103
+ def method_missing(meth, *args)
104
+ @base.send meth, *args
105
+ end
106
+
107
+ def to_s
108
+ @output
109
+ end
110
+
111
+ end
112
+
113
+ # Renders a block of javascript behaviours inside +script+ tags
114
+ # directly within the page
115
+ def render_inline_behaviour_block(selector, behaviour, opts)
116
+ script = UJS::BehaviourScript.new
117
+ script.add_rule(selector, behaviour)
118
+ javascript_tag(script.to_s)
119
+ end
120
+
121
+ # Use this to set the default :external option for helper calls.
122
+ # it set external to false if its an xhr request or false if it's a normal request.
123
+ def set_default_external!(options)
124
+ options.reverse_merge!(:external => !current_controller.request.xhr?)
125
+ end
126
+
127
+ # Returns a new JavascriptArgumentProxy for the element the behaviour
128
+ # has been applied to.
129
+ def element_proxy(generator)
130
+ UJS::JavascriptProxies::JavascriptArgumentProxy.new(UJS::JavascriptProxies::ReferencedJavascriptElementProxy, generator, 'this')
131
+ end
132
+
133
+ # Returns a new JavascriptArgumentProxy for the event the behaviour has
134
+ # been applied to.
135
+ def event_proxy(generator)
136
+ UJS::JavascriptProxies::JavascriptArgumentProxy.new(UJS::JavascriptProxies::JavascriptEventProxy, generator, 'event')
137
+ end
138
+
139
+ # Returns a new JavasScriptGenerator object
140
+ def new_javascript_generator
141
+ ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template) { }
142
+ end
143
+
144
+ def current_controller
145
+ @controller
146
+ end
147
+
148
+ def normalise_behaviour_string(behaviour)
149
+ behaviour << ';' unless behaviour =~ /;$/
150
+ behaviour
151
+ end
152
+ end
@@ -0,0 +1,57 @@
1
+ module ActionView
2
+ module Helpers
3
+ class JavaScriptProxy
4
+ public :method_missing
5
+
6
+ protected
7
+
8
+ def wrap(function, *args)
9
+ args = [function_chain[-1].chomp(';')].concat(args.collect(&:to_json)).join(', ')
10
+ replace_line("#{function.to_s}(#{args});")
11
+ end
12
+
13
+ def replace_line(new_line)
14
+ function_chain[-1] = new_line
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+ module UJS
23
+ module JavascriptProxies
24
+
25
+ class ReferencedJavascriptElementProxy < ActionView::Helpers::JavaScriptElementProxy
26
+
27
+ def initialize(generator, var)
28
+ @generator = generator
29
+ @generator << var
30
+ end
31
+
32
+ def reload; end
33
+
34
+ end
35
+
36
+ class JavascriptArgumentProxy
37
+ def initialize(proxy, *contructor_args)
38
+ @proxy, @args = proxy, contructor_args
39
+ end
40
+
41
+ def method_missing(meth, *args)
42
+ proxy = @proxy.new(*@args)
43
+ proxy.__send__(meth, *args)
44
+ end
45
+ end
46
+
47
+ class JavascriptEventProxy < ActionView::Helpers::JavaScriptProxy
48
+ def stop
49
+ wrap('Event.stop')
50
+ end
51
+
52
+ def element
53
+ wrap('Event.element')
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ namespace :unobtrusive_javascript do
2
+
3
+ PLUGIN_ROOT = File.dirname(__FILE__) + '/../'
4
+
5
+ desc 'Installs required javascript files to the public/javascripts directory.'
6
+ task :install do
7
+ FileUtils.cp Dir[PLUGIN_ROOT + '/assets/javascripts/*.js'], RAILS_ROOT + '/public/javascripts'
8
+ end
9
+
10
+ desc 'Removes the javascripts for the plugin.'
11
+ task :remove do
12
+ FileUtils.rm %{lowpro.js}.collect { |f| RAILS_ROOT + "/public/javascripts/" + f }
13
+ end
14
+
15
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'asset_tag_helper_patches'
3
+
4
+ class JavascriptIncludeTagWithUnobtrusiveOption < Test::Unit::TestCase
5
+ include ActionView::Helpers::AssetTagHelper
6
+ include ActionView::Helpers::TagHelper
7
+
8
+ def setup
9
+ initialize_test_request
10
+ @output = javascript_include_tag(:unobtrusive).split("\n")
11
+ end
12
+
13
+ def test_should_render_script_tag_for_lowpro
14
+ assert @output.include?('<script src="/javascripts/lowpro.js?" type="text/javascript"></script>')
15
+ end
16
+
17
+ def test_should_render_script_tag_for_current_requests_behaviour
18
+ assert @output.include?('<script src="/behaviours/controller_stub.js?" type="text/javascript"></script>')
19
+ end
20
+
21
+ def test_should_render_index_behaviour_when_request_path_is_just_a_forward_slash
22
+ @controller.request.stubs(:path).returns('/')
23
+ @output = javascript_include_tag(:unobtrusive).split("\n")
24
+ assert @output.include?('<script src="/behaviours/index.js?" type="text/javascript"></script>')
25
+ end
26
+
27
+ def test_should_render_index_behaviour_when_request_path_is_blank_as_a_result_of_a_url_prefix
28
+ @controller.request.stubs(:path).returns('')
29
+ @output = javascript_include_tag(:unobtrusive).split("\n")
30
+ assert @output.include?('<script src="/behaviours/index.js?" type="text/javascript"></script>')
31
+ end
32
+ end
@@ -0,0 +1,180 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'prototype_helper_patches'
3
+ require 'scriptaculous_helper_patches'
4
+ require 'ujs/behaviour_helper'
5
+
6
+ class MakeSortableTest < Test::Unit::TestCase
7
+ include ActionView::Helpers::JavaScriptHelper
8
+ include ActionView::Helpers::ScriptaculousHelper
9
+ include ActionView::Helpers::PrototypeHelper
10
+ include ActionView::Helpers::UrlHelper
11
+ include ActionView::Helpers::TagHelper
12
+ include UJS::BehaviourHelper
13
+
14
+ def setup
15
+ initialize_test_request
16
+ end
17
+
18
+ def test_should_output_sortable_javascript
19
+ output = make_sortable
20
+
21
+ assert_equal sortable_element_js(javascript_variable('this')), output
22
+ end
23
+
24
+ def test_should_pass_arguments_through
25
+ output = make_sortable :onUpdate => 'function() { alert("updated") }'
26
+ assert_equal 'Sortable.create(this, {onUpdate:function() { alert("updated") }});', output
27
+ end
28
+ end
29
+
30
+ class MakeRemoteLinkTest < Test::Unit::TestCase
31
+ include ActionView::Helpers::JavaScriptHelper
32
+ include ActionView::Helpers::ScriptaculousHelper
33
+ include ActionView::Helpers::PrototypeHelper
34
+ include ActionView::Helpers::UrlHelper
35
+ include ActionView::Helpers::TagHelper
36
+ include UJS::BehaviourHelper
37
+
38
+ def setup
39
+ initialize_test_request
40
+ end
41
+
42
+ def test_should_generate_ajax_request
43
+ output = make_remote_link
44
+ assert_match(/new Ajax\.Request/, output)
45
+ end
46
+
47
+ def test_should_default_to_element_href
48
+ output = make_remote_link
49
+ assert_match(/\(this\.href/, output)
50
+ end
51
+
52
+ def test_should_respond_to_given_options
53
+ output = make_remote_link( :update => 'fartknocker' )
54
+ assert_match(/new Ajax\.Updater\('fartknocker'/, output)
55
+ end
56
+ end
57
+
58
+ class MakeRemoteFormTest < Test::Unit::TestCase
59
+ include ActionView::Helpers::JavaScriptHelper
60
+ include ActionView::Helpers::ScriptaculousHelper
61
+ include ActionView::Helpers::PrototypeHelper
62
+ include ActionView::Helpers::UrlHelper
63
+ include ActionView::Helpers::TagHelper
64
+ include UJS::BehaviourHelper
65
+
66
+ def setup
67
+ initialize_test_request
68
+ end
69
+
70
+ def test_should_generate_ajax_request
71
+ output = make_remote_form
72
+ assert_match(/new Ajax\.Request/, output)
73
+ end
74
+
75
+ def test_should_default_to_form_action
76
+ output = make_remote_form
77
+ assert_match(/\(this\.action/, output)
78
+ end
79
+ end
80
+
81
+ class MakeDraggableTest < Test::Unit::TestCase
82
+ include ActionView::Helpers::JavaScriptHelper
83
+ include ActionView::Helpers::ScriptaculousHelper
84
+ include ActionView::Helpers::PrototypeHelper
85
+ include ActionView::Helpers::UrlHelper
86
+ include ActionView::Helpers::TagHelper
87
+ include UJS::BehaviourHelper
88
+
89
+ def setup
90
+ initialize_test_request
91
+ end
92
+
93
+ def test_should_create_draggable_instance
94
+ output = make_draggable
95
+ assert_match(/new Draggable/, output)
96
+ end
97
+
98
+ def test_should_pass_this
99
+ output = make_draggable
100
+ assert_match(/\(this/, output)
101
+ end
102
+
103
+ def test_should_respond_to_options
104
+ output = make_draggable( :revert => true )
105
+ assert_match(/revert\:true/, output)
106
+ end
107
+ end
108
+
109
+ class MakeDropRecievingTest < Test::Unit::TestCase
110
+ include ActionView::Helpers::JavaScriptHelper
111
+ include ActionView::Helpers::ScriptaculousHelper
112
+ include ActionView::Helpers::PrototypeHelper
113
+ include ActionView::Helpers::UrlHelper
114
+ include ActionView::Helpers::TagHelper
115
+ include UJS::BehaviourHelper
116
+
117
+ def setup
118
+ initialize_test_request
119
+ end
120
+
121
+ def test_should_add_to_droppables
122
+ output = make_drop_receiving
123
+ assert_match(/Droppables\.add/, output)
124
+ end
125
+
126
+ def test_should_pass_this
127
+ output = make_drop_receiving
128
+ assert_match(/\(this/, output)
129
+ end
130
+
131
+ def test_should_generate_a_url_from_options
132
+ output = make_drop_receiving( :url => { :action => "bingo" } )
133
+ assert_match(/controller_stub\/bingo/, output)
134
+ end
135
+ end
136
+
137
+ class MakeObservedTest < Test::Unit::TestCase
138
+ include ActionView::Helpers::JavaScriptHelper
139
+ include ActionView::Helpers::ScriptaculousHelper
140
+ include ActionView::Helpers::PrototypeHelper
141
+ include ActionView::Helpers::UrlHelper
142
+ include ActionView::Helpers::TagHelper
143
+ include UJS::BehaviourHelper
144
+
145
+ def setup
146
+ initialize_test_request
147
+ end
148
+
149
+ def test_should_make_form_observer
150
+ output = make_observed(:form)
151
+ assert_match(/new Form\.EventObserver/, output)
152
+ end
153
+
154
+ def test_should_make_field_observer
155
+ output = make_observed(:field)
156
+ assert_match(/new Form\.Element\.EventObserver/, output)
157
+ end
158
+
159
+ def test_should_pass_this
160
+ output = make_observed(:field)
161
+ assert_match(/\(this/, output)
162
+ end
163
+
164
+ def test_should_make_a_timed_observer_if_frequency_passed
165
+ output = make_observed(:form, :frequency => 3 )
166
+ assert_match(/new Form.Observer/, output)
167
+ assert_match(/3,/, output)
168
+ end
169
+
170
+ def test_should_generate_a_url_from_options
171
+ output = make_observed(:field, :url => { :action => "bingo" } )
172
+ assert_match(/controller_stub\/bingo/, output)
173
+ end
174
+
175
+ def test_should_respond_to_options
176
+ output = make_observed(:field, :function => 'alert("boo")' )
177
+ assert_match(/function\(element, value\) \{alert\("boo"\)\}/, output)
178
+ end
179
+ end
180
+