spontaneous 0.2.0.beta4 → 0.2.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/Gemfile +11 -6
  4. data/Readme.markdown +136 -69
  5. data/application/css/core.css.scss +27 -7
  6. data/application/css/editing.css.scss +4 -26
  7. data/application/css/schema_error.css.scss +22 -0
  8. data/application/js/content.js +11 -3
  9. data/application/js/edit_panel.js +1 -4
  10. data/application/js/field/file.js +17 -0
  11. data/application/js/field/image.js +30 -21
  12. data/application/js/field/string.js +4 -1
  13. data/application/js/field_preview.js +21 -16
  14. data/application/js/publish.js +6 -6
  15. data/application/js/types.js +5 -13
  16. data/application/js/views.js +2 -2
  17. data/application/js/views/box_view.js +3 -2
  18. data/application/js/views/page_piece_view.js +1 -1
  19. data/application/js/views/piece_view.js +1 -1
  20. data/application/views/schema_modification_error.html.erb +13 -3
  21. data/db/migrations/20131104101935_site_must_publish_all.rb +14 -0
  22. data/lib/spontaneous.rb +0 -1
  23. data/lib/spontaneous/box_style.rb +15 -9
  24. data/lib/spontaneous/capistrano/deploy.rb +13 -1
  25. data/lib/spontaneous/change.rb +11 -13
  26. data/lib/spontaneous/cli.rb +5 -2
  27. data/lib/spontaneous/cli/assets.rb +7 -1
  28. data/lib/spontaneous/cli/console.rb +7 -1
  29. data/lib/spontaneous/cli/content.rb +35 -0
  30. data/lib/spontaneous/cli/fields.rb +3 -2
  31. data/lib/spontaneous/cli/generate.rb +5 -2
  32. data/lib/spontaneous/cli/server.rb +12 -8
  33. data/lib/spontaneous/cli/site.rb +12 -12
  34. data/lib/spontaneous/cli/user.rb +28 -14
  35. data/lib/spontaneous/collections/box_set.rb +4 -4
  36. data/lib/spontaneous/collections/field_set.rb +4 -4
  37. data/lib/spontaneous/collections/prototype_set.rb +12 -4
  38. data/lib/spontaneous/data_mapper.rb +11 -7
  39. data/lib/spontaneous/data_mapper/content_model.rb +8 -0
  40. data/lib/spontaneous/data_mapper/content_model/associations.rb +1 -1
  41. data/lib/spontaneous/data_mapper/dataset.rb +14 -2
  42. data/lib/spontaneous/data_mapper/scope.rb +33 -13
  43. data/lib/spontaneous/facet.rb +4 -0
  44. data/lib/spontaneous/field.rb +12 -12
  45. data/lib/spontaneous/field/base.rb +27 -22
  46. data/lib/spontaneous/field/boolean.rb +4 -4
  47. data/lib/spontaneous/field/date.rb +2 -2
  48. data/lib/spontaneous/field/file.rb +24 -18
  49. data/lib/spontaneous/field/html.rb +1 -1
  50. data/lib/spontaneous/field/image.rb +6 -19
  51. data/lib/spontaneous/field/location.rb +1 -1
  52. data/lib/spontaneous/field/long_string.rb +3 -3
  53. data/lib/spontaneous/field/markdown.rb +3 -3
  54. data/lib/spontaneous/field/select.rb +2 -2
  55. data/lib/spontaneous/field/string.rb +2 -2
  56. data/lib/spontaneous/field/tags.rb +2 -2
  57. data/lib/spontaneous/field/update.rb +21 -20
  58. data/lib/spontaneous/field/webvideo.rb +6 -6
  59. data/lib/spontaneous/field/webvideo/fallback.rb +2 -2
  60. data/lib/spontaneous/field/webvideo/vimeo.rb +7 -7
  61. data/lib/spontaneous/generators/site.rb +2 -2
  62. data/lib/spontaneous/generators/site/Gemfile.tt +5 -1
  63. data/lib/spontaneous/layout.rb +2 -2
  64. data/lib/spontaneous/media.rb +1 -0
  65. data/lib/spontaneous/media/file.rb +6 -5
  66. data/lib/spontaneous/media/image/attributes.rb +4 -0
  67. data/lib/spontaneous/media/image/renderable.rb +4 -4
  68. data/lib/spontaneous/media/store.rb +22 -0
  69. data/lib/spontaneous/{storage → media/store}/backend.rb +1 -1
  70. data/lib/spontaneous/{storage → media/store}/cloud.rb +1 -1
  71. data/lib/spontaneous/{storage → media/store}/local.rb +1 -1
  72. data/lib/spontaneous/media/temp_file.rb +1 -1
  73. data/lib/spontaneous/model.rb +10 -7
  74. data/lib/spontaneous/model/action.rb +7 -0
  75. data/lib/spontaneous/model/action/clean.rb +87 -0
  76. data/lib/spontaneous/model/box/allowed_types.rb +15 -1
  77. data/lib/spontaneous/model/core.rb +10 -0
  78. data/lib/spontaneous/model/core/aliases.rb +1 -1
  79. data/lib/spontaneous/model/core/content_groups.rb +1 -1
  80. data/lib/spontaneous/model/core/fields.rb +1 -1
  81. data/lib/spontaneous/model/core/modifications.rb +2 -2
  82. data/lib/spontaneous/model/core/page_search.rb +4 -0
  83. data/lib/spontaneous/model/core/publishing.rb +4 -17
  84. data/lib/spontaneous/model/core/render.rb +4 -4
  85. data/lib/spontaneous/model/core/styles.rb +2 -2
  86. data/lib/spontaneous/model/core/visibility.rb +6 -2
  87. data/lib/spontaneous/model/page.rb +6 -2
  88. data/lib/spontaneous/model/page/controllers.rb +55 -17
  89. data/lib/spontaneous/model/page/formats.rb +12 -7
  90. data/lib/spontaneous/model/page/layouts.rb +2 -2
  91. data/lib/spontaneous/model/page/locks.rb +4 -1
  92. data/lib/spontaneous/model/page/page_tree.rb +40 -6
  93. data/lib/spontaneous/output.rb +14 -52
  94. data/lib/spontaneous/output/context.rb +11 -39
  95. data/lib/spontaneous/output/context/navigation.rb +31 -0
  96. data/lib/spontaneous/output/format.rb +15 -19
  97. data/lib/spontaneous/output/renderable.rb +99 -0
  98. data/lib/spontaneous/output/store.rb +24 -0
  99. data/lib/spontaneous/output/store/backend.rb +52 -0
  100. data/lib/spontaneous/output/store/file.rb +77 -0
  101. data/lib/spontaneous/output/store/moneta.rb +117 -0
  102. data/lib/spontaneous/output/store/revision.rb +34 -0
  103. data/lib/spontaneous/output/store/store.rb +15 -0
  104. data/lib/spontaneous/output/store/transaction.rb +44 -0
  105. data/lib/spontaneous/output/template/engine.rb +17 -7
  106. data/lib/spontaneous/output/template/renderer.rb +66 -40
  107. data/lib/spontaneous/page_lock.rb +5 -7
  108. data/lib/spontaneous/page_piece.rb +2 -2
  109. data/lib/spontaneous/permissions/user.rb +14 -7
  110. data/lib/spontaneous/plugins/application/features.rb +8 -4
  111. data/lib/spontaneous/plugins/application/state.rb +12 -6
  112. data/lib/spontaneous/prototypes/box_prototype.rb +9 -10
  113. data/lib/spontaneous/prototypes/field_prototype.rb +66 -15
  114. data/lib/spontaneous/publishing/immediate.rb +30 -26
  115. data/lib/spontaneous/rack.rb +12 -7
  116. data/lib/spontaneous/rack/back.rb +43 -37
  117. data/lib/spontaneous/rack/back/base.rb +4 -4
  118. data/lib/spontaneous/rack/back/changes.rb +2 -2
  119. data/lib/spontaneous/rack/back/file.rb +16 -24
  120. data/lib/spontaneous/rack/back/map.rb +5 -5
  121. data/lib/spontaneous/rack/back/preview.rb +3 -4
  122. data/lib/spontaneous/rack/back/schema.rb +1 -1
  123. data/lib/spontaneous/rack/back/site.rb +6 -7
  124. data/lib/spontaneous/rack/front.rb +19 -16
  125. data/lib/spontaneous/rack/middleware/authenticate.rb +3 -3
  126. data/lib/spontaneous/rack/middleware/reloader.rb +3 -2
  127. data/lib/spontaneous/rack/middleware/scope.rb +25 -19
  128. data/lib/spontaneous/rack/page_controller.rb +164 -13
  129. data/lib/spontaneous/rack/public.rb +23 -62
  130. data/lib/spontaneous/rack/static.rb +2 -3
  131. data/lib/spontaneous/schema.rb +27 -8
  132. data/lib/spontaneous/schema/schema_modification.rb +9 -1
  133. data/lib/spontaneous/schema/uid.rb +2 -2
  134. data/lib/spontaneous/schema/uid_map.rb +3 -2
  135. data/lib/spontaneous/search/database.rb +2 -2
  136. data/lib/spontaneous/search/field.rb +5 -3
  137. data/lib/spontaneous/search/index.rb +12 -7
  138. data/lib/spontaneous/search/results.rb +5 -3
  139. data/lib/spontaneous/server.rb +2 -2
  140. data/lib/spontaneous/site.rb +10 -3
  141. data/lib/spontaneous/site/features.rb +26 -6
  142. data/lib/spontaneous/site/helpers.rb +9 -12
  143. data/lib/spontaneous/site/level.rb +7 -9
  144. data/lib/spontaneous/site/map.rb +9 -11
  145. data/lib/spontaneous/site/paths.rb +5 -5
  146. data/lib/spontaneous/site/publishing.rb +83 -80
  147. data/lib/spontaneous/site/schema.rb +1 -7
  148. data/lib/spontaneous/site/search.rb +8 -18
  149. data/lib/spontaneous/site/selectors.rb +60 -54
  150. data/lib/spontaneous/site/state.rb +36 -30
  151. data/lib/spontaneous/site/storage.rb +10 -16
  152. data/lib/spontaneous/state.rb +8 -0
  153. data/lib/spontaneous/style.rb +32 -33
  154. data/lib/spontaneous/version.rb +1 -1
  155. data/spontaneous.gemspec +22 -21
  156. data/test/fixtures/public/templates/layouts/default.html.cut +1 -1
  157. data/test/fixtures/public/templates/layouts/default.pdf.cut +1 -1
  158. data/test/fixtures/public/templates/layouts/default.rss.cut +1 -1
  159. data/test/fixtures/search/config/indexes.rb +1 -1
  160. data/test/fixtures/serialisation/class_hash.yaml.erb +13 -1
  161. data/test/fixtures/serialisation/root_hash.yaml.erb +10 -0
  162. data/test/functional/test_application.rb +20 -24
  163. data/test/functional/test_back.rb +26 -27
  164. data/test/functional/test_cli.rb +146 -0
  165. data/test/functional/test_front.rb +287 -216
  166. data/test/functional/test_user_manager.rb +1 -1
  167. data/test/test_helper.rb +15 -11
  168. data/test/unit/test_alias.rb +32 -25
  169. data/test/unit/test_asset_bundler.rb +1 -1
  170. data/test/unit/test_assets.rb +34 -33
  171. data/test/unit/test_authentication.rb +1 -1
  172. data/test/unit/test_boxes.rb +16 -2
  173. data/test/unit/test_changesets.rb +23 -11
  174. data/test/unit/test_content.rb +15 -0
  175. data/test/unit/test_context.rb +139 -0
  176. data/test/unit/test_controllers.rb +374 -0
  177. data/test/{experimental → unit}/test_crypt.rb +0 -0
  178. data/test/unit/test_datamapper.rb +260 -237
  179. data/test/unit/test_datamapper_content.rb +42 -12
  180. data/test/{experimental → unit}/test_features.rb +85 -3
  181. data/test/unit/test_fields.rb +117 -42
  182. data/test/unit/test_formats.rb +11 -1
  183. data/test/unit/test_generators.rb +2 -2
  184. data/test/unit/test_helpers.rb +7 -8
  185. data/test/unit/test_images.rb +39 -2
  186. data/test/unit/test_layouts.rb +14 -12
  187. data/test/unit/test_media.rb +32 -23
  188. data/test/unit/test_output_store.rb +342 -0
  189. data/test/unit/test_page.rb +8 -1
  190. data/test/unit/test_permissions.rb +11 -7
  191. data/test/unit/test_plugins.rb +3 -3
  192. data/test/unit/test_prototype_set.rb +8 -1
  193. data/test/unit/test_publishing.rb +67 -54
  194. data/test/unit/test_render.rb +91 -38
  195. data/test/unit/test_revisions.rb +4 -4
  196. data/test/unit/test_schema.rb +109 -84
  197. data/test/unit/test_search.rb +42 -42
  198. data/test/unit/test_serialisation.rb +3 -2
  199. data/test/unit/test_site.rb +39 -27
  200. data/test/unit/test_storage.rb +9 -6
  201. data/test/unit/test_styles.rb +25 -32
  202. data/test/unit/test_templates.rb +8 -4
  203. metadata +89 -54
  204. data/lib/spontaneous/model/page/request.rb +0 -105
  205. data/lib/spontaneous/storage.rb +0 -22
@@ -4,15 +4,13 @@ class Spontaneous::Site
4
4
  module Level
5
5
  extend Spontaneous::Concern
6
6
 
7
- module ClassMethods
8
- def at_depth(level)
9
- case level
10
- when 0, :root
11
- Spontaneous::Site.root
12
- when 1, :section
13
- Spontaneous::Site.root.at_depth(1)
14
- end
7
+ def at_depth(level)
8
+ case level
9
+ when 0, :root, :home
10
+ home
11
+ when 1, :section
12
+ home.at_depth(1)
15
13
  end
16
- end # ClassMethods
14
+ end
17
15
  end # Level
18
16
  end
@@ -4,17 +4,15 @@ class Spontaneous::Site
4
4
  module Map
5
5
  extend Spontaneous::Concern
6
6
 
7
- module ClassMethods
8
- def map(root_id=nil)
9
- page = \
10
- if root_id.nil?
11
- content_model::Page.root
12
- else
13
- content_model.get root_id
14
- end
15
- return nil unless page
16
- page.map_entry
7
+ def map(root_id=nil)
8
+ page = \
9
+ if root_id.nil?
10
+ model::Page.root
11
+ else
12
+ model.get root_id
17
13
  end
18
- end # ClassMethods
14
+ return nil unless page
15
+ page.map_entry
16
+ end
19
17
  end # Map
20
18
  end
@@ -4,10 +4,10 @@ class Spontaneous::Site
4
4
  module Paths
5
5
  extend Spontaneous::Concern
6
6
 
7
- module ClassMethods
8
- def paths(group)
9
- instance.facets.flat_map { |facet| facet.paths.expanded(group) }
10
- end
11
- end # ClassMethods
7
+ def paths(*args)
8
+ return _paths if args.empty?
9
+ group = args.first
10
+ facets.flat_map { |facet| facet._paths.expanded(group) }
11
+ end
12
12
  end # Paths
13
13
  end
@@ -4,86 +4,89 @@ class Spontaneous::Site
4
4
  module Publishing
5
5
  extend Spontaneous::Concern
6
6
 
7
- module ClassMethods
8
- def content_model
9
- Spontaneous::Content
7
+ def background_mode
8
+ @background_mode ||= (config.background_mode || :immediate)
9
+ end
10
+
11
+ def background_mode=(method)
12
+ @background_mode = method
13
+ end
14
+
15
+ def resolve_background_mode(mod)
16
+ klass_name = background_mode.to_s.camelize
17
+ begin
18
+ mod.const_get(klass_name)
19
+ rescue NameError => e
20
+ puts "Unknown method #{method} (#{mod}::#{klass_name})"
21
+ mod::Immediate
22
+ rescue NameError => e
23
+ raise "Illegal background mode #{mod}::Immediate"
10
24
  end
11
-
12
- def background_mode
13
- @background_mode ||= (Spontaneous::Site.config.background_mode || :immediate)
14
- end
15
-
16
- def background_mode=(method)
17
- @background_mode = method
18
- end
19
-
20
- def resolve_background_mode(mod)
21
- klass_name = background_mode.to_s.camelize
22
- begin
23
- mod.const_get(klass_name)
24
- rescue NameError => e
25
- puts "Unknown method #{method} (#{mod}::#{klass_name})"
26
- mod::Immediate
27
- rescue NameError => e
28
- raise "Illegal background mode #{mod}::Immediate"
29
- end
30
- end
31
-
32
- def publishing_method
33
- resolve_background_mode(Spontaneous::Publishing)
34
- end
35
-
36
- def publish_pages(page_list=nil)
37
- publishing_method.new(self.revision, content_model).publish_pages(page_list)
38
- end
39
-
40
- def publish_all
41
- publishing_method.new(self.revision, content_model).publish_all
42
- end
43
-
44
- def rerender
45
- publishing_method.new(self.published_revision, content_model).rerender_revision
46
- end
47
-
48
- def publishing_status
49
- status = rest = nil
50
- # if r = S::Site.pending_revision
51
- status, *rest = publishing_method.status.split(':')
52
- rest = rest.join(':')
53
- # end
54
- Hash[[:status, :progress].zip([status, rest])] rescue ""
55
- end
56
-
57
- def publishing_status=(status)
58
- publishing_method.status = status
59
- end
60
-
61
- def with_published(&block)
62
- Spontaneous::Content.scope(published_revision, true, &block)
63
- end
64
-
65
- def with_editable(&block)
66
- Spontaneous::Content.scope(nil, false, &block)
67
- end
68
-
69
- def with_preview(&block)
70
- Spontaneous::Content.scope(nil, true, &block)
71
- end
72
-
73
- protected
74
-
75
- def set_published_revision(revision)
76
- instance = S::State.instance
77
- instance.published_revision = revision
78
- instance.revision = revision + 1
79
- instance.save
80
- end
81
-
82
- def pending_revision=(revision)
83
- instance = S::State.instance
84
- instance.pending_revision = revision
85
- instance.save
86
- end
87
- end # ClassMethods
25
+ end
26
+
27
+ def publishing_method
28
+ resolve_background_mode(Spontaneous::Publishing)
29
+ end
30
+
31
+ def output_store(*args)
32
+ return current_output_store if args.empty?
33
+ @output_store = Spontaneous::Output::Store.new(*args)
34
+ end
35
+
36
+ def current_output_store
37
+ @output_store ||= Spontaneous::Output::Store.new(:File, root: revision_root)
38
+ end
39
+
40
+ def publish_pages(page_list=nil)
41
+ publishing_method.new(self, self.revision).publish_pages(page_list)
42
+ end
43
+
44
+ def publish_all
45
+ publishing_method.new(self, self.revision).publish_all
46
+ end
47
+
48
+ def rerender
49
+ publishing_method.new(self, self.published_revision).rerender_revision
50
+ end
51
+
52
+ def publishing_status
53
+ status = rest = nil
54
+ # if r = S::Site.pending_revision
55
+ status, *rest = publishing_method.status.split(':')
56
+ rest = rest.join(':')
57
+ # end
58
+ Hash[[:status, :progress].zip([status, rest])] rescue ""
59
+ end
60
+
61
+ def publishing_status=(status)
62
+ publishing_method.status = status
63
+ end
64
+
65
+ def with_published(&block)
66
+ Spontaneous::Content.scope(published_revision, true, &block)
67
+ end
68
+
69
+ def with_editable(&block)
70
+ Spontaneous::Content.scope(nil, false, &block)
71
+ end
72
+
73
+ def with_preview(&block)
74
+ Spontaneous::Content.scope(nil, true, &block)
75
+ end
76
+
77
+ protected
78
+
79
+ def set_published_revision(revision)
80
+ instance = S::State.instance
81
+ instance.published_revision = revision
82
+ instance.revision = revision + 1
83
+ instance.save
84
+ end
85
+
86
+ def pending_revision=(revision)
87
+ instance = S::State.instance
88
+ instance.pending_revision = revision
89
+ instance.save
90
+ end
88
91
  end # Publishing
89
92
  end # Spontaneous::Plugins::Site
@@ -4,12 +4,6 @@ class Spontaneous::Site
4
4
  module Schema
5
5
  extend Spontaneous::Concern
6
6
 
7
- module ClassMethods
8
- def schema
9
- instance.schema
10
- end
11
- end # ClassMethods
12
-
13
7
  def uid
14
8
  schema.uids
15
9
  end
@@ -19,7 +13,7 @@ class Spontaneous::Site
19
13
  end
20
14
 
21
15
  def schema
22
- @schema ||= Spontaneous::Schema::Schema.new(root, schema_loader_class)
16
+ @schema ||= Spontaneous::Schema::Schema.new(self, root, schema_loader_class)
23
17
  end
24
18
 
25
19
  def schema_loader_class
@@ -4,24 +4,14 @@ class Spontaneous::Site
4
4
  module Search
5
5
  extend Spontaneous::Concern
6
6
 
7
- module ClassMethods
8
- def index(name, &definition)
9
- instance.index(name, &definition)
7
+ def indexer(revision)
8
+ indexer = S::Search::CompoundIndexer.new(revision, indexes.values)
9
+ begin
10
+ yield(indexer)
11
+ ensure
12
+ indexer.close
10
13
  end
11
-
12
- def indexes
13
- instance.indexes
14
- end
15
-
16
- def indexer(revision)
17
- indexer = S::Search::CompoundIndexer.new(revision, indexes.values)
18
- begin
19
- yield(indexer)
20
- ensure
21
- indexer.close
22
- end
23
- end
24
- end # ClassMethods
14
+ end
25
15
 
26
16
  def indexes
27
17
  @indexes ||= {}
@@ -36,7 +26,7 @@ class Spontaneous::Site
36
26
  end
37
27
 
38
28
  def index(name, &definition)
39
- index = S::Search::Index.new(name, &definition)
29
+ index = S::Search::Index.new(self, name, &definition)
40
30
  self[name] = index
41
31
  end
42
32
  end
@@ -4,70 +4,76 @@ class Spontaneous::Site
4
4
  module Selectors
5
5
  extend Spontaneous::Concern
6
6
 
7
- module ClassMethods
8
- def root(content_model = Spontaneous::Content)
9
- content_model.root
10
- end
7
+ def home
8
+ model.root
9
+ end
11
10
 
12
- # roots returns the list of top-level pages
13
- # Only one of these is publicly visible and this is mapped to the
14
- # configured site domain.
15
- #
16
- # The rest are "hidden" roots.
17
- def roots(user = nil, content_model = Spontaneous::Content)
18
- domain = config.site_domain
19
- roots = pages_dataset(content_model).where(depth: 0).all
20
- pub, hidden = roots.partition { |p| p.root? }
21
- map = {}
22
- map[domain] = pub.first.id unless pub.empty?
23
- hidden.each { |p| map[p.path] = p.id }
24
- { "public" => domain, "roots" => map }
25
- end
11
+ # roots returns the list of top-level pages
12
+ # Only one of these is publicly visible and this is mapped to the
13
+ # configured site domain.
14
+ #
15
+ # The rest are "hidden" roots.
16
+ def roots(user = nil)
17
+ domain = config.site_domain
18
+ roots = pages_dataset.where(depth: 0).all
19
+ pub, hidden = roots.partition { |p| p.root? }
20
+ map = {}
21
+ map[domain] = pub.first.id unless pub.empty?
22
+ hidden.each { |p| map[p.path] = p.id }
23
+ { "public" => domain, "roots" => map }
24
+ end
26
25
 
27
- def pages(content_model = Spontaneous::Content)
28
- pages_dataset(content_model).all
29
- end
26
+ def pages
27
+ pages_dataset.all
28
+ end
30
29
 
31
- def pages_dataset(content_model = Spontaneous::Content)
32
- content_model::Page.order(:depth)
33
- end
30
+ def pages_dataset
31
+ model::Page.order(:depth)
32
+ end
34
33
 
35
- ID_PATH = /\A\d+\z/o
36
- PATH_PATH = /^[\/#]/o
37
- UID_PATH = /^\$/o
34
+ ID_SELECTOR = /\A\d+\z/o
35
+ PATH_SELECTOR = /\A[\/#]/o
36
+ UID_SELECTOR = /\A\$/o
38
37
 
39
- def [](path_or_uid)
40
- case path_or_uid
41
- when Fixnum, ID_PATH
42
- by_id(path_or_uid)
43
- when PATH_PATH
44
- by_path(path_or_uid)
45
- when UID_PATH
46
- by_uid(path_or_uid[1..-1])
47
- else
48
- by_uid(path_or_uid)
49
- end
50
- end
38
+ def [](selector)
39
+ fetch(selector)
40
+ end
51
41
 
52
- def by_id(id)
53
- Spontaneous::Content[id]
42
+ def fetch(selector)
43
+ case selector
44
+ when Symbol
45
+ by_uid(selector.to_s)
46
+ when Fixnum
47
+ by_id(selector)
48
+ when ID_SELECTOR
49
+ by_id(selector)
50
+ when PATH_SELECTOR
51
+ by_path(selector)
52
+ when UID_SELECTOR
53
+ by_uid(selector[1..-1])
54
+ else
55
+ by_uid(selector)
54
56
  end
57
+ end
55
58
 
56
- def by_path(path)
57
- Spontaneous::Content.path(path)
58
- end
59
+ def by_id(id)
60
+ model.id(id)
61
+ end
59
62
 
60
- def by_uid(uid)
61
- Spontaneous::Content.uid(uid)
62
- end
63
+ def by_path(path)
64
+ model.path(path)
65
+ end
66
+
67
+ def by_uid(uid)
68
+ model.uid(uid)
69
+ end
63
70
 
64
- def method_missing(method, *args)
65
- if page = self[method.to_s]
66
- page
67
- else
68
- super
69
- end
71
+ def method_missing(method, *args)
72
+ if (page = fetch(method))
73
+ page
74
+ else
75
+ super
70
76
  end
71
- end # ClassMethods
77
+ end
72
78
  end
73
79
  end
@@ -4,34 +4,40 @@ class Spontaneous::Site
4
4
  module State
5
5
  extend Spontaneous::Concern
6
6
 
7
- module ClassMethods
8
- def working_revision
9
- Spontaneous::State.revision
10
- end
11
-
12
- def revision
13
- Spontaneous::State.revision
14
- end
15
-
16
- def published_revision
17
- Spontaneous::State.published_revision
18
- end
19
-
20
- def pending_revision
21
- Spontaneous::State.pending_revision
22
- end
23
-
24
- def modified_at
25
- Spontaneous::State.modified_at
26
- end
27
-
28
- def revision_root(*path)
29
- instance.revision_root(*path)
30
- end
31
-
32
- def revision_dir(revision=nil, root = nil)
33
- instance.revision_dir(revision, root)
34
- end
35
- end # ClassMethods
36
- end # Revisions
7
+ def working_revision
8
+ Spontaneous::State.revision
9
+ end
10
+
11
+ def revision
12
+ Spontaneous::State.revision
13
+ end
14
+
15
+ def published_revision
16
+ Spontaneous::State.published_revision
17
+ end
18
+
19
+ def pending_revision
20
+ Spontaneous::State.pending_revision
21
+ end
22
+
23
+ def modified_at
24
+ Spontaneous::State.modified_at
25
+ end
26
+
27
+ def must_publish_all?
28
+ Spontaneous::State.must_publish_all?
29
+ end
30
+
31
+ def must_publish_all!(state = true)
32
+ Spontaneous::State.must_publish_all!(state)
33
+ end
34
+
35
+ def revision_root(*path)
36
+ instance.revision_root(*path)
37
+ end
38
+
39
+ def revision_dir(revision=nil, root = nil)
40
+ instance.revision_dir(revision, root)
41
+ end
42
+ end
37
43
  end