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,11 @@
1
+ require 'action_pack'
2
+ require 'action_controller'
3
+ require 'action_controller/test_process'
4
+
5
+ ActionController::Base.ignore_missing_templates = true
6
+
7
+ if PTK::Configuration.load :routes
8
+ ActionController::Routing::Routes.reload rescue nil
9
+ end
10
+
11
+ class ActionController::Base; def rescue_action(e) raise e end; end
@@ -0,0 +1,4 @@
1
+ require 'action_mailer'
2
+
3
+ ActionMailer::Base.delivery_method = :test
4
+ ActionMailer::Base.perform_deliveries = true
@@ -0,0 +1,27 @@
1
+ require 'active_record'
2
+ require 'active_record/fixtures'
3
+
4
+ ActiveRecord::Base.logger = Logger.new(File.join(RAILS_ROOT, 'test.log'))
5
+
6
+ # Load the database.yml from #{plugin_path}/test/config if it exists
7
+ if file = PTK::Configuration.find_path(:database)
8
+
9
+ config = YAML::load_file(file)
10
+ ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
11
+
12
+ # Load a schema if it exists
13
+ if schema = PTK::Configuration.find_path(:schema)
14
+
15
+ load(schema)
16
+
17
+ # Setup fixtures if the directory exists
18
+ if fixtures = PTK::Configuration.find_path(:fixtures)
19
+
20
+ PTK::LoadPath.add fixtures
21
+
22
+ Test::Unit::TestCase.fixture_path = fixtures
23
+ Test::Unit::TestCase.use_instantiated_fixtures = false
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # We require the initializer to setup the environment properly
2
+ unless defined?(Rails::Initializer)
3
+ if File.directory?("#{RAILS_ROOT}/../../../rails")
4
+ require "#{RAILS_ROOT}/../../../rails/railties/lib/initializer"
5
+ else
6
+ require 'rubygems'
7
+ require_gem 'rails'
8
+ require 'initializer'
9
+ end
10
+ Rails::Initializer.run(:set_load_path)
11
+ end
12
+
13
+ # We overwrite load_environment so we can have only one file
14
+ module Rails
15
+ class Initializer
16
+ def load_environment
17
+ end
18
+ end
19
+ end
20
+
21
+ # We overwrite the default log to be a directory up
22
+ module Rails
23
+ class Configuration
24
+ def default_log_path
25
+ File.join(root_path, "#{environment}.log")
26
+ end
27
+ end
28
+ end
29
+
30
+ # We then load it manually
31
+ PTK::Configuration.load :environment
@@ -0,0 +1,148 @@
1
+ require 'singleton'
2
+
3
+ module PTK
4
+
5
+ class Configuration
6
+ class << self
7
+ def load(config, fatal = false)
8
+ if (file = PTK::PathSet.instance.send(config)) == :ignore then false
9
+ elsif File.exists?(file)
10
+ require file
11
+ true
12
+ elsif fatal then raise LoadError, "PTK could not find #{file}"
13
+ else
14
+ STDERR.puts "PTK::WARNING: could not find #{file}"
15
+ false
16
+ end
17
+ end
18
+
19
+ def find_path(config, fatal = false)
20
+ if (file = PTK::PathSet.instance.send(config)) == :ignore then false
21
+ elsif File.exists?(file) then file
22
+ elsif fatal then raise LoadError, "PTK could not find #{file}"
23
+ else
24
+ STDERR.puts "PTK::WARNING: could not find #{file}"
25
+ false
26
+ end
27
+ end
28
+
29
+ def draw
30
+ yield PTK::PathSet.instance
31
+ end
32
+ end
33
+ end
34
+
35
+ class PathSet
36
+ include Singleton
37
+
38
+ attr_accessor :ptk_prefix
39
+ attr_accessor :config
40
+ attr_accessor :fixtures
41
+ attr_accessor :environment
42
+ attr_accessor :schema
43
+ attr_accessor :database
44
+ attr_accessor :routes
45
+
46
+ def initialize
47
+ self.ptk_prefix = 'ptk'
48
+ self.config = File.join(RAILS_ROOT, 'config')
49
+ self.fixtures = File.join(RAILS_ROOT, 'fixtures')
50
+
51
+ self.environment = File.join(self.config, 'environment.rb')
52
+
53
+ self.database = File.join(self.config, 'database.yml')
54
+ self.schema = File.join(self.config, 'schema.rb')
55
+
56
+ self.routes = File.join(self.config, 'routes.rb')
57
+ end
58
+ end
59
+
60
+ class Initializer
61
+
62
+ # The init.rb in the root directory of the plugin will be loaded by default
63
+ attr_accessor :init
64
+
65
+ # The specific environmental frameworks of a plugin, such as needing the ActionController
66
+ # ActionMailer or ActiveRecord gems to be preloaded. A special requirement called
67
+ # 'environment' will load tests as though they were in the test environment of a normal
68
+ # Rails application.
69
+ attr_accessor :frameworks
70
+ def frameworks
71
+ [@frameworks].flatten
72
+ end
73
+
74
+ # Suites are test extensions including assertions and various tools for easier testing
75
+ attr_accessor :suites
76
+ def suites
77
+ [@suites].flatten
78
+ end
79
+
80
+ # A container for the PathSet instance
81
+ attr_reader :paths
82
+
83
+ def initialize
84
+ self.init = true
85
+ self.frameworks = :none
86
+ self.suites = :all
87
+ @paths = PTK::PathSet.instance
88
+ end
89
+
90
+ def self.run(command = :process)
91
+ initializer = PTK::Initializer.new
92
+ yield initializer if block_given?
93
+ initializer.send(command)
94
+ end
95
+
96
+ def process
97
+ initialize_frameworks
98
+ initialize_suites
99
+ initialize_plugin
100
+ end
101
+
102
+ def initialize_frameworks
103
+ return if frameworks.include?(:none)
104
+ self.frameworks = [:rails] if frameworks.include?(:rails)
105
+ frameworks.each { |lib| require_ptk File.join('gem', lib.to_s) }
106
+ end
107
+
108
+ def initialize_suites
109
+ return if suites.include?(:none)
110
+ self.suites = all_suites if suites.include?(:all)
111
+ suites.each { |lib| require_ptk File.join('suite', lib.to_s) }
112
+ end
113
+
114
+ def initialize_plugin
115
+ return unless self.init
116
+ require File.join(RAILS_ROOT, '..', 'init')
117
+ end
118
+
119
+ protected
120
+
121
+ def all_suites
122
+ Dir.glob(File.join(RAILS_ROOT, 'lib', 'ptk', 'suite', '*.rb')).inject([]) do |a, file|
123
+ a << File.basename(file, '.rb').to_sym
124
+ a
125
+ end
126
+ end
127
+
128
+ def require_ptk(library)
129
+ file = paths.ptk_prefix.empty? ? library : File.join(paths.ptk_prefix, library)
130
+ require file
131
+ end
132
+
133
+ end
134
+
135
+ class LoadPath
136
+
137
+ def self.expand(file, *dirs)
138
+ File.join(*([File.expand_path(File.dirname(file))] << dirs))
139
+ end
140
+
141
+ def self.add(*dirs)
142
+ path = File.expand_path(File.join(*dirs))
143
+ $:.unshift path
144
+ $:.uniq!
145
+ end
146
+
147
+ end
148
+ end
@@ -0,0 +1,23 @@
1
+ class Test::Unit::TestCase
2
+
3
+ # http://project.ioni.st/post/217#post-217
4
+ #
5
+ # def test_new_publication
6
+ # assert_difference(Publication, :count) do
7
+ # post :create, :publication => {...}
8
+ # # ...
9
+ # end
10
+ # end
11
+ #
12
+ # modified by mabs29 to include arguments
13
+ def assert_difference(object, method = nil, difference = 1, *args)
14
+ initial_value = object.send(method, *args)
15
+ yield
16
+ assert_equal initial_value + difference, object.send(method, *args), "#{object}##{method}"
17
+ end
18
+
19
+ def assert_no_difference(object, method, *args, &block)
20
+ assert_difference object, method, 0, *args, &block
21
+ end
22
+
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'action_controller/test_process'
2
+ require 'ujs/controller_methods'
3
+
4
+ class ControllerStub < ActionController::Base
5
+ def index
6
+ render :nothing => true
7
+ end
8
+ end
9
+
10
+ ControllerStub.send(:include, UJS::ControllerMethods)
@@ -0,0 +1,29 @@
1
+ # Do not comment out this line; it sets the RAILS_ROOT constant and load paths, not Rails itself
2
+ require File.join(File.dirname(__FILE__), 'lib', 'ptk', 'boot')
3
+
4
+ PTK::Initializer.run do |setup|
5
+ # You can also redefine the paths of certain directories and files, namely:
6
+ #setup.paths.config = File.join(RAILS_ROOT, 'config')
7
+ #setup.paths.fixtures = File.join(RAILS_ROOT, 'fixtures')
8
+
9
+ #setup.paths.database = File.join(setup.paths.config, 'database.yml')
10
+ #setup.paths.schema = File.join(setup.paths.config, 'schema.rb')
11
+ #setup.paths.routes = File.join(setup.paths.config, 'routes.rb')
12
+ #setup.paths.environment = File.join(setup.paths.config, 'environment.rb')
13
+
14
+ # If any of these paths are set to ':ignore', no warnings will appear if they are missing.
15
+
16
+ # Frameworks are the gems from Rails which you need PTK to load for your plugin.
17
+ # The special :rails framework creates a fully-fledged Rails environment and requires
18
+ # the environment.rb file.
19
+ # Valid options are: :action_controller, :action_mailer, :active_record, :rails
20
+ setup.frameworks = :action_controller # :active_record, :action_controller
21
+
22
+ # Extra libraries of assertions and other common methods that provide more testing
23
+ # utilities. To hand-pick which suites you want, uncomment the below
24
+ #setup.suites = :difference
25
+
26
+ # If for some particular reason you do not want your plugin's init to be called
27
+ # at the end of this block, uncomment the below:
28
+ setup.init = false
29
+ end
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ContentTagWithJavascriptEventsTest < Test::Unit::TestCase
4
+ include ActionView::Helpers::TagHelper
5
+
6
+ def setup
7
+ @controller = ControllerStub.new
8
+ @request = ActionController::TestRequest.new
9
+ @response = ActionController::TestResponse.new
10
+ get :index
11
+ @output = content_tag('div', 'my test div', {
12
+ :id => 'my_test_div', :class => 'some_class',
13
+ :onclick => 'alert("foo")',
14
+ :onmouseup => 'alert("foo")',
15
+ :onmousedown => 'alert("foo")',
16
+ :ondblclick => 'alert("foo")',
17
+ :onmouseover => 'alert("foo")',
18
+ :onmouseout => 'alert("foo")',
19
+ :onload => 'alert("foo")',
20
+ :onmousemove => 'alert("foo")'
21
+ })
22
+ end
23
+
24
+ def test_result_should_not_contain_any_inline_javascript_events
25
+ assert_equal '<div class="some_class" id="my_test_div">my test div</div>', @output
26
+ end
27
+
28
+ def test_should_have_javascript_events_registered_as_unobtrusive
29
+ assert_equal 8, assigns(:js_behaviours).rules.size
30
+ assert assigns(:js_behaviours).rules.include?(['#my_test_div:click', 'alert("foo");'])
31
+ assert assigns(:js_behaviours).rules.include?(['#my_test_div:mouseup', 'alert("foo");'])
32
+ assert assigns(:js_behaviours).rules.include?(['#my_test_div:mousedown', 'alert("foo");'])
33
+ assert assigns(:js_behaviours).rules.include?(['#my_test_div:dblclick', 'alert("foo");'])
34
+ assert assigns(:js_behaviours).rules.include?(['#my_test_div:mouseover', 'alert("foo");'])
35
+ assert assigns(:js_behaviours).rules.include?(['#my_test_div:mouseout', 'alert("foo");'])
36
+ assert assigns(:js_behaviours).rules.include?(['#my_test_div:load', 'alert("foo");'])
37
+ assert assigns(:js_behaviours).rules.include?(['#my_test_div:mousemove', 'alert("foo");'])
38
+ end
39
+ end
40
+
41
+ class TagOptionsForFormTextFieldsTest < Test::Unit::TestCase
42
+ include ActionView::Helpers::FormTagHelper
43
+ include ActionView::Helpers::FormHelper
44
+ include ActionView::Helpers::TagHelper
45
+
46
+ def setup
47
+ @controller = ControllerStub.new
48
+ @request = ActionController::TestRequest.new
49
+ @response = ActionController::TestResponse.new
50
+ get :index
51
+ @text_field_tag = text_field_tag('login')
52
+ @text_field = text_field(:user, :first_name)
53
+ end
54
+
55
+ def test_should_not_contain_any_inline_javascript_events
56
+ assert_equal '<input id="login" name="login" type="text" />', @text_field_tag
57
+ assert_equal '<input id="user_first_name" name="user[first_name]" size="30" type="text" />', @text_field
58
+ end
59
+ end
@@ -0,0 +1,25 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ # load plugin test kit
4
+ require File.join(File.dirname(__FILE__), 'ptk_helper')
5
+
6
+ # load stubba and other stubs
7
+ require 'stubba'
8
+ require 'stubs/controller_stub'
9
+
10
+ # load plugin files
11
+ require 'actionview_helpers_patches'
12
+ require 'prototype_helper_patches'
13
+ require 'scriptaculous_helper_patches'
14
+ require 'asset_tag_helper_patches'
15
+ require 'tag_helper_patches'
16
+ require 'behaviour_caching'
17
+
18
+ $:.unshift(File.join(File.dirname(__FILE__), '../lib/'))
19
+
20
+ def initialize_test_request
21
+ @controller = ControllerStub.new
22
+ @request = ActionController::TestRequest.new
23
+ @response = ActionController::TestResponse.new
24
+ get :index
25
+ end
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ # inject the controller methods to add the appropriate filters
4
+ # before loading in the unobtrusive js controller otherwise its
5
+ # skip_ filters will be fubarred.
6
+ ActionController::Base.send(:include, UJS::ControllerMethods)
7
+
8
+ require 'controllers/unobtrusive_javascript_controller'
9
+
10
+ class BehaviourGenerationControllerTest < Test::Unit::TestCase
11
+ def test_should_always_skip_the_initialise_js_behaviours_filter
12
+ assert !UnobtrusiveJavascriptController.before_filters.include?(:initialise_js_behaviours)
13
+ end
14
+
15
+ def test_should_always_skip_the_store_js_behaviours_filter
16
+ assert !UnobtrusiveJavascriptController.before_filters.include?(:store_js_behaviours)
17
+ end
18
+
19
+ def test_should_always_perform_any_caching_after_a_request
20
+ assert UnobtrusiveJavascriptController.after_filters.include?(:perform_any_caching)
21
+ end
22
+
23
+ def test_should_always_reset_any_js_behaviours_after_a_request
24
+ assert UnobtrusiveJavascriptController.after_filters.include?(:reset_js_behaviours)
25
+ end
26
+ end
27
+
28
+ class BehaviourGenerationWithNoBehavioursTest < Test::Unit::TestCase
29
+ def setup
30
+ @controller = UnobtrusiveJavascriptController.new
31
+ @request = ActionController::TestRequest.new
32
+ @response = ActionController::TestResponse.new
33
+ UnobtrusiveJavascriptController.any_instance.stubs(:js_behaviours).returns(UJS::BehaviourScript.new)
34
+ get :generate
35
+ end
36
+
37
+ def test_should_set_content_type_to_text_javascript
38
+ assert_equal "text/javascript", @response.headers["Content-Type"]
39
+ end
40
+
41
+ def test_should_render_nothing
42
+ assert_equal "", @response.body
43
+ end
44
+ end
45
+
46
+ class BehaviourGenerationWithAppliedBehavioursTest < Test::Unit::TestCase
47
+ def setup
48
+ @behaviours = UJS::BehaviourScript.new
49
+ @behaviours.add_rule("div.foo", "alert('foo')")
50
+ @behaviours.add_rule("div.bar", "alert('bar')")
51
+ UnobtrusiveJavascriptController.any_instance.stubs(:js_behaviours).returns(@behaviours)
52
+ @controller = UnobtrusiveJavascriptController.new
53
+ @request = ActionController::TestRequest.new
54
+ @response = ActionController::TestResponse.new
55
+ get :generate
56
+ end
57
+
58
+ def test_should_set_content_type_to_text_javascript
59
+ assert_equal "text/javascript", @response.headers["Content-Type"]
60
+ end
61
+
62
+ def test_should_render_behaviour_script_output
63
+ assert_equal @behaviours.to_s, @response.body
64
+ end
65
+
66
+ def test_should_generate_an_etag_for_the_behaviours
67
+ assert_equal Digest::MD5.hexdigest(@behaviours.to_s), @response.headers["ETag"]
68
+ end
69
+ end
70
+
71
+ class BehaviourGenerationWithUnchangedBehavioursTest < Test::Unit::TestCase
72
+ def setup
73
+ @behaviours = UJS::BehaviourScript.new
74
+ @behaviours.add_rule("div.foo", "alert('foo')")
75
+ @behaviours.add_rule("div.bar", "alert('bar')")
76
+ UnobtrusiveJavascriptController.any_instance.stubs(:js_behaviours).returns(@behaviours)
77
+ @controller = UnobtrusiveJavascriptController.new
78
+ @request = ActionController::TestRequest.new
79
+ @response = ActionController::TestResponse.new
80
+ @request.env['HTTP_IF_NONE_MATCH'] = Digest::MD5.hexdigest(@behaviours.to_s)
81
+ get :generate
82
+ end
83
+
84
+ def test_should_set_content_type_to_text_javascript
85
+ assert_equal "text/javascript", @response.headers["Content-Type"]
86
+ end
87
+
88
+ def test_should_render_nothing
89
+ assert_equal " ", @response.body
90
+ end
91
+
92
+ def test_should_send_304_not_modified_http_status
93
+ assert_response 304
94
+ end
95
+ end