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
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ Sequel.migration do
4
+ up do
5
+ add_column :spontaneous_state, :must_publish_all, TrueClass, default: true
6
+ # although we want new state instances to set the force publish all flag it
7
+ # would be wrong for existing sites to have this flag set
8
+ self[:spontaneous_state].update(must_publish_all: false)
9
+ end
10
+
11
+ down do
12
+ drop_column :spontaneous_state, :must_publish_all, TrueClass
13
+ end
14
+ end
data/lib/spontaneous.rb CHANGED
@@ -69,7 +69,6 @@ module Spontaneous
69
69
  autoload :Simultaneous, "spontaneous/simultaneous"
70
70
  autoload :Site, "spontaneous/site"
71
71
  autoload :State, "spontaneous/state"
72
- autoload :Storage, "spontaneous/storage"
73
72
  autoload :Style, "spontaneous/style"
74
73
  autoload :Utils, "spontaneous/utils"
75
74
 
@@ -5,12 +5,6 @@ module Spontaneous
5
5
  class BoxStyle < Style
6
6
  attr_reader :box
7
7
 
8
- def self.excluded_classes
9
- [Spontaneous::Box, Spontaneous::Content::Box].tap do |classes|
10
- classes.push(::Box) if defined?(::Box)
11
- end
12
- end
13
-
14
8
  def self.to_directory_name(klass)
15
9
  return nil if excluded_classes.include?(klass)
16
10
  super
@@ -25,7 +19,7 @@ module Spontaneous
25
19
  nil
26
20
  end
27
21
 
28
- def try_supertype_styles
22
+ def try_supertype_styles(renderer)
29
23
  []
30
24
  end
31
25
 
@@ -64,9 +58,21 @@ module Spontaneous
64
58
 
65
59
  def box_directory_names
66
60
  box_class = box._prototype.box_base_class
67
- box_supertypes = [box_class].concat(class_ancestors(box_class)).reject { |type| self.class.excluded_classes.include?(type) }
61
+ box_supertypes = [box_class].concat(class_ancestors(box_class)).reject { |type| excluded_classes.include?(type) }
68
62
  return [nil] if box_supertypes.empty?
69
- box_supertypes.map { |type| self.class.to_directory_name(type) }
63
+ box_supertypes.map { |type| to_directory_name(type) }
64
+ end
65
+
66
+ def excluded_classes
67
+ model = box.model.content_model
68
+ [Spontaneous::Box, model::Box].tap do |classes|
69
+ classes.push(::Box) if defined?(::Box)
70
+ end
71
+ end
72
+
73
+ def to_directory_name(klass)
74
+ return nil if excluded_classes.include?(klass)
75
+ super
70
76
  end
71
77
 
72
78
  def box_directory_paths(name)
@@ -15,7 +15,7 @@ Capistrano::Configuration.instance(:must_exist).load do
15
15
  namespace :spot do
16
16
  task :symlink_cache do
17
17
  cache_dir = File.join(latest_release, 'cache')
18
- run "mkdir #{cache_dir}; ln -s #{deploy_to}/media #{cache_dir}; ln -s #{deploy_to}/revisions #{cache_dir}; ln -s #{deploy_to}/uploadcache #{cache_dir}/tmp"
18
+ run "if [[ -d #{cache_dir} ]]; then rm -r #{cache_dir}; fi ; mkdir #{cache_dir}; ln -s #{deploy_to}/media #{cache_dir}; ln -s #{deploy_to}/revisions #{cache_dir}; ln -s #{deploy_to}/uploadcache #{cache_dir}/tmp"
19
19
  end
20
20
 
21
21
  task :symlink_application do
@@ -31,6 +31,16 @@ Capistrano::Configuration.instance(:must_exist).load do
31
31
  task :bundle_assets do
32
32
  run "cd #{release_path} && ./bin/spot assets compile --destination=#{release_path}"
33
33
  end
34
+
35
+ task :migrate, :roles => :db do
36
+ spot_env = fetch(:spot_env, "production")
37
+ run "cd #{release_path} && SPOT_ENV=#{spot_env} ./bin/spot migrate"
38
+ end
39
+
40
+ task :content_clean, :roles => :db do
41
+ spot_env = fetch(:spot_env, "production")
42
+ run "cd #{release_path} && SPOT_ENV=#{spot_env} ./bin/spot content clean"
43
+ end
34
44
  end
35
45
 
36
46
  namespace :deploy do
@@ -44,4 +54,6 @@ Capistrano::Configuration.instance(:must_exist).load do
44
54
  after 'deploy:finalize_update', 'spot:symlink_tmpdir'
45
55
  after 'bundle:install', 'spot:symlink_application'
46
56
  after 'bundle:install', 'spot:bundle_assets'
57
+ after 'bundle:install', 'spot:migrate'
58
+ after 'bundle:install', 'spot:content_clean'
47
59
  end
@@ -2,22 +2,20 @@
2
2
 
3
3
  module Spontaneous
4
4
  class Change
5
-
6
-
7
5
  class << self
8
- def outstanding
9
- outstanding = { :published_revision => Spontaneous::Site.published_revision,
10
- :changes => unpublished_changes }
6
+ def outstanding(site)
7
+ outstanding = { :published_revision => site.published_revision, :must_publish_all => site.must_publish_all?,
8
+ :changes => unpublished_changes(site) }
11
9
  outstanding[:first_publish] = true if outstanding[:published_revision] == 0
12
10
  outstanding
13
11
  end
14
12
 
15
- def unpublished_changes
16
- changes = unpublished_pages.map { |page| Change.new(page) }
13
+ def unpublished_changes(site)
14
+ changes = unpublished_pages(site).map { |page| Change.new(page) }
17
15
  end
18
16
 
19
- def unpublished_pages
20
- Spontaneous::Content::Page.filter { (modified_at > last_published_at) | {:first_published_at => nil} }.order(:modified_at.desc).all
17
+ def unpublished_pages(site)
18
+ site.model::Page.filter { (modified_at > last_published_at) | {:first_published_at => nil} }.order(Sequel.desc(:modified_at)).all
21
19
  end
22
20
 
23
21
  def include_dependencies(page_list)
@@ -26,9 +24,9 @@ module Spontaneous
26
24
  pages
27
25
  end
28
26
 
29
- def export
27
+ def export(site)
30
28
  exported = {}
31
- outstanding.each do |k, v|
29
+ outstanding(site).each do |k, v|
32
30
  case k
33
31
  when :changes
34
32
  exported[k] = v.map { |change_set| change_set.export }
@@ -39,8 +37,8 @@ module Spontaneous
39
37
  exported
40
38
  end
41
39
 
42
- def serialise_http(user = nil)
43
- Spontaneous.serialise_http(export)
40
+ def serialise_http(site)
41
+ Spontaneous.serialise_http(export(site))
44
42
  end
45
43
  end
46
44
 
@@ -66,6 +66,7 @@ module Spontaneous
66
66
  def boot!
67
67
  begin
68
68
  require File.expand_path('config/boot.rb')
69
+ Spontaneous::Site.instance
69
70
  rescue Spontaneous::SchemaModificationError => error
70
71
  fix_schema(error)
71
72
  end
@@ -94,6 +95,7 @@ module Spontaneous
94
95
  autoload :Site, "spontaneous/cli/site"
95
96
  autoload :Sync, "spontaneous/cli/sync"
96
97
  autoload :User, "spontaneous/cli/user"
98
+ autoload :Content, "spontaneous/cli/content"
97
99
 
98
100
  class Root < ::Thor
99
101
  register Spontaneous::Cli::Console, "console", "console", "Gives you console access to the current site"
@@ -104,11 +106,12 @@ module Spontaneous
104
106
  register Spontaneous::Cli::Init, "init", "init", "Creates databases and initialises a new Spontaneous site"
105
107
  register Spontaneous::Cli::Server, "server", "server [ACTION]", "Launch development server(s)"
106
108
  register Spontaneous::Cli::Server, "s", "s [ACTION]", "Launch development server(s)"
107
- register Spontaneous::Cli::Media, "media", "media [ACTION]", "Manage site media"
108
- register Spontaneous::Cli::Sync, "sync", "sync [DIRECTION]", "Sync database and media to and from the production server"
109
+ # register Spontaneous::Cli::Media, "media", "media [ACTION]", "Manage site media"
110
+ # register Spontaneous::Cli::Sync, "sync", "sync [DIRECTION]", "Sync database and media to and from the production server"
109
111
  register Spontaneous::Cli::Migrate, "migrate", "migrate", "Runs Spontaneous migrations"
110
112
  register Spontaneous::Cli::Assets, "assets", "assets [ACTION]", "Manage Spontaneous assets"
111
113
  register Spontaneous::Cli::Fields, "fields", "fields [ACTION]", "Manage Spontaneous fields"
114
+ register Spontaneous::Cli::Content, "content", "content [ACTION]", "Manage Spontaneous content"
112
115
 
113
116
  desc :browse, "Launces a browser pointing to the current development CMS"
114
117
  def browse
@@ -11,7 +11,13 @@ module Spontaneous
11
11
 
12
12
  method_option :destination, :type => :string, :aliases => "-d", :required => true, :desc => "Compile assets into DESTINATION"
13
13
 
14
- def compile
14
+ def compile(*args)
15
+ compile_assets
16
+ end
17
+
18
+ protected
19
+
20
+ def compile_assets
15
21
  prepare(:compile)
16
22
  # options[:mode] = :console
17
23
  # Find path to install of Spontaneous using bundler and then
@@ -11,7 +11,13 @@ module ::Spontaneous::Cli
11
11
  default_task :open
12
12
 
13
13
  desc "open", "Gives you console access to the current site"
14
- def open
14
+ def open(*args)
15
+ open_console
16
+ end
17
+
18
+ protected
19
+
20
+ def open_console
15
21
  prepare! :console
16
22
 
17
23
  ARGV.clear
@@ -0,0 +1,35 @@
1
+ module Spontaneous
2
+ module Cli
3
+ class Content < ::Thor
4
+ include Spontaneous::Cli::TaskUtils
5
+
6
+ namespace :content
7
+
8
+ desc "clean", "Cleans up the content after schema migration(s) by deleting instances belonging to deleted types and their children"
9
+
10
+ def clean(*args)
11
+ clean_content
12
+ end
13
+
14
+ protected
15
+
16
+ def clean_content
17
+ prepare!(:clean)
18
+ say "==> Cleaning content table..."
19
+ say ""
20
+ result = Spontaneous::Model::Action::Clean.run(Spontaneous::instance)
21
+ say "----> Deleted ", :bold
22
+ say "#{result[:invalid]} ", [:red, :bold]
23
+ say "entries with invalid schema types"
24
+ say "----> Deleted ", :bold
25
+ say "#{result[:orphans]} ", [:red, :bold]
26
+ say "orphaned entries"
27
+ say ""
28
+ if result[:publish]
29
+ say("====> Site is configured to force a full publish", [:red, :bold])
30
+ say ""
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -11,8 +11,9 @@ module Spontaneous
11
11
  method_option :fields, :type => :array, :desc => "List of field IDs to update"
12
12
  def update
13
13
  prepare! :update, :console
14
- fields = Spontaneous::Field.find(*options.fields)
15
- updater = Spontaneous::Field::Update::Immediate.new(fields)
14
+ site = Spontaneous::Site.instance
15
+ fields = Spontaneous::Field.find(site.model, *options.fields)
16
+ updater = Spontaneous::Field::Update::Immediate.new(site, fields)
16
17
  updater.run
17
18
  send_completion_event(updater)
18
19
  end
@@ -18,8 +18,7 @@ module Spontaneous::Cli
18
18
  method_option :password, :type => :string, :default => "", :aliases => "-p", :desc => "Database admin user"
19
19
 
20
20
  def site(*args)
21
- # require "spontaneous"
22
- ::Spontaneous::Generators::Site.start(ARGV.drop_while { |e| %w(generate site).include?(e) })
21
+ generate_site(args)
23
22
  end
24
23
 
25
24
  def method_missing(method, *args)
@@ -32,6 +31,10 @@ module Spontaneous::Cli
32
31
  super
33
32
  end
34
33
  end
34
+
35
+ def generate_site(args)
36
+ ::Spontaneous::Generators::Site.start(args.drop_while { |e| %w(generate site).include?(e) })
37
+ end
35
38
  end # Generate
36
39
  end # Spontaneous::Cli
37
40
 
@@ -23,7 +23,7 @@ module Spontaneous
23
23
  # method_option :adapter, :type => :string, :aliases => "-a", :desc => "Rack Handler (default: autodetect)"
24
24
  method_option :host, :type => :string, :aliases => "-h", :desc => "Bind to HOST address"
25
25
  method_option :port, :type => :numeric, :aliases => "-p", :desc => "Use PORT"
26
- def front
26
+ def front(*args)
27
27
  start_server(:front)
28
28
  end
29
29
 
@@ -31,16 +31,14 @@ module Spontaneous
31
31
  # method_option :adapter, :type => :string, :aliases => "-a", :desc => "Rack Handler (default: autodetect)"
32
32
  method_option :host, :type => :string, :aliases => "-h", :desc => "Bind to HOST address"
33
33
  method_option :port, :type => :numeric, :aliases => "-p", :desc => "Use PORT"
34
- def back
34
+ def back(*args)
35
35
  start_server(:back)
36
36
  end
37
37
 
38
38
  desc "simultaneous", "Launches the Simultaneous server"
39
39
  method_option :connection, :type => :string, :aliases => "-c", :desc => "Use CONNECTION"
40
- def simultaneous
41
- prepare! :start
42
- connection = options[:connection] || ::Spontaneous.config.simultaneous_connection
43
- exec({"BUNDLE_GEMFILE" => nil}, "#{::Simultaneous.server_binary} -c #{connection} --debug")
40
+ def simultaneous(*args)
41
+ start_simultaneous
44
42
  end
45
43
 
46
44
  # A shorter name for the 'simultaneous' task is useful (Foreman appends
@@ -65,8 +63,14 @@ module Spontaneous
65
63
  end
66
64
 
67
65
  def start_server(mode)
68
- prepare! :server, mode
69
- Spontaneous::Server.run!(options)
66
+ site = prepare! :server, mode
67
+ Spontaneous::Server.run!(site, options)
68
+ end
69
+
70
+ def start_simultaneous
71
+ prepare! :start
72
+ connection = options[:connection] || ::Spontaneous.config.simultaneous_connection
73
+ exec({"BUNDLE_GEMFILE" => nil}, "#{::Simultaneous.server_binary} -c #{connection} --debug")
70
74
  end
71
75
  end
72
76
  end
@@ -117,16 +117,16 @@ module Spontaneous
117
117
  method_option :pages, :type => :array, :desc => "List of pages to publish"
118
118
  method_option :logfile, :type => :string, :desc => "Location of logfile"
119
119
  def publish
120
- prepare! :publish
121
- Spontaneous::Site.background_mode = :immediate
120
+ site = prepare! :publish
121
+ site.background_mode = :immediate
122
122
  ::Spontaneous::Logger.setup(:logfile => options.logfile) if options.logfile
123
- say "Creating revision #{Spontaneous::Site.revision}", :green, true
123
+ say "Creating revision #{site.revision}", :green, true
124
124
  if options.pages
125
125
  say "> Publishing pages #{options.pages.inspect}", :green, true
126
- Spontaneous::Site.publish_pages(options.pages)
126
+ site.publish_pages(options.pages)
127
127
  else
128
128
  say "> Publishing all", :green, true
129
- Spontaneous::Site.publish_all
129
+ site.publish_all
130
130
  end
131
131
  # Rescue all errors to feed back to the UI
132
132
  rescue => e
@@ -136,23 +136,23 @@ module Spontaneous
136
136
 
137
137
  desc "render", "Re-renders the current content"
138
138
  def render
139
- prepare! :render
140
- Spontaneous::Site.background_mode = :immediate
141
- Spontaneous::Site.rerender
139
+ site = prepare! :render
140
+ site.background_mode = :immediate
141
+ site.rerender
142
142
  end
143
143
 
144
144
  desc "revision", "Shows the site status"
145
145
  def revision
146
- prepare! :revision
147
- say "Site is at revision #{Spontaneous::Site.revision}", :green
146
+ site = prepare! :revision
147
+ say "Site is at revision #{site.revision}", :green
148
148
  end
149
149
 
150
150
  desc "browse", "Launches a browser pointing to the current development CMS"
151
151
  def browse
152
- prepare :browse
152
+ site = prepare :browse
153
153
  require 'launchy'
154
154
  boot!
155
- ::Launchy.open("http://localhost:#{Spontaneous::Site.config.port}/@spontaneous")
155
+ ::Launchy.open("http://localhost:#{site.config.port}/@spontaneous")
156
156
  end
157
157
 
158
158
  private
@@ -20,7 +20,32 @@ module ::Spontaneous
20
20
  method_option :level, :type => :string, :aliases => "-a",
21
21
  :desc => "The user's access level"
22
22
 
23
- def add
23
+ def add(*args)
24
+ add_user
25
+ end
26
+
27
+
28
+ desc "list", "List the current users"
29
+ method_option :bare, :type => :boolean, :default => false, :aliases => %w(-b),
30
+ :desc => "Remove descriptive text from result"
31
+ def list(*args)
32
+ list_users
33
+ end
34
+
35
+
36
+ desc "authenticate LOGIN PASSWORD", "Test a user/password combination"
37
+ method_option :bare, :type => :boolean, :default => false, :aliases => %w(-b),
38
+ :desc => "Remove descriptive text from result"
39
+
40
+ def authenticate(*args)
41
+ args.shift if args.first == "authenticate"
42
+ login, password = args[0], args[1]
43
+ authenticate_user(login, password)
44
+ end
45
+
46
+ protected
47
+
48
+ def add_user
24
49
  prepare! :adduser, :console
25
50
 
26
51
  users = ::Spontaneous::Permissions::User.count
@@ -45,21 +70,12 @@ module ::Spontaneous
45
70
  end
46
71
  end
47
72
 
48
-
49
- desc "list", "List the current users"
50
- method_option :bare, :type => :boolean, :default => false, :aliases => %w(-b),
51
- :desc => "Remove descriptive text from result"
52
- def list
73
+ def list_users
53
74
  prepare! :listusers, :console
54
75
  user_table(::Spontaneous::Permissions::User.all, options.bare)
55
76
  end
56
77
 
57
-
58
- desc "authenticate LOGIN PASSWORD", "Test a user/password combination"
59
- method_option :bare, :type => :boolean, :default => false, :aliases => %w(-b),
60
- :desc => "Remove descriptive text from result"
61
-
62
- def authenticate(login, password)
78
+ def authenticate_user(login, password)
63
79
  prepare! :user_authenticate, :console
64
80
  key = Spontaneous::Permissions::User.authenticate login, password
65
81
  if key
@@ -71,8 +87,6 @@ module ::Spontaneous
71
87
  end
72
88
  end
73
89
 
74
- protected
75
-
76
90
  def user_table(users, hide_headers = false)
77
91
  columns = [:login, :name, :email, :level]
78
92
  users = ::Spontaneous::Permissions::User.all.map { |user|