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
@@ -5,7 +5,8 @@ require 'digest/sha1'
5
5
  module Spontaneous
6
6
  module Media
7
7
 
8
- autoload :File, "spontaneous/media/file"
8
+ autoload :File, "spontaneous/media/file"
9
+ autoload :TempFile, "spontaneous/media/temp_file"
9
10
 
10
11
  include Spontaneous::Constants
11
12
 
@@ -15,25 +16,6 @@ module Spontaneous
15
16
  ::File.join(Spontaneous.media_dir, *args)
16
17
  end
17
18
 
18
- @@upload_uid_lock = Mutex.new
19
- @@upload_uid_index = 0
20
-
21
- def upload_index
22
- @@upload_uid_lock.synchronize do
23
- @@upload_uid_index = (@@upload_uid_index + 1) % 0xFFFFFF
24
- end
25
- end
26
-
27
- def upload_path(filename)
28
- time = Time.now.to_i
29
- dir = "#{time}.#{upload_index}"
30
- Spontaneous.cache_path("tmp", dir, filename)
31
- end
32
-
33
- # def to_urlpath(filepath)
34
- # filepath.gsub(%r{^#{Spontaneous.media_dir}}, "/media")
35
- # end
36
-
37
19
  def to_filepath(urlpath)
38
20
  parts = urlpath.split("/")
39
21
  parts[1] = Spontaneous.media_dir
@@ -52,6 +34,14 @@ module Spontaneous
52
34
  end
53
35
 
54
36
 
37
+ def pad_id(r)
38
+ r.to_s.rjust(5, "0")
39
+ end
40
+
41
+ def pad_revision(r)
42
+ r.to_s.rjust(4, "0")
43
+ end
44
+
55
45
  def sha1(filepath)
56
46
  Digest::SHA1.file(filepath).hexdigest
57
47
  end
@@ -61,27 +51,18 @@ module Spontaneous
61
51
  def combine_shards(hashes, &block)
62
52
  hashes = hashes.split(',') unless hashes.is_a?(Array)
63
53
  shards = hashes.map { |hash| Spontaneous.shard_path(hash) }
64
- combined = Tempfile.new('shard')
65
- combined.binmode
66
-
67
- shards.each do |shard|
68
- ::File.open(shard, 'rb') do |part|
69
- while data = part.read(131072)
70
- combined.write(data)
54
+ Tempfile.open('shard') do |combined|
55
+ combined.binmode
56
+ shards.each do |shard|
57
+ ::File.open(shard, 'rb') do |part|
58
+ while (data = part.read(131072))
59
+ combined.write(data)
60
+ end
71
61
  end
72
62
  end
73
- end
74
- combined.close
75
-
76
- if block_given?
77
- begin
78
- yield(combined)
79
- ensure
80
- combined.close!
81
- end
82
- else
83
- # caller's responsibility to close & delete tempfile
84
- combined
63
+ combined.flush
64
+ combined.rewind
65
+ yield(combined) if block_given?
85
66
  end
86
67
  end
87
68
 
@@ -1,15 +1,17 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Box
4
4
  module AllowedTypes
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  class AllowedType
8
8
  attr_accessor :allow_subclasses
9
9
 
10
- def initialize(type, options={})
11
- @type = type
12
- @options = options
10
+ def initialize(box, type, options={}, &definition)
11
+ @box_class = box
12
+ @type = type
13
+ @options = options
14
+ define_instance_class(definition) if definition
13
15
  end
14
16
 
15
17
  def check_instance_class
@@ -31,13 +33,15 @@ module Spontaneous::Plugins
31
33
  resolve_instance_class(@type)
32
34
  end
33
35
 
34
- def resolve_instance_class(name)
35
- case name
36
- when Class
37
- name
38
- when Symbol, String
39
- name.to_s.constantize
40
- end
36
+ def define_instance_class(definition)
37
+ content_type = Class.new(instance_class_supertype, &definition)
38
+ @box_class.const_set @type, content_type
39
+ @type = content_type.name
40
+ end
41
+
42
+ def instance_class_supertype
43
+ type = @options[:supertype] || (defined?(::Piece) ? ::Piece : Content::Piece)
44
+ constantize type
41
45
  end
42
46
 
43
47
  def styles(content)
@@ -93,6 +97,21 @@ module Spontaneous::Plugins
93
97
  Spontaneous::Permissions.has_level?(user, user_level)
94
98
  end
95
99
  alias_method :addable?, :readable?
100
+
101
+ protected
102
+
103
+ def resolve_instance_class(name)
104
+ constantize(name)
105
+ end
106
+
107
+ def constantize(name)
108
+ case name
109
+ when Class
110
+ name
111
+ when Symbol, String
112
+ name.to_s.constantize
113
+ end
114
+ end
96
115
  end
97
116
 
98
117
  class AllowedGroup < AllowedType
@@ -102,7 +121,7 @@ module Spontaneous::Plugins
102
121
 
103
122
  def instance_classes
104
123
  schema = Spontaneous::Site.schema
105
- names = groups.flat_map { |name| Spontaneous::Site.schema.groups[name] }
124
+ names = groups.flat_map { |name| schema.groups[name] }
106
125
  names.map { |name| resolve_instance_class(name) }.uniq
107
126
  end
108
127
 
@@ -135,13 +154,15 @@ module Spontaneous::Plugins
135
154
  # :prototype => The name of the prototype to use when creating pieces of this type
136
155
  #
137
156
  # TODO: finish these!
138
- def allow(type, options={})
139
- allowed_types_config << AllowedType.new(type, options)
157
+ def allow(type, options={}, &definition)
158
+ allowed = AllowedType.new(self, type, options, &definition)
159
+ allowed_types_config << allowed
160
+ allowed
140
161
  end
141
162
 
142
163
  # TODO: implement this in a way that doesn't require searching through constants at load-time
143
164
  def allow_subclasses(type, options = {})
144
- parent_type = AllowedType.new(type)
165
+ parent_type = AllowedType.new(self, type)
145
166
  parent_type.allow_subclasses = true
146
167
  allowed_types_config << parent_type
147
168
  # parent_type.instance_class.subclasses.each do |subclass|
@@ -151,7 +172,7 @@ module Spontaneous::Plugins
151
172
 
152
173
  def allow_group(*group_names)
153
174
  options = group_names.extract_options!
154
- allowed_types_config << AllowedGroup.new(group_names, options)
175
+ allowed_types_config << AllowedGroup.new(self, group_names, options)
155
176
  end
156
177
 
157
178
  alias_method :allow_groups, :allow_group
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+
3
+ module Spontaneous::Model
4
+ module Box
5
+ autoload :AllowedTypes, "spontaneous/model/box/allowed_types"
6
+
7
+ extend Spontaneous::Concern
8
+
9
+ module ClassMethods
10
+
11
+ def inherited(subclass)
12
+ subclass.instance_variable_set(:"@mapper", mapper)
13
+ mapper.schema.inherited(self, subclass)
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,17 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
 
4
- module Spontaneous::Plugins
4
+ module Spontaneous::Model::Core
5
5
  module Aliases
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- # '__target' rather than 'target' because we want to override the behaviour of the
10
- # Content#target method only on classes that are aliases, and this is defined dynamically
11
- many_to_one :__target, :class => self, :key => :target_id, :reciprocal => :aliases
12
- one_to_many :aliases, :class => self, :key => :target_id, :reciprocal => :__target
13
- add_association_dependencies :aliases => :destroy
14
- end
6
+ extend Spontaneous::Concern
15
7
 
16
8
  module ClassMethods
17
9
  def alias_of(*args)
@@ -38,10 +30,14 @@ module Spontaneous::Plugins
38
30
  when Proc
39
31
  targets.concat(source[*proc_args])
40
32
  else
41
- classes.concat(source.to_s.constantize.sti_subclasses_array)
33
+ type = source.to_s.constantize
34
+ classes.push(type)
35
+ classes.concat(type.subclasses)
42
36
  end
43
37
  end
44
- query = S::Content.filter(sti_key => classes.map { |c| c.to_s })
38
+
39
+ query = content_model.filter(:type_sid => classes.map { |c| c.schema_id })
40
+
45
41
  if (container_procs = @alias_options[:container])
46
42
  containers = [container_procs].flatten.map { |p| p[*proc_args] }.flatten
47
43
  params = []
@@ -50,7 +46,7 @@ module Spontaneous::Plugins
50
46
  params << Sequel::SQL::BooleanExpression.new(:'=', :page_id, container.id)
51
47
  else
52
48
  box_params = [
53
- [:box_sid, container.id],
49
+ [:box_sid, container.schema_id],
54
50
  [:owner_id, container.owner.id]
55
51
  ]
56
52
  params << Sequel::SQL::BooleanExpression.from_value_pairs(box_params, :AND)
@@ -174,7 +170,7 @@ module Spontaneous::Plugins
174
170
 
175
171
  def exported_target(user = nil)
176
172
  case target
177
- when S::Content
173
+ when Spontaneous::Content
178
174
  target.shallow_export(user)
179
175
  else
180
176
  target.to_json
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Boxes
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
8
  def box(name, options = {}, &block)
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module ContentGroups
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
8
  attr_reader :group_memberships
@@ -0,0 +1,4 @@
1
+ # encoding: UTF-8
2
+
3
+ module Spontaneous::Model::Core::Field
4
+ end
@@ -1,12 +1,17 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Entries
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
- included do
8
- alias_method :<<, :push
9
- end
7
+ # before_include do
8
+ # puts "owner= defined?"
9
+ # p method_defined?(:owner=)
10
+ # end
11
+
12
+ # included do
13
+ # # alias_method :<<, :push
14
+ # end
10
15
  #
11
16
  # def self.configure(base)
12
17
  # base.__send__(:alias_method, :<<, :push)
@@ -29,6 +34,10 @@ module Spontaneous::Plugins
29
34
  super
30
35
  end
31
36
 
37
+ def depth
38
+ super || 0
39
+ end
40
+
32
41
  def after_save
33
42
  contents.each do |entry|
34
43
  entry.save if entry.modified?
@@ -71,7 +80,7 @@ module Spontaneous::Plugins
71
80
  end
72
81
 
73
82
  def contents
74
- return visible_contents if Spontaneous::Content.visible_only?
83
+ return visible_contents if model.visible_only?
75
84
  all_contents
76
85
  end
77
86
 
@@ -106,6 +115,8 @@ module Spontaneous::Plugins
106
115
  insert(-1, page_or_piece)
107
116
  end
108
117
 
118
+ alias_method :<<, :push
119
+
109
120
  def insert(index, page_or_piece, box)
110
121
  save if new?
111
122
  if page_or_piece.page?
@@ -135,7 +146,7 @@ module Spontaneous::Plugins
135
146
  end
136
147
 
137
148
  def insert_with_style(type, index, content, box)
138
- self._pieces << content
149
+ self.pieces << content
139
150
  entry_style = style_for_content(content, box)
140
151
  content.box_sid = box.schema_id if box
141
152
  content._prototype = box.prototype_for_content(content) if box
@@ -195,6 +206,7 @@ module Spontaneous::Plugins
195
206
  content.class.styles
196
207
  end
197
208
 
209
+
198
210
  def owner=(owner)
199
211
  super
200
212
  set_visibility_path
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Entry
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  # InstanceMethods
8
8
 
@@ -13,7 +13,7 @@ module Spontaneous::Plugins
13
13
  end
14
14
 
15
15
  def box_sid
16
- @box_sid ||= Spontaneous.schema.uids[self[:box_sid]]
16
+ @box_sid ||= mapper.schema_uid(self[:box_sid])
17
17
  end
18
18
 
19
19
  def box_sid=(sid)
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Fields
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
8
  def field(name, type=nil, options={}, &block)
@@ -81,7 +81,7 @@ module Spontaneous::Plugins
81
81
  end
82
82
 
83
83
  def field_versions(field)
84
- Spontaneous::FieldVersion.filter(:content_id => self.id, :field_sid => field.schema_id.to_s).order(:created_at.desc)
84
+ Spontaneous::Field::FieldVersion.filter(:content_id => self.id, :field_sid => field.schema_id.to_s).order(:created_at.desc)
85
85
  end
86
86
 
87
87
  def save_field_versions
@@ -108,8 +108,41 @@ module Spontaneous::Plugins
108
108
  end
109
109
 
110
110
  # TODO: unify the update mechanism for these two stores
111
- def field_modified!(modified_field)
112
- self.field_store = @field_set.serialize_db
111
+ def field_modified!(modified_field = nil)
112
+ serialize_fields
113
+ end
114
+
115
+ def serialize_fields(fields = nil)
116
+ self.field_store = update_serialized_fields(fields)
117
+ end
118
+
119
+ def update_serialized_fields(fields = nil)
120
+ if fields.nil?
121
+ @field_set.serialize_db
122
+ else
123
+ field_store = (self.field_store || []).dup
124
+ fields.each do |field|
125
+ before_save_field(field)
126
+ schema_id = field.schema_id.to_s
127
+ if (index = field_store.index { |f| f[0] == schema_id })
128
+ field_store[index.to_i] = field.serialize_db
129
+ else
130
+ field_store << field.serialize_db
131
+ end
132
+ end
133
+ field_store
134
+ end
135
+ end
136
+
137
+ def before_save_field(field)
138
+ end
139
+
140
+ # Re-serializes the field store.
141
+ #
142
+ # If fields is given then only the fields included in it will be written
143
+ def save_fields(fields = nil)
144
+ serialize_fields(fields)
145
+ save
113
146
  end
114
147
 
115
148
  def type_for_mime_type(mime_type)
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module InstanceCode
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  # InstanceMethods
8
8
 
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Media
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  # InstanceMethods
8
8
 
@@ -26,15 +26,5 @@ module Spontaneous::Plugins
26
26
  def padded_revision
27
27
  Spontaneous::Site.working_revision.to_s.rjust(4, "0")
28
28
  end
29
-
30
- # TODO: Is this still used? It shouldn't be
31
- def make_media_file(src_file, filename = nil)
32
- filename ||= File.basename(src_file)
33
- filename = Spontaneous::Media.to_filename(filename)
34
- media_filepath = media_filepath(filename)
35
- FileUtils.mkdir_p(File.dirname(media_filepath))
36
- FileUtils.cp(src_file, media_filepath)
37
- media_filepath
38
- end
39
29
  end
40
30
  end
@@ -1,7 +1,7 @@
1
- module Spontaneous::Plugins
1
+ module Spontaneous::Model::Core
2
2
  # Modifications is responsible for tracking changes made to Content items
3
3
  module Modifications
4
- extend ActiveSupport::Concern
4
+ extend Spontaneous::Concern
5
5
 
6
6
  class SlugModification
7
7
  def self.type
@@ -27,7 +27,7 @@ module Spontaneous::Plugins
27
27
 
28
28
  def dataset
29
29
  path_like = :ancestor_path.like("#{owner[:ancestor_path]}.#{owner.id}%")
30
- Spontaneous::Content.filter(path_like)
30
+ owner.content_model.filter(path_like)
31
31
  end
32
32
 
33
33
  def count
@@ -70,14 +70,14 @@ module Spontaneous::Plugins
70
70
 
71
71
  def apply(revision)
72
72
  owner.with_revision(revision) do
73
- published = Spontaneous::Content.first :id => owner.id
73
+ published = owner.content_model.get(owner.id)
74
74
  published.set_visible_with_cascade!(!new_value)
75
75
  end
76
76
  end
77
77
 
78
78
  def dataset
79
79
  path_like = :visibility_path.like("#{owner[:visibility_path]}.#{owner.id}%")
80
- Spontaneous::Page.filter(path_like)
80
+ owner.content_model::Page.filter(path_like)
81
81
  end
82
82
  end
83
83
 
@@ -116,6 +116,7 @@ module Spontaneous::Plugins
116
116
  # This is to correctly map changes to a list of pages to publish. In the case of a page
117
117
  # addition the change is owned by the new page.
118
118
  self.modified_at = Time.now unless @__ignore_page_modification or changed_columns.empty?
119
+ @__ignore_page_modification = false
119
120
  # marks this object as the modified object appending modifications to the list
120
121
  # needed in order to know if changes to the modification list will be saved automatically
121
122
  # or if we need an explicit call to #save
@@ -150,7 +151,7 @@ module Spontaneous::Plugins
150
151
 
151
152
  def create_deletion_modifications
152
153
  if @child_page_deletion_count && @child_page_deletion_count > 0
153
- count = S::Page.count
154
+ count = content_model::Page.count
154
155
  append_modification DeletionModification.new(self, current_editor, Time.now, count + @child_page_deletion_count, count)
155
156
  end
156
157
  end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+
3
+ module Spontaneous::Model::Core
4
+ module PageSearch
5
+ extend Spontaneous::Concern
6
+
7
+ module ClassMethods
8
+ # An uncached test for the existance of a site home/root page.
9
+ def has_root?
10
+ content_model.filter(:path => Spontaneous::SLASH).count > 0
11
+ end
12
+
13
+ def root
14
+ path(Spontaneous::SLASH)
15
+ end
16
+
17
+ def uid(uid)
18
+ first_visible("uid:#{uid}", :uid => uid)
19
+ end
20
+
21
+ def path(path)
22
+ first_visible("path:#{path}", :path => path)
23
+ end
24
+
25
+ def first_visible(cache_key, params)
26
+ mapper.with_cache(cache_key) {
27
+ page = content_model.first(params)
28
+ # don't want to return nil if a page matching the params exists but is hidden
29
+ # if we return blank we force searches via other routes (such as aliased pages)
30
+ return false if page and mapper.visible_only? and page.hidden?
31
+ page
32
+ }
33
+ end
34
+ end # ClassMethods
35
+ end
36
+ end
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Permissions
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  module ClassMethods
8
8
  def box_readable?(user, box_name)
@@ -21,7 +21,7 @@ module Spontaneous::Plugins
21
21
  end
22
22
 
23
23
  def field_permission(user, field_name, test)
24
- return true unless user# = Spontaneous::Permissions.active_user
24
+ return true unless user
25
25
  if field = field_prototypes[field_name.to_sym]
26
26
  user.level >= field.__send__(test)
27
27
  else
@@ -30,7 +30,7 @@ module Spontaneous::Plugins
30
30
  end
31
31
 
32
32
  def box_permission(user, box_name, test)
33
- return true unless user# = Spontaneous::Permissions.active_user
33
+ return true unless user
34
34
  if box = boxes[box_name.to_sym]
35
35
  user.level >= box.__send__(test)
36
36
  else
@@ -1,8 +1,8 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module Spontaneous::Plugins
3
+ module Spontaneous::Model::Core
4
4
  module Prototypes
5
- extend ActiveSupport::Concern
5
+ extend Spontaneous::Concern
6
6
 
7
7
  DEFAULT_PROTOTYPE_NAME = :__default_prototype unless defined?(DEFAULT_PROTOTYPE_NAME)
8
8
 
@@ -47,7 +47,7 @@ module Spontaneous::Plugins
47
47
  end
48
48
 
49
49
  def prototype_method_name(name)
50
- return Spontaneous::Plugins::Prototypes::DEFAULT_PROTOTYPE_NAME if name.blank?
50
+ return Spontaneous::Model::Core::Prototypes::DEFAULT_PROTOTYPE_NAME if name.blank?
51
51
  "_apply_prototype_#{name}"
52
52
  end
53
53
  end # ClassMethods
@@ -60,7 +60,7 @@ module Spontaneous::Plugins
60
60
  end
61
61
 
62
62
  # Add in an empty default prototype method for subclasses to override
63
- define_method(Spontaneous::Plugins::Prototypes::DEFAULT_PROTOTYPE_NAME) { |instance| }
63
+ define_method(Spontaneous::Model::Core::Prototypes::DEFAULT_PROTOTYPE_NAME) { |instance| }
64
64
 
65
65
  protected
66
66