spontaneous 0.2.0.beta5 → 0.2.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +39 -0
  4. data/Gemfile +2 -0
  5. data/Readme.markdown +4 -4
  6. data/application/css/core.css.scss +144 -43
  7. data/application/css/definitions.css.scss +50 -16
  8. data/application/css/dialogue.css.scss +5 -2
  9. data/application/css/editing.css.scss +7 -7
  10. data/application/css/font.css.scss +1 -1
  11. data/application/css/meta.css.scss +6 -6
  12. data/application/css/popover.css.scss +6 -6
  13. data/application/css/top.css.scss +8 -1
  14. data/application/js/add_alias_dialogue.js +137 -36
  15. data/application/js/add_home_dialogue.js +10 -10
  16. data/application/js/ajax.js +26 -26
  17. data/application/js/authentication.js +2 -2
  18. data/application/js/box.js +21 -10
  19. data/application/js/box_container.js +13 -7
  20. data/application/js/compatibility.js +19 -17
  21. data/application/js/conflicted_field_dialogue.js +5 -5
  22. data/application/js/content.js +22 -16
  23. data/application/js/content_area.js +62 -33
  24. data/application/js/dialogue.js +16 -16
  25. data/application/js/dom.js +9 -10
  26. data/application/js/edit_panel.js +25 -20
  27. data/application/js/editing.js +21 -8
  28. data/application/js/entry.js +1 -1
  29. data/application/js/extensions.js +11 -11
  30. data/application/js/field/boolean.js +6 -6
  31. data/application/js/field/date.js +1 -1
  32. data/application/js/field/file.js +17 -17
  33. data/application/js/field/image.js +27 -27
  34. data/application/js/field/markdown.js +72 -71
  35. data/application/js/field/select.js +9 -9
  36. data/application/js/field/string.js +3 -3
  37. data/application/js/field/webvideo.js +2 -2
  38. data/application/js/field_preview.js +3 -0
  39. data/application/js/init.js +3 -2
  40. data/application/js/jquery-selection-position.js +13 -13
  41. data/application/js/location.js +17 -12
  42. data/application/js/login.js +2 -2
  43. data/application/js/meta_view/user_admin.js +101 -101
  44. data/application/js/metadata.js +1 -1
  45. data/application/js/page.js +2 -2
  46. data/application/js/page_browser.js +13 -13
  47. data/application/js/page_entry.js +1 -1
  48. data/application/js/panel/root_menu.js +10 -10
  49. data/application/js/popover.js +6 -5
  50. data/application/js/popover_view.js +5 -5
  51. data/application/js/preview.js +10 -4
  52. data/application/js/progress.js +6 -6
  53. data/application/js/properties.js +35 -6
  54. data/application/js/publish.js +43 -43
  55. data/application/js/require.js +14 -14
  56. data/application/js/services.js +3 -3
  57. data/application/js/sharded_upload.js +9 -8
  58. data/application/js/side_bar.js +5 -5
  59. data/application/js/state.js +2 -2
  60. data/application/js/status_bar.js +6 -6
  61. data/application/js/top_bar.js +97 -65
  62. data/application/js/types.js +9 -6
  63. data/application/js/upload.js +4 -4
  64. data/application/js/upload_manager.js +21 -21
  65. data/application/js/user.js +1 -1
  66. data/application/js/vendor/jquery.velocity.min.js +7 -0
  67. data/application/js/views.js +32 -8
  68. data/application/js/views/box_view.js +51 -31
  69. data/application/js/views/page_piece_view.js +17 -15
  70. data/application/js/views/page_view.js +54 -43
  71. data/application/js/views/piece_view.js +44 -37
  72. data/application/static/font/fontawesome-webfont-4f0022f25672c7f501c339cbf98d9117.ttf +0 -0
  73. data/application/views/index.erb +1 -0
  74. data/db/migrations/20130114120000_create_revision_tables.rb +2 -1
  75. data/db/migrations/20130813111009_increase_path_length.rb +11 -2
  76. data/db/migrations/20140506171823_add_index_to_target_id.rb +11 -0
  77. data/db/migrations/20140514090204_add_content_hash.rb +59 -0
  78. data/db/migrations/20140519150253_add_content_hash_timestamp.rb +20 -0
  79. data/lib/spontaneous.rb +0 -1
  80. data/lib/spontaneous/asset/environment.rb +77 -15
  81. data/lib/spontaneous/box.rb +21 -0
  82. data/lib/spontaneous/capistrano/deploy.rb +1 -1
  83. data/lib/spontaneous/capistrano/sync.rb +8 -7
  84. data/lib/spontaneous/change.rb +4 -2
  85. data/lib/spontaneous/cli/fields.rb +7 -3
  86. data/lib/spontaneous/cli/generate.rb +2 -0
  87. data/lib/spontaneous/cli/init.rb +24 -93
  88. data/lib/spontaneous/cli/init/db.rb +94 -0
  89. data/lib/spontaneous/cli/init/mysql.rb +17 -0
  90. data/lib/spontaneous/cli/init/postgresql.rb +33 -0
  91. data/lib/spontaneous/cli/init/sqlite.rb +14 -0
  92. data/lib/spontaneous/cli/site.rb +45 -20
  93. data/lib/spontaneous/collections/box_set.rb +3 -0
  94. data/lib/spontaneous/collections/entry_set.rb +43 -4
  95. data/lib/spontaneous/collections/field_set.rb +14 -2
  96. data/lib/spontaneous/data_mapper.rb +40 -7
  97. data/lib/spontaneous/data_mapper/content_model.rb +1 -1
  98. data/lib/spontaneous/data_mapper/content_model/associations.rb +63 -12
  99. data/lib/spontaneous/data_mapper/content_model/timestamps.rb +9 -14
  100. data/lib/spontaneous/data_mapper/content_table.rb +4 -2
  101. data/lib/spontaneous/data_mapper/dataset.rb +31 -2
  102. data/lib/spontaneous/data_mapper/scope.rb +37 -20
  103. data/lib/spontaneous/errors.rb +6 -0
  104. data/lib/spontaneous/facet.rb +20 -10
  105. data/lib/spontaneous/field/base.rb +8 -1
  106. data/lib/spontaneous/field/file.rb +28 -3
  107. data/lib/spontaneous/field/image.rb +2 -0
  108. data/lib/spontaneous/field/update.rb +6 -0
  109. data/lib/spontaneous/field/webvideo/vimeo.rb +6 -1
  110. data/lib/spontaneous/field/webvideo/vine.rb +1 -1
  111. data/lib/spontaneous/field/webvideo/youtube.rb +1 -1
  112. data/lib/spontaneous/generators/site.rb +6 -4
  113. data/lib/spontaneous/generators/site/.gitignore +1 -0
  114. data/lib/spontaneous/generators/site/Gemfile.tt +3 -3
  115. data/lib/spontaneous/generators/site/config/{indexes.rb.tt → initializers/indexes.rb.tt} +0 -0
  116. data/lib/spontaneous/generators/site/config/initializers/publishing.rb.tt +78 -0
  117. data/lib/spontaneous/generators/site/{config/database.yml.tt → db/mysql2.yml.tt} +7 -6
  118. data/lib/spontaneous/generators/site/db/postgres.yml.tt +25 -0
  119. data/lib/spontaneous/generators/site/db/sqlite3.yml.tt +18 -0
  120. data/lib/spontaneous/generators/site/public/humans.txt.tt +14 -0
  121. data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +51 -0
  122. data/lib/spontaneous/loader.rb +1 -1
  123. data/lib/spontaneous/logger.rb +1 -1
  124. data/lib/spontaneous/media/image/optimizer.rb +1 -1
  125. data/lib/spontaneous/media/image/processor.rb +11 -2
  126. data/lib/spontaneous/media/image/renderable.rb +2 -0
  127. data/lib/spontaneous/model.rb +3 -0
  128. data/lib/spontaneous/model/box/allowed_types.rb +17 -4
  129. data/lib/spontaneous/model/core.rb +36 -3
  130. data/lib/spontaneous/model/core/aliases.rb +5 -2
  131. data/lib/spontaneous/model/core/boxes.rb +6 -0
  132. data/lib/spontaneous/model/core/cascading_change.rb +38 -0
  133. data/lib/spontaneous/model/core/content_hash.rb +171 -0
  134. data/lib/spontaneous/model/core/entries.rb +0 -19
  135. data/lib/spontaneous/model/core/fields.rb +11 -0
  136. data/lib/spontaneous/model/core/modifications.rb +22 -21
  137. data/lib/spontaneous/model/core/render.rb +3 -0
  138. data/lib/spontaneous/model/core/serialisation.rb +18 -17
  139. data/lib/spontaneous/model/page.rb +35 -8
  140. data/lib/spontaneous/model/page/page_tree.rb +20 -8
  141. data/lib/spontaneous/model/page/paths.rb +79 -50
  142. data/lib/spontaneous/model/page/singleton.rb +71 -0
  143. data/lib/spontaneous/model/page/site_map.rb +2 -1
  144. data/lib/spontaneous/model/page/site_timestamps.rb +2 -2
  145. data/lib/spontaneous/model/piece.rb +10 -0
  146. data/lib/spontaneous/output/context.rb +13 -6
  147. data/lib/spontaneous/output/format.rb +30 -5
  148. data/lib/spontaneous/output/helpers/script_helper.rb +8 -0
  149. data/lib/spontaneous/output/helpers/stylesheet_helper.rb +7 -0
  150. data/lib/spontaneous/output/renderable.rb +16 -0
  151. data/lib/spontaneous/output/store.rb +1 -1
  152. data/lib/spontaneous/output/template/renderer.rb +2 -2
  153. data/lib/spontaneous/page_piece.rb +25 -1
  154. data/lib/spontaneous/prototypes/box_prototype.rb +13 -0
  155. data/lib/spontaneous/prototypes/field_prototype.rb +7 -4
  156. data/lib/spontaneous/publishing.rb +10 -5
  157. data/lib/spontaneous/publishing/immediate.rb +32 -349
  158. data/lib/spontaneous/publishing/pipeline.rb +43 -0
  159. data/lib/spontaneous/publishing/progress.rb +186 -0
  160. data/lib/spontaneous/publishing/publish.rb +107 -0
  161. data/lib/spontaneous/publishing/rerender.rb +17 -0
  162. data/lib/spontaneous/publishing/revision.rb +53 -18
  163. data/lib/spontaneous/publishing/simultaneous.rb +1 -1
  164. data/lib/spontaneous/publishing/steps.rb +154 -0
  165. data/lib/spontaneous/publishing/steps/activate_revision.rb +45 -0
  166. data/lib/spontaneous/publishing/steps/archive_old_revisions.rb +22 -0
  167. data/lib/spontaneous/publishing/steps/base_step.rb +49 -0
  168. data/lib/spontaneous/publishing/steps/copy_static_files.rb +74 -0
  169. data/lib/spontaneous/publishing/steps/create_revision_directory.rb +24 -0
  170. data/lib/spontaneous/publishing/steps/generate_rackup_file.rb +51 -0
  171. data/lib/spontaneous/publishing/steps/generate_search_indexes.rb +24 -0
  172. data/lib/spontaneous/publishing/steps/render_revision.rb +69 -0
  173. data/lib/spontaneous/publishing/steps/write_revision_file.rb +43 -0
  174. data/lib/spontaneous/rack/back.rb +3 -1
  175. data/lib/spontaneous/rack/back/alias.rb +9 -8
  176. data/lib/spontaneous/rack/front.rb +1 -1
  177. data/lib/spontaneous/rack/middleware.rb +7 -4
  178. data/lib/spontaneous/rack/middleware/transaction.rb +14 -0
  179. data/lib/spontaneous/rack/page_controller.rb +23 -8
  180. data/lib/spontaneous/revision.rb +5 -10
  181. data/lib/spontaneous/schema.rb +5 -0
  182. data/lib/spontaneous/server.rb +3 -1
  183. data/lib/spontaneous/site.rb +17 -10
  184. data/lib/spontaneous/site/publishing.rb +25 -3
  185. data/lib/spontaneous/site/state.rb +7 -3
  186. data/lib/spontaneous/tasks/database.rake +5 -10
  187. data/lib/spontaneous/utils/database/mysql_dumper.rb +5 -1
  188. data/lib/spontaneous/version.rb +1 -1
  189. data/spontaneous.gemspec +4 -3
  190. data/test/fixtures/example_application/config/initializers/initializer1.rb +1 -0
  191. data/test/fixtures/example_application/config/initializers/initializer2.rb +1 -0
  192. data/test/fixtures/example_application/config/initializers/publishing.rb +13 -0
  193. data/test/fixtures/search/config/{indexes.rb → initializers/indexes.rb} +0 -0
  194. data/test/fixtures/serialisation/root_hash.yaml.erb +10 -4
  195. data/test/functional/test_application.rb +10 -0
  196. data/test/functional/test_back.rb +23 -5
  197. data/test/functional/test_cli.rb +98 -34
  198. data/test/functional/test_front.rb +7 -3
  199. data/test/test_helper.rb +35 -28
  200. data/test/unit/test_alias.rb +20 -3
  201. data/test/unit/test_assets.rb +58 -30
  202. data/test/unit/test_changesets.rb +20 -12
  203. data/test/unit/test_content_hash.rb +496 -0
  204. data/test/unit/test_context.rb +28 -1
  205. data/test/unit/test_controllers.rb +96 -61
  206. data/test/unit/test_crypt.rb +1 -8
  207. data/test/unit/test_datamapper.rb +95 -19
  208. data/test/unit/test_features.rb +1 -4
  209. data/test/unit/test_fields.rb +61 -12
  210. data/test/unit/test_generators.rb +39 -2
  211. data/test/unit/test_images.rb +3 -1
  212. data/test/unit/test_modifications.rb +224 -219
  213. data/test/unit/test_output_store.rb +10 -0
  214. data/test/unit/{test_formats.rb → test_outputs.rb} +75 -6
  215. data/test/unit/test_page.rb +61 -15
  216. data/test/unit/test_plugins.rb +2 -42
  217. data/test/unit/test_publishing_pipeline.rb +1050 -0
  218. data/test/unit/test_render.rb +30 -0
  219. data/test/unit/test_revisions.rb +110 -2
  220. data/test/unit/test_schema.rb +4 -0
  221. data/test/unit/test_search.rb +1 -1
  222. data/test/unit/test_serialisation.rb +6 -1
  223. data/test/unit/test_singletons.rb +159 -0
  224. data/test/unit/test_site.rb +71 -44
  225. metadata +140 -86
  226. data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
  227. data/test/unit/test_publishing.rb +0 -330
@@ -343,7 +343,7 @@ module Spontaneous
343
343
  end
344
344
 
345
345
  def hash
346
- [model, id.nil? ? @values.sort_by{|k,v| k.to_s} : id].hash
346
+ [model, id.nil? ? (@values || {}).sort_by{|k,v| k.to_s} : id].hash
347
347
  end
348
348
  end
349
349
  end
@@ -58,15 +58,41 @@ module Spontaneous
58
58
  end
59
59
  end
60
60
 
61
+ # Using prepared statements for associations within sqlite causes
62
+ # problems with multiprocess access as preparing the ps within a
63
+ # transaction locks the content table and prevents the field update &
64
+ # publishing processes from updating it
65
+ def associations_use_prepared_statements?
66
+ mapper.db.database_type != :sqlite
67
+ end
68
+
61
69
  def has_many_content(name, opts = {})
62
70
  opts[:association] = :one_to_many
63
71
  opts[:dataset_method] = "#{name}_dataset"
72
+ opts[:load_ps_method] = "load_#{name}_association_prepared_statement".to_sym
73
+ opts[:ps_method] = "#{name}_prepared_statement".to_sym
74
+ opts[:ps_name] = "#{name}_#{opts[:association]}_association".to_sym
64
75
  opts[:add_method] = "add_#{name.to_s.singularize}"
76
+ opts[:load_method] = "load_#{opts[:association]}_association".to_sym
77
+ opts[:dataset] = Proc.new do |var|
78
+ mapper.where!([[mapper.qualify_column(opts[:key]), var]])
79
+ end
65
80
  mod = opts[:module] ||= association_method_module
66
-
81
+ if associations_use_prepared_statements?
82
+ define_association_method(mod, opts[:load_ps_method]) {
83
+ ps = self.send(opts[:ps_method])
84
+ ps.call(id: id)
85
+ }
86
+ else
87
+ define_association_method(mod, opts[:load_ps_method]) {
88
+ opts[:dataset].call(id).all
89
+ }
90
+ end
91
+ define_association_method(mod, opts[:ps_method]) {
92
+ mapper.prepare(:select, opts[:ps_name]) { opts[:dataset].call(:$id) }
93
+ }
67
94
  define_association_method(mod, opts[:dataset_method]) {
68
- m = mapper
69
- m.where!([[m.qualify_column(opts[:key]), id]])
95
+ opts[:dataset].call(id)
70
96
  }
71
97
  define_association_method(mod, name) { |options = {}|
72
98
  load_cached_association(name, options)
@@ -83,11 +109,35 @@ module Spontaneous
83
109
  opts[:association] = :many_to_one
84
110
  opts[:dataset_method] = "#{name}_dataset"
85
111
  opts[:add_method] = "#{name}="
112
+ opts[:load_method] = "load_#{opts[:association]}_association".to_sym
113
+ opts[:load_ps_method] = "load_#{name}_association_prepared_statement".to_sym
114
+ opts[:ps_method] = "#{name}_prepared_statement".to_sym
115
+ opts[:ps_name] = "load_#{name}_#{opts[:association]}_association".to_sym
116
+ opts[:dataset] = Proc.new do |var|
117
+ m = mapper
118
+ m.where!([[m.qualify_column(:id), var]])
119
+ end
86
120
  mod = opts[:module] ||= association_method_module
87
121
 
122
+ if associations_use_prepared_statements?
123
+ define_association_method(mod, opts[:load_ps_method]) {
124
+ id = send(opts[:key])
125
+ return nil if id.nil?
126
+ ps = self.send(opts[:ps_method])
127
+ ps.call(id: id)
128
+ }
129
+ else
130
+ define_association_method(mod, opts[:load_ps_method]) {
131
+ id = send(opts[:key])
132
+ return nil if id.nil?
133
+ opts[:dataset].call(id).first
134
+ }
135
+ end
136
+ define_association_method(mod, opts[:ps_method]) {
137
+ mapper.prepare(:first, opts[:ps_name]) { opts[:dataset].call(:$id) }
138
+ }
88
139
  define_association_method(mod, opts[:dataset_method]) {
89
- m = mapper
90
- m.where!([[m.qualify_column(:id), send(opts[:key])]])
140
+ opts[:dataset].call(send(opts[:key]))
91
141
  }
92
142
  define_association_method(mod, name) { |options = {}|
93
143
  load_cached_association(name, options)
@@ -201,13 +251,11 @@ module Spontaneous
201
251
  end
202
252
 
203
253
  def load_many_to_one_association(assoc)
204
- id = send(assoc[:key])
205
- return nil if id.nil?
206
- mapper[id]
254
+ self.send(assoc[:load_ps_method])
207
255
  end
208
256
 
209
257
  def load_one_to_many_association(assoc)
210
- members = self.send(assoc[:dataset_method]).all.compact
258
+ members = self.send(assoc[:load_ps_method])#.all.compact
211
259
  if (reciprocal = assoc[:reciprocal])
212
260
  members.each do |member|
213
261
  member.send :set_association_cache, reciprocal, self
@@ -221,8 +269,7 @@ module Spontaneous
221
269
  clear_association_cache(name) if options[:reload]
222
270
  ac = associations_cache
223
271
  unless ac.key?(name)
224
- load_method = "load_#{assoc[:association]}_association"
225
- ac[name] = send(load_method, assoc)
272
+ ac[name] = send(assoc[:load_method], assoc)
226
273
  end
227
274
  ac[name]
228
275
  end
@@ -239,8 +286,12 @@ module Spontaneous
239
286
  associations_cache.delete(name)
240
287
  end
241
288
 
242
- def refresh
289
+ def clear_association_cache!
243
290
  associations_cache.clear
291
+ end
292
+
293
+ def refresh
294
+ clear_association_cache!
244
295
  @association_proxy_instance = nil
245
296
  super
246
297
  end
@@ -12,27 +12,22 @@ module Spontaneous
12
12
  super
13
13
  end
14
14
 
15
- # I have disabled update timestamps because the logic is more complex
16
- # than this. Modification timestamps are controlled by the modification
17
- # logic, e.g. preventing parent pages from appearing as modified on the
18
- # addition of a new child page.
19
- #
20
- # def before_update
21
- # # set_update_timestamp
22
- # super
23
- # end
15
+ def before_update
16
+ set_update_timestamp
17
+ super
18
+ end
24
19
 
25
20
  def set_create_timestamp(time=nil)
26
21
  return unless self.respond_to?(:created_at)
27
22
  time ||= Spontaneous::DataMapper.timestamp
28
23
  self.send(:"created_at=", time) if send(:created_at).nil?
29
- # set_update_timestamp(time)
24
+ set_update_timestamp(time)
30
25
  end
31
26
 
32
- # def set_update_timestamp(time=nil)
33
- # return unless self.respond_to?(:modified_at)
34
- # self.send(:modified_at=, time || Spontaneous::DataMapper.timestamp)
35
- # end
27
+ def set_update_timestamp(time=nil)
28
+ return unless self.respond_to?(:modified_at)
29
+ self.send(:modified_at=, time || Spontaneous::DataMapper.timestamp)
30
+ end
36
31
  end
37
32
  end
38
33
  end
@@ -45,8 +45,10 @@ module Spontaneous
45
45
  :id
46
46
  end
47
47
 
48
- def dataset(revision = nil)
49
- @database[revision_table(revision)]
48
+ def dataset(revision = nil, visible_only = false)
49
+ ds = @database[revision_table(revision)]
50
+ ds.filter!(hidden: false) if visible_only
51
+ ds
50
52
  end
51
53
 
52
54
  def logger
@@ -143,6 +143,33 @@ module Spontaneous
143
143
  self
144
144
  end
145
145
 
146
+ class PreparedStatement
147
+ def initialize(name, ds, ps)
148
+ @name = name
149
+ @ds = ds
150
+ @ps = ps
151
+ end
152
+
153
+ def call(vars = {})
154
+ results = @ps.call(vars)
155
+ case results
156
+ when Array
157
+ @ds.load_instances(results)
158
+ else
159
+ @ds.load_instance(results)
160
+ end
161
+ end
162
+ end
163
+
164
+ def prepare(type, name, *values)
165
+ ps = @dataset.prepare(type, name, *values)
166
+ PreparedStatement.new(name, self, ps)
167
+ end
168
+
169
+ def db
170
+ @dataset.db
171
+ end
172
+
146
173
  def qualify_to_first_source
147
174
  @dataset = @dataset.qualify_to_first_source
148
175
  self
@@ -156,9 +183,11 @@ module Spontaneous
156
183
  @dataset.sql
157
184
  end
158
185
 
159
- alias_method :sql, :to_sql
186
+ def unfiltered
187
+ @dataset.unfiltered
188
+ end
160
189
 
161
- private
190
+ alias_method :sql, :to_sql
162
191
 
163
192
  def get_raw(id)
164
193
  @dataset.first(id: id)
@@ -2,11 +2,11 @@ module Spontaneous
2
2
  module DataMapper
3
3
  class Scope
4
4
 
5
- def initialize(revision, visible, table, schema)
6
- @revision, @visible = revision, visible
7
- @table, @schema = table, schema
8
- @identity_map = {}
9
- @schema_types = @schema.types
5
+ def initialize(dataset, schema)
6
+ @dataset = dataset
7
+ @schema = schema
8
+ @identity_map = {}
9
+ @schema_types = @schema.types
10
10
  end
11
11
 
12
12
  def count(types = nil)
@@ -125,16 +125,27 @@ module Spontaneous
125
125
  dataset(types).select(*columns, &block)
126
126
  end
127
127
 
128
+ def prepare(type, name, *values, &block)
129
+ prepared_statements[name] ||= begin
130
+ ds = block.call
131
+ ds.prepare(type, name, *values)
132
+ end
133
+ end
134
+
135
+ def prepared_statements
136
+ @prepared_statements ||= {}
137
+ end
138
+
128
139
  def schema_uid(id_string)
129
140
  @schema.uids[id_string]
130
141
  end
131
142
 
132
143
  def columns
133
- @table.columns
144
+ @dataset.columns
134
145
  end
135
146
 
136
147
  def qualify_column(col)
137
- @table.qualify(@revision, col)
148
+ Sequel::SQL::QualifiedIdentifier.new(@dataset.first_source, col)
138
149
  end
139
150
 
140
151
  def each(&block)
@@ -150,29 +161,25 @@ module Spontaneous
150
161
  end
151
162
 
152
163
  def pk
153
- @table.pk
164
+ @dataset.db.primary_key(@dataset.first_source).to_sym
154
165
  end
155
166
 
156
167
  def table_name
157
- naked_dataset.first_source_alias
168
+ naked_dataset.first_source_table
158
169
  end
159
170
 
160
171
  def logger
161
- @table.logger
172
+ @dataset.logger
162
173
  end
163
174
 
164
175
  def logger=(logger)
165
- @table.logger = logger
176
+ @dataset.db.logger = logger
166
177
  end
167
178
 
168
179
  def revision
169
180
  self
170
181
  end
171
182
 
172
- def visible_only?
173
- @visible || false
174
- end
175
-
176
183
  def dataset(types = nil, fallback_type_condition = all_types_condition)
177
184
  Dataset.new(table_dataset(types, fallback_type_condition), @schema, @identity_map)
178
185
  end
@@ -184,17 +191,27 @@ module Spontaneous
184
191
  private
185
192
 
186
193
  def table_dataset(types, fallback_type_condition)
187
- naked_dataset.filter(conditions(types, fallback_type_condition))
194
+ conditions = conditions(types, fallback_type_condition)
195
+ return naked_dataset.filter(conditions)
196
+ ds = nil
197
+ unless (ds = cached_datasets[conditions])
198
+ p [:new_dataset, conditions]
199
+ cached_datasets[conditions] = ds = naked_dataset.filter(conditions)
200
+ end
201
+ p [:ds, ds]
202
+ ds
203
+ end
204
+
205
+ def cached_datasets
206
+ @cached_datasets ||= {}
188
207
  end
189
208
 
190
209
  def naked_dataset
191
- @table.dataset(@revision)
210
+ @dataset.dup
192
211
  end
193
212
 
194
213
  def conditions(types, fallback_type_condition)
195
- cond = type_conditions(types, fallback_type_condition)
196
- cond[:hidden] = false if @visible
197
- cond
214
+ type_conditions(types, fallback_type_condition)
198
215
  end
199
216
 
200
217
  def type_conditions(types, fallback_type_condition)
@@ -52,6 +52,12 @@ module Spontaneous
52
52
  end
53
53
  end
54
54
 
55
+ class SingletonException < Error
56
+ def initialize(type)
57
+ super("Attempt to create a second instance of #{type}")
58
+ end
59
+ end
60
+
55
61
  class SchemaModificationError < Error
56
62
  extend Forwardable
57
63
 
@@ -23,6 +23,16 @@ module Spontaneous
23
23
  File.join(@root, path)
24
24
  end
25
25
 
26
+ def path(*args)
27
+ Pathname.new(@root).join(*args)
28
+ end
29
+
30
+ def path!(*args)
31
+ self.path(*args).tap do |path|
32
+ path.mkpath
33
+ end
34
+ end
35
+
26
36
  def name
27
37
  File.basename(root)
28
38
  end
@@ -51,10 +61,12 @@ module Spontaneous
51
61
  end
52
62
  end
53
63
 
54
- def load_indexes!
64
+ # use Rails' alphabetical load order for initializers
65
+ def run_initializers
55
66
  paths.expanded(:config).each do |config_path|
56
- index_file = config_path / "indexes.rb"
57
- Kernel.load(index_file) if File.exists?(index_file)
67
+ Dir["#{config_path / "initializers"}/*.rb"].sort.each do |initializer|
68
+ require initializer
69
+ end
58
70
  end
59
71
  end
60
72
 
@@ -81,13 +93,11 @@ module Spontaneous
81
93
 
82
94
  def loaders
83
95
  @loaders ||= \
84
- begin
85
- use_reloader = config.reload_classes
86
- {
87
- :schema => Spontaneous::SchemaLoader.new(schema_load_paths, use_reloader),
88
- :lib => Spontaneous::Loader.new(load_paths, use_reloader)
89
- }
90
- end
96
+ begin
97
+ use_reloader = config.reload_classes
98
+ {:schema => Spontaneous::SchemaLoader.new(schema_load_paths, use_reloader),
99
+ :lib => Spontaneous::Loader.new(load_paths, use_reloader) }
100
+ end
91
101
  end
92
102
 
93
103
  def load_paths
@@ -56,12 +56,14 @@ module Spontaneous
56
56
  end
57
57
 
58
58
  extend ClassMethods
59
+ include Spontaneous::Model::Core::ContentHash::FieldMethods
59
60
 
60
61
  attr_accessor :owner, :name, :unprocessed_value, :template_params, :version
61
62
  attr_accessor :prototype
62
63
 
63
64
 
64
65
  def initialize(params={}, default_values=true)
66
+ @default_values = default_values
65
67
  @processed_values = {}
66
68
  deserialize(params, default_values)
67
69
  @values = nil
@@ -331,10 +333,14 @@ module Spontaneous
331
333
  value(format)
332
334
  end
333
335
 
336
+ alias_method :render_inline, :render
337
+
334
338
  def render_using(renderer, format = :html, locals = {}, *args)
335
339
  render(format, locals)
336
340
  end
337
341
 
342
+ alias_method :render_inline_using, :render_using
343
+
338
344
  def to_html(locals = {})
339
345
  value(:html)
340
346
  end
@@ -358,7 +364,7 @@ module Spontaneous
358
364
  end
359
365
 
360
366
  def modified?
361
- @modified
367
+ @modified || false
362
368
  end
363
369
 
364
370
  def schema_id
@@ -437,6 +443,7 @@ module Spontaneous
437
443
  :version => version,
438
444
  :value => @initial_value,
439
445
  :user => owner.current_editor)
446
+ mark_unmodified
440
447
  end
441
448
 
442
449
  def <=>(o)