compages 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.project +18 -0
- data/README +180 -0
- data/Rakefile +10 -0
- data/app/controllers/application.rb +4 -0
- data/app/controllers/contents_controller.rb +116 -0
- data/app/controllers/pages_controller.rb +59 -0
- data/app/controllers/render_controller.rb +24 -0
- data/app/helpers/application_helper.rb +6 -0
- data/app/helpers/contents_helper.rb +5 -0
- data/app/helpers/pages_helper.rb +5 -0
- data/app/helpers/render_helper.rb +2 -0
- data/app/models/content.rb +26 -0
- data/app/models/meta_data.rb +3 -0
- data/app/models/page.rb +106 -0
- data/app/models/page_element.rb +9 -0
- data/app/views/contents/_content_preview.rhtml +1 -0
- data/app/views/contents/_contents_list.rhtml +3 -0
- data/app/views/contents/_show_library.rhtml +60 -0
- data/app/views/contents/_write_now.rhtml +42 -0
- data/app/views/layouts/pages.rhtml +24 -0
- data/app/views/layouts/render.rhtml +11 -0
- data/app/views/pages/_change_theme.rhtml +0 -0
- data/app/views/pages/_edit_menu.rhtml +62 -0
- data/app/views/pages/_page_listed.rhtml +13 -0
- data/app/views/pages/_select_theme.rhtml +4 -0
- data/app/views/pages/edit.rhtml +35 -0
- data/app/views/pages/index.rhtml +45 -0
- data/app/views/pages/list.rhtml +41 -0
- data/app/views/pages/list_a.rhtml +40 -0
- data/app/views/pages/welcome.rhtml +27 -0
- data/app/views/render/_blank.rhtml +3 -0
- data/app/views/render/show.rhtml +1 -0
- data/bin/compages +14 -0
- data/config/boot.rb +44 -0
- data/config/database.yml.home +35 -0
- data/config/environment.rb +53 -0
- data/config/environments/development.rb +21 -0
- data/config/environments/production.rb +18 -0
- data/config/environments/test.rb +19 -0
- data/config/routes.rb +32 -0
- data/db/Copia di schema.rb +48 -0
- data/db/migrate/001_create_pages.rb +12 -0
- data/db/migrate/002_create_contents.rb +12 -0
- data/db/migrate/003_create_meta_datas.rb +14 -0
- data/db/migrate/004_create_page_elements.rb +17 -0
- data/db/migrate/005_add_urlnames.rb +15 -0
- data/db/migrate/006_add_sessions.rb +15 -0
- data/db/schema.mysql.sql +65 -0
- data/db/schema.postgresql.sql +65 -0
- data/db/schema.rb +49 -0
- data/db/schema.sqlite.sql +65 -0
- data/db/schema.sqlserver.sql +71 -0
- data/db/schema_version +1 -0
- data/doc/ER-model/v1.dia +0 -0
- data/doc/ER-model/v2.dia +0 -0
- data/doc/ER-model/v3.dia +0 -0
- data/doc/README_FOR_APP +2 -0
- data/doc/esempi/doc-vir/ecds.htm +2362 -0
- data/doc/esempi/doc-vir/ecds_files/search.gif +0 -0
- data/doc/esempi/doc-vir/ecds_files/upld.gif +0 -0
- data/doc/esempi/doc-vir/ecds_files/upld.jpg +0 -0
- data/installer/apache13.conf.example.template +33 -0
- data/installer/apache20.conf.example.template +40 -0
- data/installer/lighttpd.conf.example.template +6 -0
- data/installer/rails_installer_defaults.yml +5 -0
- data/lib/redcloth.rb +1130 -0
- data/lib/render_engine.rb +94 -0
- data/lib/tasks/release.rake +46 -0
- data/public/.htaccess +41 -0
- data/public/404.html +8 -0
- data/public/500.html +8 -0
- data/public/_index.html +277 -0
- data/public/favicon.ico +0 -0
- data/public/images/body_bg.gif +0 -0
- data/public/images/body_bg_short.gif +0 -0
- data/public/images/ie_shadow.png +0 -0
- data/public/images/journal_reflex.gif +0 -0
- data/public/images/journal_shadow.gif +0 -0
- data/public/images/logo_journal_small.bmp +0 -0
- data/public/images/logo_journal_small.png +0 -0
- data/public/images/page_edit_shadow.png +0 -0
- data/public/images/restore_bar.png +0 -0
- data/public/images/spinner.gif +0 -0
- data/public/javascripts/application.js +23 -0
- data/public/javascripts/controls.js +815 -0
- data/public/javascripts/dragdrop.js +913 -0
- data/public/javascripts/effects.js +958 -0
- data/public/javascripts/lowpro.js +307 -0
- data/public/javascripts/prototype.js +2006 -0
- data/public/robots.txt +1 -0
- data/public/stylesheets/compages.css +196 -0
- data/public/stylesheets/editing.css +180 -0
- data/public/stylesheets/editing_ie_filth.css +36 -0
- data/public/themes/Doc_basic/_script.js +342 -0
- data/public/themes/Doc_basic/images/Thumbs.db +0 -0
- data/public/themes/Doc_basic/images/search.gif +0 -0
- data/public/themes/Doc_basic/images/upld.gif +0 -0
- data/public/themes/Doc_basic/images/upld.jpg +0 -0
- data/public/themes/Doc_basic/index.html +114 -0
- data/public/themes/Doc_basic/style.css +1743 -0
- data/public/themes/color7boxes/default2.css +42 -0
- data/public/themes/color7boxes/index.html +40 -0
- data/public/themes/prova/index.html +12 -0
- data/public/zDoc/images/search.gif +0 -0
- data/public/zDoc/images/upld.gif +0 -0
- data/public/zDoc/images/upld.jpg +0 -0
- data/public/zDoc/index.html +176 -0
- data/public/zDoc/script.js +342 -0
- data/public/zDoc/style.css +1741 -0
- data/script/about +3 -0
- data/script/breakpointer +3 -0
- data/script/console +3 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/test/fixtures/contents.yml +5 -0
- data/test/fixtures/meta_datas.yml +5 -0
- data/test/fixtures/page_elements.yml +5 -0
- data/test/fixtures/pages.yml +5 -0
- data/test/functional/contents_controller_test.rb +18 -0
- data/test/functional/pages_controller_test.rb +18 -0
- data/test/functional/render_controller_test.rb +18 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/content_test.rb +10 -0
- data/test/unit/meta_data_test.rb +10 -0
- data/test/unit/page_element_test.rb +10 -0
- data/test/unit/page_test.rb +10 -0
- data/tmp/sessions/ruby_sess.0ced4c30e36477ab +0 -0
- data/tmp/sessions/ruby_sess.20fbe26671422e70 +0 -0
- data/tmp/sessions/ruby_sess.2c72521f3a7e2ba9 +0 -0
- data/tmp/sessions/ruby_sess.4107a69d982a2eb7 +0 -0
- data/tmp/sessions/ruby_sess.573ded9c7fdd9035 +0 -0
- data/tmp/sessions/ruby_sess.5a9767815bb96258 +0 -0
- data/tmp/sessions/ruby_sess.85d723b794005388 +0 -0
- data/tmp/sessions/ruby_sess.875b3b3e3529afdb +0 -0
- data/tmp/sessions/ruby_sess.936766f3a397c88b +0 -0
- data/tmp/sessions/ruby_sess.984e2e4c9a2e7891 +0 -0
- data/tmp/sessions/ruby_sess.a1faebd7448bc45d +0 -0
- data/tmp/sessions/ruby_sess.a415768c7635bc15 +0 -0
- data/tmp/sessions/ruby_sess.b2dadcbe6c1b0add +0 -0
- data/tmp/sessions/ruby_sess.ca9100beb103a428 +0 -0
- data/tmp/sessions/ruby_sess.d649c800a046efde +0 -0
- data/tmp/sessions/ruby_sess.db73bbfafd5a537c +0 -0
- data/tmp/sessions/ruby_sess.e32487b847524df1 +0 -0
- data/tmp/sessions/ruby_sess.f4e45d67828cc437 +0 -0
- data/tmp/sessions/ruby_sess.f5a3f064f2f7a26f +0 -0
- data/tmp/sessions/ruby_sess.ff0c47b35f238cda +0 -0
- data/vendor/plugins/acts_as_urlnameable.tar.gz +0 -0
- data/vendor/plugins/acts_as_urlnameable/LICENSE +19 -0
- data/vendor/plugins/acts_as_urlnameable/README +193 -0
- data/vendor/plugins/acts_as_urlnameable/Rakefile +25 -0
- data/vendor/plugins/acts_as_urlnameable/TODO +5 -0
- data/vendor/plugins/acts_as_urlnameable/db/00x_add_urlnames_table.rb +15 -0
- data/vendor/plugins/acts_as_urlnameable/db/urlnames_table.sql +7 -0
- data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/ClassMethods.html +167 -0
- data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/InstanceMethods.html +213 -0
- data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/SingletonMethods.html +189 -0
- data/vendor/plugins/acts_as_urlnameable/doc/created.rid +1 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/LICENSE.html +129 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/README.html +333 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/TODO.html +121 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/lib/acts_as_urlnameable_rb.html +101 -0
- data/vendor/plugins/acts_as_urlnameable/doc/fr_class_index.html +29 -0
- data/vendor/plugins/acts_as_urlnameable/doc/fr_file_index.html +30 -0
- data/vendor/plugins/acts_as_urlnameable/doc/fr_method_index.html +34 -0
- data/vendor/plugins/acts_as_urlnameable/doc/index.html +24 -0
- data/vendor/plugins/acts_as_urlnameable/doc/rdoc-style.css +208 -0
- data/vendor/plugins/acts_as_urlnameable/init.rb +3 -0
- data/vendor/plugins/acts_as_urlnameable/lib/acts_as_urlnameable.rb +159 -0
- data/vendor/plugins/acts_as_urlnameable/lib/urlname.rb +3 -0
- data/vendor/plugins/acts_as_urlnameable/test/acts_as_urlnameable_test.rb +233 -0
- data/vendor/plugins/acts_as_urlnameable/test/connection.rb +8 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/article.rb +13 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/articles.yml +62 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/page.rb +14 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/pages.yml +35 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/people.yml +9 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/person.rb +26 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/schema.rb +24 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/section.rb +5 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/sections.yml +9 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/urlnames.yml +153 -0
- data/vendor/plugins/acts_as_urlnameable/test/test_helper.rb +42 -0
- data/vendor/plugins/gems/README +30 -0
- data/vendor/plugins/gems/init.rb +9 -0
- data/vendor/plugins/gems/tasks/gems_tasks.rake +32 -0
- data/vendor/plugins/unobtrusive_javascript/CHANGELOG +72 -0
- data/vendor/plugins/unobtrusive_javascript/README +73 -0
- data/vendor/plugins/unobtrusive_javascript/Rakefile +33 -0
- data/vendor/plugins/unobtrusive_javascript/about.yml +6 -0
- data/vendor/plugins/unobtrusive_javascript/assets/javascripts/lowpro.js +307 -0
- data/vendor/plugins/unobtrusive_javascript/init.rb +21 -0
- data/vendor/plugins/unobtrusive_javascript/install.rb +1 -0
- data/vendor/plugins/unobtrusive_javascript/lib/actionview_helpers_patches.rb +17 -0
- data/vendor/plugins/unobtrusive_javascript/lib/asset_tag_helper_patches.rb +33 -0
- data/vendor/plugins/unobtrusive_javascript/lib/behaviour_caching.rb +70 -0
- data/vendor/plugins/unobtrusive_javascript/lib/controllers/unobtrusive_javascript_controller.rb +52 -0
- data/vendor/plugins/unobtrusive_javascript/lib/prototype_helper_patches.rb +72 -0
- data/vendor/plugins/unobtrusive_javascript/lib/scriptaculous_helper_patches.rb +62 -0
- data/vendor/plugins/unobtrusive_javascript/lib/tag_helper_patches.rb +37 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs.rb +32 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_helper.rb +62 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script.rb +54 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script_converter.rb +23 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/controller_methods.rb +55 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/helpers.rb +152 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/javascript_proxies.rb +57 -0
- data/vendor/plugins/unobtrusive_javascript/tasks/unobtrusive_javascript_tasks.rake +15 -0
- data/vendor/plugins/unobtrusive_javascript/test/asset_tag_helper_patches_test.rb +32 -0
- data/vendor/plugins/unobtrusive_javascript/test/behaviour_helper_test.rb +180 -0
- data/vendor/plugins/unobtrusive_javascript/test/behaviour_script_converter_test.rb +72 -0
- data/vendor/plugins/unobtrusive_javascript/test/behaviour_script_test.rb +98 -0
- data/vendor/plugins/unobtrusive_javascript/test/config/environment.rb +8 -0
- data/vendor/plugins/unobtrusive_javascript/test/config/routes.rb +4 -0
- data/vendor/plugins/unobtrusive_javascript/test/config/schema.rb +3 -0
- data/vendor/plugins/unobtrusive_javascript/test/controller_methods_test.rb +48 -0
- data/vendor/plugins/unobtrusive_javascript/test/helpers_test.rb +186 -0
- data/vendor/plugins/unobtrusive_javascript/test/javascript_proxies_test.rb +3 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/boot.rb +26 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_controller.rb +11 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_mailer.rb +4 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/active_record.rb +27 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/rails.rb +31 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/ptk.rb +148 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/suite/difference.rb +23 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/stubs/controller_stub.rb +10 -0
- data/vendor/plugins/unobtrusive_javascript/test/ptk_helper.rb +29 -0
- data/vendor/plugins/unobtrusive_javascript/test/tag_helper_patches_test.rb +59 -0
- data/vendor/plugins/unobtrusive_javascript/test/test_helper.rb +25 -0
- data/vendor/plugins/unobtrusive_javascript/test/unobtrusive_javascript_controller_test.rb +95 -0
- data/vendor/plugins/unobtrusive_javascript/uninstall.rb +1 -0
- data/vendor/redcloth/bin/redcloth +3 -0
- data/vendor/redcloth/doc/CHANGELOG +160 -0
- data/vendor/redcloth/doc/COPYING +25 -0
- data/vendor/redcloth/doc/README +106 -0
- data/vendor/redcloth/doc/REFERENCE +216 -0
- data/vendor/redcloth/doc/make.rb +359 -0
- data/vendor/redcloth/lib/redcloth.rb +1130 -0
- data/vendor/redcloth/run-tests.rb +28 -0
- data/vendor/redcloth/setup.rb +1376 -0
- data/vendor/redcloth/tests/code.yml +105 -0
- data/vendor/redcloth/tests/hard_breaks.yml +26 -0
- data/vendor/redcloth/tests/images.yml +171 -0
- data/vendor/redcloth/tests/instiki.yml +39 -0
- data/vendor/redcloth/tests/links.yml +155 -0
- data/vendor/redcloth/tests/lists.yml +77 -0
- data/vendor/redcloth/tests/markdown.yml +218 -0
- data/vendor/redcloth/tests/poignant.yml +64 -0
- data/vendor/redcloth/tests/table.yml +198 -0
- data/vendor/redcloth/tests/textism.yml +406 -0
- 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
|
data/vendor/plugins/unobtrusive_javascript/lib/controllers/unobtrusive_javascript_controller.rb
ADDED
@@ -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
|