wagn 1.13.0 → 1.14.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (459) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +3 -2
  3. data/VERSION +1 -1
  4. data/app/controllers/card_controller.rb +33 -38
  5. data/config/routes.rb +2 -2
  6. data/config/version.txt +1 -1
  7. data/db/bootstrap/card_actions.yml +3543 -0
  8. data/db/bootstrap/card_acts.yml +7 -0
  9. data/db/bootstrap/card_changes.yml +9150 -0
  10. data/db/bootstrap/card_references.yml +666 -344
  11. data/db/bootstrap/cards.yml +3256 -1702
  12. data/db/migrate/20140822073704_create_new_revision_tables.rb +43 -0
  13. data/db/migrate/20141001105348_move_revisions_to_actions.rb +62 -0
  14. data/db/migrate_cards/20130411191151_renaming_for_menu.rb +42 -45
  15. data/db/migrate_cards/20130411211600_delete_old_related_tab_cards.rb +13 -16
  16. data/db/migrate_cards/20130419215612_import_help_text.rb +7 -10
  17. data/db/migrate_cards/20130823192433_add_style_cards.rb +77 -81
  18. data/db/migrate_cards/20130910183318_move_styles_to_content.rb +4 -7
  19. data/db/migrate_cards/20130920214038_jsonize_tinymce.rb +9 -12
  20. data/db/migrate_cards/20130920291703_update_stylesheets.rb +10 -13
  21. data/db/migrate_cards/20130927191728_account_events.rb +15 -18
  22. data/db/migrate_cards/20131016172445_common_css_patch.rb +5 -8
  23. data/db/migrate_cards/20140110193325_reset_account_request_type.rb +4 -7
  24. data/db/migrate_cards/20140307231621_user_data_to_cards.rb +50 -53
  25. data/db/migrate_cards/20140317035504_account_requests_to_signups.rb +39 -42
  26. data/db/migrate_cards/20140512155840_add_script_cards.rb +56 -59
  27. data/db/migrate_cards/20140629222005_add_email_cards.rb +168 -0
  28. data/db/migrate_cards/20140725180118_config_card_updates.rb +4 -7
  29. data/db/migrate_cards/data/mailer/follower_notification_email.html +9 -0
  30. data/db/migrate_cards/data/mailer/follower_notification_email.txt +11 -0
  31. data/db/migrate_cards/data/mailer/mail_config.json +22 -0
  32. data/db/migrate_cards/data/mailer/password_reset_email.html +10 -0
  33. data/db/migrate_cards/data/mailer/password_reset_email.txt +11 -0
  34. data/db/migrate_cards/data/mailer/signup_alert_email.html +7 -0
  35. data/db/migrate_cards/data/mailer/signup_alert_email.txt +5 -0
  36. data/db/migrate_cards/data/mailer/verification_email.html +9 -0
  37. data/db/migrate_cards/data/mailer/verification_email.txt +8 -0
  38. data/db/schema.rb +31 -1
  39. data/features/conflict.feature +39 -0
  40. data/features/flexmail.feature +54 -54
  41. data/features/notifications.feature +4 -2
  42. data/features/reset_password.feature +1 -1
  43. data/features/step_definitions/wagn_steps.rb +20 -2
  44. data/features/step_definitions/window_steps.rb +23 -0
  45. data/features/support/env.rb +1 -0
  46. data/features/update_includers.feature +16 -10
  47. data/features/watch.feature +2 -2
  48. data/lib/card.rb +11 -10
  49. data/lib/card/act.rb +63 -0
  50. data/lib/card/action.rb +194 -0
  51. data/lib/card/change.rb +29 -0
  52. data/lib/card/content.rb +1 -1
  53. data/lib/card/diff.rb +229 -276
  54. data/lib/card/env.rb +4 -3
  55. data/lib/card/format.rb +2 -5
  56. data/lib/card/generators/card_migration/USAGE +15 -3
  57. data/lib/card/generators/card_migration/card_migration_generator.rb +22 -2
  58. data/lib/card/generators/card_migration/templates/card_migration.erb +4 -5
  59. data/lib/card/generators/format/USAGE +2 -2
  60. data/lib/card/generators/format/format_generator.rb +2 -2
  61. data/lib/card/generators/set/USAGE +2 -2
  62. data/lib/card/mailer.rb +21 -100
  63. data/lib/card/name.rb +4 -3
  64. data/lib/card/query.rb +2 -2
  65. data/lib/card/query/card_spec.rb +20 -30
  66. data/lib/card/query/value_spec.rb +2 -3
  67. data/lib/card/set.rb +3 -0
  68. data/lib/wagn/all.rb +6 -0
  69. data/lib/wagn/application.rb +16 -6
  70. data/lib/wagn/commands.rb +87 -27
  71. data/lib/wagn/config/environments/development.rb +17 -0
  72. data/lib/wagn/config/environments/test.rb +14 -1
  73. data/lib/wagn/config/initializers/airbrake.rb +1 -1
  74. data/lib/wagn/generators/wagn/templates/Gemfile +27 -9
  75. data/lib/wagn/generators/wagn/templates/config/application.rb +12 -3
  76. data/lib/wagn/generators/wagn/templates/simplecov +5 -0
  77. data/lib/wagn/generators/wagn/templates/spec/spec_helper.rb +1 -0
  78. data/lib/wagn/generators/wagn/wagn_generator.rb +75 -45
  79. data/lib/wagn/location.rb +9 -0
  80. data/lib/wagn/migration.rb +96 -0
  81. data/lib/wagn/mods_spec_helper.rb +16 -8
  82. data/lib/wagn/simplecov_helper.rb +61 -0
  83. data/lib/wagn/{wagn_spec_helper.rb → spec_helper.rb} +11 -3
  84. data/lib/wagn/tasks/test.rake +1 -1
  85. data/lib/wagn/tasks/wagn.rake +100 -34
  86. data/lib/wagn/version.rb +7 -2
  87. data/mod/{core → 01_core}/chunk/include.rb +0 -0
  88. data/mod/{core → 01_core}/chunk/link.rb +0 -0
  89. data/mod/{core → 01_core}/chunk/literal.rb +0 -0
  90. data/mod/{core → 01_core}/chunk/reference.rb +15 -3
  91. data/mod/{core → 01_core}/chunk/uri.rb +0 -0
  92. data/mod/{core → 01_core}/format/data_format.rb +0 -0
  93. data/mod/{core → 01_core}/format/html_format.rb +5 -2
  94. data/mod/{core → 01_core}/format/text_format.rb +0 -0
  95. data/mod/{core → 01_core}/layout/blank.html +0 -0
  96. data/mod/{core → 01_core}/layout/default.html +0 -0
  97. data/mod/{core → 01_core}/layout/noside.html +0 -0
  98. data/mod/{core → 01_core}/layout/pre.html +0 -0
  99. data/mod/{core → 01_core}/layout/simple.html +0 -0
  100. data/mod/{core → 01_core}/set/all/active_card.rb +0 -0
  101. data/mod/{core → 01_core}/set/all/collection.rb +33 -5
  102. data/mod/01_core/set/all/content.rb +144 -0
  103. data/mod/01_core/set/all/erb.rb +11 -0
  104. data/mod/{core → 01_core}/set/all/fetch.rb +8 -1
  105. data/mod/01_core/set/all/haml.rb +7 -0
  106. data/mod/{core → 01_core}/set/all/initialize.rb +4 -2
  107. data/mod/{core → 01_core}/set/all/name.rb +2 -3
  108. data/mod/01_core/set/all/notify.rb +215 -0
  109. data/mod/{core → 01_core}/set/all/pattern.rb +0 -0
  110. data/mod/{core → 01_core}/set/all/permissions.rb +1 -1
  111. data/mod/{core → 01_core}/set/all/phases.rb +24 -8
  112. data/mod/{core → 01_core}/set/all/references.rb +2 -2
  113. data/mod/{core → 01_core}/set/all/rules.rb +2 -2
  114. data/mod/{core → 01_core}/set/all/states.rb +1 -1
  115. data/mod/{core → 01_core}/set/all/templating.rb +4 -4
  116. data/mod/{core → 01_core}/set/all/tracked_attributes.rb +15 -64
  117. data/mod/{core → 01_core}/set/all/trash.rb +6 -5
  118. data/mod/{core → 01_core}/set/all/type.rb +0 -0
  119. data/mod/{core → 01_core}/set/all/utils.rb +1 -1
  120. data/mod/{core → 01_core}/set_pattern/01_all.rb +0 -0
  121. data/mod/{core → 01_core}/set_pattern/02_all_plus.rb +0 -0
  122. data/mod/{core → 01_core}/set_pattern/03_type.rb +0 -0
  123. data/mod/{core → 01_core}/set_pattern/04_star.rb +0 -0
  124. data/mod/{core → 01_core}/set_pattern/05_rstar.rb +0 -0
  125. data/mod/{core → 01_core}/set_pattern/06_right.rb +0 -0
  126. data/mod/{core → 01_core}/set_pattern/07_type_plus_right.rb +0 -0
  127. data/mod/{core → 01_core}/set_pattern/08_self.rb +0 -0
  128. data/mod/01_core/spec/chunk/literal_spec.rb +14 -0
  129. data/{spec/mod/core → mod/01_core/spec}/chunk/uri_spec.rb +3 -3
  130. data/{spec/mod/core → mod/01_core/spec}/format/data_format_spec.rb +0 -0
  131. data/{spec/mod/core → mod/01_core/spec}/format/html_format_spec.rb +9 -8
  132. data/{spec/mod/core → mod/01_core/spec}/format/text_format_spec.rb +0 -0
  133. data/{spec/mod/core → mod/01_core/spec}/set/all/active_card_spec.rb +0 -0
  134. data/mod/01_core/spec/set/all/attribute_tracking_spec.rb +21 -0
  135. data/mod/01_core/spec/set/all/collection_spec.rb +65 -0
  136. data/mod/01_core/spec/set/all/content_spec.rb +15 -0
  137. data/{spec/mod/core → mod/01_core/spec}/set/all/fetch_spec.rb +70 -68
  138. data/{spec/mod/core → mod/01_core/spec}/set/all/initialize_spec.rb +12 -12
  139. data/{spec/mod/core → mod/01_core/spec}/set/all/name_spec.rb +7 -7
  140. data/mod/01_core/spec/set/all/notify_spec.rb +199 -0
  141. data/{spec/mod/core → mod/01_core/spec}/set/all/pattern_spec.rb +16 -16
  142. data/{spec/mod/core → mod/01_core/spec}/set/all/permissions_spec.rb +62 -62
  143. data/{spec/mod/core → mod/01_core/spec}/set/all/phases_spec.rb +0 -0
  144. data/{spec/mod/core → mod/01_core/spec}/set/all/references_spec.rb +1 -1
  145. data/{spec/mod/core → mod/01_core/spec}/set/all/rules2_spec.rb +57 -57
  146. data/mod/01_core/spec/set/all/rules_spec.rb +81 -0
  147. data/{spec/mod/core → mod/01_core/spec}/set/all/states_spec.rb +0 -0
  148. data/{spec/mod/core → mod/01_core/spec}/set/all/templating_spec.rb +16 -12
  149. data/{spec/mod/core → mod/01_core/spec}/set/all/tracked_attributes_spec.rb +24 -22
  150. data/{spec/mod/core → mod/01_core/spec}/set/all/trash_spec.rb +2 -2
  151. data/{spec/mod/core → mod/01_core/spec}/set/all/type_spec.rb +13 -13
  152. data/{spec/mod/core → mod/01_core/spec}/set/all/utils_spec.rb +0 -0
  153. data/mod/{core → 02_basic_types}/set/type/plain_text.rb +0 -0
  154. data/mod/{standard → 02_basic_types}/set/type/pointer.rb +21 -8
  155. data/{spec/mod/standard/set/type → mod/02_basic_types/spec/set}/plain_text_spec.rb +0 -0
  156. data/{spec/mod/standard/set/type → mod/02_basic_types/spec/set}/pointer_spec.rb +22 -9
  157. data/mod/{standard → 03_machines}/lib/card/machine.rb +3 -2
  158. data/mod/{standard → 03_machines}/lib/card/machine_input.rb +1 -1
  159. data/mod/{standard → 03_machines}/lib/javascript/html5shiv-printshiv.js +0 -0
  160. data/mod/{standard → 03_machines}/lib/javascript/jquery-ui.js +0 -0
  161. data/mod/{standard → 03_machines}/lib/javascript/jquery.autosize.js +0 -0
  162. data/mod/{standard → 03_machines}/lib/javascript/jquery.fileupload.js +0 -0
  163. data/mod/{standard → 03_machines}/lib/javascript/jquery.iframe-transport.js +0 -0
  164. data/mod/{standard → 03_machines}/lib/javascript/jquery.js +0 -0
  165. data/mod/{standard → 03_machines}/lib/javascript/jquery.ui.autocomplete.html.js +0 -0
  166. data/mod/{standard → 03_machines}/lib/javascript/jquery_ujs.js +0 -0
  167. data/mod/{standard → 03_machines}/lib/javascript/jquerymobile.js +0 -0
  168. data/mod/{standard → 03_machines}/lib/javascript/tinymce.js +0 -0
  169. data/mod/{standard → 03_machines}/lib/javascript/wagn.js.coffee +17 -9
  170. data/mod/{standard → 03_machines}/lib/javascript/wagn_menu.js +0 -0
  171. data/mod/{standard → 03_machines}/lib/javascript/wagn_mod.js.coffee +1 -1
  172. data/mod/{standard → 03_machines}/lib/stylesheets/functional.scss +1 -1
  173. data/mod/{standard → 03_machines}/lib/stylesheets/jquery-ui-smoothness.css +0 -0
  174. data/mod/{standard → 03_machines}/lib/stylesheets/standard.scss +126 -21
  175. data/mod/{standard → 03_machines}/set/right/machine_output.rb +3 -2
  176. data/mod/{standard → 03_machines}/set/self/script_card_menu.rb +1 -1
  177. data/mod/{standard → 03_machines}/set/self/script_html5shiv_printshiv.rb +1 -1
  178. data/mod/{standard → 03_machines}/set/self/script_jquery.rb +1 -1
  179. data/mod/{standard → 03_machines}/set/self/script_jquery_helper.rb +1 -1
  180. data/mod/{standard → 03_machines}/set/self/script_slot.rb +1 -1
  181. data/mod/{standard → 03_machines}/set/self/script_tinymce.rb +1 -1
  182. data/mod/{standard → 03_machines}/set/self/style_functional.rb +1 -1
  183. data/mod/{standard → 03_machines}/set/self/style_jquery_ui_smoothness.rb +1 -1
  184. data/mod/{standard → 03_machines}/set/self/style_standard.rb +1 -1
  185. data/mod/{standard → 03_machines}/set/type/coffee_script.rb +0 -0
  186. data/mod/{standard → 03_machines}/set/type/css.rb +0 -0
  187. data/mod/{standard → 03_machines}/set/type/java_script.rb +0 -0
  188. data/mod/{standard → 03_machines}/set/type/scss.rb +0 -0
  189. data/mod/{standard → 03_machines}/set/type/skin.rb +0 -0
  190. data/{spec/mod/standard → mod/03_machines/spec}/lib/machine_input_spec.rb +0 -0
  191. data/{spec/mod/standard → mod/03_machines/spec}/lib/machine_spec.rb +4 -4
  192. data/{spec/mod/standard → mod/03_machines/spec}/set/right/machine_output_spec.rb +0 -0
  193. data/{spec/mod/standard → mod/03_machines/spec}/set/self/style_functional_spec.rb +0 -0
  194. data/{spec/mod/standard → mod/03_machines/spec}/set/self/style_jquery_ui_smoothness_spec.rb +0 -0
  195. data/{spec/mod/standard → mod/03_machines/spec}/set/self/style_standard_spec.rb +0 -0
  196. data/{spec/mod/standard → mod/03_machines/spec}/set/type/coffeescript_spec.rb +0 -0
  197. data/{spec/mod/standard → mod/03_machines/spec}/set/type/css_spec.rb +0 -0
  198. data/{spec/mod/standard → mod/03_machines/spec}/set/type/javascript_spec.rb +0 -0
  199. data/{spec/mod/standard → mod/03_machines/spec}/set/type/scss_spec.rb +1 -1
  200. data/{spec/mod/standard → mod/03_machines/spec}/set/type/skin_spec.rb +22 -0
  201. data/mod/04_settings/lib/card/setting.rb +57 -0
  202. data/mod/{core/set/right/structure.rb → 04_settings/set/right/add_help.rb} +0 -2
  203. data/mod/{standard → 04_settings}/set/right/comment.rb +0 -1
  204. data/mod/{standard → 04_settings}/set/right/create.rb +0 -1
  205. data/mod/04_settings/set/right/default.rb +3 -0
  206. data/mod/{standard → 04_settings}/set/right/delete.rb +2 -0
  207. data/mod/04_settings/set/right/help.rb +3 -0
  208. data/mod/{standard → 04_settings}/set/right/read.rb +0 -0
  209. data/mod/{standard → 04_settings}/set/right/script.rb +0 -0
  210. data/mod/04_settings/set/right/structure.rb +4 -0
  211. data/mod/{standard → 04_settings}/set/right/style.rb +0 -0
  212. data/mod/{standard → 04_settings}/set/right/update.rb +0 -0
  213. data/mod/04_settings/set/self/accountable.rb +2 -0
  214. data/mod/04_settings/set/self/add_help.rb +2 -0
  215. data/mod/04_settings/set/self/autoname.rb +2 -0
  216. data/mod/04_settings/set/self/captcha.rb +2 -0
  217. data/mod/04_settings/set/self/comment.rb +2 -0
  218. data/mod/04_settings/set/self/create.rb +2 -0
  219. data/mod/04_settings/set/self/default.rb +2 -0
  220. data/mod/04_settings/set/self/delete.rb +2 -0
  221. data/mod/04_settings/set/self/help.rb +2 -0
  222. data/mod/04_settings/set/self/input.rb +2 -0
  223. data/mod/04_settings/set/self/layout.rb +2 -0
  224. data/mod/04_settings/set/self/on_create.rb +2 -0
  225. data/mod/04_settings/set/self/on_delete.rb +2 -0
  226. data/mod/04_settings/set/self/on_update.rb +2 -0
  227. data/mod/04_settings/set/self/options.rb +2 -0
  228. data/mod/04_settings/set/self/options_label.rb +2 -0
  229. data/mod/04_settings/set/self/read.rb +2 -0
  230. data/mod/04_settings/set/self/script.rb +2 -0
  231. data/mod/04_settings/set/self/structure.rb +2 -0
  232. data/mod/04_settings/set/self/style.rb +2 -0
  233. data/mod/04_settings/set/self/table_of_contents.rb +2 -0
  234. data/mod/04_settings/set/self/thanks.rb +2 -0
  235. data/mod/04_settings/set/self/update.rb +2 -0
  236. data/mod/{standard → 04_settings}/set/type/setting.rb +8 -14
  237. data/{spec/mod/standard → mod/04_settings/spec}/set/right/add_help_spec.rb +0 -0
  238. data/{spec/mod/standard → mod/04_settings/spec}/set/right/comment_spec.rb +5 -5
  239. data/{spec/mod/standard → mod/04_settings/spec}/set/right/create_spec.rb +0 -0
  240. data/{spec/mod/standard → mod/04_settings/spec}/set/right/default_spec.rb +0 -0
  241. data/{spec/mod/standard → mod/04_settings/spec}/set/right/delete_spec.rb +0 -0
  242. data/{spec/mod/standard → mod/04_settings/spec}/set/right/help_spec.rb +0 -0
  243. data/{spec/mod/standard → mod/04_settings/spec}/set/right/read_spec.rb +0 -0
  244. data/{spec/mod/standard → mod/04_settings/spec}/set/right/script_spec.rb +0 -0
  245. data/{spec/mod/standard → mod/04_settings/spec}/set/right/structure_spec.rb +4 -2
  246. data/{spec/mod/standard → mod/04_settings/spec}/set/right/style_spec.rb +1 -1
  247. data/{spec/mod/standard → mod/04_settings/spec}/set/right/update_spec.rb +0 -0
  248. data/{spec/mod/standard → mod/04_settings/spec}/set/type/setting_spec.rb +0 -0
  249. data/mod/{standard → 05_standard}/file/103/icon-6566.ico +0 -0
  250. data/mod/{standard → 05_standard}/file/103/large-6566.ico +0 -0
  251. data/mod/{standard → 05_standard}/file/103/medium-6566.ico +0 -0
  252. data/mod/{standard → 05_standard}/file/103/original-6566.ico +0 -0
  253. data/mod/{standard → 05_standard}/file/103/small-6566.ico +0 -0
  254. data/mod/{standard → 05_standard}/file/79/icon-6556.png +0 -0
  255. data/mod/{standard → 05_standard}/file/79/large-6556.png +0 -0
  256. data/mod/{standard → 05_standard}/file/79/medium-6556.png +0 -0
  257. data/mod/{standard → 05_standard}/file/79/original-6556.png +0 -0
  258. data/mod/{standard → 05_standard}/file/79/small-6556.png +0 -0
  259. data/mod/{standard → 05_standard}/file/790/icon-6419.png +0 -0
  260. data/mod/{standard → 05_standard}/file/790/large-6419.png +0 -0
  261. data/mod/{standard → 05_standard}/file/790/medium-6419.png +0 -0
  262. data/mod/{standard → 05_standard}/file/790/original-6419.png +0 -0
  263. data/mod/{standard → 05_standard}/file/790/small-6419.png +0 -0
  264. data/mod/{standard → 05_standard}/format/css_format.rb +0 -0
  265. data/mod/{standard → 05_standard}/format/csv_format.rb +0 -0
  266. data/mod/{standard → 05_standard}/format/file_format.rb +0 -0
  267. data/mod/{standard → 05_standard}/format/js_format.rb +0 -0
  268. data/mod/{standard → 05_standard}/format/json_format.rb +0 -0
  269. data/mod/{standard → 05_standard}/format/rss_format.rb +0 -0
  270. data/mod/{standard → 05_standard}/format/xml_format.rb +0 -0
  271. data/mod/{standard → 05_standard}/set/all/account.rb +0 -0
  272. data/mod/{standard → 05_standard}/set/all/all_css.rb +0 -0
  273. data/mod/{standard → 05_standard}/set/all/all_csv.rb +1 -1
  274. data/mod/05_standard/set/all/all_js.rb +7 -0
  275. data/mod/{standard → 05_standard}/set/all/attach.rb +33 -33
  276. data/mod/{standard → 05_standard}/set/all/base.rb +0 -0
  277. data/mod/{standard → 05_standard}/set/all/comment.rb +0 -0
  278. data/mod/{standard → 05_standard}/set/all/event_viz.rb +0 -0
  279. data/mod/{standard → 05_standard}/set/all/file.rb +0 -0
  280. data/mod/05_standard/set/all/follow.rb +51 -0
  281. data/mod/05_standard/set/all/history.rb +294 -0
  282. data/mod/{standard → 05_standard}/set/all/json.rb +2 -1
  283. data/mod/05_standard/set/all/observer.rb +27 -0
  284. data/mod/{standard → 05_standard}/set/all/rich_html.rb +21 -28
  285. data/mod/{standard → 05_standard}/set/all/rss.rb +0 -0
  286. data/mod/{standard → 05_standard}/set/all/text.rb +0 -0
  287. data/mod/{standard → 05_standard}/set/right/account.rb +53 -7
  288. data/mod/{standard → 05_standard}/set/right/email.rb +0 -1
  289. data/mod/{standard → 05_standard}/set/right/password.rb +1 -1
  290. data/mod/{standard → 05_standard}/set/right/salt.rb +0 -0
  291. data/mod/{standard → 05_standard}/set/right/stats.rb +1 -1
  292. data/mod/{standard → 05_standard}/set/right/status.rb +0 -0
  293. data/mod/{standard → 05_standard}/set/right/token.rb +0 -0
  294. data/mod/{standard → 05_standard}/set/right/when_created.rb +0 -0
  295. data/mod/{standard → 05_standard}/set/right/when_last_edited.rb +0 -0
  296. data/mod/{standard → 05_standard}/set/rstar/rules.rb +8 -7
  297. data/mod/{standard → 05_standard}/set/self/account_links.rb +0 -0
  298. data/mod/{standard → 05_standard}/set/self/alerts.rb +0 -0
  299. data/mod/{standard → 05_standard}/set/self/all.rb +1 -1
  300. data/mod/{standard → 05_standard}/set/self/foot.rb +0 -0
  301. data/mod/{standard → 05_standard}/set/self/head.rb +21 -6
  302. data/mod/{standard → 05_standard}/set/self/navbox.rb +0 -0
  303. data/mod/{standard → 05_standard}/set/self/now.rb +0 -0
  304. data/mod/{standard → 05_standard}/set/self/recent.rb +0 -0
  305. data/mod/{standard → 05_standard}/set/self/search.rb +0 -0
  306. data/mod/{standard → 05_standard}/set/self/signin.rb +1 -1
  307. data/mod/{standard → 05_standard}/set/self/stats.rb +2 -2
  308. data/mod/{standard → 05_standard}/set/self/version.rb +0 -0
  309. data/mod/{standard → 05_standard}/set/type/basic.rb +0 -0
  310. data/mod/{standard → 05_standard}/set/type/cardtype.rb +4 -6
  311. data/mod/{standard → 05_standard}/set/type/date.rb +0 -0
  312. data/mod/{standard → 05_standard}/set/type/file.rb +0 -0
  313. data/mod/{standard → 05_standard}/set/type/html.rb +0 -0
  314. data/mod/{standard → 05_standard}/set/type/image.rb +7 -6
  315. data/mod/{standard → 05_standard}/set/type/layout_type.rb +0 -0
  316. data/mod/{standard → 05_standard}/set/type/number.rb +0 -0
  317. data/mod/{standard → 05_standard}/set/type/phrase.rb +0 -0
  318. data/mod/{standard → 05_standard}/set/type/search_type.rb +6 -3
  319. data/mod/{standard → 05_standard}/set/type/set.rb +16 -9
  320. data/mod/{standard → 05_standard}/set/type/signup.rb +16 -17
  321. data/mod/{standard → 05_standard}/set/type/toggle.rb +0 -0
  322. data/mod/{standard → 05_standard}/set/type/user.rb +10 -11
  323. data/{spec/mod/standard → mod/05_standard/spec}/chunk/include_spec.rb +39 -39
  324. data/mod/05_standard/spec/chunk/link_spec.rb +61 -0
  325. data/{spec/mod/standard → mod/05_standard/spec}/format/css_format_spec.rb +0 -0
  326. data/{spec/mod/standard → mod/05_standard/spec}/format/csv_format_spec.rb +0 -0
  327. data/{spec/mod/standard → mod/05_standard/spec}/format/email_html_format_spec.rb +0 -0
  328. data/{spec/mod/standard → mod/05_standard/spec}/format/file_format_spec.rb +0 -0
  329. data/{spec/mod/standard → mod/05_standard/spec}/format/js_format_spec.rb +0 -0
  330. data/{spec/mod/standard → mod/05_standard/spec}/format/json_format_spec.rb +0 -0
  331. data/{spec/mod/standard → mod/05_standard/spec}/format/rss_format_spec.rb +0 -0
  332. data/{spec/mod/standard → mod/05_standard/spec}/format/xml_format_spec.rb +0 -0
  333. data/{spec/mod/standard → mod/05_standard/spec}/set/all/account_spec.rb +16 -16
  334. data/{spec/mod/standard → mod/05_standard/spec}/set/all/all_css_spec.rb +1 -1
  335. data/{spec/mod/standard → mod/05_standard/spec}/set/all/all_csv_spec.rb +1 -1
  336. data/{spec/mod/standard → mod/05_standard/spec}/set/all/attach_spec.rb +1 -1
  337. data/{spec/mod/standard → mod/05_standard/spec}/set/all/base_spec.rb +10 -10
  338. data/{spec/mod/standard → mod/05_standard/spec}/set/all/comment_spec.rb +0 -0
  339. data/mod/05_standard/spec/set/all/email_html_spec.rb +15 -0
  340. data/{spec/mod/standard → mod/05_standard/spec}/set/all/event_viz_spec.rb +1 -1
  341. data/{spec/mod/standard → mod/05_standard/spec}/set/all/file_spec.rb +0 -0
  342. data/mod/05_standard/spec/set/all/follow_spec.rb +83 -0
  343. data/mod/05_standard/spec/set/all/history_spec.rb +161 -0
  344. data/{spec/mod/standard → mod/05_standard/spec}/set/all/json_spec.rb +4 -4
  345. data/mod/05_standard/spec/set/all/observer_spec.rb +74 -0
  346. data/{spec/mod/standard → mod/05_standard/spec}/set/all/rich_html_spec.rb +14 -14
  347. data/{spec/mod/standard → mod/05_standard/spec}/set/all/rss_spec.rb +1 -1
  348. data/{spec/mod/standard → mod/05_standard/spec}/set/all/text_spec.rb +0 -0
  349. data/mod/05_standard/spec/set/right/account_spec.rb +162 -0
  350. data/{spec/mod/standard → mod/05_standard/spec}/set/right/email_spec.rb +7 -7
  351. data/{spec/mod/standard → mod/05_standard/spec}/set/right/password_spec.rb +7 -7
  352. data/{spec/mod/standard → mod/05_standard/spec}/set/right/salt_spec.rb +0 -0
  353. data/{spec/mod/standard → mod/05_standard/spec}/set/right/stats_spec.rb +0 -0
  354. data/{spec/mod/standard → mod/05_standard/spec}/set/right/status_spec.rb +0 -0
  355. data/{spec/mod/standard → mod/05_standard/spec}/set/right/token_spec.rb +0 -0
  356. data/{spec/mod/standard → mod/05_standard/spec}/set/right/when_created_spec.rb +1 -1
  357. data/{spec/mod/standard → mod/05_standard/spec}/set/right/when_last_edited_spec.rb +1 -1
  358. data/{spec/mod/standard → mod/05_standard/spec}/set/rstar/rules_spec.rb +4 -4
  359. data/{spec/mod/standard → mod/05_standard/spec}/set/self/account_links_spec.rb +0 -0
  360. data/{spec/mod/standard → mod/05_standard/spec}/set/self/alerts_spec.rb +0 -0
  361. data/{spec/mod/standard → mod/05_standard/spec}/set/self/all_spec.rb +7 -6
  362. data/{spec/mod/standard → mod/05_standard/spec}/set/self/foot_spec.rb +0 -0
  363. data/{spec/mod/standard → mod/05_standard/spec}/set/self/head_spec.rb +0 -0
  364. data/{spec/mod/standard → mod/05_standard/spec}/set/self/navbox_spec.rb +0 -0
  365. data/{spec/mod/standard → mod/05_standard/spec}/set/self/now_spec.rb +1 -1
  366. data/{spec/mod/standard → mod/05_standard/spec}/set/self/recent_spec.rb +0 -0
  367. data/{spec/mod/standard → mod/05_standard/spec}/set/self/search_spec.rb +0 -0
  368. data/{spec/mod/standard → mod/05_standard/spec}/set/self/signin_spec.rb +12 -12
  369. data/{spec/mod/standard → mod/05_standard/spec}/set/self/stats_spec.rb +0 -0
  370. data/{spec/mod/standard → mod/05_standard/spec}/set/self/version_spec.rb +1 -1
  371. data/{spec/mod/standard → mod/05_standard/spec}/set/type/basic_spec.rb +0 -0
  372. data/{spec/mod/standard → mod/05_standard/spec}/set/type/cardtype_spec.rb +0 -0
  373. data/{spec/mod/standard → mod/05_standard/spec}/set/type/date_spec.rb +0 -0
  374. data/mod/05_standard/spec/set/type/email_template_spec.rb +130 -0
  375. data/{spec/mod/standard → mod/05_standard/spec}/set/type/file_spec.rb +0 -0
  376. data/{spec/mod/standard → mod/05_standard/spec}/set/type/html_spec.rb +3 -3
  377. data/{spec/mod/standard → mod/05_standard/spec}/set/type/image_spec.rb +1 -1
  378. data/{spec/mod/standard → mod/05_standard/spec}/set/type/layout_type_spec.rb +1 -1
  379. data/{spec/mod/standard → mod/05_standard/spec}/set/type/number_spec.rb +0 -0
  380. data/{spec/mod/standard → mod/05_standard/spec}/set/type/phrase_spec.rb +0 -0
  381. data/mod/05_standard/spec/set/type/search_type_spec.rb +27 -0
  382. data/mod/05_standard/spec/set/type/set_spec.rb +26 -0
  383. data/mod/05_standard/spec/set/type/signup_spec.rb +209 -0
  384. data/{spec/mod/standard → mod/05_standard/spec}/set/type/toggle_spec.rb +2 -2
  385. data/{spec/mod/standard → mod/05_standard/spec}/set/type/user_spec.rb +0 -0
  386. data/mod/{standard → 06_email}/format/email_html_format.rb +0 -0
  387. data/mod/06_email/format/email_text_format.rb +7 -0
  388. data/mod/06_email/set/all/email_html.rb +9 -0
  389. data/mod/{standard/set/all/email_html.rb → 06_email/set/all/email_text.rb} +2 -1
  390. data/mod/06_email/set/right/bcc.rb +31 -0
  391. data/mod/06_email/set/right/cc.rb +2 -0
  392. data/mod/06_email/set/right/from.rb +2 -0
  393. data/mod/06_email/set/right/html_message.rb +3 -0
  394. data/mod/06_email/set/right/to.rb +2 -0
  395. data/mod/06_email/set/type/email_template.rb +99 -0
  396. data/spec/controllers/card_controller_spec.rb +34 -46
  397. data/spec/lib/card/action_spec.rb +14 -0
  398. data/spec/lib/card/chunk_spec.rb +3 -3
  399. data/spec/lib/card/codename_spec.rb +5 -5
  400. data/spec/lib/card/content_spec.rb +25 -25
  401. data/spec/lib/card/diff_spec.rb +107 -107
  402. data/spec/lib/card/format_spec.rb +11 -11
  403. data/spec/lib/card/loader_spec.rb +35 -29
  404. data/spec/lib/card/name_spec.rb +82 -82
  405. data/spec/lib/card/query_spec.rb +83 -82
  406. data/spec/lib/card/reference_spec.rb +30 -30
  407. data/spec/lib/card/set_pattern_spec.rb +1 -1
  408. data/spec/lib/card/set_spec.rb +86 -82
  409. data/spec/lib/wagn/cache_spec.rb +24 -24
  410. data/spec/mailers/mailer_spec.rb +41 -30
  411. data/spec/models/card/cardtype_spec.rb +19 -19
  412. data/spec/models/card/create_spec.rb +14 -14
  413. data/spec/models/card/trash_spec.rb +37 -36
  414. data/spec/models/card/type_transition_spec.rb +13 -13
  415. data/spec/models/card/validation_spec.rb +6 -6
  416. data/spec/models/card_spec.rb +40 -39
  417. data/spec/spec_helper.rb +37 -11
  418. data/test/fixtures/card_actions.yml +4726 -0
  419. data/test/fixtures/card_acts.yml +589 -0
  420. data/test/fixtures/card_changes.yml +12644 -0
  421. data/test/fixtures/card_references.yml +976 -591
  422. data/test/fixtures/cards.yml +4544 -2781
  423. data/test/seed.rb +14 -13
  424. data/wagn.gemspec +4 -0
  425. metadata +404 -403
  426. data/db/bootstrap/card_revisions.yml +0 -3379
  427. data/lib/card/flexmail.rb +0 -53
  428. data/lib/card/mailer/change_notice.html.erb +0 -32
  429. data/lib/card/mailer/confirmation_email.html.erb +0 -12
  430. data/lib/card/mailer/flexmail.html.erb +0 -6
  431. data/lib/card/mailer/password_reset.html.erb +0 -9
  432. data/lib/card/mailer/signup_alert.html.erb +0 -14
  433. data/lib/card/revision.rb +0 -47
  434. data/lib/wagn/migration_helper.rb +0 -34
  435. data/mod/core/set/all/attribute_tracking.rb +0 -85
  436. data/mod/core/set/all/content.rb +0 -94
  437. data/mod/standard/set/all/flexmail.rb +0 -3
  438. data/mod/standard/set/all/follow.rb +0 -119
  439. data/mod/standard/set/all/history.rb +0 -107
  440. data/mod/standard/set/right/add_help.rb +0 -3
  441. data/mod/standard/set/right/default.rb +0 -3
  442. data/mod/standard/set/right/help.rb +0 -3
  443. data/spec/lib/card/flexmail_spec.rb +0 -209
  444. data/spec/lib/card/revision_spec.rb +0 -30
  445. data/spec/mod/core/chunk/literal_spec.rb +0 -14
  446. data/spec/mod/core/set/all/attribute_tracking_spec.rb +0 -21
  447. data/spec/mod/core/set/all/collection_spec.rb +0 -45
  448. data/spec/mod/core/set/all/content_spec.rb +0 -14
  449. data/spec/mod/core/set/all/rules_spec.rb +0 -98
  450. data/spec/mod/standard/chunk/link_spec.rb +0 -59
  451. data/spec/mod/standard/set/all/email_html_spec.rb +0 -13
  452. data/spec/mod/standard/set/all/flexmail_spec.rb +0 -5
  453. data/spec/mod/standard/set/all/follow_spec.rb +0 -95
  454. data/spec/mod/standard/set/all/history_spec.rb +0 -10
  455. data/spec/mod/standard/set/right/account_spec.rb +0 -90
  456. data/spec/mod/standard/set/type/search_type_spec.rb +0 -27
  457. data/spec/mod/standard/set/type/set_spec.rb +0 -26
  458. data/spec/mod/standard/set/type/signup_spec.rb +0 -169
  459. data/test/fixtures/card_revisions.yml +0 -4560
@@ -1,9 +1,9 @@
1
1
  Feature: Updates for Children of watched cards
2
2
  In order to keep track of changes that are important to me
3
3
  As an Editor
4
- I want to be notified when someone changes a child of a card I'm watching
4
+ I want to be notified when someone changes a child of a card I'm watching #'
5
5
 
6
- #should this be in watch?
6
+ #should this be in watch?
7
7
 
8
8
  Background:
9
9
  Given I am signed in as Joe User
@@ -13,11 +13,11 @@ Feature: Updates for Children of watched cards
13
13
 
14
14
  Scenario: Watcher should be notified of updates to included plus card
15
15
  When I create card "Ulysses+author" with content "James Joyce"
16
- Then Joe Camel should be notified that "Joe User updated \"Ulysses\""
17
16
  #And He should see "added Ulysses+author" in the email -- FIXME need multiline matching
18
- And Joe Admin should be notified that "Joe User updated \"Ulysses\""
19
- When Joe Admin edits "Ulysses+author" setting content to "Jim"
20
- Then Joe Camel should be notified that "Joe Admin updated \"Ulysses\""
17
+ Then Joe Admin should be notified that "Joe User created \"Ulysses\+author\""
18
+ And Joe Camel should be notified that "Joe User created \"Ulysses\+author\""
19
+ When Joe Admin edits "Ulysses\+author" setting content to "Jim"
20
+ Then Joe Camel should be notified that "Joe Admin updated \"Ulysses\+author\""
21
21
  #And Joe Admin should be notified that "Joe User updated \"Ulysses\""
22
22
 
23
23
  Scenario: Should not notify of included but not plussed card
@@ -50,19 +50,25 @@ Feature: Updates for Children of watched cards
50
50
  When I edit "Banana" with plusses:
51
51
  |color|flavor|
52
52
  |spotted|mushy|
53
- Then Joe Camel should be notified that "Joe User updated \"Banana\+color\""
53
+ Then Joe Camel should be notified that "Joe User updated \"Banana\""
54
54
  When Joe Camel is watching "Banana"
55
55
  And I wait a sec
56
56
  And I edit "Banana" with plusses:
57
57
  |color|flavor|
58
- |spotted|mushy|
58
+ |green|mushy|
59
59
  Then Joe Camel should be notified that "Joe User updated \"Banana\""
60
+ Given a clear email queue
61
+ And I edit "Banana" with plusses:
62
+ |color|flavor|
63
+ |green|mushy|
64
+ Then No notification should be sent
65
+
60
66
 
61
67
  Scenario: Watching a plus card & including card on regular edit
62
68
  When I create card "Ulysses+author" with content "Joyce"
63
- Then Joe Camel should be notified that "Joe User updated \"Ulysses\""
69
+ Then Joe Camel should be notified that "Joe User created \"Ulysses\+author\""
64
70
  When Joe Camel is watching "Ulysses+author"
65
71
  And I edit "Ulysses+author" setting content to "Jim"
66
- Then Joe Camel should be notified that "Joe User updated \"Ulysses\""
72
+ Then Joe Camel should be notified that "Joe User updated \"Ulysses\+author\""
67
73
 
68
74
 
@@ -20,7 +20,7 @@ Feature: Watch interface
20
20
  Then In the main card menu I should see "following|unfollow"
21
21
  # assumes focus still on that link. otherwise "following"
22
22
  # selenium behavior not totally consistent here.
23
- And the card Home+*watchers should contain "Joe User"
23
+ And the card Joe User+*following should contain "Home"
24
24
 
25
25
  Scenario: Unwatching a Card
26
26
  Given Joe User is watching "Home"
@@ -29,7 +29,7 @@ Feature: Watch interface
29
29
  And In the main card menu I click "following"
30
30
  #note: turns to "unfollow on mouseover"
31
31
  Then In the main card menu I should see "follow"
32
- And the card Home+*watchers should not contain "Joe User"
32
+ And the card Joe User+*following should not contain "Home"
33
33
 
34
34
  Scenario: Watching a Cardtype
35
35
  When I go to card User
@@ -1,7 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  class Card < ActiveRecord::Base
4
-
4
+
5
5
  require_dependency 'card/active_record_ext'
6
6
  require_dependency 'card/codename'
7
7
  require_dependency 'card/query'
@@ -12,29 +12,30 @@ class Card < ActiveRecord::Base
12
12
  require_dependency 'card/auth'
13
13
  require_dependency 'card/loader'
14
14
 
15
- has_many :revisions, :order => :id
16
15
  has_many :references_from, :class_name => :Reference, :foreign_key => :referee_id
17
16
  has_many :references_to, :class_name => :Reference, :foreign_key => :referer_id
17
+ has_many :acts, :order => :id
18
+ has_many :actions, :order => :id, :conditions=>{:draft => [nil,false]}
19
+ has_many :drafts, :order=>:id, :conditions=>{:draft=>true}, :class_name=> :Action
18
20
 
19
21
  cache_attributes 'name', 'type_id' # review - still worth it in Rails 3?
20
22
 
21
23
  cattr_accessor :set_patterns, :error_codes
22
24
  @@set_patterns, @@error_codes = [], {}
23
25
 
24
- attr_writer :selected_revision_id #writer because read method is in mod (and does not override upon load)
25
- attr_accessor :action, :supercard,
26
+ attr_accessor :action, :supercard, :current_act, :current_action,
26
27
  :comment, :comment_author, # obviated soon
27
- :update_referencers # wrong mechanism for this
28
-
28
+ :update_referencers, # wrong mechanism for this
29
+ :follower_stash,
30
+ :last_action_id_before_edit
31
+
29
32
  define_callbacks :approve, :store, :extend
30
33
 
31
34
  before_validation :approve
32
35
  around_save :store
33
36
  after_save :extend
34
-
37
+
38
+ TRACKED_FIELDS = %w(name type_id db_content trash)
35
39
  Loader.load_mods if count > 0
36
-
37
- tracks :content # we can phase this out and just use "dirty" handling once current content is stored in the cards table
38
40
 
39
41
  end
40
-
@@ -0,0 +1,63 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Card
3
+ class Act < ActiveRecord::Base
4
+ before_save :set_actor
5
+ has_many :actions, :foreign_key=>:card_act_id, :inverse_of=> :act, :order => :id, :class_name=> "Card::Action"
6
+ belongs_to :actor, class_name: "Card"
7
+ belongs_to :card
8
+ def set_actor
9
+ self.actor_id ||= Auth.current_id
10
+ end
11
+
12
+ def self.delete_actionless
13
+ Card::Act.where(
14
+ "id NOT IN (?)",
15
+ Card::Action.pluck("card_act_id"),
16
+ ).delete_all
17
+ end
18
+
19
+ def self.find_all_with_actions_on card_ids, args={}
20
+ sql = if args[:with_drafts]
21
+ 'card_actions.card_id IN (:card_ids) AND ( (draft = 0 OR draft IS null) OR actor_id = :current_user_id)'
22
+ else
23
+ 'card_actions.card_id IN (:card_ids) AND ( (draft = 0 OR draft IS null) )'
24
+ end
25
+ Card::Act.joins(:actions).where(sql,
26
+ {:card_ids => card_ids, :current_user_id=>Card::Auth.current_id }).uniq.order(:id).reverse_order
27
+ end
28
+
29
+ # def actor
30
+ # Card[ actor_id ]
31
+ # end
32
+
33
+ # def card
34
+ # Card[ card_id ]
35
+ # end
36
+
37
+ def action_on card_id
38
+ actions.find_by_card_id(card_id)
39
+ end
40
+
41
+ def elapsed_time
42
+ DateTime.new(acted_at).distance_of_time_in_words_to_now
43
+ end
44
+
45
+ def relevant_drafts_for card
46
+ drafts.select do |action|
47
+ card.included_card_ids.include?(action.card_id) || (card == action.card)
48
+ end
49
+ end
50
+
51
+ def relevant_actions_for card, with_drafts=false
52
+ actions.select do |action|
53
+ card.included_card_ids.include?(action.card_id) || (card == action.card)
54
+ end
55
+ end
56
+
57
+ private
58
+ def timestamp_attributes_for_create
59
+ super << :acted_at
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,194 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Card
3
+
4
+ #fixme - these Card class methods should probably be in a set module
5
+ def find_action_by_params args
6
+ case
7
+ when args[:rev]
8
+ nth_action(args[:rev].to_i-1)
9
+ when args[:rev_id]
10
+ if action = Action.fetch(args[:rev_id]) and action.card_id == id
11
+ action
12
+ end
13
+ end
14
+ end
15
+
16
+ def nth_action index
17
+ Action.where("(draft IS NULL OR draft = :draft) AND card_id = ':id'", {:draft=>false, :id=>id})[index-1]
18
+ end
19
+
20
+ def revision action
21
+ # a "revision" refers to the state of all tracked fields at the time of a given action
22
+ if action.is_a? Integer
23
+ action = Card::Action.fetch(action)
24
+ end
25
+ action and Card::TRACKED_FIELDS.inject({}) do |attr_changes, field|
26
+ last_change = action.changes.find_by_field(field) || last_change_on(field, :not_after=>action)
27
+ attr_changes[field.to_sym] = (last_change ? last_change.value : self[field])
28
+ attr_changes
29
+ end
30
+ end
31
+
32
+ def delete_old_actions
33
+ Card::TRACKED_FIELDS.each do |field|
34
+ # assign previous changes on each tracked field to the last action
35
+ if (not last_action.change_for(field).present?) and (last_change = last_change_on(field))
36
+ last_change = Card::Change.find(last_change.id) # last_change comes as readonly record
37
+ last_change.update_attributes!(:card_action_id=>last_action_id)
38
+ end
39
+ end
40
+ actions.where('id != ?', last_action_id ).delete_all
41
+ end
42
+
43
+
44
+ class Action < ActiveRecord::Base
45
+ belongs_to :card
46
+ belongs_to :act, :foreign_key=>:card_act_id, :inverse_of=>:actions
47
+ has_many :changes, :foreign_key=>:card_action_id, :inverse_of=>:action, :dependent=>:delete_all
48
+
49
+ belongs_to :super_action, class_name: "Action", :inverse_of=>:sub_actions
50
+ has_many :sub_actions, class_name: "Action", :inverse_of=>:super_action
51
+
52
+ scope :created_by, lambda { |actor_id| joins(:act).where('card_acts.actor_id = ?', actor_id) }
53
+
54
+ # replace with enum if we start using rails 4
55
+ TYPE = [:create, :update, :delete]
56
+
57
+ class << self
58
+ def cache
59
+ Wagn::Cache[Action]
60
+ end
61
+
62
+ def fetch id
63
+ cache.read(id.to_s) or begin
64
+ cache.write id.to_s, Action.find(id.to_i)
65
+ end
66
+ end
67
+
68
+
69
+ def delete_cardless
70
+ Card::Action.where( Card.where( :id=>arel_table[:card_id] ).exists.not ).delete_all
71
+ end
72
+
73
+ def delete_old
74
+ Card.find_each do |card|
75
+ card.delete_old_actions
76
+ end
77
+ Card::Act.delete_actionless
78
+ end
79
+ end
80
+
81
+ def edit_info
82
+ @edit_info ||= {
83
+ :action_type => "#{action_type}d",
84
+ :new_content => new_values[:content],
85
+ :new_name => new_values[:name],
86
+ :new_cardtype => new_values[:cardtype],
87
+ :old_content => old_values[:content],
88
+ :old_name => old_values[:name],
89
+ :old_cardtype => old_values[:cardtype]
90
+ }
91
+ end
92
+
93
+ def new_values
94
+ @new_values ||= {
95
+ :content => new_value_for(:db_content),
96
+ :name => new_value_for(:name),
97
+ :cardtype => ( typecard = Card[new_value_for(:type_id).to_i] and typecard.name.capitalize )
98
+ }
99
+ end
100
+
101
+ def old_values
102
+ @old_values ||= {
103
+ :content => last_value_for(:db_content),
104
+ :name => last_value_for(:name),
105
+ :cardtype => ( value = last_value_for(:type_id) and
106
+ typecard = Card.find(value) and typecard.name.capitalize )
107
+ }
108
+ end
109
+
110
+ def last_value_for field
111
+ ch = self.card.last_change_on(field, :before=>self) and ch.value
112
+ end
113
+
114
+ def new_value_for(field)
115
+ ch = changes.find_by_field(field) and ch.value
116
+ end
117
+ def change_for(field)
118
+ changes.where('card_changes.field = ?', field)
119
+ end
120
+
121
+
122
+ def new_type?
123
+ new_value_for(:type_id)
124
+ end
125
+ def new_content?
126
+ new_value_for(:db_content)
127
+ end
128
+ def new_name?
129
+ new_value_for(:name)
130
+ end
131
+
132
+
133
+ def action_type=(value)
134
+ write_attribute(:action_type, TYPE.index(value))
135
+ end
136
+
137
+ def action_type
138
+ TYPE[read_attribute(:action_type)]
139
+ end
140
+
141
+ def set_act
142
+ self.set_act ||= self.acts.last
143
+ end
144
+
145
+ def revision_nr
146
+ self.card.actions.index_of(self)
147
+ end
148
+
149
+ def red?
150
+ content_diff_builder.red?
151
+ end
152
+
153
+ def green?
154
+ content_diff_builder.green?
155
+ end
156
+
157
+
158
+ # def diff
159
+ # @diff ||= { :cardtype=>type_diff, :content=>content_diff, :name=>name_diff}
160
+ # end
161
+
162
+
163
+ def name_diff
164
+ if new_name?
165
+ Card::Diff::DiffBuilder.new(old_values[:name],new_values[:name]).complete
166
+ end
167
+ end
168
+
169
+ def cardtype_diff
170
+ if new_type?
171
+ Card::Diff::DiffBuilder.new(old_values[:cardtype],new_values[:cardtype]).complete
172
+ end
173
+ end
174
+
175
+ def content_diff diff_type=:expanded
176
+ if new_content?
177
+ if diff_type == :summary
178
+ content_diff_builder.summary
179
+ else
180
+ content_diff_builder.complete
181
+ end
182
+ end
183
+ end
184
+
185
+ def content_diff_builder
186
+ @content_diff_builder ||= begin
187
+ Card::Diff::DiffBuilder.new(old_values[:content], new_values[:content], :compare_html=>false)
188
+ end
189
+ end
190
+
191
+ end
192
+ end
193
+
194
+
@@ -0,0 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Card
3
+ class Change < ActiveRecord::Base
4
+ belongs_to :action, :foreign_key=>:card_action_id, :inverse_of=>:changes
5
+
6
+ # replace with enum if we start using rails 4
7
+ def field=(value)
8
+ write_attribute(:field, Card::TRACKED_FIELDS.index(value.to_s))
9
+ end
10
+
11
+ def field
12
+ Card::TRACKED_FIELDS[read_attribute(:field)]
13
+ end
14
+
15
+ def self.delete_actionless
16
+ Card::Change.where(
17
+ "card_action_id NOT IN (?)",
18
+ Card::Action.pluck("id"),
19
+ ).delete_all
20
+ end
21
+
22
+ def self.find_by_field(value)
23
+ index = value.is_a?(Integer) ? value : Card::TRACKED_FIELDS.index(value.to_s)
24
+ super(index)
25
+ end
26
+ end
27
+ end
28
+
29
+
@@ -16,7 +16,7 @@ class Card
16
16
  @opts = opts || {}
17
17
 
18
18
  unless Array === content
19
- content = parse_content content
19
+ content = parse_content content
20
20
  end
21
21
  super content
22
22
  end
@@ -1,317 +1,270 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Card::Diff
3
3
 
4
- def diff(a, b)
5
- DiffBuilder.new(a, b).build
4
+ def diff_complete(a, b)
5
+ DiffBuilder.new(a, b).complete
6
6
  end
7
-
8
-
9
- Match = Struct.new(:start_in_old, :start_in_new, :size)
10
- class Match
11
- def end_in_old
12
- self.start_in_old + self.size
13
- end
14
-
15
- def end_in_new
16
- self.start_in_new + self.size
17
- end
7
+
8
+ def diff_summary(a, b)
9
+ DiffBuilder.new(a, b).summary
10
+ end
11
+
12
+ def self.render_added_chunk text
13
+ "<ins class='diffins diff-green'>#{text}</ins>"
14
+ end
15
+
16
+ def self.render_deleted_chunk text, count=true
17
+ "<del class='diffdel diff-red'>#{text}</del>"
18
18
  end
19
-
20
- Operation = Struct.new(:action, :start_in_old, :end_in_old, :start_in_new, :end_in_new)
21
19
 
22
20
  class DiffBuilder
23
-
24
- def initialize(old_version, new_version)
21
+ def initialize(old_version, new_version, opts={})
25
22
  @old_version, @new_version = old_version, new_version
26
- @content = []
23
+ @opts = opts
24
+ @new_version ||= ''
25
+ if !opts[:compare_html]
26
+ @old_version.gsub! /<[^>]*>/,'' if @old_version
27
+ @new_version.gsub! /<[^>]*>/,''
28
+ else
29
+ @old_version = CGI::escapeHTML(@old_version) if @old_version
30
+ @new_version = CGI::escapeHTML(@new_version)
31
+ end
32
+ @summary = false
33
+ @complete = false
34
+ @adds = 0
35
+ @dels = 0
27
36
  end
28
37
 
29
- def build
30
- split_inputs_to_words
31
- index_new_words
32
- operations.each { |op| perform_operation(op) }
33
- return @content.join
38
+
39
+ def red?
40
+ complete and @dels > 0
34
41
  end
35
-
36
- def split_inputs_to_words
37
- @old_words = convert_html_to_list_of_words(explode(@old_version))
38
- @new_words = convert_html_to_list_of_words(explode(@new_version))
42
+ def green?
43
+ complete and @adds > 0
39
44
  end
40
-
41
- def index_new_words
42
- @word_indices = Hash.new { |h, word| h[word] = [] }
43
- @new_words.each_with_index { |word, i| @word_indices[word] << i }
45
+
46
+ def summary max_length = 50, joint = '...'
47
+ @summary ||= begin
48
+ if @old_version
49
+ last_position = 0
50
+ remaining_chars = max_length
51
+ res = ''
52
+ new_aggregated_lcs.each do |change|
53
+ if change[:position] > last_position
54
+ res += joint
55
+ end
56
+ res += render_chunk change[:action], change[:text][0..remaining_chars], false
57
+ remaining_chars -= change[:text].size
58
+ if remaining_chars < 0 # no more space left
59
+ res += joint
60
+ break
61
+ end
62
+ last_position = change[:position]
63
+ end
64
+ res
65
+ else
66
+ res = @new_version[0..max_length]
67
+ res += joint if @new_version.size > max_length
68
+ added_chunk(res, false)
69
+ end
70
+ end
44
71
  end
45
-
46
- def operations
47
- position_in_old = position_in_new = 0
48
- operations = []
49
-
50
- matches = matching_blocks
51
- # an empty match at the end forces the loop below to handle the unmatched tails
52
- # I'm sure it can be done more gracefully, but not at 23:52
53
- matches << Match.new(@old_words.length, @new_words.length, 0)
54
-
55
- matches.each_with_index do |match, i|
56
- match_starts_at_current_position_in_old = (position_in_old == match.start_in_old)
57
- match_starts_at_current_position_in_new = (position_in_new == match.start_in_new)
58
-
59
- action_upto_match_positions =
60
- case [match_starts_at_current_position_in_old, match_starts_at_current_position_in_new]
61
- when [false, false]
62
- :replace
63
- when [true, false]
64
- :insert
65
- when [false, true]
66
- :delete
72
+
73
+ def complete
74
+ @complete ||= begin
75
+ clear_stats
76
+ if @old_version
77
+ if @old_version.size < 1000
78
+ better_complete_lcs_diff
67
79
  else
68
- # this happens if the first few words are same in both versions
69
- :none
80
+ fast_diff
70
81
  end
71
-
72
- if action_upto_match_positions != :none
73
- operation_upto_match_positions =
74
- Operation.new(action_upto_match_positions,
75
- position_in_old, match.start_in_old,
76
- position_in_new, match.start_in_new)
77
- operations << operation_upto_match_positions
78
- end
79
- if match.size != 0
80
- match_operation = Operation.new(:equal,
81
- match.start_in_old, match.end_in_old,
82
- match.start_in_new, match.end_in_new)
83
- operations << match_operation
84
- end
85
-
86
- position_in_old = match.end_in_old
87
- position_in_new = match.end_in_new
82
+ else
83
+ added_chunk(@new_version)
84
+ end
88
85
  end
89
-
90
- operations
91
86
  end
92
-
93
- def matching_blocks
94
- matching_blocks = []
95
- recursively_find_matching_blocks(0, @old_words.size, 0, @new_words.size, matching_blocks)
96
- matching_blocks
87
+
88
+ private
89
+
90
+ def clear_stats
91
+ @adds = 0
92
+ @dels = 0
97
93
  end
98
-
99
- def recursively_find_matching_blocks(start_in_old, end_in_old, start_in_new, end_in_new, matching_blocks)
100
- match = find_match(start_in_old, end_in_old, start_in_new, end_in_new)
101
- if match
102
- if start_in_old < match.start_in_old and start_in_new < match.start_in_new
103
- recursively_find_matching_blocks(
104
- start_in_old, match.start_in_old, start_in_new, match.start_in_new, matching_blocks)
105
- end
106
- matching_blocks << match
107
- if match.end_in_old < end_in_old and match.end_in_new < end_in_new
108
- recursively_find_matching_blocks(
109
- match.end_in_old, end_in_old, match.end_in_new, end_in_new, matching_blocks)
110
- end
94
+
95
+ def added_chunk text, count=true
96
+ @adds += 1 if count
97
+ Card::Diff.render_added_chunk text
98
+ end
99
+
100
+ def deleted_chunk text, count=true
101
+ @dels += 1 if count
102
+ Card::Diff.render_deleted_chunk text
103
+ end
104
+
105
+
106
+ def render_chunk action, text, count=true
107
+ case action
108
+ when '+' then added_chunk(text,count)
109
+ when :added then added_chunk(text,count)
110
+ when '-' then deleted_chunk(text,count)
111
+ when :deleted then deleted_chunk(text,count)
112
+ else text
111
113
  end
112
114
  end
113
115
 
114
- def find_match(start_in_old, end_in_old, start_in_new, end_in_new)
115
116
 
116
- best_match_in_old = start_in_old
117
- best_match_in_new = start_in_new
118
- best_match_size = 0
119
-
120
- match_length_at = Hash.new { |h, index| h[index] = 0 }
121
-
122
- start_in_old.upto(end_in_old - 1) do |index_in_old|
123
-
124
- new_match_length_at = Hash.new { |h, index| h[index] = 0 }
125
-
126
- @word_indices[@old_words[index_in_old]].each do |index_in_new|
127
- next if index_in_new < start_in_new
128
- break if index_in_new >= end_in_new
129
-
130
- new_match_length = match_length_at[index_in_new - 1] + 1
131
- new_match_length_at[index_in_new] = new_match_length
132
-
133
- if new_match_length > best_match_size
134
- best_match_in_old = index_in_old - new_match_length + 1
135
- best_match_in_new = index_in_new - new_match_length + 1
136
- best_match_size = new_match_length
117
+ def better_complete_lcs_diff old_v=@old_version, new_v=@new_version
118
+ old_v = old_v.split(' ')
119
+ new_v = new_v.split(' ')
120
+ res = ''
121
+ dels = []
122
+ adds = []
123
+ prev_action = nil
124
+ ::Diff::LCS.traverse_balanced(old_v, new_v) do |chunk|
125
+ if prev_action and prev_action != chunk.action and
126
+ !(prev_action == '-' and chunk.action == '!') and
127
+ !(prev_action == '!' and chunk.action == '+')
128
+
129
+ if dels.present?
130
+ res << deleted_chunk(dels.join(' '))
131
+ dels = []
132
+ end
133
+ if !adds.empty?
134
+ res << added_chunk(adds.join(' '))
135
+ adds = []
137
136
  end
138
137
  end
139
- match_length_at = new_match_length_at
140
- end
141
-
142
- # best_match_in_old, best_match_in_new, best_match_size = add_matching_words_left(
143
- # best_match_in_old, best_match_in_new, best_match_size, start_in_old, start_in_new)
144
- # best_match_in_old, best_match_in_new, match_size = add_matching_words_right(
145
- # best_match_in_old, best_match_in_new, best_match_size, end_in_old, end_in_new)
146
-
147
- return (best_match_size != 0 ? Match.new(best_match_in_old, best_match_in_new, best_match_size) : nil)
148
- end
149
-
150
- def add_matching_words_left(match_in_old, match_in_new, match_size, start_in_old, start_in_new)
151
- while match_in_old > start_in_old and
152
- match_in_new > start_in_new and
153
- @old_words[match_in_old - 1] == @new_words[match_in_new - 1]
154
- match_in_old -= 1
155
- match_in_new -= 1
156
- match_size += 1
138
+
139
+ case chunk.action
140
+ when '-' then dels << chunk.old_element
141
+ when '+' then adds << chunk.new_element
142
+ when '!'
143
+ dels << chunk.old_element
144
+ adds << chunk.new_element
145
+ else
146
+ res += ' ' + chunk.new_element
147
+ end
148
+ prev_action = chunk.action
157
149
  end
158
- [match_in_old, match_in_new, match_size]
150
+ res += deleted_chunk(dels.join(' ')) if dels.present?
151
+ res += added_chunk(adds.join(' ')) if adds.present?
152
+ res
159
153
  end
160
-
161
- def add_matching_words_right(match_in_old, match_in_new, match_size, end_in_old, end_in_new)
162
- while match_in_old + match_size < end_in_old and
163
- match_in_new + match_size < end_in_new and
164
- @old_words[match_in_old + match_size] == @new_words[match_in_new + match_size]
165
- match_size += 1
154
+
155
+
156
+
157
+ def complete_lcs_diff old_v=@old_version, new_v=@new_version
158
+ last_position = 0
159
+ res = ''
160
+ dels = ''
161
+ adds = ''
162
+ prev_action = nil
163
+ ::Diff::LCS.traverse_balanced(old_v, new_v) do |chunk|
164
+ if prev_action and prev_action != chunk.action and
165
+ !(prev_action == '-' and chunk.action == '!') and
166
+ !(prev_action == '!' and chunk.action == '+')
167
+
168
+ if dels.present?
169
+ res += deleted_chunk(dels)
170
+ dels = ''
171
+ end
172
+ if !adds.empty?
173
+ res += added_chunk(adds)
174
+ adds = ''
175
+ end
176
+ end
177
+
178
+ case chunk.action
179
+ when '-' then dels += chunk.old_element
180
+ when '+' then adds += chunk.new_element
181
+ when '!'
182
+ dels += chunk.old_element
183
+ adds += chunk.new_element
184
+ else
185
+ res += chunk.new_element
186
+ end
187
+ prev_action = chunk.action
166
188
  end
167
- [match_in_old, match_in_new, match_size]
189
+ res += deleted_chunk(dels) if dels.present?
190
+ res += added_chunk(adds) if adds.present?
191
+ res
168
192
  end
169
-
170
- VALID_METHODS = [:replace, :insert, :delete, :equal]
171
-
172
- def perform_operation(operation)
173
- @operation = operation
174
- self.send operation.action, operation
175
- end
176
-
177
- def replace(operation)
178
- delete(operation, 'diffmod')
179
- insert(operation, 'diffmod')
193
+
194
+ def complete_diffy_diff
195
+ new_diffy.to_s(:html)
180
196
  end
181
-
182
- def insert(operation, tagclass = 'diffins')
183
- insert_tag('ins', tagclass, @new_words[operation.start_in_new...operation.end_in_new])
184
- end
185
-
186
- def delete(operation, tagclass = 'diffdel')
187
- insert_tag('del', tagclass, @old_words[operation.start_in_old...operation.end_in_old])
188
- end
189
-
190
- def equal(operation)
191
- # no tags to insert, simply copy the matching words from one of the versions
192
- @content += @new_words[operation.start_in_new...operation.end_in_new]
193
- end
194
-
195
- def opening_tag?(item)
196
- item =~ %r!^\s*<[^>]+>\s*$!
197
- end
198
-
199
- def closing_tag?(item)
200
- item =~ %r!^\s*</[^>]+>\s*$!
201
- end
202
-
203
- def tag?(item)
204
- opening_tag?(item) or closing_tag?(item)
205
- end
206
-
207
- def extract_consecutive_words(words, &condition)
208
- index_of_first_tag = nil
209
- words.each_with_index do |word, i|
210
- if !condition.call(word)
211
- index_of_first_tag = i
212
- break
197
+
198
+ # combines diffy and lcs:
199
+ # find with diffy line changes
200
+ # whenever added lines follow immediately after deleted lines compare them with lcs
201
+ def fast_diff
202
+ lines = { :deleted => [], :added=>[], :unchanged=>[], :eof=>[] }
203
+ prev_action = nil
204
+ res = ''
205
+ inspect = false
206
+ new_diffy.each_chunk do |line|
207
+ action = case line
208
+ when /^\+/ then :added
209
+ when /^-/ then :deleted
210
+ when /^ / then :unchanged
211
+ else
212
+ next
213
+ end
214
+ lines[action] << line.sub(/^./,'')
215
+ if action == :added and prev_action == :deleted
216
+ inspect = true
217
+ end
218
+
219
+ if inspect
220
+ if action != :added
221
+ res += better_complete_lcs_diff lines[:deleted].join, lines[:added].join
222
+ inspect = false
223
+ lines[:deleted].clear
224
+ lines[:added].clear
225
+ end
226
+ elsif prev_action and action != prev_action
227
+ text = lines[prev_action].join
228
+ res += render_chunk prev_action, text
229
+ lines[prev_action].clear
213
230
  end
231
+ prev_action = action
214
232
  end
215
- if index_of_first_tag
216
- return words.slice!(0...index_of_first_tag)
233
+
234
+ res += if inspect
235
+ better_complete_lcs_diff lines[:deleted].join, lines[:added].join
236
+ elsif lines[prev_action].present?
237
+ render_chunk prev_action, lines[prev_action].join
217
238
  else
218
- return words.slice!(0..words.length)
239
+ ''
219
240
  end
220
241
  end
221
-
222
- # This method encloses words within a specified tag (ins or del), and adds this into @content,
223
- # with a twist: if there are words contain tags, it actually creates multiple ins or del,
224
- # so that they don't include any ins or del. This handles cases like
225
- # old: '<p>a</p>'
226
- # new: '<p>ab</p><p>c</b>'
227
- # diff result: '<p>a<ins>b</ins></p><p><ins>c</ins></p>'
228
- # this still doesn't guarantee valid HTML (hint: think about diffing a text containing ins or
229
- # del tags), but handles correctly more cases than the earlier version.
230
- #
231
- # P.S.: Spare a thought for people who write HTML browsers. They live in this ... every day.
232
-
233
- def insert_tag(tagname, cssclass, words)
234
- loop do
235
- break if words.empty?
236
- non_tags = extract_consecutive_words(words) { |word| not tag?(word) }
237
- @content << wrap_text(non_tags.join, tagname, cssclass) unless non_tags.empty?
238
-
239
- break if words.empty?
240
- @content += extract_consecutive_words(words) { |word| tag?(word) }
241
- end
242
- end
243
-
244
- def wrap_text(text, tagname, cssclass)
245
- %(<#{tagname} class="#{cssclass}">#{text}</#{tagname}>)
246
- end
247
-
248
- def explode(sequence)
249
- sequence.is_a?(String) ? sequence.split(//) : sequence
250
- end
251
-
252
- def end_of_tag?(char)
253
- char == '>'
254
- end
255
-
256
- def start_of_tag?(char)
257
- char == '<'
258
- end
259
-
260
- def whitespace?(char)
261
- char =~ /\s/
262
- end
263
-
264
- def convert_html_to_list_of_words(x, use_brackets = false)
265
- mode = :char
266
- current_word = ''
267
- words = []
268
-
269
- explode(x).each do |char|
270
- case mode
271
- when :tag
272
- if end_of_tag? char
273
- current_word << (use_brackets ? ']' : '>')
274
- words << current_word
275
- current_word = ''
276
- if whitespace?(char)
277
- mode = :whitespace
278
- else
279
- mode = :char
280
- end
242
+
243
+
244
+ def new_aggregated_lcs
245
+ new_lcs.inject([]) do |res, change_block|
246
+ last_action = nil
247
+ change_block.each do |change|
248
+ if change.action != last_action
249
+ res << { :position => change.position,
250
+ :action => change.action,
251
+ :text => change.element
252
+ }
281
253
  else
282
- current_word << char
254
+ res.last[:text] += change.element
283
255
  end
284
- when :char
285
- if start_of_tag? char
286
- words << current_word unless current_word.empty?
287
- current_word = (use_brackets ? '[' : '<')
288
- mode = :tag
289
- elsif /\s/.match char
290
- words << current_word unless current_word.empty?
291
- current_word = char
292
- mode = :whitespace
293
- else
294
- current_word << char
295
- end
296
- when :whitespace
297
- if start_of_tag? char
298
- words << current_word unless current_word.empty?
299
- current_word = (use_brackets ? '[' : '<')
300
- mode = :tag
301
- elsif /\s/.match char
302
- current_word << char
303
- else
304
- words << current_word unless current_word.empty?
305
- current_word = char
306
- mode = :char
307
- end
308
- else
309
- raise "Unknown mode #{mode.inspect}"
256
+ last_action = change.action
310
257
  end
258
+ res
311
259
  end
312
- words << current_word unless current_word.empty?
313
- words
314
260
  end
315
-
261
+
262
+ def new_diffy
263
+ ::Diffy::Diff.new(@old_version, @new_version)
264
+ end
265
+
266
+ def new_lcs
267
+ ::Diff::LCS.diff(@old_version,@new_version)
268
+ end
316
269
  end
317
270
  end