card 1.19.6 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/card.gemspec +8 -7
  4. data/config/initializers/01_core_extensions/array.rb +4 -0
  5. data/config/initializers/01_core_extensions/persistent_identifiers.rb +12 -0
  6. data/config/initializers/02_patches/better_errors.rb +56 -0
  7. data/config/initializers/core_extensions.rb +13 -18
  8. data/config/initializers/patches.rb +8 -0
  9. data/config/locales/de.yml +0 -2
  10. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +22 -12
  11. data/db/migrate_core_cards/20161102202156_tweak_recaptcha_setting_cards.rb +17 -0
  12. data/db/migrate_core_cards/20161103154836_update_keys.rb +46 -0
  13. data/lib/card.rb +1 -8
  14. data/lib/card/act_manager.rb +4 -0
  15. data/lib/card/auth/permissions.rb +5 -3
  16. data/lib/card/cache.rb +1 -20
  17. data/lib/card/cache/persistent.rb +6 -0
  18. data/lib/card/content/chunk.rb +4 -3
  19. data/lib/card/content/diff.rb +2 -2
  20. data/lib/card/content/diff/result.rb +11 -0
  21. data/lib/card/env/success.rb +4 -0
  22. data/lib/card/error.rb +2 -0
  23. data/lib/card/format.rb +14 -17
  24. data/lib/card/format/content.rb +16 -8
  25. data/lib/card/format/error.rb +3 -5
  26. data/lib/card/format/names.rb +22 -16
  27. data/lib/card/format/nest.rb +67 -61
  28. data/lib/card/format/nest/fetch.rb +40 -33
  29. data/lib/card/format/nest/main.rb +39 -19
  30. data/lib/card/format/nest/subformat.rb +3 -16
  31. data/lib/card/format/nest/view.rb +23 -32
  32. data/lib/card/format/permission.rb +49 -34
  33. data/lib/card/format/registration.rb +12 -6
  34. data/lib/card/format/render.rb +62 -73
  35. data/lib/card/migration.rb +14 -10
  36. data/lib/card/migration/import.rb +20 -19
  37. data/lib/card/migration/import/import_data.rb +50 -59
  38. data/lib/card/migration/import/import_data/card_attributes.rb +56 -0
  39. data/lib/card/migration/import/import_data/card_content.rb +33 -0
  40. data/lib/card/migration/import/merger.rb +47 -0
  41. data/lib/card/mod/loader.rb +4 -4
  42. data/lib/card/model/save_helper.rb +49 -10
  43. data/lib/card/name.rb +16 -52
  44. data/lib/card/name/fields_and_traits.rb +67 -0
  45. data/lib/card/name/variants.rb +17 -0
  46. data/lib/card/query.rb +6 -2
  47. data/lib/card/query/attributes.rb +1 -1
  48. data/lib/card/query/interpretation.rb +3 -3
  49. data/lib/card/set/event.rb +2 -1
  50. data/lib/card/set/format.rb +18 -7
  51. data/lib/card/set_pattern.rb +17 -13
  52. data/lib/card/tasks/card.rake +1 -1
  53. data/lib/card/view.rb +55 -0
  54. data/lib/card/view/cache.rb +90 -0
  55. data/lib/card/view/fetch.rb +109 -0
  56. data/lib/card/view/options.rb +164 -0
  57. data/lib/card/view/stub.rb +30 -0
  58. data/lib/card/view/visibility.rb +95 -0
  59. data/lib/cardio.rb +3 -2
  60. data/lib/cardio/schema.rb +21 -8
  61. data/lib/generators/card.rb +16 -2
  62. data/lib/generators/card/format/format_generator.rb +10 -9
  63. data/lib/generators/card/migration/migration_generator.rb +10 -5
  64. data/lib/generators/card/set/USAGE +1 -1
  65. data/lib/generators/card/set/set_generator.rb +11 -9
  66. data/mod/account/set/right/account.rb +38 -40
  67. data/mod/account/set/right/token.rb +2 -1
  68. data/mod/account/set/self/account_links.rb +34 -54
  69. data/mod/account/set/self/signin.rb +107 -93
  70. data/mod/account/set/type/signup.rb +33 -32
  71. data/mod/account/set/type/user.rb +28 -21
  72. data/mod/account/spec/set/all/account_spec.rb +9 -9
  73. data/mod/account/spec/set/right/account_spec.rb +23 -14
  74. data/mod/account/spec/set/right/email_spec.rb +6 -6
  75. data/mod/account/spec/set/right/password_spec.rb +4 -4
  76. data/mod/account/spec/set/right/token_spec.rb +3 -3
  77. data/mod/account/spec/set/self/account_links_spec.rb +3 -3
  78. data/mod/account/spec/set/self/signin_spec.rb +2 -2
  79. data/mod/account/spec/set/type/signup_spec.rb +7 -8
  80. data/mod/ace_editor/set/abstract/ace_editor.rb +1 -4
  81. data/mod/admin/set/self/admin.rb +2 -2
  82. data/mod/admin/set/self/admin_info.rb +1 -1
  83. data/mod/admin/set/self/recaptcha_private_key.rb +3 -0
  84. data/mod/admin/set/self/recaptcha_proxy.rb +3 -0
  85. data/mod/admin/set/self/recaptcha_public_key.rb +3 -0
  86. data/mod/admin/set/self/trash.rb +4 -4
  87. data/mod/admin/spec/set/self/admin_spec.rb +4 -4
  88. data/mod/admin/spec/set/self/version_spec.rb +1 -1
  89. data/mod/basic_formats/set/all/all_css.rb +3 -3
  90. data/mod/basic_formats/set/all/all_csv.rb +6 -6
  91. data/mod/basic_formats/set/all/all_js.rb +4 -0
  92. data/mod/basic_formats/set/all/base.rb +40 -62
  93. data/mod/basic_formats/set/all/json.rb +34 -39
  94. data/mod/basic_formats/set/all/rss.rb +6 -6
  95. data/mod/basic_formats/set/all/text.rb +3 -2
  96. data/mod/basic_formats/set/self/01_head/javascript.rb +2 -2
  97. data/mod/basic_formats/set/self/head.rb +6 -10
  98. data/mod/basic_formats/spec/set/all/all_css_spec.rb +1 -1
  99. data/mod/basic_formats/spec/set/all/all_csv_spec.rb +1 -1
  100. data/mod/basic_formats/spec/set/all/base_spec.rb +8 -5
  101. data/mod/basic_formats/spec/set/all/json_spec.rb +2 -2
  102. data/mod/basic_formats/spec/set/all/rss_spec.rb +4 -4
  103. data/mod/basic_types/set/type/plain_text.rb +3 -5
  104. data/mod/basic_types/spec/set/type/plain_text_spec.rb +2 -2
  105. data/mod/bootstrap/lib/bootstrap.rb +16 -0
  106. data/mod/bootstrap/lib/bootstrap/basic_tags.rb +26 -0
  107. data/mod/bootstrap/lib/bootstrap/component.rb +133 -0
  108. data/mod/bootstrap/lib/bootstrap/component/form.rb +31 -0
  109. data/mod/bootstrap/lib/bootstrap/component/horizontal_form.rb +38 -0
  110. data/mod/bootstrap/lib/bootstrap/component/layout.rb +83 -0
  111. data/mod/bootstrap/lib/bootstrap/component/panel.rb +9 -0
  112. data/mod/bootstrap/lib/bootstrap/component_loader.rb +30 -0
  113. data/mod/bootstrap/lib/bootstrap/delegate.rb +16 -0
  114. data/mod/bootstrap/lib/bootstrapper.rb +16 -0
  115. data/mod/bootstrap/lib/stylesheets/bootstrap/_tables.scss +55 -52
  116. data/mod/bootstrap/lib/stylesheets/bootstrap/mixins/_table-row.scss +12 -12
  117. data/mod/bootstrap/lib/stylesheets/bootstrap_cards.scss +12 -0
  118. data/mod/bootstrap/set/all/bootstrap/accordion.rb +63 -0
  119. data/mod/bootstrap/set/all/bootstrap/helper.rb +7 -140
  120. data/mod/bootstrap/set/all/bootstrap/navbar.rb +74 -0
  121. data/mod/bootstrap/set/all/bootstrap/table.rb +76 -46
  122. data/mod/bootstrap/set/all/bootstrap/tabs.rb +58 -23
  123. data/mod/bootstrap/set/all/bootstrap/wrapper.rb +14 -8
  124. data/mod/bootstrap/set/all/rich_bootstrap.rb +5 -3
  125. data/mod/bootstrap/spec/set/all/bootstrap/bootstrap_builder_spec.rb +31 -0
  126. data/mod/bootstrap/spec/set/all/bootstrap/bootstrap_spec.rb +20 -0
  127. data/mod/bootstrap/spec/set/all/bootstrap/form_spec.rb +59 -1
  128. data/mod/bootstrap/spec/set/all/bootstrap/layout_spec.rb +104 -15
  129. data/mod/carrierwave/set/abstract/attachment.rb +4 -3
  130. data/mod/carrierwave/set/abstract/attachment/paths.rb +1 -1
  131. data/mod/carrierwave/set/abstract/attachment/storage_type.rb +5 -11
  132. data/mod/carrierwave/set/type/file.rb +39 -32
  133. data/mod/carrierwave/set/type/image.rb +59 -34
  134. data/mod/carrierwave/spec/set/type/image_spec.rb +3 -3
  135. data/mod/core/chunk/link.rb +5 -0
  136. data/mod/core/chunk/{include.rb → nest.rb} +8 -29
  137. data/mod/core/chunk/reference.rb +5 -6
  138. data/mod/core/chunk/view_stub.rb +42 -0
  139. data/mod/core/format/html_format.rb +23 -26
  140. data/mod/core/set/abstract/code_file.rb +1 -1
  141. data/mod/core/set/all/actify.rb +1 -1
  142. data/mod/core/set/all/active_card.rb +0 -1
  143. data/mod/core/set/all/{tracked_attributes.rb → assign_attributes.rb} +55 -24
  144. data/mod/core/set/all/collection.rb +136 -122
  145. data/mod/core/set/all/content.rb +8 -0
  146. data/mod/core/set/all/event.rb +5 -2
  147. data/mod/core/set/all/export.rb +7 -7
  148. data/mod/core/set/all/fetch.rb +90 -26
  149. data/mod/core/set/all/initialize.rb +17 -6
  150. data/mod/core/set/all/name.rb +2 -3
  151. data/mod/core/set/all/permissions.rb +19 -11
  152. data/mod/core/set/all/states.rb +12 -2
  153. data/mod/core/set/all/trash.rb +1 -1
  154. data/mod/core/set/all/type.rb +2 -0
  155. data/mod/core/set/all/utils.rb +4 -3
  156. data/mod/core/spec/chunk/literal_spec.rb +2 -2
  157. data/mod/core/spec/chunk/uri_spec.rb +17 -17
  158. data/mod/core/spec/format/html_format_spec.rb +11 -13
  159. data/mod/core/spec/set/all/attribute_tracking_spec.rb +2 -2
  160. data/mod/core/spec/set/all/collection_spec.rb +21 -24
  161. data/mod/core/spec/set/all/content_spec.rb +1 -1
  162. data/mod/core/spec/set/all/export_spec.rb +3 -3
  163. data/mod/core/spec/set/all/fetch_spec.rb +5 -5
  164. data/mod/core/spec/set/all/initialize_spec.rb +4 -4
  165. data/mod/core/spec/set/all/name_spec.rb +6 -6
  166. data/mod/core/spec/set/all/permissions_spec.rb +10 -10
  167. data/mod/core/spec/set/all/references_spec.rb +1 -1
  168. data/mod/core/spec/set/all/rules2_spec.rb +24 -24
  169. data/mod/core/spec/set/all/rules_spec.rb +1 -1
  170. data/mod/core/spec/set/all/templating_spec.rb +8 -8
  171. data/mod/core/spec/set/all/tracked_attributes_spec.rb +6 -6
  172. data/mod/core/spec/set/all/type_spec.rb +5 -5
  173. data/mod/developer/spec/set/all/event_viz_spec.rb +1 -1
  174. data/mod/developer/spec/set/right/debug_spec.rb +1 -1
  175. data/mod/email/set/all/email_html.rb +2 -2
  176. data/mod/email/set/all/notify.rb +8 -3
  177. data/mod/email/set/right/bcc.rb +3 -3
  178. data/mod/email/set/right/follow.rb +5 -5
  179. data/mod/email/set/right/following.rb +1 -1
  180. data/mod/email/set/self/follow_defaults.rb +27 -16
  181. data/mod/email/set/type/email_template.rb +1 -1
  182. data/mod/email/set/type_plus_right/user/follow.rb +10 -9
  183. data/mod/history/lib/card/act.rb +4 -0
  184. data/mod/history/lib/card/act/act_renderer.rb +194 -0
  185. data/mod/history/lib/card/act/act_renderer/absolute_act_renderer.rb +25 -0
  186. data/mod/history/lib/card/act/act_renderer/relative_act_renderer.rb +41 -0
  187. data/mod/history/lib/card/action.rb +1 -0
  188. data/mod/history/lib/card/action/action_renderer.rb +92 -0
  189. data/mod/history/lib/card/action/differ.rb +6 -1
  190. data/mod/history/set/all/act_view.rb +64 -0
  191. data/mod/history/set/all/action_view.rb +65 -0
  192. data/mod/history/set/all/content_history.rb +44 -37
  193. data/mod/history/set/all/history.rb +49 -263
  194. data/mod/machines/lib/stylesheets/style_cards.scss +30 -115
  195. data/mod/machines/set/abstract/script.rb +42 -7
  196. data/mod/machines/set/right/machine_input.rb +4 -0
  197. data/mod/machines/set/type/coffee_script.rb +8 -22
  198. data/mod/machines/set/type/css.rb +2 -2
  199. data/mod/machines/set/type/java_script.rb +4 -24
  200. data/mod/machines/set/type/scss.rb +1 -1
  201. data/mod/machines/spec/set/type/css_spec.rb +1 -1
  202. data/mod/machines/spec/set/type/scss_spec.rb +3 -3
  203. data/mod/machines/spec/set/type/skin_spec.rb +7 -7
  204. data/mod/pointer/set/abstract/01_pointer.rb +44 -46
  205. data/mod/pointer/set/abstract/01_pointer/edit.rb +13 -13
  206. data/mod/pointer/set/right/options.rb +4 -0
  207. data/mod/pointer/spec/set/type/pointer_spec.rb +7 -7
  208. data/mod/prosemirror_editor/set/abstract/prosemirror_editor.rb +3 -3
  209. data/mod/settings/set/abstract/permission.rb +25 -18
  210. data/mod/settings/set/right/add_help.rb +3 -3
  211. data/mod/settings/set/right/structure.rb +10 -16
  212. data/mod/settings/spec/set/right/comment_spec.rb +3 -3
  213. data/mod/settings/spec/set/right/create_spec.rb +1 -1
  214. data/mod/settings/spec/set/right/style_spec.rb +1 -1
  215. data/mod/settings/spec/set/type/setting_spec.rb +1 -1
  216. data/mod/solid_cache/set/abstract/solid_cache.rb +4 -4
  217. data/mod/solid_cache/set/right/solid_cache.rb +9 -10
  218. data/mod/standard/set/abstract/01_search_params.rb +41 -0
  219. data/mod/standard/set/abstract/search.rb +132 -0
  220. data/mod/standard/set/abstract/search/paging.rb +81 -0
  221. data/mod/standard/set/abstract/search/paging/paging_links.rb +90 -0
  222. data/mod/standard/set/abstract/wql_search.rb +67 -0
  223. data/mod/standard/set/all/error.rb +89 -82
  224. data/mod/standard/set/all/links.rb +1 -1
  225. data/mod/standard/set/all/rich_html/content.rb +125 -141
  226. data/mod/standard/set/all/rich_html/editing.rb +115 -178
  227. data/mod/standard/set/all/rich_html/form.rb +111 -131
  228. data/mod/standard/set/all/rich_html/header.rb +57 -39
  229. data/mod/standard/set/all/rich_html/menu.rb +94 -94
  230. data/mod/standard/set/all/rich_html/modal.rb +5 -10
  231. data/mod/standard/set/all/rich_html/new.rb +103 -0
  232. data/mod/standard/set/all/rich_html/toolbar.rb +54 -74
  233. data/mod/standard/set/all/rich_html/wrapper.rb +111 -138
  234. data/mod/standard/set/rstar/rules.rb +27 -38
  235. data/mod/standard/set/rstar/rules_editor.rb +298 -277
  236. data/mod/standard/set/self/navbox.rb +20 -15
  237. data/mod/standard/set/self/recent.rb +25 -17
  238. data/mod/standard/set/self/search.rb +25 -4
  239. data/mod/standard/set/type/cardtype.rb +11 -9
  240. data/mod/standard/set/type/date.rb +1 -1
  241. data/mod/standard/set/type/number.rb +1 -1
  242. data/mod/standard/set/type/phrase.rb +1 -1
  243. data/mod/standard/set/type/search_type.rb +17 -282
  244. data/mod/standard/set/type/session.rb +1 -1
  245. data/mod/standard/set/type/set.rb +155 -131
  246. data/mod/standard/set/type/toggle.rb +1 -1
  247. data/mod/standard/set/type/uri.rb +4 -4
  248. data/mod/standard/spec/chunk/include_spec.rb +13 -31
  249. data/mod/standard/spec/chunk/link_spec.rb +1 -1
  250. data/mod/standard/spec/set/all/error_spec.rb +1 -1
  251. data/mod/standard/spec/set/all/history_spec.rb +2 -2
  252. data/mod/standard/spec/set/all/rich_html/form_spec.rb +4 -4
  253. data/mod/standard/spec/set/all/rich_html/toolbar_spec.rb +22 -0
  254. data/mod/standard/spec/set/all/rich_html/wrapper_spec.rb +3 -2
  255. data/mod/standard/spec/set/right/when_created_spec.rb +1 -1
  256. data/mod/standard/spec/set/right/when_last_edited_spec.rb +1 -1
  257. data/mod/standard/spec/set/rstar/rules_spec.rb +2 -3
  258. data/mod/standard/spec/set/self/head_spec.rb +2 -2
  259. data/mod/standard/spec/set/self/navbox_spec.rb +1 -1
  260. data/mod/standard/spec/set/self/now_spec.rb +1 -1
  261. data/mod/standard/spec/set/type/date_spec.rb +1 -1
  262. data/mod/standard/spec/set/type/email_template_spec.rb +1 -1
  263. data/mod/standard/spec/set/type/layout_type_spec.rb +1 -1
  264. data/mod/standard/spec/set/type/number_spec.rb +1 -1
  265. data/mod/standard/spec/set/type/phrase_spec.rb +1 -1
  266. data/mod/standard/spec/set/type/search_type_spec.rb +2 -2
  267. data/mod/standard/spec/set/type/set_spec.rb +2 -2
  268. data/mod/standard/spec/set/type/toggle_spec.rb +2 -2
  269. data/mod/standard/spec/set/type/uri_spec.rb +3 -1
  270. data/mod/tinymce_editor/set/abstract/tinymce_editor.rb +1 -1
  271. data/spec/config/initializers/core_extensions_spec.rb +40 -10
  272. data/spec/lib/card/auth_spec.rb +8 -8
  273. data/spec/lib/card/cache_spec.rb +3 -3
  274. data/spec/lib/card/chunk_spec.rb +4 -4
  275. data/spec/lib/card/codename_spec.rb +2 -2
  276. data/spec/lib/card/content_spec.rb +23 -23
  277. data/spec/lib/card/diff_spec.rb +1 -1
  278. data/spec/lib/card/format_spec.rb +19 -24
  279. data/spec/lib/card/loader_spec.rb +4 -4
  280. data/spec/lib/card/name_spec.rb +16 -16
  281. data/spec/lib/card/query_spec.rb +80 -80
  282. data/spec/lib/card/reference_spec.rb +5 -5
  283. data/spec/lib/card/set_spec.rb +6 -6
  284. data/spec/lib/card/subcards_spec.rb +14 -0
  285. data/spec/lib/card/view_cache_spec.rb +5 -5
  286. data/spec/models/card/cardtype_spec.rb +15 -15
  287. data/spec/models/card/create_spec.rb +2 -2
  288. data/spec/models/card/trash_spec.rb +24 -24
  289. data/spec/models/card/type_transition_spec.rb +8 -8
  290. data/spec/models/card/validation_spec.rb +5 -5
  291. data/spec/models/card_spec.rb +14 -14
  292. data/spec/spec_helper.rb +6 -2
  293. data/spec/support/card_spec_helper.rb +21 -11
  294. data/spec/support/helper/card_helper.rb +11 -4
  295. metadata +73 -15
  296. data/lib/card/cache/view_cache.rb +0 -103
  297. data/mod/bootstrap/set/all/bootstrap/layout.rb +0 -58
  298. data/mod/core/set/all/view_cache.rb +0 -9
@@ -15,6 +15,10 @@ class Card
15
15
  @summary.rendered
16
16
  end
17
17
 
18
+ def summary_omits_content?
19
+ @summary.omits_content?
20
+ end
21
+
18
22
  def write_added_chunk text
19
23
  @adds_cnt += 1
20
24
  @complete << Card::Content::Diff.render_added_chunk(text)
@@ -45,6 +49,7 @@ class Card
45
49
 
46
50
  @summary = nil
47
51
  @chunks = []
52
+ @content_omitted = false
48
53
  end
49
54
 
50
55
  def rendered
@@ -52,6 +57,7 @@ class Card
52
57
  begin
53
58
  truncate_overlap
54
59
  @chunks.map do |chunk|
60
+ @content_omitted ||= chunk[:action] == :ellipsis
55
61
  render_chunk chunk[:action], chunk[:text]
56
62
  end.join
57
63
  end
@@ -71,6 +77,10 @@ class Card
71
77
  end
72
78
  end
73
79
 
80
+ def omits_content?
81
+ @content_omitted || @remaining_chars < 0
82
+ end
83
+
74
84
  private
75
85
 
76
86
  def add_chunk text, action
@@ -105,6 +115,7 @@ class Card
105
115
  def process_ellipsis
106
116
  return unless @chunks.last[:action] == :ellipsis
107
117
  @chunks.pop
118
+ @content_omitted = true
108
119
  @remaining_chars += @joint.size
109
120
  end
110
121
 
@@ -116,6 +116,10 @@ class Card
116
116
  @params.marshal_dump
117
117
  end
118
118
 
119
+ def raw_params
120
+ @params
121
+ end
122
+
119
123
  def to_url name_context=@name_context
120
124
  case (target = target(name_context))
121
125
  when Card
@@ -45,6 +45,8 @@ class Card
45
45
 
46
46
  class << self
47
47
  def exception_view card, exception
48
+ Card::Error.current = exception
49
+
48
50
  case exception
49
51
  ## arguably the view and status should be defined in the error class;
50
52
  ## some are redundantly defined in view
@@ -32,7 +32,6 @@ class Card
32
32
  include Content
33
33
  include Error
34
34
 
35
- extend Nest::ClassMethods
36
35
  extend Registration
37
36
 
38
37
  # FIXME: should be set in views
@@ -45,28 +44,30 @@ class Card
45
44
  send "#{accessor_name}=", {}
46
45
  end
47
46
 
48
- attr_reader :card, :root, :parent, :main_opts
49
- attr_accessor :form, :error_status, :nest_opts
47
+ attr_reader :card, :root, :parent, :main_opts, :mode
48
+ attr_accessor :form, :error_status
50
49
 
51
50
  def initialize card, opts={}
52
- unless (@card = card)
53
- msg = I18n.t :exception_init_without_card, scope: "lib.card.format"
54
- raise Card::Error, msg
55
- end
51
+ @card = card
52
+ require_card_to_initialize!
56
53
 
57
- opts.each do |key, value|
58
- instance_variable_set "@#{key}", value
59
- end
54
+ opts.each { |key, value| instance_variable_set "@#{key}", value }
60
55
 
61
56
  @mode ||= :normal
62
57
  @root ||= self
63
58
  @depth ||= 0
64
59
 
65
- @context_names = initialize_context_names
60
+ @context_names = initial_context_names
66
61
  include_set_format_modules
67
62
  self
68
63
  end
69
64
 
65
+ def require_card_to_initialize!
66
+ return if @card
67
+ msg = I18n.t :exception_init_without_card, scope: "lib.card.format"
68
+ raise Card::Error, msg
69
+ end
70
+
70
71
  def include_set_format_modules
71
72
  self.class.format_ancestry.reverse_each do |klass|
72
73
  card.set_format_modules(klass).each do |m|
@@ -98,11 +99,7 @@ class Card
98
99
  end
99
100
 
100
101
  def focal? # meaning the current card is the requested card
101
- if Env.ajax?
102
- @depth.zero?
103
- else
104
- main?
105
- end
102
+ @depth.zero?
106
103
  end
107
104
 
108
105
  def template
@@ -116,7 +113,7 @@ class Card
116
113
 
117
114
  def method_missing method, *opts, &proc
118
115
  if method =~ /(_)?(optional_)?render(_(\w+))?/
119
- render_api Regexp.last_match, opts
116
+ api_render Regexp.last_match, opts
120
117
  else
121
118
  pass_method_to_template_object(method, opts, proc) { yield }
122
119
  end
@@ -5,7 +5,7 @@ class Card
5
5
  content = override_content || render_raw || ""
6
6
  content_object = get_content_object content, opts
7
7
  content_object.process_each_chunk do |chunk_opts|
8
- prepare_nest chunk_opts.merge(opts)
8
+ content_nest chunk_opts.merge(opts)
9
9
  end
10
10
  content_object.to_s
11
11
  end
@@ -33,7 +33,17 @@ class Card
33
33
  end
34
34
 
35
35
  def add_class options, klass
36
- options[:class] = [options[:class], klass].flatten.uniq.compact * " "
36
+ options[:class] = css_classes options[:class], klass
37
+ end
38
+
39
+ alias_method :append_class, :add_class
40
+
41
+ def prepend_class options, klass
42
+ options[:class] = css_classes klass, options[:class]
43
+ end
44
+
45
+ def css_classes *array
46
+ array.flatten.uniq.compact * " "
37
47
  end
38
48
 
39
49
  def id_counter
@@ -43,14 +53,12 @@ class Card
43
53
  end
44
54
 
45
55
  def unique_id
46
- "#{card.key}-#{id_counter}"
56
+ "#{card.cardname.safe_key}-#{id_counter}"
47
57
  end
48
58
 
49
- def output content
50
- case content
51
- when String then content
52
- when Array then content.compact.join "\n"
53
- end
59
+ def output *content
60
+ content ||= yield
61
+ Array.wrap(content).flatten.compact.join "\n"
54
62
  end
55
63
  end
56
64
  end
@@ -3,14 +3,12 @@ class Card
3
3
  module Error
4
4
  def rescue_view e, view
5
5
  raise e if Rails.env =~ /^cucumber|test$/
6
- Card::Error.current = e
7
- card.notable_exception_raised
6
+ error_view = Card::Error.exception_view @card, e
7
+ # TODO: consider rendering dynamic error view here.
8
8
  rendering_error e, view
9
9
  end
10
10
 
11
- def debug_error e, view
12
- Rails.logger.info "#{rendering_error e, view}:\n" \
13
- "#{e.class} : #{e.message}"
11
+ def debug_error e
14
12
  debug = Card[:debugger]
15
13
  raise e if debug && debug.content == "on"
16
14
  end
@@ -1,14 +1,15 @@
1
1
  class Card
2
2
  class Format
3
3
  module Names
4
- def initialize_context_names
5
- if @context_names
6
- context_names_minus_irrelevants
7
- elsif params[:slot]
8
- context_names_from_params
9
- else
10
- []
11
- end
4
+ def initial_context_names
5
+ @initial_context_names ||=
6
+ if @context_names
7
+ context_names_minus_irrelevants
8
+ elsif params[:slot]
9
+ context_names_from_params
10
+ else
11
+ []
12
+ end
12
13
  end
13
14
 
14
15
  def context_names_minus_irrelevants
@@ -21,23 +22,28 @@ class Card
21
22
  context_name_list.split(",").map(&:to_name)
22
23
  end
23
24
 
25
+ def context_names_to_params
26
+ return unless @context_names
27
+ @context_names.join(",")
28
+ end
29
+
24
30
  def add_name_context name=nil
25
31
  name ||= card.name
26
32
  @context_names += name.to_name.part_names
27
33
  @context_names.uniq!
28
34
  end
29
35
 
30
- def with_name_context name
31
- old_context = @context_names
32
- add_name_context name
33
- result = yield
34
- @context_names = old_context
35
- result
36
- end
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
37
43
 
38
44
  def showname title=nil
39
45
  if title
40
- title.to_name.to_absolute_name(card.cardname).to_show(*@context_names)
46
+ card.cardname.title title, @context_names
41
47
  else
42
48
  @showname ||= card.cardname.to_show(*@context_names)
43
49
  end
@@ -6,80 +6,84 @@ class Card
6
6
  include Subformat
7
7
  include View
8
8
 
9
- def nest name_or_card_or_opts, opts={}
10
- nested_card = fetch_nested_card name_or_card_or_opts, opts
11
- opts = name_or_card_or_opts if name_or_card_or_opts.is_a? Hash
12
- opts[:inc_name] ||= nested_card.name
13
- nest_card nested_card, opts
9
+ # nested by another card's content
10
+ # (as opposed to a direct API nest)
11
+ def content_nest opts={}
12
+ return opts[:comment] if opts.key? :comment # commented nest
13
+ nest_name = opts[:nest_name]
14
+ return main_nest(opts) if main_nest?(nest_name)
15
+ nest nest_name, opts
14
16
  end
15
17
 
16
- # Main difference compared to #nest is that you can use
17
- # codename symbols to get nested fields
18
- # @example
19
- # home = Card['home'].format
20
- # home.nest :self # => nest for '*self'
21
- # home.field_nest :self # => nest for 'Home+*self'
22
- def field_nest field, opts={}
23
- if field.is_a?(Card)
24
- nest_card field, opts
25
- else
26
- prepare_nest opts.merge(inc_name: card.cardname.field(field))
27
- end
18
+ def nest cardish, options={}, &block
19
+ return "" if nest_invisible?
20
+ nested_card = fetch_nested_card cardish, options
21
+ view, options = interpret_nest_options nested_card, options
22
+ nest_render nested_card, view, options, &block
28
23
  end
29
24
 
30
- def process_nest opts
31
- opts ||= {}
32
-
33
- if opts.key?(:comment)
34
- # commented nest
35
- opts[:comment]
36
- elsif content_out_of_view?
37
- ""
38
- elsif main_nest_within_layout? opts
39
- main_nest opts
40
- else
41
- # standard nest
42
- count_chars { nest opts }
43
- end
25
+ def interpret_nest_options nested_card, options
26
+ options[:nest_name] ||= nested_card.name
27
+ view = options[:view] || implicit_nest_view
28
+ view = Card::View.canonicalize view
29
+
30
+ # FIXME: should handle in closed / edit view definitions
31
+ options[:home_view] ||= [:closed, :edit].member?(view) ? :open : view
32
+
33
+ [view, options]
44
34
  end
45
35
 
46
- # deprecated, use process_nest
47
- alias_method :prepare_nest, :process_nest
36
+ def implicit_nest_view
37
+ view = voo_items_view || default_nest_view
38
+ Card::View.canonicalize view
39
+ end
48
40
 
49
- def nest_card nested_card, opts={}
50
- # ActiveSupport::Notifications.instrument('card', message:
51
- # "nest: #{nested_card.name}, #{opts}") do
52
- opts.delete_if { |_k, v| v.nil? }
53
- opts.reverse_merge! nest_defaults(nested_card)
41
+ def default_nest_view
42
+ :name
43
+ end
54
44
 
55
- subformat = nest_subformat nested_card, opts
56
- view = canonicalize_view opts.delete :view
57
- opts[:home_view] = [:closed, :edit].member?(view) ? :open : view
58
- # FIXME: special views should be represented in view definitions
59
- subformat.nest_render view, opts
45
+ def nest_render nested_card, view, options
46
+ subformat = nest_subformat nested_card, options, view
47
+ view = subformat.modal_nest_view view
48
+ rendered = count_chars { subformat.optional_render view, options }
49
+ block_given? ? yield(rendered, view) : rendered
60
50
  end
61
51
 
62
- def nest_defaults nested_card
63
- @nest_defaults ||= begin
64
- defaults = get_nest_defaults(nested_card).clone
65
- defaults.merge! @nest_opts if @nest_opts
66
- defaults
67
- end
52
+ def nest_subformat nested_card, opts, view
53
+ return self if reuse_format? opts, view
54
+ sub = subformat nested_card
55
+ sub.main! if opts[:main]
56
+ sub
68
57
  end
69
58
 
70
- def get_nest_defaults _nested_card
71
- { view: :name }
59
+ def reuse_format? opts, view
60
+ return false unless opts[:nest_name] =~ /^_(self)?$/
61
+ !content_view? view
72
62
  end
73
63
 
74
- private
64
+ def content_view? view
65
+ # TODO: this should be specified in view definition
66
+ [:core, :content, :titled, :open, :closed].member? view.to_sym
67
+ end
75
68
 
76
- def content_out_of_view?
77
- @mode == :closed && @char_count &&
78
- @char_count > Card.config.max_char_count
69
+ # Main difference compared to #nest is that you can use
70
+ # codename symbols to get nested fields
71
+ # @example
72
+ # home = Card['home'].format
73
+ # home.nest :self # => nest for '*self'
74
+ # home.field_nest :self # => nest for 'Home+*self'
75
+ def field_nest field, opts={}
76
+ field = card.cardname.field(field) unless field.is_a? Card
77
+ nest field, opts
79
78
  end
80
79
 
81
- def main_nest_within_layout? opts
82
- opts[:inc_name] == "_main" && show_layout? && @depth.zero?
80
+ # opts[:home_view] = [:closed, :edit].member?(view) ? :open : view
81
+ # FIXME: special views should be represented in view definitions
82
+
83
+ private
84
+
85
+ def nest_invisible?
86
+ @mode == :closed && @char_count && @char_count > max_char_count
83
87
  end
84
88
 
85
89
  def count_chars
@@ -90,10 +94,12 @@ class Card
90
94
  result
91
95
  end
92
96
 
93
- module ClassMethods
94
- def max_depth
95
- Card.config.max_depth
96
- end
97
+ def max_depth
98
+ Card.config.max_depth
99
+ end
100
+
101
+ def max_char_count
102
+ Card.config.max_char_count
97
103
  end
98
104
  end
99
105
  end
@@ -3,49 +3,56 @@ class Card
3
3
  module Nest
4
4
  # Fetch card for a nest
5
5
  module Fetch
6
- def fetch_nested_card name_or_card_or_opts, opts={}
7
- case name_or_card_or_opts
8
- when Card
9
- name_or_card_or_opts
10
- when Hash
11
- opts = name_or_card_or_opts
12
- Card.fetch(opts[:inc_name], new: nest_new_args(opts))
13
- when Symbol
14
- Card.fetch(name_or_card_or_opts)
6
+ def fetch_nested_card cardish, opts={}
7
+ case cardish
8
+ when Card then cardish
9
+ when Symbol, Integer then Card.fetch cardish
15
10
  else
16
- opts[:inc_name] = name_or_card_or_opts.to_s
17
- Card.fetch name_or_card_or_opts, new: nest_new_args(opts)
11
+ opts[:nest_name] = cardish.to_s
12
+ Card.fetch cardish, new: nest_new_args(opts)
18
13
  end
19
14
  end
20
15
 
21
16
  private
22
17
 
23
- def nest_content cardname
24
- content = params[cardname.to_s.tr("+", "_")]
18
+ def nest_new_args nest_opts
19
+ nest_name = nest_opts[:nest_name].to_s
20
+ new_args = { name: nest_name, type: nest_opts[:type] }
25
21
 
26
- # CLEANME This is a hack so plus cards re-populate on failed signups
27
- p = params["subcards"]
28
- if p && (card_params = p[cardname.to_s])
29
- content = card_params["content"]
30
- end
31
- content if content.present? # returns nil for empty string
22
+ new_args[:supercard] = card unless nest_name.strip.blank?
23
+ # special case. gets absolutized incorrectly. fix in smartname?
24
+
25
+ nest_new_main_args new_args if nest_name =~ /^_main\+/
26
+ nest_new_content_args new_args, nest_name
27
+ new_args
32
28
  end
33
29
 
34
- def nest_new_args opts
35
- args = { name: opts[:inc_name], type: opts[:type], supercard: card }
36
- args.delete(:supercard) if opts[:inc_name].strip.blank?
37
- # special case. gets absolutized incorrectly. fix in smartname?
38
- if opts[:inc_name] =~ /^_main\+/
39
- # FIXME: this is a rather hacky (and untested) way to get @superleft
40
- # to work on new cards named _main+whatever
41
- args[:name] = args[:name].gsub(/^_main\+/, "+")
42
- args[:supercard] = root.card
43
- end
44
- if (content = nest_content opts[:inc_name])
45
- args[:content] = content
46
- end
47
- args
30
+ def nest_new_main_args new_args
31
+ # FIXME: this is a rather hacky way to get @superleft
32
+ # to work on new cards named _main+whatever
33
+ new_args[:name] = new_args[:name].gsub(/^_main\+/, "+")
34
+ new_args[:supercard] = root.card
48
35
  end
36
+
37
+ def nest_new_content_args new_args, nest_name
38
+ content = nest_content_from_shorthand_param(nest_name) ||
39
+ nest_content_from_subcard_params(nest_name)
40
+ new_args[:content] = content if content.present?
41
+ end
42
+
43
+ def nest_content_from_shorthand_param nest_name
44
+ shorthand_param = nest_name.tr "+", "_"
45
+ # FIXME: this is a lame shorthand; could be another card's key
46
+ # should be more robust and managed by Card::Name
47
+ params[shorthand_param]
48
+ end
49
+
50
+ def nest_content_from_subcard_params nest_name
51
+ return unless (subcard_params = params["subcards"])
52
+ return unless (nestcard_params = subcard_params[nest_name])
53
+ nestcard_params["content"]
54
+ end
55
+
49
56
  end
50
57
  end
51
58
  end