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
@@ -0,0 +1,195 @@
1
+ module Spontaneous
2
+ module DataMapper
3
+ class Scope
4
+
5
+ def initialize(revision, visible, table, schema)
6
+ @revision, @visible = revision, visible
7
+ @table, @schema = table, schema
8
+ @identity_map = {}
9
+ end
10
+
11
+ def count(types = nil)
12
+ dataset(types).count
13
+ end
14
+
15
+ # A type free version of #count
16
+ def count!
17
+ count(nil)
18
+ end
19
+
20
+ def filter(types, *cond, &block)
21
+ dataset(types).filter(*cond, &block)
22
+ end
23
+
24
+ # A type free version of #filter
25
+ def filter!(*cond, &block)
26
+ filter(nil, *cond, &block)
27
+ end
28
+
29
+ def where(types, *cond, &block)
30
+ dataset(types).where(*cond, &block)
31
+ end
32
+
33
+ # A type free version of #where
34
+ def where!(*cond, &block)
35
+ where(nil, *cond, &block)
36
+ end
37
+
38
+ def first(types, *args, &block)
39
+ dataset(types).first(*args, &block)
40
+ end
41
+
42
+ # A type free version of #first
43
+ def first!(*args, &block)
44
+ first(nil, *args, &block)
45
+ end
46
+
47
+ def all(*types, &block)
48
+ instances = dataset(types).all
49
+ instances.each(&block) if block_given?
50
+ instances
51
+ end
52
+
53
+ # A type free version of #all
54
+ def all!(&block)
55
+ all(nil, &block)
56
+ end
57
+
58
+ # Get doesn't need typing as it retrieves a single instance by direct
59
+ # id reference.
60
+ def get(id)
61
+ dataset.get(id)
62
+ end
63
+
64
+ alias_method :[], :get
65
+
66
+ def insert(*values, &block)
67
+ dataset.insert(*values, &block)
68
+ end
69
+
70
+ def instance(model, attributes)
71
+ model.create(attributes)
72
+ end
73
+
74
+ def update(types, columns)
75
+ dataset(types).update(columns)
76
+ end
77
+
78
+ # A type free version of #update
79
+ def update!(columns)
80
+ update(nil, columns)
81
+ end
82
+
83
+ def for_update
84
+ dataset.for_update
85
+ end
86
+
87
+ def delete(types)
88
+ dataset(types).delete
89
+ end
90
+
91
+ def delete_instance(instance)
92
+ dataset.delete_instance(instance)
93
+ end
94
+
95
+ def reload(instance)
96
+ dataset.reload(instance)
97
+ end
98
+
99
+ def create(instance)
100
+ dataset.create(instance)
101
+ end
102
+
103
+ def save(instance)
104
+ dataset.save(instance)
105
+ end
106
+
107
+ def order(types, *columns, &block)
108
+ dataset(types).order(*columns, &block)
109
+ end
110
+
111
+ def limit(types, l, o = (no_offset = true; nil))
112
+ dataset(types).limit(l, o)
113
+ end
114
+
115
+ def select(types, *columns, &block)
116
+ dataset(types).select(*columns, &block)
117
+ end
118
+
119
+ def schema_uid(id_string)
120
+ @schema.uids[id_string]
121
+ end
122
+
123
+ def columns
124
+ @table.columns
125
+ end
126
+
127
+ def qualify_column(col)
128
+ @table.qualify(@revision, col)
129
+ end
130
+
131
+ def each(&block)
132
+ dataset.each(&block)
133
+ end
134
+
135
+ def with_cache(key, &block)
136
+ if @identity_map.key?(key)
137
+ @identity_map[key]
138
+ else
139
+ @identity_map[key] = block.call
140
+ end
141
+ end
142
+
143
+ def pk
144
+ @table.pk
145
+ end
146
+
147
+ def table_name
148
+ naked_dataset.first_source_alias
149
+ end
150
+
151
+ def logger
152
+ @table.logger
153
+ end
154
+
155
+ def logger=(logger)
156
+ @table.logger = logger
157
+ end
158
+
159
+ def revision
160
+ self
161
+ end
162
+
163
+ def visible_only?
164
+ @visible || false
165
+ end
166
+
167
+ def dataset(types = nil)
168
+ Dataset.new(table_dataset(types), @schema, @identity_map)
169
+ end
170
+
171
+ private
172
+
173
+ def table_dataset(types)
174
+ naked_dataset.filter(conditions(types))
175
+ end
176
+
177
+ def naked_dataset
178
+ @table.dataset(@revision)
179
+ end
180
+
181
+ def conditions(types)
182
+ cond = type_conditions(types)
183
+ cond[:hidden] = false if @visible
184
+ cond
185
+ end
186
+
187
+ def type_conditions(types)
188
+ return {} if types.nil?
189
+ types = Array(types)
190
+ return {} if types.empty?
191
+ { :type_sid => types.flatten.map { |model| @schema.to_id(model) } }
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,161 @@
1
+ require "spontaneous/data_mapper/scope"
2
+ require "spontaneous/data_mapper/dataset"
3
+ require "spontaneous/data_mapper/content_model"
4
+ require "spontaneous/data_mapper/content_table"
5
+
6
+ module Spontaneous
7
+ module DataMapper
8
+
9
+ def self.Model(table_name, database, schema, &block)
10
+ table = ::Spontaneous::DataMapper::ContentTable.new(table_name, database)
11
+ mapper = ScopingMapper.new(table, schema)
12
+ Spontaneous::DataMapper::ContentModel.generate(mapper, &block)
13
+ end
14
+
15
+ def self.new(table, schema)
16
+ ScopingMapper.new(table, schema)
17
+ end
18
+
19
+ class ScopingMapper
20
+ extend Forwardable
21
+
22
+ attr_reader :schema
23
+
24
+ def initialize(table, schema)
25
+ @table, @schema = table, schema
26
+ name = table.name
27
+ @keys = {
28
+ :visible => :"#{name}_mapper_visibility",
29
+ :revision => :"#{name}_mapper_revision",
30
+ :dataset => :"#{name}_mapper_dataset"
31
+ }
32
+ end
33
+
34
+ def_delegators :dataset,
35
+ :filter, :where,
36
+ :filter!, :where!,
37
+ :count, :count!,
38
+ :order, :limit,
39
+ :all, :get, :[], :first,
40
+ :all!, :first!,
41
+ :reload,
42
+ :instance,
43
+ :create, :save, :insert,
44
+ :update, :update!,
45
+ :delete, :delete_instance,
46
+ :for_update, :select,
47
+ :columns, :table_name,
48
+ :qualify_column, :quote_identifier,
49
+ :with_cache,
50
+ :logger=, :logger
51
+
52
+ def_delegators :@schema,
53
+ :subclasses, :inherited
54
+
55
+ def_delegators :@table,
56
+ :db, :primary_key,
57
+ :revision_table, :revision_table?, :revision_from_table,
58
+ :revision_history_table, :revision_archive_table,
59
+ :revision_history_dataset, :revision_archive_dataset,
60
+ :quote_identifier
61
+
62
+ def visible(visible_only = true, &block)
63
+ scope(current_revision, visible_only, &block)
64
+ end
65
+
66
+ def visible!(visible_only = true, &block)
67
+ scope!(current_revision, visible_only, &block)
68
+ end
69
+
70
+ def revision(r = current_revision, &block)
71
+ scope(r, visible_only?, &block)
72
+ end
73
+
74
+ def revision!(r = current_revision, &block)
75
+ scope!(r, visible_only?, &block)
76
+ end
77
+
78
+ def editable(&block)
79
+ revision(nil, &block)
80
+ end
81
+
82
+ def editable!(&block)
83
+ revision!(nil, &block)
84
+ end
85
+
86
+ def scope(revision, visible, &block)
87
+ if use_current_scope?(revision, visible)
88
+ if block_given?
89
+ yield
90
+ else
91
+ dataset
92
+ end
93
+ else
94
+ scope!(revision, visible, &block)
95
+ end
96
+ end
97
+
98
+ def scope!(revision, visible, &block)
99
+ if block_given?
100
+ r, v, d = @keys.values_at(:revision, :visible, :dataset)
101
+ thread = Thread.current
102
+ state = [thread[r], thread[v], thread[d]]
103
+ begin
104
+ thread[r] = to_revision(revision)
105
+ thread[v] = visible
106
+ thread[d] = current_scope
107
+ yield
108
+ ensure
109
+ thread[r], thread[v], thread[d] = state
110
+ end
111
+ else
112
+ scope_for(revision, visible)
113
+ end
114
+ end
115
+
116
+ def dataset
117
+ Thread.current[@keys[:dataset]] || current_scope
118
+ end
119
+
120
+ def cached_dataset?
121
+ !Thread.current[@keys[:dataset]].nil?
122
+ end
123
+
124
+ def use_current_scope?(revision, visible)
125
+ cached_dataset? &&
126
+ (current_revision == to_revision(revision)) &&
127
+ ((visible || false) == visible_only?)
128
+ end
129
+
130
+ def to_revision(r)
131
+ r.nil? ? nil : r.to_i
132
+ end
133
+
134
+ def current_revision
135
+ Thread.current[@keys[:revision]]
136
+ end
137
+
138
+ def visible_only?
139
+ Thread.current[@keys[:visible]] || false
140
+ end
141
+
142
+ def base_table
143
+ @table.name
144
+ end
145
+
146
+ def schema_uid(id_string)
147
+ @schema.uids[id_string]
148
+ end
149
+
150
+ private
151
+
152
+ def current_scope
153
+ scope_for(current_revision, visible_only?)
154
+ end
155
+
156
+ def scope_for(revision, visibility)
157
+ Scope.new(revision, visibility, @table, @schema)
158
+ end
159
+ end
160
+ end
161
+ end
@@ -37,12 +37,12 @@ module Spontaneous
37
37
  end
38
38
 
39
39
  def config
40
- Site.instance.config
40
+ Spontaneous::Site.instance.config
41
41
  end
42
42
 
43
43
  def load_config!
44
44
  paths.expanded(:config).each do |config_path|
45
- Site.config.load(config_path)
45
+ Spontaneous::Site.config.load(config_path)
46
46
  end
47
47
  end
48
48