pulitzer 0.14.4 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/pulitzer/arrangement_styles_controller.rb +1 -3
  3. data/app/controllers/pulitzer/background_styles_controller.rb +1 -3
  4. data/app/controllers/pulitzer/free_form_section_types_controller.rb +4 -4
  5. data/app/controllers/pulitzer/justification_styles_controller.rb +1 -3
  6. data/app/controllers/pulitzer/partial_types_controller.rb +0 -1
  7. data/app/controllers/pulitzer/post_type_content_element_types_controller.rb +4 -4
  8. data/app/controllers/pulitzer/post_type_versions_controller.rb +54 -0
  9. data/app/controllers/pulitzer/post_types_controller.rb +1 -5
  10. data/app/controllers/pulitzer/posts_controller.rb +3 -3
  11. data/app/controllers/pulitzer/sequence_flow_styles_controller.rb +1 -3
  12. data/app/controllers/pulitzer/versions_controller.rb +8 -2
  13. data/app/helpers/pulitzer/posts_helper.rb +7 -7
  14. data/app/interactions/pulitzer/create_free_form_section_partials.rb +2 -2
  15. data/app/interactions/pulitzer/create_post_type_content_elements.rb +3 -3
  16. data/app/interactions/pulitzer/create_post_type_free_form_sections.rb +3 -3
  17. data/app/interactions/pulitzer/create_singleton_post.rb +6 -6
  18. data/app/interactions/pulitzer/destroy_post_type_content_elements.rb +3 -3
  19. data/app/interactions/pulitzer/destroy_post_type_free_form_sections.rb +3 -3
  20. data/app/interactions/pulitzer/post_type_versions_controller/change_state.rb +15 -0
  21. data/app/interactions/pulitzer/post_type_versions_controller/create.rb +18 -0
  22. data/app/interactions/pulitzer/post_types_controller/create_singleton_post.rb +15 -0
  23. data/app/interactions/pulitzer/post_types_controller/create_template_version.rb +12 -0
  24. data/app/interactions/pulitzer/update_post_type_content_elements.rb +4 -4
  25. data/app/interactions/pulitzer/update_post_type_free_form_sections.rb +3 -3
  26. data/app/interactions/pulitzer/update_singleton_post.rb +6 -4
  27. data/app/models/pulitzer/arrangement_style.rb +1 -1
  28. data/app/models/pulitzer/background_style.rb +1 -1
  29. data/app/models/pulitzer/free_form_section_type.rb +1 -1
  30. data/app/models/pulitzer/justification_style.rb +1 -1
  31. data/app/models/pulitzer/partial.rb +8 -3
  32. data/app/models/pulitzer/post.rb +10 -2
  33. data/app/models/pulitzer/post_type.rb +10 -39
  34. data/app/models/pulitzer/post_type_content_element_type.rb +1 -1
  35. data/app/models/pulitzer/post_type_element.rb +1 -1
  36. data/app/models/pulitzer/post_type_version.rb +84 -0
  37. data/app/models/pulitzer/sequence_flow_style.rb +1 -1
  38. data/app/services/pulitzer/post_type_version/preview.rb +30 -0
  39. data/app/services/pulitzer/post_type_version/publish.rb +38 -0
  40. data/app/services/pulitzer/post_type_version/retire.rb +20 -0
  41. data/app/views/pulitzer/arrangement_styles/_new.html.erb +3 -3
  42. data/app/views/pulitzer/arrangement_styles/_show.html.erb +10 -6
  43. data/app/views/pulitzer/background_styles/_new.html.erb +3 -3
  44. data/app/views/pulitzer/background_styles/_show.html.erb +10 -6
  45. data/app/views/pulitzer/free_form_section_types/_new.html.erb +3 -3
  46. data/app/views/pulitzer/justification_styles/_new.html.erb +3 -3
  47. data/app/views/pulitzer/justification_styles/_show.html.erb +10 -6
  48. data/app/views/pulitzer/partials/_new.html.erb +8 -8
  49. data/app/views/pulitzer/post_type_content_element_types/_form.html.erb +0 -2
  50. data/app/views/pulitzer/post_type_content_element_types/_form_fields.html.erb +2 -2
  51. data/app/views/pulitzer/post_type_content_element_types/_new.html.erb +2 -2
  52. data/app/views/pulitzer/post_type_content_element_types/_show.html.erb +6 -2
  53. data/app/views/pulitzer/post_type_versions/_index.html.erb +15 -0
  54. data/app/views/pulitzer/post_type_versions/_show.html.erb +20 -0
  55. data/app/views/pulitzer/post_type_versions/_show_wrapper.html.erb +3 -0
  56. data/app/views/pulitzer/{post_types → post_type_versions}/_template.html.erb +34 -34
  57. data/app/views/pulitzer/post_types/_show.html.erb +3 -9
  58. data/app/views/pulitzer/post_types/index.html.erb +13 -10
  59. data/app/views/pulitzer/posts/_breadcrumbs.html.erb +4 -0
  60. data/app/views/pulitzer/posts/_edit.html.erb +5 -4
  61. data/app/views/pulitzer/posts/_index.html.erb +3 -3
  62. data/app/views/pulitzer/posts/_new.html.erb +1 -1
  63. data/app/views/pulitzer/posts/_show.html.erb +1 -1
  64. data/app/views/pulitzer/posts/_show_slug.html.erb +1 -1
  65. data/app/views/pulitzer/sequence_flow_styles/_new.html.erb +3 -3
  66. data/app/views/pulitzer/sequence_flow_styles/_show.html.erb +10 -6
  67. data/config/routes.rb +6 -4
  68. data/db/migrate/20170515230633_create_post_type_version.rb +9 -0
  69. data/db/migrate/20170515232938_reconnect_post_type_to_post.rb +13 -0
  70. data/lib/generators/pulitzer/post_type_generator.rb +24 -4
  71. data/lib/pulitzer.rb +1 -0
  72. data/lib/pulitzer/controller_helpers.rb +9 -0
  73. data/lib/pulitzer/version.rb +1 -1
  74. metadata +19 -4
  75. data/app/interactions/pulitzer/destroy_free_form_section_partials.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d336f6ddeff452b294cb889da9d0847707f893d1
4
- data.tar.gz: bd1ebbfa2c2882b65d39921d8990cd232a5fb279
3
+ metadata.gz: 0df49a7939d9ace02ebfe847087de3131b1a965a
4
+ data.tar.gz: f4f23a63b4f53dece53b66a4f0ed29a7952c1af1
5
5
  SHA512:
6
- metadata.gz: e80809191cf130c66281f092577cc6c6236583f69231026bfeae2020bacffc97425c7358f95c6b83dbc172718544dc1d82e825998ba74bda7854834c267df170
7
- data.tar.gz: a6fe3bed005ab4c753dc4ab7d1ac99d8e7017afd7790a9271abb66648edb3455e3f9a4c1a19ce220a11bd686f11a895a6c496868c2c5c449f7ae0690083fb2c4
6
+ metadata.gz: 6bc0696eac392143c15aad0104e106e86802382dce526bf2a0c098e1ff57a4acd5d3b88df9c238e57e0403f98b0f5c74fcc05bde2d83bb97c02f00b93edd4d37
7
+ data.tar.gz: fc751dcec13a5765799467e27c3d516bb26526fe1e9b93b942a61028561badcfb8df8e07111ba43eff832f0a03298775e13229de4556bbe7546936a06d179b33
@@ -3,7 +3,6 @@ class Pulitzer::ArrangementStylesController < Pulitzer::ApplicationController
3
3
 
4
4
  def new
5
5
  @arrangement_style = Pulitzer::ArrangementStyle.new(arrangement_style_params)
6
- @post_type = @arrangement_style.post_type
7
6
  render partial: 'new', locals: {arrangement_style: @arrangement_style}
8
7
  end
9
8
 
@@ -12,8 +11,7 @@ class Pulitzer::ArrangementStylesController < Pulitzer::ApplicationController
12
11
  if @arrangement_style.errors.empty?
13
12
  render partial: 'show_wrapper', locals: {arrangement_style: @arrangement_style}
14
13
  else
15
- @post_type = @arrangement_style.post_type
16
- render partial: 'new', locals: {arrangement_style: @arrangement_style}
14
+ render partial: 'new', locals: {arrangement_style: @arrangement_style}, status: 409
17
15
  end
18
16
  end
19
17
 
@@ -3,7 +3,6 @@ class Pulitzer::BackgroundStylesController < Pulitzer::ApplicationController
3
3
 
4
4
  def new
5
5
  @background_style = Pulitzer::BackgroundStyle.new(background_style_params)
6
- @post_type = @background_style.post_type
7
6
  render partial: 'new', locals: {background_style: @background_style}
8
7
  end
9
8
 
@@ -12,8 +11,7 @@ class Pulitzer::BackgroundStylesController < Pulitzer::ApplicationController
12
11
  if @background_style.errors.empty?
13
12
  render partial: 'show_wrapper', locals: {background_style: @background_style}
14
13
  else
15
- @post_type = @background_style.post_type
16
- render partial: 'new', locals: {background_style: @background_style}
14
+ render partial: 'new', locals: {background_style: @background_style}, status: 409
17
15
  end
18
16
  end
19
17
 
@@ -2,14 +2,14 @@ class Pulitzer::FreeFormSectionTypesController < Pulitzer::ApplicationController
2
2
  before_action :get_ffst, only: [:show, :edit, :update, :destroy]
3
3
 
4
4
  def new
5
- @post_type = Pulitzer::PostType.find(params[:post_type_id])
6
- @ffst = @post_type.free_form_section_types.build
5
+ @post_type_version = Pulitzer::PostTypeVersion.find(params[:post_type_version_id])
6
+ @ffst = @post_type_version.free_form_section_types.build
7
7
  render partial: 'new', locals: {ffst: @ffst}
8
8
  end
9
9
 
10
10
  def create
11
- @post_type = Pulitzer::PostType.find(ffst_params[:post_type_id])
12
- @ffst = @post_type.free_form_section_types.create(ffst_params)
11
+ @post_type_version = Pulitzer::PostTypeVersion.find(ffst_params[:post_type_version_id])
12
+ @ffst = @post_type_version.free_form_section_types.create(ffst_params)
13
13
  Pulitzer::CreatePostTypeFreeFormSections.new(@ffst).call
14
14
  render partial: 'show_wrapper', locals: {ffst: @ffst}
15
15
  end
@@ -3,7 +3,6 @@ class Pulitzer::JustificationStylesController < Pulitzer::ApplicationController
3
3
 
4
4
  def new
5
5
  @justification_style = Pulitzer::JustificationStyle.new(justification_style_params)
6
- @post_type = @justification_style.post_type
7
6
  render partial: 'new', locals: {justification_style: @justification_style}
8
7
  end
9
8
 
@@ -12,8 +11,7 @@ class Pulitzer::JustificationStylesController < Pulitzer::ApplicationController
12
11
  if @justification_style.errors.empty?
13
12
  render partial: 'show_wrapper', locals: {justification_style: @justification_style}
14
13
  else
15
- @post_type = @justification_style.post_type
16
- render partial: 'new', locals: {justification_style: @justification_style}
14
+ render partial: 'new', locals: {justification_style: @justification_style}, status: 409
17
15
  end
18
16
  end
19
17
 
@@ -29,7 +29,6 @@ class Pulitzer::PartialTypesController < Pulitzer::ApplicationController
29
29
  end
30
30
 
31
31
  def destroy
32
- Pulitzer::DestroyFreeFormSectionPartials.new(@partial_type).call
33
32
  @partial_type.destroy
34
33
  head :ok
35
34
  end
@@ -2,14 +2,14 @@ class Pulitzer::PostTypeContentElementTypesController < Pulitzer::ApplicationCon
2
2
  before_action :get_ptcet, only: [:show, :edit, :update, :destroy]
3
3
 
4
4
  def new
5
- @post_type = Pulitzer::PostType.find(params[:post_type_id])
6
- @ptcet = @post_type.post_type_content_element_types.build
5
+ @post_type_version = Pulitzer::PostTypeVersion.find(params[:post_type_version_id])
6
+ @ptcet = @post_type_version.post_type_content_element_types.build
7
7
  render partial: 'new', locals: {ptcet: @ptcet}
8
8
  end
9
9
 
10
10
  def create
11
- @post_type = Pulitzer::PostType.find(ptcet_params[:post_type_id])
12
- @ptcet = @post_type.post_type_content_element_types.create(ptcet_params)
11
+ @post_type_version = Pulitzer::PostTypeVersion.find(ptcet_params[:post_type_version_id])
12
+ @ptcet = @post_type_version.post_type_content_element_types.create(ptcet_params)
13
13
  Pulitzer::CreatePostTypeContentElements.new(@ptcet).call
14
14
  render partial: 'show_wrapper', locals: {ptcet: @ptcet}
15
15
  end
@@ -0,0 +1,54 @@
1
+ class Pulitzer::PostTypeVersionsController < Pulitzer::ApplicationController
2
+ before_filter :get_post_type_version, except: [:index, :new, :create]
3
+
4
+ def index
5
+ @post_type = Pulitzer::PostType.find(params[:post_type_id])
6
+ @post_type_versions = @post_type.post_type_versions
7
+ render_ajax
8
+ end
9
+
10
+ def create
11
+ @post_type_version = Create.new(post_type_version_params).call
12
+ render partial: 'show_wrapper', locals: {post_type_version: @post_type_version}
13
+ end
14
+
15
+ def show
16
+ render partial: 'show', locals: {post_type_version: @post_type_version}
17
+ end
18
+
19
+ def destroy
20
+ @post_type_version.destroy
21
+ render nothing: true
22
+ end
23
+
24
+ def template
25
+ render_ajax locals: {post_type_version: @post_type_version}
26
+ end
27
+
28
+ def change_state
29
+ Pulitzer::PostTypeVersionsController::ChangeState.new(@post_type_version,params[:state_change]).call
30
+ if @post_type_version.errors.empty?
31
+ render partial: 'show', locals: {post_type_version: @post_type_version}
32
+ else
33
+ render json: {
34
+ flash_message: @post_type_version.errors.full_messages.join('<br>'),
35
+ html: render_to_string(partial: 'show', locals: {post_type_version: @post_type_version}) },
36
+ status: :conflict
37
+ end
38
+ end
39
+
40
+ protected
41
+
42
+ def post_type_version_params
43
+ params[:post_type_version].permit!
44
+ end
45
+
46
+ def post_params_name
47
+ params[:post_type_version][:name]
48
+ end
49
+
50
+ def get_post_type_version
51
+ @post_type_version = Pulitzer::PostTypeVersion.find(params[:id])
52
+ end
53
+
54
+ end
@@ -20,7 +20,7 @@ class Pulitzer::PostTypesController < Pulitzer::ApplicationController
20
20
 
21
21
  def create
22
22
  @post_type = Pulitzer::PostType.create(post_type_params)
23
- Pulitzer::CreateSingletonPost.new(@post_type).call
23
+ CreateTemplateVersion.new(@post_type).call
24
24
  render partial: 'show_wrapper', locals: {post_type: @post_type}
25
25
  end
26
26
 
@@ -28,10 +28,6 @@ class Pulitzer::PostTypesController < Pulitzer::ApplicationController
28
28
  render partial: 'show', locals: {post_type: @post_type}
29
29
  end
30
30
 
31
- def template
32
- render_ajax locals: {post_type: @post_type}
33
- end
34
-
35
31
  def edit
36
32
  render partial: 'form', locals: {post_type: @post_type}
37
33
  end
@@ -4,13 +4,13 @@ class Pulitzer::PostsController < Pulitzer::ApplicationController
4
4
  before_action :get_version, only: [:edit_slug, :show_slug, :update_slug]
5
5
 
6
6
  def index
7
- @post_type = Pulitzer::PostType.find params[:post_type_id]
8
- @posts = Pulitzer::Post.where(post_type: @post_type).order(id: :desc)
7
+ @post_type_version = Pulitzer::PostTypeVersion.find params[:post_type_version_id]
8
+ @posts = Pulitzer::Post.where(post_type_version_id: @post_type_version).order(id: :desc)
9
9
  render_ajax
10
10
  end
11
11
 
12
12
  def new
13
- @post = Pulitzer::Post.new(post_type_id: params[:post_type_id])
13
+ @post = Pulitzer::Post.new(post_type_version_id: params[:post_type_version_id])
14
14
  render_ajax locals: { post: @post }
15
15
  end
16
16
 
@@ -3,7 +3,6 @@ class Pulitzer::SequenceFlowStylesController < Pulitzer::ApplicationController
3
3
 
4
4
  def new
5
5
  @sequence_flow_style = Pulitzer::SequenceFlowStyle.new(sequence_flow_style_params)
6
- @post_type = @sequence_flow_style.post_type
7
6
  render partial: 'new', locals: {sequence_flow_style: @sequence_flow_style}
8
7
  end
9
8
 
@@ -12,8 +11,7 @@ class Pulitzer::SequenceFlowStylesController < Pulitzer::ApplicationController
12
11
  if @sequence_flow_style.errors.empty?
13
12
  render partial: 'show_wrapper', locals: {sequence_flow_style: @sequence_flow_style}
14
13
  else
15
- @post_type = @sequence_flow_style.post_type
16
- render partial: 'new', locals: {sequence_flow_style: @sequence_flow_style}
14
+ render partial: 'new', locals: {sequence_flow_style: @sequence_flow_style}, status: 409
17
15
  end
18
16
  end
19
17
 
@@ -3,8 +3,14 @@ class Pulitzer::VersionsController < Pulitzer::ApplicationController
3
3
 
4
4
  def edit
5
5
  if @version.preview?
6
- route = "#{Pulitzer.preview_namespace}_#{@post.post_type.name.parameterize('_')}_path"
7
- @preview_path = main_app.public_send(route, @post.slug) if main_app.respond_to?(route)
6
+ route = "#{Pulitzer.preview_namespace}_#{@post.post_type.name.parameterize('_')}_path"
7
+ if main_app.respond_to?(route)
8
+ if @post.plural?
9
+ @preview_path = main_app.public_send(route, @post.slug, {version_number: @post.post_type_version.version_number})
10
+ else
11
+ @preview_path = main_app.public_send(route, {version_number: @post.post_type_version.version_number})
12
+ end
13
+ end
8
14
  end
9
15
  render_ajax locals: { version: @version }
10
16
  end
@@ -1,17 +1,17 @@
1
1
  module Pulitzer
2
2
  module PostsHelper
3
3
 
4
- def link_to_posts(post_type, plural_label, singular_label)
5
- if post_type.plural?
6
- ajax_link plural_label, posts_path(post_type_id: post_type.id), {}, '[data-tab-id="templates"]'
4
+ def link_to_posts(post_type_version, plural_label, singular_label)
5
+ if post_type_version.plural?
6
+ ajax_link plural_label, posts_path(post_type_version_id: post_type_version.id), {}, '[data-tab-id="templates"]'
7
7
  else
8
- ajax_link singular_label, edit_post_path(post_type.singleton_post), {}, '[data-tab-id="templates"]'
8
+ ajax_link singular_label, edit_post_path(post_type_version.singleton_post), {}, '[data-tab-id="templates"]'
9
9
  end
10
10
  end
11
11
 
12
- def link_back_to_posts(post_type, plural_label, singular_label)
13
- if post_type.plural?
14
- ajax_link plural_label, pulitzer.posts_path(post_type_id: post_type.id), {}, '[data-tab-id="templates"]'
12
+ def link_back_to_posts(post_type_version, plural_label, singular_label)
13
+ if post_type_version.plural?
14
+ ajax_link plural_label, pulitzer.posts_path(post_type_version_id: post_type_version.id), {}, '[data-tab-id="templates"]'
15
15
  else
16
16
  ajax_link singular_label, pulitzer.post_types_path, {}, '[data-tab-id="templates"]'
17
17
  end
@@ -6,8 +6,8 @@ class Pulitzer::CreateFreeFormSectionPartials
6
6
 
7
7
  def call
8
8
  free_form_section_type = @partial_type.free_form_section_type
9
- post_type = free_form_section_type.post_type
10
- post_type.posts.each do |post|
9
+ post_type_version = free_form_section_type.post_type_version
10
+ post_type_version.posts.each do |post|
11
11
  if post.preview_version
12
12
  free_form_section = post.preview_version.free_form_sections.find_by(name: free_form_section_type.name)
13
13
  partial = free_form_section.partials.create do |p|
@@ -1,13 +1,13 @@
1
1
  class Pulitzer::CreatePostTypeContentElements
2
- attr_accessor :post_type, :ptcet, :old_label
2
+ attr_accessor :post_type_version, :ptcet, :old_label
3
3
 
4
4
  def initialize(ptcet)
5
- self.post_type = ptcet.post_type
5
+ self.post_type_version = ptcet.post_type_version
6
6
  self.ptcet = ptcet
7
7
  end
8
8
 
9
9
  def call
10
- post_type.posts.each do |post|
10
+ post_type_version.posts.each do |post|
11
11
  post.preview_version.content_elements.create do |ce|
12
12
  ce.label = ptcet.label
13
13
  ce.height = ptcet.height
@@ -1,13 +1,13 @@
1
1
  class Pulitzer::CreatePostTypeFreeFormSections
2
- attr_accessor :post_type, :ffst, :old_label
2
+ attr_accessor :post_type_version, :ffst, :old_label
3
3
 
4
4
  def initialize(ffst)
5
- self.post_type = ffst.post_type
5
+ self.post_type_version = ffst.post_type_version
6
6
  self.ffst = ffst
7
7
  end
8
8
 
9
9
  def call
10
- post_type.posts.each do |post|
10
+ post_type_version.posts.each do |post|
11
11
  if post.preview_version
12
12
  post.preview_version.free_form_sections.create do |ffs|
13
13
  ffs.name = ffst.name
@@ -1,14 +1,14 @@
1
1
  class Pulitzer::CreateSingletonPost
2
- attr_accessor :post_type, :title
2
+ attr_accessor :post_type_version, :title
3
3
 
4
- def initialize(post_type)
5
- self.post_type = post_type
6
- self.title = post_type.name
4
+ def initialize(post_type_version)
5
+ self.post_type_version = post_type_version
6
+ self.title = post_type_version.name
7
7
  end
8
8
 
9
9
  def call
10
- if post_type.singular? && !post_type.posts.any?
11
- singleton_post = post_type.posts.create(title: title)
10
+ if post_type_version.singular? && !post_type_version.posts.any?
11
+ singleton_post = post_type_version.posts.create(title: title)
12
12
  Pulitzer::CreatePostContentElements.new(singleton_post).call
13
13
  end
14
14
  end
@@ -1,13 +1,13 @@
1
1
  class Pulitzer::DestroyPostTypeContentElements
2
- attr_accessor :post_type, :ptcet
2
+ attr_accessor :post_type_version, :ptcet
3
3
 
4
4
  def initialize(ptcet)
5
- self.post_type = ptcet.post_type
5
+ self.post_type_version = ptcet.post_type_version
6
6
  self.ptcet = ptcet
7
7
  end
8
8
 
9
9
  def call
10
- post_type.posts.each do |post|
10
+ post_type_version.posts.each do |post|
11
11
  post.preview_version.content_elements.where(label: ptcet.label).each do |ce|
12
12
  ce.destroy
13
13
  end
@@ -1,13 +1,13 @@
1
1
  class Pulitzer::DestroyPostTypeFreeFormSections
2
- attr_accessor :post_type, :ffst
2
+ attr_accessor :post_type_version, :ffst
3
3
 
4
4
  def initialize(ffst)
5
- self.post_type = ffst.post_type
5
+ self.post_type_version = ffst.post_type_version
6
6
  self.ffst = ffst
7
7
  end
8
8
 
9
9
  def call
10
- post_type.posts.each do |post|
10
+ post_type_version.posts.each do |post|
11
11
  post.preview_version.free_form_sections.where(free_form_section_type_id: ffst.id).each do |ffs|
12
12
  ffs.destroy
13
13
  end
@@ -0,0 +1,15 @@
1
+ class Pulitzer::PostTypeVersionsController::ChangeState
2
+
3
+ def initialize(ptv,state_change)
4
+ @ptv, @state_change = ptv, state_change.to_sym
5
+ end
6
+
7
+ def call
8
+ sanitize_state_change or return false
9
+ @ptv.send @state_change
10
+ end
11
+
12
+ def sanitize_state_change
13
+ return [:publish,:retire,:preview].include? @state_change
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ class Pulitzer::PostTypeVersionsController::Create
2
+
3
+ def initialize(params)
4
+ @params = params.to_h.to_hash.symbolize_keys
5
+ end
6
+
7
+ def call
8
+ @ptv = Pulitzer::PostTypeVersion.new(@params)
9
+ @post_type = @ptv.post_type
10
+ last_version_number = @post_type.post_type_versions.maximum(:version_number) || 0
11
+ this_version_number = last_version_number + 1
12
+ @ptv.version_number = this_version_number
13
+ @ptv.save
14
+ CreateSingletonPost.new(@ptv).call
15
+ @ptv
16
+ end
17
+
18
+ end
@@ -0,0 +1,15 @@
1
+ class Pulitzer::CreateSingletonPost
2
+ attr_accessor :post_type_version, :title
3
+
4
+ def initialize(post_type_version)
5
+ self.post_type_version = post_type_version
6
+ self.title = post_type_version.name
7
+ end
8
+
9
+ def call
10
+ if post_type_version.singular? && !post_type_version.posts.any?
11
+ singleton_post = post_type_version.posts.create(title: title)
12
+ Pulitzer::CreatePostContentElements.new(singleton_post).call
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ class Pulitzer::PostTypesController::CreateTemplateVersion
2
+
3
+ def initialize(post_type)
4
+ @post_type = post_type
5
+ end
6
+
7
+ def call
8
+ post_type_version = @post_type.post_type_versions.create
9
+ CreateSingletonPost.new(post_type_version).call
10
+ end
11
+
12
+ end