spontaneous 0.2.0.alpha7 → 0.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/Gemfile +10 -4
  2. data/Readme.markdown +1 -1
  3. data/application/css/definitions.css.scss +5 -0
  4. data/application/css/dialogue.css.scss +62 -0
  5. data/application/js/content.js +1 -1
  6. data/application/js/dom.js +1 -1
  7. data/application/js/event_source.js +3 -0
  8. data/application/js/{field_types/date_field.js → field/date.js} +2 -2
  9. data/application/js/{field_types/file_field.js → field/file.js} +2 -2
  10. data/application/js/{field_types/image_field.js → field/image.js} +54 -20
  11. data/application/js/{field_types/long_string_field.js → field/long_string.js} +2 -2
  12. data/application/js/{field_types/markdown_field.js → field/markdown.js} +2 -2
  13. data/application/js/{field_types/select_field.js → field/select.js} +2 -2
  14. data/application/js/{field_types/string_field.js → field/string.js} +21 -7
  15. data/application/js/{field_types/webvideo_field.js → field/webvideo.js} +2 -2
  16. data/application/js/field.js +2 -2
  17. data/application/js/publish.js +99 -19
  18. data/application/js/spontaneous.js +8 -8
  19. data/application/js/top_bar.js +6 -4
  20. data/db/migrations/20130109125023_add_page_publish_lock.rb +17 -0
  21. data/db/migrations/20130111161934_convert_bcrypt_passwords.rb +22 -0
  22. data/db/migrations/20130114120000_create_revision_tables.rb +106 -0
  23. data/db/migrations/20130116220423_add_index_to_archive.rb +9 -0
  24. data/lib/spontaneous/box.rb +53 -18
  25. data/lib/spontaneous/box_style.rb +2 -3
  26. data/lib/spontaneous/change.rb +39 -13
  27. data/lib/spontaneous/cli/fields.rb +29 -0
  28. data/lib/spontaneous/cli/init.rb +2 -2
  29. data/lib/spontaneous/cli/migrate.rb +0 -1
  30. data/lib/spontaneous/cli/server.rb +14 -10
  31. data/lib/spontaneous/cli/site.rb +20 -9
  32. data/lib/spontaneous/cli.rb +8 -6
  33. data/lib/spontaneous/collections/box_set.rb +11 -0
  34. data/lib/spontaneous/collections/field_set.rb +24 -1
  35. data/lib/spontaneous/concern.rb +37 -0
  36. data/lib/spontaneous/config.rb +3 -4
  37. data/lib/spontaneous/crypt/version.rb +130 -0
  38. data/lib/spontaneous/crypt.rb +84 -0
  39. data/lib/spontaneous/data_mapper/content_model/associations.rb +199 -0
  40. data/lib/spontaneous/data_mapper/content_model/column_accessors.rb +52 -0
  41. data/lib/spontaneous/data_mapper/content_model/instance_hooks.rb +34 -0
  42. data/lib/spontaneous/data_mapper/content_model/serialization.rb +54 -0
  43. data/lib/spontaneous/data_mapper/content_model/timestamps.rb +39 -0
  44. data/lib/spontaneous/data_mapper/content_model.rb +343 -0
  45. data/lib/spontaneous/data_mapper/content_table.rb +103 -0
  46. data/lib/spontaneous/data_mapper/dataset.rb +194 -0
  47. data/lib/spontaneous/data_mapper/scope.rb +195 -0
  48. data/lib/spontaneous/data_mapper.rb +161 -0
  49. data/lib/spontaneous/facet.rb +2 -2
  50. data/lib/spontaneous/field/base.rb +418 -0
  51. data/lib/spontaneous/field/date.rb +54 -0
  52. data/lib/spontaneous/{field_version.rb → field/field_version.rb} +1 -1
  53. data/lib/spontaneous/field/file.rb +100 -0
  54. data/lib/spontaneous/{field_types/image_field.rb → field/image.rb} +33 -33
  55. data/lib/spontaneous/{field_types/location_field.rb → field/location.rb} +2 -2
  56. data/lib/spontaneous/{field_types/long_string_field.rb → field/long_string.rb} +3 -3
  57. data/lib/spontaneous/field/markdown.rb +36 -0
  58. data/lib/spontaneous/{field_types/select_field.rb → field/select.rb} +4 -5
  59. data/lib/spontaneous/field/string.rb +17 -0
  60. data/lib/spontaneous/field/update.rb +156 -0
  61. data/lib/spontaneous/field/webvideo.rb +310 -0
  62. data/lib/spontaneous/field.rb +80 -0
  63. data/lib/spontaneous/generators/site/Gemfile.tt +2 -2
  64. data/lib/spontaneous/generators/site/config/environments/development.rb.tt +1 -1
  65. data/lib/spontaneous/generators/site/config/environments/production.rb.tt +1 -1
  66. data/lib/spontaneous/generators/site/lib/content.rb.tt +6 -0
  67. data/lib/spontaneous/generators/site/schema/box.rb.tt +3 -2
  68. data/lib/spontaneous/generators/site/schema/page.rb.tt +3 -1
  69. data/lib/spontaneous/generators/site/schema/piece.rb.tt +3 -1
  70. data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +3 -1
  71. data/lib/spontaneous/generators/site.rb +4 -3
  72. data/lib/spontaneous/image_size.rb +8 -1
  73. data/lib/spontaneous/layout.rb +5 -1
  74. data/lib/spontaneous/loader.rb +2 -5
  75. data/lib/spontaneous/media/file.rb +11 -2
  76. data/lib/spontaneous/media/temp_file.rb +23 -0
  77. data/lib/spontaneous/media.rb +20 -39
  78. data/lib/spontaneous/{plugins → model/box}/allowed_types.rb +38 -17
  79. data/lib/spontaneous/model/box.rb +18 -0
  80. data/lib/spontaneous/{plugins → model/core}/aliases.rb +10 -14
  81. data/lib/spontaneous/{plugins → model/core}/boxes.rb +2 -2
  82. data/lib/spontaneous/{plugins → model/core}/content_groups.rb +2 -2
  83. data/lib/spontaneous/model/core/editor_class.rb +4 -0
  84. data/lib/spontaneous/{plugins → model/core}/entries.rb +19 -7
  85. data/lib/spontaneous/{plugins → model/core}/entry.rb +3 -3
  86. data/lib/spontaneous/{plugins → model/core}/fields.rb +38 -5
  87. data/lib/spontaneous/{plugins → model/core}/instance_code.rb +2 -2
  88. data/lib/spontaneous/{plugins → model/core}/media.rb +2 -12
  89. data/lib/spontaneous/{plugins → model/core}/modifications.rb +7 -6
  90. data/lib/spontaneous/model/core/page_search.rb +36 -0
  91. data/lib/spontaneous/{plugins → model/core}/permissions.rb +4 -4
  92. data/lib/spontaneous/{plugins → model/core}/prototypes.rb +4 -4
  93. data/lib/spontaneous/{plugins → model/core}/publishing.rb +93 -115
  94. data/lib/spontaneous/{plugins → model/core}/render.rb +2 -2
  95. data/lib/spontaneous/{plugins → model/core}/schema_hierarchy.rb +7 -11
  96. data/lib/spontaneous/model/core/schema_id.rb +65 -0
  97. data/lib/spontaneous/{plugins → model/core}/schema_title.rb +2 -2
  98. data/lib/spontaneous/{plugins → model/core}/serialisation.rb +2 -2
  99. data/lib/spontaneous/{plugins → model/core}/styles.rb +2 -2
  100. data/lib/spontaneous/{plugins → model/core}/supertype.rb +2 -2
  101. data/lib/spontaneous/{plugins → model/core}/visibility.rb +7 -48
  102. data/lib/spontaneous/model/core.rb +143 -0
  103. data/lib/spontaneous/{plugins → model/page}/controllers.rb +3 -3
  104. data/lib/spontaneous/{plugins → model}/page/formats.rb +2 -2
  105. data/lib/spontaneous/{plugins → model/page}/layouts.rb +2 -2
  106. data/lib/spontaneous/model/page/locks.rb +14 -0
  107. data/lib/spontaneous/{plugins → model/page}/page_tree.rb +3 -3
  108. data/lib/spontaneous/{plugins → model/page}/paths.rb +30 -12
  109. data/lib/spontaneous/{plugins → model}/page/request.rb +2 -2
  110. data/lib/spontaneous/{plugins → model/page}/site_map.rb +2 -2
  111. data/lib/spontaneous/model/page/site_timestamps.rb +44 -0
  112. data/lib/spontaneous/{page.rb → model/page.rb} +49 -28
  113. data/lib/spontaneous/{piece.rb → model/piece.rb} +7 -6
  114. data/lib/spontaneous/model.rb +97 -0
  115. data/lib/spontaneous/output/context.rb +1 -1
  116. data/lib/spontaneous/output/format.rb +4 -0
  117. data/lib/spontaneous/output/template/renderer.rb +2 -2
  118. data/lib/spontaneous/output.rb +2 -2
  119. data/lib/spontaneous/page_lock.rb +62 -0
  120. data/lib/spontaneous/page_piece.rb +1 -1
  121. data/lib/spontaneous/permissions/access_key.rb +9 -4
  122. data/lib/spontaneous/permissions/user.rb +19 -9
  123. data/lib/spontaneous/permissions.rb +2 -5
  124. data/lib/spontaneous/plugins/application/facets.rb +1 -2
  125. data/lib/spontaneous/plugins/application/features.rb +1 -1
  126. data/lib/spontaneous/plugins/application/paths.rb +1 -1
  127. data/lib/spontaneous/plugins/application/render.rb +1 -1
  128. data/lib/spontaneous/plugins/application/serialisation.rb +1 -1
  129. data/lib/spontaneous/plugins/application/state.rb +30 -1
  130. data/lib/spontaneous/plugins/application/system.rb +12 -12
  131. data/lib/spontaneous/prototypes/box_prototype.rb +1 -1
  132. data/lib/spontaneous/prototypes/field_prototype.rb +3 -6
  133. data/lib/spontaneous/prototypes/style_prototype.rb +1 -1
  134. data/lib/spontaneous/publishing/immediate.rb +77 -49
  135. data/lib/spontaneous/publishing/revision.rb +355 -0
  136. data/lib/spontaneous/publishing/simultaneous.rb +10 -49
  137. data/lib/spontaneous/publishing.rb +1 -0
  138. data/lib/spontaneous/rack/around_back.rb +1 -1
  139. data/lib/spontaneous/rack/around_front.rb +2 -4
  140. data/lib/spontaneous/rack/around_preview.rb +1 -1
  141. data/lib/spontaneous/rack/back.rb +80 -63
  142. data/lib/spontaneous/rack/cacheable_file.rb +2 -2
  143. data/lib/spontaneous/rack/cookie_authentication.rb +1 -1
  144. data/lib/spontaneous/rack/front.rb +1 -1
  145. data/lib/spontaneous/rack/helpers.rb +8 -9
  146. data/lib/spontaneous/{page_controller.rb → rack/page_controller.rb} +1 -1
  147. data/lib/spontaneous/rack/public.rb +3 -3
  148. data/lib/spontaneous/rack.rb +15 -15
  149. data/lib/spontaneous/schema/uid.rb +4 -1
  150. data/lib/spontaneous/schema.rb +57 -24
  151. data/lib/spontaneous/search/database.rb +12 -1
  152. data/lib/spontaneous/search/index.rb +34 -6
  153. data/lib/spontaneous/search/results.rb +1 -1
  154. data/lib/spontaneous/server.rb +3 -3
  155. data/lib/spontaneous/simultaneous.rb +53 -0
  156. data/lib/spontaneous/{plugins/site → site}/features.rb +2 -2
  157. data/lib/spontaneous/{plugins/site → site}/helpers.rb +2 -3
  158. data/lib/spontaneous/{plugins/site → site}/hooks.rb +2 -2
  159. data/lib/spontaneous/{plugins/site → site}/instance.rb +4 -6
  160. data/lib/spontaneous/{plugins/site → site}/level.rb +2 -2
  161. data/lib/spontaneous/{plugins/site → site}/map.rb +4 -4
  162. data/lib/spontaneous/{plugins/site → site}/paths.rb +2 -2
  163. data/lib/spontaneous/site/publishing.rb +89 -0
  164. data/lib/spontaneous/{plugins/site → site}/schema.rb +4 -4
  165. data/lib/spontaneous/{plugins/site → site}/search.rb +2 -2
  166. data/lib/spontaneous/{plugins/site → site}/selectors.rb +15 -7
  167. data/lib/spontaneous/{plugins/site → site}/state.rb +2 -2
  168. data/lib/spontaneous/{plugins/site → site}/storage.rb +2 -2
  169. data/lib/spontaneous/{plugins/site → site}/url.rb +2 -2
  170. data/lib/spontaneous/site.rb +31 -14
  171. data/lib/spontaneous/state.rb +5 -6
  172. data/lib/spontaneous/style.rb +3 -2
  173. data/lib/spontaneous/utils/database/mysql_dumper.rb +13 -0
  174. data/lib/spontaneous/utils/database/postgres_dumper.rb +5 -0
  175. data/lib/spontaneous/version.rb +1 -1
  176. data/lib/spontaneous.rb +34 -89
  177. data/spontaneous.gemspec +112 -114
  178. data/test/experimental/test_crypt.rb +158 -0
  179. data/test/experimental/test_features.rb +3 -3
  180. data/test/fixtures/example_application/config/environments/development.rb +1 -1
  181. data/test/fixtures/example_application/lib/content.rb +5 -0
  182. data/test/fixtures/example_application/schema/page.rb +2 -1
  183. data/test/fixtures/example_application/schema/piece.rb +3 -2
  184. data/test/fixtures/serialisation/class_hash.yaml.erb +5 -5
  185. data/test/fixtures/serialisation/root_hash.yaml.erb +8 -0
  186. data/test/functional/test_application.rb +12 -1
  187. data/test/functional/test_back.rb +80 -48
  188. data/test/functional/test_front.rb +39 -46
  189. data/test/functional/test_user_manager.rb +3 -9
  190. data/test/javascript/test_markdown.rb +2 -2
  191. data/test/test_helper.rb +78 -23
  192. data/test/unit/test_alias.rb +21 -15
  193. data/test/unit/test_asset_bundler.rb +3 -3
  194. data/test/unit/test_assets.rb +2 -2
  195. data/test/unit/test_async.rb +7 -6
  196. data/test/unit/test_authentication.rb +43 -37
  197. data/test/unit/test_boxes.rb +46 -21
  198. data/test/unit/test_changesets.rb +65 -20
  199. data/test/unit/test_config.rb +9 -9
  200. data/test/unit/test_content.rb +50 -51
  201. data/test/unit/test_content_inheritance.rb +6 -20
  202. data/test/unit/test_datamapper.rb +1330 -0
  203. data/test/unit/test_datamapper_content.rb +214 -0
  204. data/test/unit/test_fields.rb +543 -54
  205. data/test/unit/test_formats.rb +2 -3
  206. data/test/unit/test_generators.rb +6 -6
  207. data/test/unit/test_helpers.rb +1 -1
  208. data/test/unit/test_image_size.rb +10 -5
  209. data/test/unit/test_images.rb +17 -18
  210. data/test/unit/test_layouts.rb +18 -3
  211. data/test/unit/test_media.rb +74 -49
  212. data/test/unit/test_modifications.rb +43 -43
  213. data/test/unit/test_page.rb +7 -10
  214. data/test/unit/test_permissions.rb +3 -10
  215. data/test/unit/test_piece.rb +5 -6
  216. data/test/unit/test_plugins.rb +7 -14
  217. data/test/unit/test_prototypes.rb +3 -3
  218. data/test/unit/test_publishing.rb +49 -27
  219. data/test/unit/test_render.rb +46 -15
  220. data/test/unit/test_revisions.rb +124 -127
  221. data/test/unit/test_schema.rb +53 -58
  222. data/test/unit/test_search.rb +64 -16
  223. data/test/unit/test_serialisation.rb +4 -11
  224. data/test/unit/test_site.rb +11 -12
  225. data/test/unit/test_structure.rb +2 -5
  226. data/test/unit/test_styles.rb +22 -24
  227. data/test/unit/test_type_hierarchy.rb +7 -5
  228. data/test/unit/test_visibility.rb +79 -55
  229. metadata +128 -102
  230. data/lib/sequel/plugins/content_table_inheritance.rb +0 -203
  231. data/lib/sequel/plugins/scoped_table_name.rb +0 -54
  232. data/lib/spontaneous/content.rb +0 -129
  233. data/lib/spontaneous/field_types/date_field.rb +0 -56
  234. data/lib/spontaneous/field_types/field.rb +0 -302
  235. data/lib/spontaneous/field_types/file_field.rb +0 -68
  236. data/lib/spontaneous/field_types/markdown_field.rb +0 -38
  237. data/lib/spontaneous/field_types/string_field.rb +0 -19
  238. data/lib/spontaneous/field_types/webvideo_field.rb +0 -313
  239. data/lib/spontaneous/field_types.rb +0 -38
  240. data/lib/spontaneous/generators/site/lib/site.rb.tt +0 -4
  241. data/lib/spontaneous/plugins/field/editor_class.rb +0 -13
  242. data/lib/spontaneous/plugins/page/site_timestamps.rb +0 -28
  243. data/lib/spontaneous/plugins/page_search.rb +0 -63
  244. data/lib/spontaneous/plugins/schema_id.rb +0 -68
  245. data/lib/spontaneous/plugins/site/publishing.rb +0 -75
  246. data/lib/spontaneous/rack/fiber_pool.rb +0 -26
  247. data/test/unit/test_table_scoping.rb +0 -80
@@ -1,59 +1,77 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
 
4
- module Spontaneous::Plugins
4
+ module Spontaneous::Model::Core
5
5
  module Publishing
6
- extend ActiveSupport::Concern
6
+ extend Spontaneous::Concern
7
7
 
8
8
  module ClassMethods
9
- @@dataset = nil
10
- @@revision = nil
11
9
 
12
- def current_revision_table
13
- revision_table(@@revision)
14
- end
10
+ # def current_revision_table
11
+ # revision_table(revision)
12
+ # end
15
13
 
16
- def base_table
17
- 'content'
18
- end
14
+ # def base_table
15
+ # mapper.base_table
16
+ # end
19
17
 
20
18
  # make sure that the table name is always the correct revision
21
- def simple_table
22
- current_revision_table
23
- end
19
+ # def simple_table
20
+ # current_revision_table
21
+ # end
24
22
 
25
23
  def revision_table(revision=nil)
26
- return base_table if revision.nil?
27
- "__r#{revision.to_s.rjust(5, '0')}_content"
24
+ mapper.revision_table(revision)
28
25
  end
29
26
 
30
27
  def revision_table?(table_name)
31
- /^__r\d{5}_content$/ === table_name.to_s
28
+ mapper.revision_table?(table_name)
32
29
  end
33
30
 
34
31
  def revision_exists?(revision)
35
- database.tables.include?(revision_table(revision).to_sym)
32
+ Spontaneous::Publishing::Revision.exists?(self, revision)
33
+ # database.tables.include?(revision_table(revision).to_sym)
34
+ end
35
+
36
+ # Returns a list of all tables in the database that represent a content
37
+ # revision.
38
+ def revision_tables
39
+ Spontaneous::Publishing::Revision.tables(self)
40
+ # database.tables.select { |t| revision_table?(t) }.sort
36
41
  end
37
42
 
38
43
  def revision
39
- @@revision
44
+ mapper.current_revision
40
45
  end
41
46
 
42
47
  def with_revision(revision=nil, &block)
43
- saved_revision = @@revision
44
- @@revision = revision
45
- self.with_table(revision_table(revision), &block)
46
- ensure
47
- @@revision = saved_revision
48
+ mapper.revision(revision, &block)
49
+ end
50
+
51
+ def scope(revision = nil, visible = false, &block)
52
+ mapper.scope(revision, visible, &block)
53
+ end
54
+
55
+ # A version of scope that forces the creation of a new scope
56
+ # thus allow us to bypass the cache within a particular block
57
+ def scope!(revision = nil, visible = false, &block)
58
+ mapper.scope!(revision, visible, &block)
48
59
  end
49
60
 
50
61
  def with_editable(&block)
51
- with_revision(nil, &block)
62
+ mapper.editable(&block)
63
+ end
64
+
65
+ def with_editable!(&block)
66
+ mapper.editable!(&block)
52
67
  end
53
68
 
54
69
  def with_published(&block)
55
- revision = Spontaneous::Site.published_revision
56
- with_revision(revision, &block)
70
+ scope(Spontaneous::Site.published_revision, true, &block)
71
+ end
72
+
73
+ def with_published!(&block)
74
+ scope!(Spontaneous::Site.published_revision, true, &block)
57
75
  end
58
76
 
59
77
  def database
@@ -67,92 +85,41 @@ module Spontaneous::Plugins
67
85
  # rows (taking the rest of the content from the previous revision)
68
86
  # Pass in a block if you want to tie some bit of post processing to the success or failure
69
87
  # of the publish step (used in the site render stage for example)
70
- def publish(revision, content=nil)
71
- mark_first_published = Proc.new do |dataset|
72
- dataset.update(:first_published_at => Sequel.datetime_class.now, :first_published_revision => revision)
73
- end
74
-
75
- mark_published = Proc.new do |dataset|
76
- dataset.update(:last_published_at => Sequel.datetime_class.now)
77
- end
78
-
79
- first_published = published = nil
80
-
81
- db.transaction do
82
- with_editable do
83
- first_published = self.filter(:first_published_at => nil)
84
- published = self.filter
85
-
86
- must_publish_all = (content.nil? || (!revision_exists?(revision-1)) || \
87
- (content.is_a?(Array) && content.empty?))
88
-
89
- if must_publish_all
90
- create_revision(revision)
91
- else
92
- content = content.map do |c|
93
- c.is_a?(Spontaneous::Content) ? c.reload : Spontaneous::Content.first(:id => c)
94
- end.compact
95
-
96
- # pages should be published in depth order because its possible to be publishing a child of
97
- # a page that's never been published
98
- content.sort! { |c1, c2| c1.depth <=> c2.depth }
99
-
100
- first_published = first_published.filter(:id => content.map { |c| c.id })
101
- published = published.filter(:id => content.map { |c| c.id })
102
-
103
- create_revision(revision, revision-1)
104
- content.each do |c|
105
- c.sync_to_revision(revision, true)
106
- end
107
- end
108
-
109
- # run any passed code and if it fails revert the publish step
110
- if block_given?
111
- begin
112
- with_revision(revision) { yield }
113
- rescue Exception => e
114
- delete_revision(revision)
115
- raise e
116
- end
117
- end
118
-
119
- with_editable do
120
- mark_first_published[first_published]
121
- mark_published[published]
122
- end
123
- with_revision(revision) do
124
- mark_first_published[first_published]
125
- mark_published[published]
126
- end
127
- end
128
- end
88
+ def publish(revision, content=nil, &block)
89
+ Spontaneous::Publishing::Revision.patch(self, revision, content, &block)
129
90
  end
130
91
 
131
92
  def publish_all(revision, &block)
132
93
  publish(revision, nil, &block)
133
94
  end
134
95
 
135
- def create_revision(revision, from_revision=nil)
136
- dest_table = revision_table(revision)
137
- src_table = revision_table(from_revision)
138
- sql = "CREATE TABLE #{dataset.quote_identifier(dest_table)} AS SELECT * FROM #{dataset.quote_identifier(src_table)}"
139
- database.run(sql)
140
- indexes = database.indexes(base_table)
141
- indexes.each do |name, options|
142
- columns = options.delete(:columns)
143
- database.add_index(dest_table, columns, options)
144
- end
96
+ def cleanup_revisions(current_revision, keep_revisions)
97
+ Spontaneous::Publishing::Revision.cleanup(self, current_revision, keep_revisions)
145
98
  end
146
99
 
100
+ # def delete_revision_table(revision)
101
+ # return if revision.nil?
102
+ # database.drop_table?(revision_table(revision))
103
+ # end
104
+
147
105
  def delete_revision(revision)
148
- return if revision.nil?
149
- database.drop_table?(revision_table(revision))
106
+ Spontaneous::Publishing::Revision.delete(self, revision)
150
107
  end
151
108
 
152
109
  def delete_all_revisions!
153
- database.tables.each do |table|
154
- database.drop_table(table) if revision_table?(table)
155
- end
110
+ Spontaneous::Publishing::Revision.delete_all(self)
111
+ end
112
+
113
+ # def drop_table(table)
114
+ # database.drop_table?(table)
115
+ # end
116
+
117
+ def history_dataset(revision = nil)
118
+ Spontaneous::Publishing::Revision.history_dataset(self, revision)
119
+ end
120
+
121
+ def archive_dataset(revision = nil)
122
+ Spontaneous::Publishing::Revision.archive_dataset(self, revision)
156
123
  end
157
124
  end # ClassMethods
158
125
 
@@ -177,6 +144,11 @@ module Spontaneous::Plugins
177
144
  def with_revision(revision, &block)
178
145
  self.class.with_revision(revision, &block)
179
146
  end
147
+
148
+ def scope(revision, visible, &block)
149
+ self.class.scope(revision, visible, &block)
150
+ end
151
+
180
152
  def with_editable(&block)
181
153
  self.class.with_editable(&block)
182
154
  end
@@ -196,18 +168,18 @@ module Spontaneous::Plugins
196
168
  first_publish = false
197
169
 
198
170
  with_revision(revision) do
199
- published_copy = Spontaneous::Content.first(:id => self.id)
171
+ published_copy = content_model.get(self.id)
200
172
  if published_copy
201
173
  if publish and published_copy.entry_store
202
174
  pieces_to_delete = published_copy.entry_store - self.entry_store
203
175
  pieces_to_delete.each do |entry|
204
- if c = Spontaneous::Content.first(:id => entry[0])
176
+ if c = content_model.get(entry[0])
205
177
  c.destroy(false) rescue ::Sequel::NoExistingObject
206
178
  end
207
179
  end
208
180
  end
209
181
  else # missing content (so force a publish)
210
- Spontaneous::Content.insert({:id => self.id, :type_sid => values[:type_sid]})
182
+ content_model.insert({:id => self.id, :type_sid => attributes[:type_sid]})
211
183
  publish = true
212
184
  first_publish = true
213
185
  end
@@ -224,14 +196,14 @@ module Spontaneous::Plugins
224
196
  sync_children_to_revision(revision)
225
197
  end
226
198
 
227
- Spontaneous::Content.where(:id => self.id).update(values)
199
+ content_model.where(:id => self.id).update(attributes)
228
200
 
229
201
  published_values = {}
230
202
  # ancestors can have un-published changes to their paths so we can't just directly publish the current path.
231
203
  # Instead we re-calculate our path using the published version of the ancestor's path & our (potentially) updated slug.
232
204
  if self.page?
233
- published = self.class.first :id => self.id
234
- published_values[:path] = published.calculate_path_with_slug(values[:slug])
205
+ published = self.class.get(self.id)
206
+ published_values[:path] = published.calculate_path_with_slug(attributes[:slug])
235
207
  end
236
208
 
237
209
  # need to calculate the correct visibility for published items. I can't just take this from the editable
@@ -244,7 +216,7 @@ module Spontaneous::Plugins
244
216
  published_values[:hidden] = self.recalculated_hidden unless self.hidden_origin.blank?
245
217
 
246
218
  unless published_values.empty?
247
- Spontaneous::Content.where(:id => self.id).update(published_values)
219
+ content_model.where(:id => self.id).update(published_values)
248
220
  end
249
221
 
250
222
  # Pages that haven't been published before can be published independently of their parents.
@@ -257,9 +229,9 @@ module Spontaneous::Plugins
257
229
  end
258
230
 
259
231
  def sync_children_to_revision(revision)
260
- published_children = with_revision(revision) { S::Content.filter(:parent_id => self.id) }
232
+ published_children = with_revision(revision) { content_model.filter(:parent_id => self.id) }
261
233
  published_children.each do |child_page|
262
- deleted = with_editable { S::Content.select(:id).first(:id => child_page.id).nil? }
234
+ deleted = with_editable { content_model.select(:id).get(child_page.id).nil? }
263
235
  if deleted
264
236
  with_revision(revision) do
265
237
  child_page.destroy
@@ -272,18 +244,24 @@ module Spontaneous::Plugins
272
244
  # of the newly published page. Positions are not exact as other child pages might not have
273
245
  # been published.
274
246
  def insert_entry_for_new_page(revision)
275
- detect_entry = proc { |e| e[0] == self.id }
247
+ return if parent_id.nil?
248
+ this = self.id
249
+ detect_entry = proc { |e| e[0] == this }
276
250
 
277
- parent_entry_store = with_editable { self.parent.entry_store.dup }
251
+ parent_entry_store = with_editable {
252
+ content_model[self.parent_id].entry_store.dup
253
+ }
278
254
  entry = parent_entry_store.find(&detect_entry)
279
255
  index = parent_entry_store.index(&detect_entry)
280
- published_parent = Spontaneous::Content.first :id => parent_id
256
+ published_parent = content_model.get(parent_id)
281
257
 
282
- published_parent.entry_store ||= []
258
+ store = published_parent.entry_store || []
283
259
 
284
- unless published_parent.entry_store.find(&detect_entry)
285
- published_parent.entry_store.insert(index, entry).compact!
260
+ unless store.find(&detect_entry)
261
+ store.insert(index, entry).compact!
262
+ published_parent.entry_store = store
286
263
  end
264
+
287
265
  published_parent.save
288
266
  end
289
267
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Render
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  def output(format = :html)
8
8
  return page.output(format, self) if page
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module SchemaHierarchy
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
8
  def schema_validate(schema)
@@ -56,7 +56,7 @@ module Spontaneous::Plugins
56
56
  end
57
57
 
58
58
  def __source_file=(path)
59
- @__source_file = path
59
+ @__source_file ||= path
60
60
  end
61
61
 
62
62
  protected(:__source_file=)
@@ -65,17 +65,13 @@ module Spontaneous::Plugins
65
65
  @__source_file
66
66
  end
67
67
 
68
- def subclasses
69
- Spontaneous.schema.subclasses_of(self)
70
- end
71
-
72
- def descendents
73
- Spontaneous.schema.descendents_of(self)
68
+ def __determine_source_file(subclass, _caller)
69
+ src = File.expand_path(_caller.split(':')[0])
70
+ subclass.__source_file = src
74
71
  end
75
72
 
76
73
  def inherited(subclass, real_caller = nil)
77
- subclass.__source_file = File.expand_path((real_caller || caller[0]).split(':')[0])
78
- Spontaneous.schema.add_class(self, subclass)# if subclass.schema_class?
74
+ __determine_source_file(subclass, real_caller || caller[0])
79
75
  super(subclass)
80
76
  end
81
77
 
@@ -0,0 +1,65 @@
1
+ # encoding: UTF-8
2
+
3
+ module Spontaneous::Model::Core
4
+ module SchemaId
5
+ extend Spontaneous::Concern
6
+
7
+ module ClassMethods
8
+ def schema_id
9
+ mapper.schema.to_id(self)
10
+ end
11
+
12
+ def schema_name
13
+ "type//#{self.name}"
14
+ end
15
+
16
+ def schema_owner
17
+ nil
18
+ end
19
+
20
+ def owner_sid
21
+ nil
22
+ end
23
+ end # ClassMethods
24
+
25
+ # InstanceMethods
26
+
27
+ SCHEMA_ID_COLUMNS = [:type, :style, :box]
28
+ SCHEMA_ID_COLUMNS.each do |c|
29
+ column = "#{c}_sid"
30
+ self.class_eval(<<-RUBY, __FILE__, __LINE__)
31
+ def #{column}
32
+ @_#{column}_sid ||= Spontaneous.schema.uids[super]
33
+ end
34
+
35
+ def #{column}=(sid)
36
+ @_#{column}_sid = Spontaneous.schema.uids[sid]
37
+ super(@_#{column}_sid.to_s)
38
+ end
39
+ RUBY
40
+ end
41
+
42
+ def refresh
43
+ SCHEMA_ID_COLUMNS.map { |s| "@_#{s}_sid" }.each do |s|
44
+ remove_instance_variable(s) if instance_variable_defined?(s)
45
+ end
46
+ super
47
+ end
48
+
49
+ def schema_id
50
+ self.class.schema_id
51
+ end
52
+
53
+ def schema_name
54
+ self.class.schema_name
55
+ end
56
+
57
+ def schema_owner
58
+ self.class.schema_owner
59
+ end
60
+
61
+ def owner_sid
62
+ self.class.owner_sid
63
+ end
64
+ end # SchemaId
65
+ end
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module SchemaTitle
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
8
  def class_name_with_fallback
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Serialisation
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
8
  def export(user = nil)
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Styles
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
8
  def style(name, options={})
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Supertype
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
8
  def supertype
@@ -1,59 +1,18 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Visibility
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
- @@visible_filter = false
9
-
10
- def _set_visible_dataset!
11
- @_saved_dataset ||= self.dataset
12
- ds = filter_visible self.dataset
13
- @dataset = ds
14
- # set_dataset clears the row_proc which desroys the STI
15
- # self.set_dataset(ds)
16
- end
17
-
18
- def _restore_dataset!
19
- # self.set_dataset( self.dataset.unfiltered) if @_saved_dataset
20
- @dataset = @_saved_dataset if @_saved_dataset
21
- @_saved_dataset = nil
22
- end
23
-
24
- def _content_classes
25
- [Spontaneous::Content, Spontaneous::Page, Spontaneous::Piece] + Spontaneous.schema.content_classes
26
- end
27
-
28
- def _unfiltered_dataset
29
- @_saved_dataset or dataset
30
- end
31
-
32
8
  def with_visible(&block)
33
- if @@visible_filter
9
+ mapper.visible do
34
10
  yield
35
- else
36
- begin
37
- Spontaneous::Content._set_visible_dataset!
38
- @@visible_filter = true
39
- yield
40
- ensure
41
- @@visible_filter = false
42
- Spontaneous::Content._restore_dataset!
43
- end
44
11
  end
45
12
  end
46
13
 
47
14
  def visible_only?
48
- @@visible_filter
49
- end
50
-
51
- def visible
52
- filter_visible self.dataset
53
- end
54
-
55
- def filter_visible(dataset)
56
- dataset.filter(:hidden => false)
15
+ mapper.visible_only?
57
16
  end
58
17
  end # ClassMethods
59
18
 
@@ -139,7 +98,7 @@ module Spontaneous::Plugins
139
98
  end
140
99
 
141
100
  def hide_aliases(visible)
142
- dataset = Spontaneous::Content.filter(:target_id => self.id)
101
+ dataset = content_model.filter(:target_id => self.id)
143
102
  origin = visible ? nil : self.id
144
103
  dataset.update(:hidden => !visible, :hidden_origin => origin)
145
104
  end
@@ -147,7 +106,7 @@ module Spontaneous::Plugins
147
106
  def hide_descendents(visible)
148
107
  path_like = :visibility_path.like("#{self[:visibility_path]}.#{self.id}%")
149
108
  origin = visible ? nil : self.id
150
- dataset = Spontaneous::Content.filter(path_like).filter(:hidden => visible)
109
+ dataset = content_model.filter(path_like).filter(:hidden => visible)
151
110
  # if a child item has been made invisible *before* its parent then it exists
152
111
  # with hidden = true and hidden_origin = nil
153
112
  if visible
@@ -169,7 +128,7 @@ module Spontaneous::Plugins
169
128
 
170
129
  def visibility_ancestors
171
130
  return [] if visibility_path.blank?
172
- visibility_path.split(Spontaneous::VISIBILITY_PATH_SEP).map { |id| S::Content[id] }
131
+ visibility_path.split(Spontaneous::VISIBILITY_PATH_SEP).map { |id| content_model[id] }
173
132
  end
174
133
 
175
134
  def recalculated_hidden