card 1.20.4 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/card.gemspec +9 -9
  4. data/db/migrate_core_cards/20170515101262_add_advanced_edit_cards.rb +20 -0
  5. data/db/migrate_core_cards/20170608083819_add_full_width_layout_card.rb +23 -0
  6. data/db/migrate_core_cards/20170608200649_add_input_options_codename.rb +8 -0
  7. data/db/seed/new/card_actions.yml +783 -791
  8. data/db/seed/new/card_acts.yml +65 -47
  9. data/db/seed/new/card_changes.yml +3198 -3177
  10. data/db/seed/new/card_references.yml +604 -534
  11. data/db/seed/new/cards.yml +2355 -2256
  12. data/db/seed/test/fixtures/card_actions.yml +1795 -1803
  13. data/db/seed/test/fixtures/card_acts.yml +264 -246
  14. data/db/seed/test/fixtures/card_changes.yml +6275 -6184
  15. data/db/seed/test/fixtures/card_references.yml +1305 -1263
  16. data/db/seed/test/fixtures/cards.yml +3393 -3298
  17. data/db/seed/test/seed.rb +2 -2
  18. data/db/version_core_cards.txt +1 -1
  19. data/lib/card.rb +4 -0
  20. data/lib/card/act_manager/subdirector_array.rb +1 -0
  21. data/lib/card/auth/current.rb +7 -3
  22. data/lib/card/env.rb +5 -0
  23. data/lib/card/env/success.rb +1 -1
  24. data/lib/card/format/names.rb +3 -13
  25. data/lib/card/model/save_helper.rb +4 -6
  26. data/lib/card/query.rb +2 -1
  27. data/lib/card/query/attributes.rb +34 -14
  28. data/lib/card/query/value.rb +3 -4
  29. data/lib/card/set/format.rb +29 -4
  30. data/lib/card/set/format/haml_views.rb +25 -13
  31. data/lib/card/set/trait.rb +1 -0
  32. data/lib/card/set_pattern.rb +17 -1
  33. data/lib/card/subcards.rb +3 -2
  34. data/lib/generators/card/format/format_generator.rb +2 -0
  35. data/lib/generators/card/set/set_generator.rb +2 -0
  36. data/lib/generators/card/template/USAGE +10 -0
  37. data/lib/generators/card/template/template_generator.rb +46 -0
  38. data/lib/generators/card/template/templates/haml_template.erb +1 -0
  39. data/mod/Modfile +1 -1
  40. data/mod/account/set/all/account.rb +9 -5
  41. data/mod/account/set/right/account.rb +17 -5
  42. data/mod/account/set/self/account_links.rb +1 -2
  43. data/mod/account/set/type/signup.rb +4 -5
  44. data/mod/account/set/type/user.rb +1 -1
  45. data/mod/account/spec/set/all/account_spec.rb +2 -2
  46. data/mod/account/spec/set/right/account_spec.rb +2 -2
  47. data/mod/account/spec/set/right/email_spec.rb +1 -1
  48. data/mod/account/spec/set/right/password_spec.rb +1 -1
  49. data/mod/account/spec/set/self/signin_spec.rb +2 -2
  50. data/mod/account/spec/set/type/signup_spec.rb +4 -0
  51. data/mod/ace_editor/set/abstract/ace_editor.rb +6 -3
  52. data/mod/ace_editor/set/self/script_ace.rb +1 -0
  53. data/mod/admin/set/self/admin.rb +1 -1
  54. data/mod/admin/set/self/version.rb +1 -0
  55. data/mod/basic_formats/format/css_format.rb +1 -0
  56. data/mod/basic_formats/format/csv_format.rb +1 -0
  57. data/mod/basic_formats/format/file_format.rb +1 -0
  58. data/mod/basic_formats/format/js_format.rb +1 -0
  59. data/mod/basic_formats/format/json_format.rb +1 -0
  60. data/mod/basic_formats/format/rss_format.rb +1 -0
  61. data/mod/basic_formats/format/xml_format.rb +1 -0
  62. data/mod/basic_formats/set/all/all_csv.rb +1 -1
  63. data/mod/basic_formats/set/all/base.rb +11 -3
  64. data/mod/basic_formats/set/all/json.rb +50 -8
  65. data/mod/basic_formats/set/all/rss.rb +21 -7
  66. data/mod/basic_formats/set/self/01_head/javascript.rb +1 -1
  67. data/mod/basic_formats/set/self/head.rb +1 -1
  68. data/mod/basic_formats/spec/set/all/base_spec.rb +13 -0
  69. data/mod/basic_types/set/type/html.rb +6 -2
  70. data/mod/basic_types/set/type/plain_text.rb +2 -3
  71. data/mod/bootstrap/lib/bootstrap.rb +2 -2
  72. data/mod/bootstrap/lib/bootstrap/basic_tags.rb +1 -1
  73. data/mod/bootstrap/lib/bootstrap/component.rb +2 -3
  74. data/mod/bootstrap/lib/bootstrap/component/form.rb +6 -5
  75. data/mod/bootstrap/lib/bootstrap/component/horizontal_form.rb +1 -1
  76. data/mod/bootstrap/lib/bootstrap/component/layout.rb +3 -3
  77. data/mod/bootstrap/lib/bootstrap/component_loader.rb +0 -2
  78. data/mod/bootstrap/lib/bootstrap/delegate.rb +2 -2
  79. data/mod/bootstrap/lib/bootstrapper.rb +1 -1
  80. data/mod/bootstrap/set/all/bootstrap/accordion.rb +1 -1
  81. data/mod/bootstrap/set/all/bootstrap/form.rb +2 -2
  82. data/mod/bootstrap/set/all/bootstrap/helper.rb +1 -0
  83. data/mod/bootstrap/set/all/bootstrap/wrapper.rb +1 -1
  84. data/mod/bootstrap/set/self/bootstrap_js.rb +1 -1
  85. data/mod/bootstrap/set/self/bootswatch_shared.rb +6 -6
  86. data/mod/bootstrap/set/self/script_mods.rb +1 -1
  87. data/mod/bootstrap/spec/set/all/bootstrap/bootstrap_builder_spec.rb +7 -6
  88. data/mod/bootstrap/spec/set/all/bootstrap/bootstrap_spec.rb +2 -1
  89. data/mod/bootstrap/spec/set/all/bootstrap/form_spec.rb +6 -3
  90. data/mod/bootstrap/spec/set/all/bootstrap/layout_spec.rb +3 -2
  91. data/mod/carrierwave/set/abstract/attachment.rb +1 -3
  92. data/mod/carrierwave/set/abstract/attachment/paths.rb +1 -1
  93. data/mod/carrierwave/set/abstract/attachment/storage_type.rb +11 -1
  94. data/mod/carrierwave/set/type/file.rb +3 -3
  95. data/mod/carrierwave/spec/lib/carrier_wave/file_card_uploader_spec.rb +3 -0
  96. data/mod/carrierwave/spec/set/type/file_spec.rb +24 -6
  97. data/mod/carrierwave/spec/set/type/image_spec.rb +3 -0
  98. data/mod/core/chunk/link.rb +1 -1
  99. data/mod/core/chunk/nest.rb +2 -1
  100. data/mod/core/chunk/query_reference.rb +1 -1
  101. data/mod/core/chunk/reference.rb +1 -0
  102. data/mod/core/chunk/uri.rb +4 -3
  103. data/mod/core/set/abstract/lock.rb +26 -0
  104. data/mod/core/set/all/assign_attributes.rb +8 -4
  105. data/mod/core/set/all/collection.rb +16 -7
  106. data/mod/core/set/all/content.rb +6 -0
  107. data/mod/core/set/all/event.rb +1 -1
  108. data/mod/core/set/all/fetch.rb +2 -2
  109. data/mod/core/set/all/haml.rb +5 -15
  110. data/mod/core/set/all/initialize.rb +2 -2
  111. data/mod/core/set/all/name.rb +1 -1
  112. data/mod/core/set/all/permissions.rb +28 -16
  113. data/mod/core/set/all/rules.rb +1 -2
  114. data/mod/core/set/all/subcards.rb +3 -3
  115. data/mod/core/set/all/templating.rb +5 -1
  116. data/mod/core/set/all/trash.rb +1 -1
  117. data/mod/core/set/all/utils.rb +1 -1
  118. data/mod/core/spec/set/all/actify_spec.rb +1 -1
  119. data/mod/core/spec/set/all/assign_attributes_spec.rb +2 -2
  120. data/mod/core/spec/set/all/collection_spec.rb +6 -3
  121. data/mod/core/spec/set/all/export_spec.rb +40 -112
  122. data/mod/core/spec/set/all/name_spec.rb +1 -1
  123. data/mod/core/spec/set/all/permissions_spec.rb +7 -7
  124. data/mod/core/spec/set/all/rules2_spec.rb +25 -25
  125. data/mod/core/spec/set/all/rules_spec.rb +2 -7
  126. data/mod/developer/set/all/event_viz.rb +1 -1
  127. data/mod/developer/set/right/debug.rb +1 -1
  128. data/mod/history/lib/card/act.rb +1 -0
  129. data/mod/history/lib/card/act/act_renderer.rb +23 -20
  130. data/mod/history/lib/card/act/act_renderer/absolute_act_renderer.rb +0 -1
  131. data/mod/history/lib/card/act/act_renderer/relative_act_renderer.rb +1 -0
  132. data/mod/history/lib/card/action.rb +1 -1
  133. data/mod/history/lib/card/action/action_renderer.rb +2 -2
  134. data/mod/history/lib/card/change.rb +2 -1
  135. data/mod/history/set/all/action_view.rb +1 -1
  136. data/mod/history/set/all/content_history.rb +7 -4
  137. data/mod/history/set/all/history.rb +6 -6
  138. data/mod/machines/file/all_script_machine_output/file.js +50 -34
  139. data/mod/machines/file/all_style_machine_output/file.css +1 -1
  140. data/mod/machines/lib/javascript/wagn.js.coffee +29 -18
  141. data/mod/machines/lib/javascript/wagn_layout.js.coffee +7 -3
  142. data/mod/machines/lib/stylesheets/style_cards.scss +10 -10
  143. data/mod/machines/set/abstract/machine.rb +5 -28
  144. data/mod/machines/set/abstract/script.rb +7 -4
  145. data/mod/machines/set/all/reset_machines.rb +1 -1
  146. data/mod/machines/set/self/script_jquery_helper.rb +2 -2
  147. data/mod/machines/set/self/script_slot.rb +1 -1
  148. data/mod/machines/set/type/coffee_script.rb +3 -2
  149. data/mod/machines/set/type/css.rb +7 -3
  150. data/mod/machines/set/type/scss.rb +7 -1
  151. data/mod/machines/spec/set/type/coffeescript_spec.rb +1 -1
  152. data/mod/machines/spec/set/type/javascript_spec.rb +1 -1
  153. data/mod/machines/spec/set/type/scss_spec.rb +3 -2
  154. data/mod/machines/spec/set/type/skin_spec.rb +1 -1
  155. data/mod/machines/spec/shared_examples/machine.rb +5 -3
  156. data/mod/machines/spec/shared_examples/machine_input.rb +1 -0
  157. data/mod/notifications/format/email_html_format.rb +1 -0
  158. data/mod/notifications/set/all/follow.rb +1 -1
  159. data/mod/notifications/set/all/observer.rb +1 -1
  160. data/mod/notifications/set/all/send_notifications.rb +2 -2
  161. data/mod/notifications/set/self/follow_defaults.rb +3 -8
  162. data/mod/notifications/set/type/email_template/email_config.rb +2 -2
  163. data/mod/notifications/set/type_plus_right/user/follow.rb +2 -2
  164. data/mod/notifications/spec/set/all/follow_spec.rb +7 -0
  165. data/mod/notifications/spec/set/all/notify_spec.rb +3 -0
  166. data/mod/notifications/spec/set/all/observer_spec.rb +1 -1
  167. data/mod/notifications/spec/set/right/followers_spec.rb +1 -0
  168. data/mod/pointer/set/abstract/00_paging_params.rb +11 -0
  169. data/mod/pointer/set/abstract/{00_paging.rb → 01_paging.rb} +10 -6
  170. data/mod/pointer/set/abstract/{00_paging → 01_paging}/paging_links.rb +0 -0
  171. data/mod/pointer/set/abstract/{01_pointer.rb → 02_pointer.rb} +26 -5
  172. data/mod/pointer/set/abstract/{01_pointer → 02_pointer}/edit.rb +3 -5
  173. data/mod/pointer/set/self/input_options.rb +12 -0
  174. data/mod/pointer/spec/set/self/input_options_spec.rb +8 -0
  175. data/mod/pointer/spec/set/type/pointer_spec.rb +3 -2
  176. data/mod/prosemirror_editor/set/abstract/prosemirror_editor.rb +1 -1
  177. data/mod/prosemirror_editor/set/self/script_prosemirror.rb +1 -0
  178. data/mod/settings/lib/card/setting.rb +1 -2
  179. data/mod/settings/set/abstract/permission.rb +1 -1
  180. data/mod/settings/set/self/add_help.rb +1 -1
  181. data/mod/settings/set/self/autoname.rb +1 -1
  182. data/mod/settings/set/self/csv_structure.rb +2 -0
  183. data/mod/settings/set/self/help.rb +1 -1
  184. data/mod/settings/set/self/input.rb +1 -2
  185. data/mod/settings/set/self/options.rb +2 -2
  186. data/mod/settings/set/self/options_label.rb +2 -2
  187. data/mod/settings/set/type/setting.rb +1 -1
  188. data/mod/settings/spec/set/right/script_spec.rb +1 -1
  189. data/mod/settings/spec/set/right/style_spec.rb +1 -1
  190. data/mod/solid_cache/set/abstract/solid_cache.rb +5 -3
  191. data/mod/solid_cache/spec/set/abstract/solid_cache_spec.rb +4 -3
  192. data/mod/standard/set/abstract/01_search_params.rb +4 -3
  193. data/mod/standard/set/abstract/search.rb +2 -1
  194. data/mod/standard/set/abstract/toolbar_split_button.rb +22 -0
  195. data/mod/standard/set/all/links.rb +3 -3
  196. data/mod/standard/set/all/rich_html/classy.rb +37 -0
  197. data/mod/standard/set/all/rich_html/editing.rb +6 -2
  198. data/mod/standard/set/all/rich_html/editor.rb +50 -0
  199. data/mod/standard/set/all/rich_html/form.rb +19 -12
  200. data/mod/standard/set/all/rich_html/form_elements.rb +2 -2
  201. data/mod/standard/set/all/rich_html/formgroup.rb +2 -1
  202. data/mod/standard/set/all/rich_html/header.rb +2 -27
  203. data/mod/standard/set/all/rich_html/menu.rb +1 -1
  204. data/mod/standard/set/all/rich_html/new.rb +5 -1
  205. data/mod/standard/set/all/rich_html/toolbar.rb +15 -60
  206. data/mod/standard/set/all/rich_html/wrapper.rb +6 -3
  207. data/mod/standard/set/right/when_created.rb +2 -2
  208. data/mod/standard/set/rstar/rules_editor.rb +10 -7
  209. data/mod/standard/set/self/activity_toolbar_button.rb +14 -0
  210. data/mod/standard/set/self/recent.rb +7 -2
  211. data/mod/standard/set/self/rules_toolbar_button.rb +42 -0
  212. data/mod/standard/set/self/search.rb +19 -6
  213. data/mod/standard/set/type/basic.rb +6 -6
  214. data/mod/standard/set/type/cardtype.rb +7 -3
  215. data/mod/standard/set/type/date.rb +2 -4
  216. data/mod/standard/set/type/layout_type.rb +1 -0
  217. data/mod/standard/set/type/list.rb +1 -1
  218. data/mod/standard/set/type/listed_by.rb +1 -2
  219. data/mod/standard/set/type/number.rb +4 -2
  220. data/mod/standard/set/type/phrase.rb +4 -2
  221. data/mod/standard/set/type/search_type.rb +11 -3
  222. data/mod/standard/set/type/set.rb +8 -8
  223. data/mod/standard/set/type/toggle.rb +1 -3
  224. data/mod/standard/set/type/uri.rb +6 -2
  225. data/mod/standard/spec/chunk/include_spec.rb +3 -2
  226. data/mod/standard/spec/chunk/query_reference_spec.rb +2 -2
  227. data/mod/standard/spec/set/all/history_spec.rb +1 -0
  228. data/mod/standard/spec/set/all/links_spec.rb +1 -0
  229. data/mod/standard/spec/set/all/rich_html/toolbar_spec.rb +2 -0
  230. data/mod/standard/spec/set/self/activity_toolbar_button_spec.rb +22 -0
  231. data/mod/standard/spec/set/type/email_template/email_config_spec.rb +10 -8
  232. data/mod/standard/spec/set/type/email_template_spec.rb +1 -0
  233. data/mod/standard/spec/set/type/list_spec.rb +2 -0
  234. data/mod/standard/spec/set/type/listed_by_spec.rb +5 -0
  235. data/mod/standard/spec/set/type/search_type_spec.rb +1 -1
  236. data/mod/standard/spec/set/type/toggle_spec.rb +1 -2
  237. data/mod/standard/spec/set/type/uri_spec.rb +0 -1
  238. data/mod/tinymce_editor/db/migrate_cards/20160804112560_add_tinymce_cards.rb +3 -1
  239. data/mod/tinymce_editor/set/abstract/tinymce_editor.rb +1 -1
  240. data/mod/tinymce_editor/set/self/script_tinymce.rb +1 -0
  241. data/mod/twitter/db/migrate_cards/20170305112346_add_twitter_cards.rb +1 -1
  242. data/mod/twitter/set/type/twitter_template.rb +1 -1
  243. data/spec/lib/card/format_spec.rb +26 -7
  244. data/spec/lib/card/loader_spec.rb +96 -35
  245. data/spec/lib/card/query_spec.rb +0 -1
  246. data/spec/support/card_spec_loader.rb +1 -0
  247. data/spec/support/helper/card_helper.rb +0 -36
  248. data/spec/support/helper/set_helper.rb +80 -0
  249. data/spec/support/matchers.rb +74 -0
  250. data/tmpsets/set/mod001-core/all/actify.rb +5 -6
  251. data/tmpsets/set/mod001-core/all/fetch.rb +14 -12
  252. data/tmpsets/set/mod001-core/all/name.rb +1 -1
  253. data/tmpsets/set/mod001-core/all/permissions.rb +12 -22
  254. data/tmpsets/set/mod001-core/all/tracked_attributes.rb +76 -0
  255. data/tmpsets/set/mod001-core/all/utils.rb +40 -3
  256. data/tmpsets/set/mod002-history/all/history.rb +1 -2
  257. data/tmpsets/set/mod008-solid_cache/abstract/solid_cache.rb +1 -1
  258. data/tmpsets/set/mod013-carrierwave/abstract/attachment.rb +282 -0
  259. data/tmpsets/set/mod013-carrierwave/type/file.rb +155 -0
  260. data/tmpsets/set/mod013-carrierwave/type/image.rb +96 -0
  261. data/tmpsets/set/mod014-admin/self/admin.rb +113 -0
  262. data/tmpsets/set/mod014-admin/self/admin_info.rb +110 -0
  263. data/tmpsets/set/mod014-admin/self/version.rb +15 -0
  264. data/tmpsets/set/mod015-developer/all/event_viz.rb +59 -0
  265. data/tmpsets/set/mod015-developer/all/view_viz.rb +30 -0
  266. data/tmpsets/set/mod015-developer/right/debug.rb +96 -0
  267. metadata +52 -22
@@ -42,8 +42,8 @@ class SharedData
42
42
  Card.create! name: "signup alert email+*to", content: "signups@wagn.org"
43
43
 
44
44
  # generic, shared attribute card
45
- color = Card.create! name: "color"
46
- basic = Card.create! name: "Basic Card"
45
+ Card.create! name: "color"
46
+ Card.create! name: "Basic Card"
47
47
 
48
48
  # CREATE A CARD OF EACH TYPE
49
49
  Card.create! type_id: Card::SignupID, name: "Sample Signup" # , email: "invitation@request.com"
@@ -1 +1 @@
1
- 20170314175313
1
+ 20170608200649
@@ -59,6 +59,10 @@ class Card < ActiveRecord::Base
59
59
  :only_storage_phase # used to save subcards
60
60
  )
61
61
 
62
+ def serializable_attributes
63
+ self.class.serializable_attributes + set_specific.keys
64
+ end
65
+
62
66
  attr_accessor :follower_stash
63
67
 
64
68
  define_callbacks(
@@ -15,6 +15,7 @@ class Card
15
15
  end
16
16
 
17
17
  def add card, opts={}
18
+ opts ||= {}
18
19
  card = card.card if card.is_a? StageDirector
19
20
  each { |dir| return dir if dir.card == card }
20
21
  dir = ActManager.fetch card, parent: @parent
@@ -53,12 +53,16 @@ class Card
53
53
  { as_id: as_id, current_id: current_id }
54
54
  end
55
55
 
56
- # @param auth_data [Integer|Hash] user id or a hash
56
+ # @param auth_data [Integer|Hash] user id, user name, or a hash
57
57
  # @opts auth_data [Integer] current_id
58
58
  # @opts auth_data [Integer] as_id
59
59
  def with auth_data
60
- auth_data = { current_id: auth_data } if auth_data.is_a?(Integer)
61
- raise ArgumentError unless auth_data.is_a? Hash
60
+ case auth_data
61
+ when Integer
62
+ auth_data = { current_id: auth_data }
63
+ when String
64
+ auth_data = { current_id: Card.fetch_id(auth_data) }
65
+ end
62
66
 
63
67
  tmp_current = current_id
64
68
  tmp_as_id = as_id
@@ -40,6 +40,11 @@ class Card
40
40
  self[:params] ||= {}
41
41
  end
42
42
 
43
+ def slot_opts
44
+ return {} unless params[:slot].is_a? Hash
45
+ params[:slot].deep_symbolize_keys
46
+ end
47
+
43
48
  def session
44
49
  self[:session] ||= {}
45
50
  end
@@ -25,7 +25,7 @@ class Card
25
25
  end
26
26
 
27
27
  def hard_redirect?
28
- @redirect == true
28
+ @redirect == true || @redirect == "true"
29
29
  end
30
30
 
31
31
  # reset card object and override params with success params
@@ -5,10 +5,8 @@ class Card
5
5
  @initial_context_names ||=
6
6
  if @context_names
7
7
  context_names_minus_irrelevants
8
- elsif params[:slot]
9
- context_names_from_params
10
8
  else
11
- []
9
+ context_names_from_params
12
10
  end
13
11
  end
14
12
 
@@ -18,8 +16,8 @@ class Card
18
16
  end
19
17
 
20
18
  def context_names_from_params
21
- context_name_list = params[:slot][:name_context].to_s
22
- context_name_list.split(",").map(&:to_name)
19
+ return [] unless (name_list = Card::Env.slot_opts[:name_context])
20
+ name_list.to_s.split(",").map(&:to_name)
23
21
  end
24
22
 
25
23
  def context_names_to_params
@@ -33,14 +31,6 @@ class Card
33
31
  @context_names.uniq!
34
32
  end
35
33
 
36
- # def with_name_context name
37
- # old_context = @context_names
38
- # add_name_context name
39
- # result = yield
40
- # @context_names = old_context
41
- # result
42
- # end
43
-
44
34
  def showname title=nil
45
35
  if title
46
36
  card.cardname.title title, @context_names
@@ -9,12 +9,10 @@ class Card
9
9
  # All !-methods in this module rename existing cards
10
10
  # to resolve name conflicts)
11
11
  module SaveHelper
12
- def as_user user_name
13
- current = Card::Auth.current_id
14
- Card::Auth.current_id = Card.fetch_id user_name
15
- result = yield
16
- Card::Auth.current_id = current
17
- result
12
+ def with_user user_name
13
+ Card::Auth.with current_id: Card.fetch_id(user_name) do
14
+ yield
15
+ end
18
16
  end
19
17
 
20
18
  def create_card name_or_args, content_or_args=nil
@@ -61,7 +61,8 @@ class Card
61
61
  link_to linked_to_by
62
62
  include included_by ),
63
63
  conjunction: %w(and or all any),
64
- special: %w(found_by not sort match complete extension_type),
64
+ special: %w(found_by not sort match name_match complete junction_complete
65
+ extension_type),
65
66
  ignore: %w(prepend append view params vars size)
66
67
  }.each_with_object({}) do |pair, h|
67
68
  pair[1].each { |v| h[v.to_sym] = pair[0] }
@@ -1,20 +1,14 @@
1
-
2
1
  class Card
3
2
  class Query
4
3
  module Attributes
5
4
  def found_by val
6
5
  found_by_cards(val).compact.each do |c|
7
- if c && [SearchTypeID, SetID].include?(c.type_id)
8
- # FIXME: - move this check to set mods!
9
-
10
- subquery(
11
- c.wql_hash.merge(unjoined: true, context: c.name)
12
- )
13
- else
6
+ unless c && c.respond_to?(:wql_hash)
14
7
  raise Card::Error::BadQuery,
15
8
  '"found_by" value must be valid Search, ' \
16
9
  "but #{c.name} is a #{c.type_name}"
17
10
  end
11
+ subquery c.wql_hash.merge(unjoined: true, context: c.name)
18
12
  end
19
13
  end
20
14
 
@@ -28,6 +22,10 @@ class Card
28
22
  end
29
23
  end
30
24
 
25
+ # Implements the match attribute that matches always against content and name.
26
+ # That's different from the match operator that can be restricted to names or
27
+ # content.
28
+ # Example: { match: "name or content" } vs. { name: ["match", "a name"] }
31
29
  def match val
32
30
  cxn, val = match_prep val
33
31
  val.gsub!(/[^#{Card::Name::OK4KEY_RE}]+/, " ")
@@ -40,20 +38,24 @@ class Card
40
38
  ].map do |field|
41
39
  %(#{field} #{cxn.match quote("[[:<:]]#{v}[[:>:]]")})
42
40
  end
43
- "(#{name_or_content.join ' OR '})"
41
+ or_join name_or_content
44
42
  end
45
- add_condition "(#{val_list.join ' AND '})"
43
+ add_condition and_join(val_list)
44
+ end
45
+
46
+ def name_match val
47
+ name_like "%#{val}%"
46
48
  end
47
49
 
48
50
  def complete val
49
51
  no_plus_card = (val =~ /\+/ ? "" : "and right_id is null")
50
52
  # FIXME: -- this should really be more nuanced --
51
53
  # it breaks down after one plus
54
+ name_like "#{val}%", no_plus_card
55
+ end
52
56
 
53
- add_condition(
54
- " lower(#{table_alias}.name) LIKE" \
55
- " lower(#{quote(val.to_s + '%')}) #{no_plus_card}"
56
- )
57
+ def junction_complete val
58
+ name_like ["#{val}%", "%+#{val}%"]
57
59
  end
58
60
 
59
61
  def extension_type _val
@@ -61,6 +63,24 @@ class Card
61
63
  Rails.logger.info "using DEPRECATED extension_type in WQL"
62
64
  interpret right_plus: AccountID
63
65
  end
66
+
67
+ private
68
+
69
+ def name_like patterns, extra_cond=""
70
+ likes =
71
+ Array(patterns).map do |pat|
72
+ "lower(#{table_alias}.name) LIKE lower(#{quote pat})"
73
+ end
74
+ add_condition "#{or_join(likes)} #{extra_cond}"
75
+ end
76
+
77
+ def or_join conditions
78
+ "(#{Array(conditions).join ' OR '})"
79
+ end
80
+
81
+ def and_join conditions
82
+ "(#{Array(conditions).join ' AND '})"
83
+ end
64
84
  end
65
85
  end
66
86
  end
@@ -20,11 +20,10 @@ class Card
20
20
  end
21
21
 
22
22
  def canonicalize_operator
23
- if target = OPERATORS[@operator.to_s]
24
- @operator = target
25
- else
23
+ unless (target = OPERATORS[@operator.to_s])
26
24
  raise Card::Error::BadQuery, "Invalid Operator #{@operator}"
27
25
  end
26
+ @operator = target
28
27
  end
29
28
 
30
29
  def sqlize v
@@ -47,7 +46,7 @@ class Card
47
46
  ["#{table}.db_content", v]
48
47
  else
49
48
  ["#{table}.#{safe_sql field}", v]
50
- end
49
+ end
51
50
 
52
51
  v = v[0] if Array === v && v.length == 1 && op != "in"
53
52
  if op == "~"
@@ -81,14 +81,35 @@ class Card
81
81
  include Set::Format::HamlViews
82
82
 
83
83
  mattr_accessor :views
84
- self.views = {}
84
+ self.views = Hash.new { |h, k| h[k] = {} }
85
85
 
86
86
  def view view, *args, &block
87
87
  view = view.to_viewname.key.to_sym
88
- views[self] ||= {}
89
88
  interpret_view_opts view, args[0] if block_given?
90
- view_block = views[self][view] = view_block view, args, &block
91
- define_method "_view_#{view}", view_block
89
+ view_method_block = view_block(view, args, &block)
90
+ if async_view? args
91
+ # This case makes only sense for HtmlFormat
92
+ # but I don't see an easy way to override class methods for a specific
93
+ # format. All formats are extended with this general module. So
94
+ # a HtmlFormat.view method would be overridden by AbstractFormat.view
95
+ # We need something like AbstractHtmlFormat for that.
96
+ define_async_view_method view, &view_method_block
97
+ else
98
+ define_standard_view_method view, &view_method_block
99
+ end
100
+ end
101
+
102
+ def define_standard_view_method view, &block
103
+ views[self][view] = block
104
+ define_method "_view_#{view}", &block
105
+ end
106
+
107
+ def define_async_view_method view, &block
108
+ view_content = "#{view}_async_content"
109
+ define_standard_view_method view_content, &block
110
+ define_standard_view_method view do
111
+ "<card-view-placeholder data-url=#{path view: view_content}/>"
112
+ end
92
113
  end
93
114
 
94
115
  def interpret_view_opts view, opts
@@ -112,6 +133,10 @@ class Card
112
133
  args.first.is_a?(Hash) && args.first[:template] == :haml
113
134
  end
114
135
 
136
+ def async_view? args
137
+ args.first.is_a?(Hash) && args.first[:async]
138
+ end
139
+
115
140
  def lookup_alias_block view, args
116
141
  opts = args[0].is_a?(Hash) ? args.shift : { view: args.shift }
117
142
  opts[:mod] ||= self
@@ -22,24 +22,26 @@ class Card
22
22
  # > render :with_instance_variables # => "Hello haml"
23
23
  module HamlViews
24
24
  def haml_view_block view, &block
25
- template = ::File.read haml_template_path view
25
+ template_path = haml_template_path view
26
26
  if block_given?
27
- haml_temlate_render_block_with_locals view, template, &block
27
+ haml_template_render_block_with_locals view, template_path, &block
28
28
  else
29
- haml_template_render_block view, template
29
+ haml_template_render_block view, template_path
30
30
  end
31
31
  end
32
32
 
33
- def haml_template_render_block view, template
33
+ def haml_template_render_block view, template_path
34
+ template = ::File.read template_path
34
35
  proc do |view_args|
35
36
  voo = View.new(self, view, view_args, @voo)
36
37
  with_voo voo do
37
- haml_to_html template, view_args
38
+ haml_to_html template, view_args, nil, path: template_path
38
39
  end
39
40
  end
40
41
  end
41
42
 
42
- def haml_template_render_block_with_locals view, template
43
+ def haml_template_render_block_with_locals view, template_path, &block
44
+ template = ::File.read template_path
43
45
  proc do |view_args|
44
46
  instance_exec view_args, &block
45
47
  locals = instance_variables.each_with_object({}) do |var, h|
@@ -47,30 +49,40 @@ class Card
47
49
  end
48
50
  voo = View.new(self, view, view_args, @voo)
49
51
  with_voo voo do
50
- haml_to_html template, locals
52
+ haml_to_html template, locals, nil, path: template_path
51
53
  end
52
54
  end
53
55
  end
54
56
 
55
- def haml_template_path view
56
- source = source_location
57
+ def haml_template_path view, source=nil
58
+ source ||= source_location
57
59
  basename = ::File.basename(source, ".rb")
60
+ source_dir = ::File.dirname(source)
58
61
  ["./#{basename}", "."].each do |template_dir|
59
- path = try_haml_template_path(template_dir, view, source)
62
+ path = try_haml_template_path(template_dir, view, source_dir)
60
63
  return path if path
61
64
  end
62
65
  raise(Card::Error, "can't find haml template for #{view}")
63
66
  end
64
67
 
65
- def try_haml_template_path template_path, view, source_path, ext="haml"
66
- path = ::File.expand_path("#{template_path}/#{view}.#{ext}", source_path)
68
+ def try_haml_template_path template_path, view, source_dir, ext="haml"
69
+ path = ::File.expand_path("#{template_path}/#{view}.#{ext}", source_dir)
67
70
  .sub(%r{(/mod/[^/]+)/set/}, "\\1/#{TEMPLATE_DIR}/")
68
71
  ::File.exist?(path) && path
69
72
  end
70
73
 
71
- def haml_to_html haml, locals, a_binding=nil
74
+ def haml_to_html haml, locals, a_binding=nil, debug_info={}
72
75
  a_binding ||= binding
73
76
  ::Haml::Engine.new(haml).render a_binding, locals || {}
77
+ rescue Haml::SyntaxError => e
78
+ raise Card::Error,
79
+ "haml syntax error #{template_location(debug_info)}: #{e.message}"
80
+ end
81
+
82
+ def template_location debug_info
83
+ return "" unless debug_info[:path]
84
+ Pathname.new(debug_info[:path])
85
+ .relative_path_from(Pathname.new(Dir.pwd))
74
86
  end
75
87
  end
76
88
  end
@@ -22,6 +22,7 @@ class Card
22
22
  def add_attributes *args
23
23
  Card.set_specific_attributes ||= []
24
24
  Card.set_specific_attributes += args.map(&:to_s)
25
+ Card.set_specific_attributes.uniq!
25
26
  end
26
27
 
27
28
  def get_traits mod
@@ -99,6 +99,7 @@ EOF
99
99
  @module_key
100
100
  else
101
101
  @module_key = begin
102
+ # binding.pry if to_s == "*input+*right+*options+*self"
102
103
  if self.class.anchorless?
103
104
  self.class.pattern_code.camelize
104
105
  elsif anchor_codenames
@@ -124,12 +125,27 @@ EOF
124
125
  end
125
126
 
126
127
  def anchor_codenames
127
- @anchor_name.parts.map do |part|
128
+ anchor_parts.map do |part|
128
129
  part_id = Card.fetch_id part
129
130
  part_id && Card::Codename[part_id.to_i] || (return nil)
130
131
  end
131
132
  end
132
133
 
134
+ def anchor_parts
135
+ return [@anchor_name] unless anchor_parts_count > 1
136
+ parts = @anchor_name.parts
137
+ if parts.size <= anchor_parts_count
138
+ parts
139
+ else
140
+ # handles cases where anchor is a compound card, eg A+B+*self
141
+ [@anchor_name[0..-anchor_parts_count]] + parts[(-anchor_parts_count + 1)..-1]
142
+ end
143
+ end
144
+
145
+ def anchor_parts_count
146
+ self.class.anchor_parts_count
147
+ end
148
+
133
149
  def pattern
134
150
  @pattern ||= self.class.pattern
135
151
  end
@@ -182,6 +182,7 @@ class Card
182
182
  when Card
183
183
  val.name = absolutize_subcard_name key
184
184
  new_by_card val
185
+ when nil then next
185
186
  else new_by_attributes key, val
186
187
  end
187
188
  end
@@ -246,6 +247,7 @@ class Card
246
247
  end
247
248
 
248
249
  def new_by_attributes name, attributes={}
250
+ attributes ||= {}
249
251
  absolute_name = absolutize_subcard_name name
250
252
  if absolute_name.field_of?(@context_card.name) &&
251
253
  (absolute_name.parts.size - @context_card.cardname.parts.size) > 2
@@ -255,8 +257,7 @@ class Card
255
257
  else
256
258
  subcard_args = extract_subcard_args! attributes
257
259
  t_i_s = attributes.delete(:transact_in_stage)
258
- card = Card.assign_or_initialize_by absolute_name.s, attributes,
259
- local_only: true
260
+ card = Card.assign_or_initialize_by absolute_name.s, attributes, local_only: true
260
261
  subcard = new_by_card card, transact_in_stage: t_i_s
261
262
  card.subcards.add subcard_args
262
263
  subcard