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
@@ -1,14 +1,14 @@
1
1
  class Pulitzer::UpdatePostTypeContentElements
2
- attr_accessor :post_type, :ptcet, :old_label
2
+ attr_accessor :post_type_version, :ptcet, :old_label
3
3
 
4
4
  def initialize(ptcet, old_label=nil)
5
- self.post_type = ptcet.post_type
5
+ self.post_type_version = ptcet.post_type_version
6
6
  self.ptcet = ptcet
7
7
  self.old_label = old_label || ptcet.label
8
8
  end
9
9
 
10
10
  def call
11
- post_type.posts.each do |post|
11
+ post_type_version.posts.each do |post|
12
12
  begin
13
13
  preview_version = post.get_preview_version!
14
14
  post.preview_version.content_elements.where(label: old_label).each do |content_element|
@@ -23,7 +23,7 @@ class Pulitzer::UpdatePostTypeContentElements
23
23
  # if there is no preview version, skip this one.
24
24
  end
25
25
  end
26
- post_type.partials.joins(free_form_section: :version).where(pulitzer_versions: {status: 0}).each do |partial|
26
+ post_type_version.partials.joins(free_form_section: :version).where(pulitzer_versions: {status: 0}).each do |partial|
27
27
  partial.content_elements.where(label: old_label).each do |content_element|
28
28
  content_element.update(label: ptcet.label,
29
29
  height: ptcet.height,
@@ -1,14 +1,14 @@
1
1
  class Pulitzer::UpdatePostTypeFreeFormSections
2
- attr_accessor :post_type, :ffst, :old_label
2
+ attr_accessor :post_type_version, :ffst, :old_label
3
3
 
4
4
  def initialize(ffst, old_label=nil)
5
- self.post_type = ffst.post_type
5
+ self.post_type_version = ffst.post_type_version
6
6
  self.ffst = ffst
7
7
  self.old_label = old_label || ffst.label
8
8
  end
9
9
 
10
10
  def call
11
- post_type.posts.each do |post|
11
+ post_type_version.posts.each do |post|
12
12
  post.preview_version.free_form_sections.where(free_form_section_type_id: ffst.id).each do |ffs|
13
13
  ffs.update(name: ffst.name)
14
14
  end
@@ -8,10 +8,12 @@ class Pulitzer::UpdateSingletonPost
8
8
 
9
9
  def call
10
10
  if post_type.singular?
11
- unless post_type.singleton_post?
12
- Pulitzer::CreateSingletonPost.new(post_type).call
13
- else
14
- post_type.singleton_post.update(title: title)
11
+ post_type.preview_type_versions.each do |ptv|
12
+ unless ptv.singleton_post?
13
+ Pulitzer::CreateSingletonPost.new(ptv).call
14
+ else
15
+ ptv.singleton_post.update(title: title)
16
+ end
15
17
  end
16
18
  end
17
19
  end
@@ -1,6 +1,6 @@
1
1
  module Pulitzer
2
2
  class ArrangementStyle < ActiveRecord::Base
3
- belongs_to :post_type
3
+ belongs_to :post_type_version
4
4
  has_many :partials
5
5
  validates :display_name, presence: true
6
6
  validates :view_file_name, presence: true
@@ -1,6 +1,6 @@
1
1
  module Pulitzer
2
2
  class BackgroundStyle < ActiveRecord::Base
3
- belongs_to :post_type
3
+ belongs_to :post_type_version
4
4
  has_many :partials
5
5
  validates :display_name, presence: true
6
6
  validates :css_class_name, presence: true
@@ -2,7 +2,7 @@ module Pulitzer
2
2
  class FreeFormSectionType < ActiveRecord::Base
3
3
  include Pulitzer::PostTypeElement
4
4
 
5
- belongs_to :post_type
5
+ belongs_to :post_type_version
6
6
  has_many :free_form_sections
7
7
  has_many :partial_types, -> { order :id }
8
8
 
@@ -1,6 +1,6 @@
1
1
  module Pulitzer
2
2
  class JustificationStyle < ActiveRecord::Base
3
- belongs_to :post_type
3
+ belongs_to :post_type_version
4
4
  has_many :partials
5
5
  validates :display_name, presence: true
6
6
  validates :css_class_name, presence: true
@@ -1,15 +1,16 @@
1
1
  module Pulitzer
2
2
  class Partial < ActiveRecord::Base
3
3
  belongs_to :free_form_section
4
- belongs_to :post_type
4
+ belongs_to :post_type_version
5
5
  belongs_to :background_style
6
6
  belongs_to :justification_style
7
7
  belongs_to :sequence_flow_style
8
8
  belongs_to :arrangement_style
9
+ has_one :post_type, through: :post_type_version
9
10
 
10
11
  has_many :content_elements, dependent: :destroy
11
12
 
12
- delegate :name, :post_type_content_element_types, :has_display?, to: :post_type
13
+ delegate :name, :post_type_content_element_types, :has_display?, :post_type_id, :version_number, to: :post_type_version
13
14
  delegate :template_path, to: :layout, allow_nil: true
14
15
 
15
16
  before_save :handle_sort_order
@@ -56,6 +57,10 @@ module Pulitzer
56
57
  name.downcase.gsub(/ /,'_').gsub(/\W/,'')
57
58
  end
58
59
 
60
+ def version_folder
61
+ "v_#{version_number}"
62
+ end
63
+
59
64
  def template_path
60
65
  if arrangement_style.present?
61
66
  arrangement_style.view_file_name
@@ -65,7 +70,7 @@ module Pulitzer
65
70
  end
66
71
 
67
72
  def full_view_path
68
- Pulitzer.partial_folder + '/' + folder_path + '/' + template_path
73
+ File.join Pulitzer.partial_folder, folder_path, version_folder, template_path
69
74
  end
70
75
 
71
76
  def clone_me
@@ -5,8 +5,8 @@ module Pulitzer
5
5
  has_many :versions, dependent: :destroy
6
6
  has_one :active_version, -> { where(status: 'active') }, class_name: "Pulitzer::Version"
7
7
 
8
- belongs_to :post_type
9
- delegate :post_type_content_element_types, :free_form_section_types, :has_free_form_sections?, :has_templated_content_elements?, to: :post_type
8
+ belongs_to :post_type_version
9
+ delegate :post_type_content_element_types, :free_form_section_types, :has_free_form_sections?, :has_templated_content_elements?, :post_type, :post_type_id, :plural?, to: :post_type_version
10
10
  delegate :post_tags, :content_elements, :content_element, :section, :has_label_type, :has_label, :post_tags_for, to: :active_version, allow_nil: true
11
11
 
12
12
  friendly_id :title, use: [:slugged, :finders]
@@ -74,6 +74,14 @@ module Pulitzer
74
74
  versions.create(status: :processing)
75
75
  end
76
76
 
77
+ def editor_title
78
+ if post_type_version.published?
79
+ title
80
+ else
81
+ title + " version #{post_type_version.version_number}"
82
+ end
83
+ end
84
+
77
85
  def serialize
78
86
  self.attributes.merge \
79
87
  new_preview_version: self.new_preview_version
@@ -1,14 +1,14 @@
1
1
  class Pulitzer::PostType < ActiveRecord::Base
2
2
  enum kind: [ :template, :partial ]
3
- has_many :posts, dependent: :destroy
4
- has_many :partials, dependent: :destroy
5
- has_many :post_type_content_element_types, dependent: :destroy
3
+ has_many :post_type_versions, dependent: :destroy
4
+ has_one :published_type_version, -> { where(status: 'published') }, class_name: 'PostTypeVersion'
5
+ has_many :preview_type_versions, -> { where(status: 'prevew') }, class_name: 'PostTypeVersion'
6
+ has_many :posts, through: :published_type_version
7
+ has_many :partials, through: :published_type_version
8
+ has_many :post_type_content_element_types, through: :published_type_version
6
9
  has_many :content_element_types, through: :post_type_content_element_types
7
- has_many :free_form_section_types, dependent: :destroy
8
- has_many :background_styles, dependent: :destroy
9
- has_many :justification_styles, dependent: :destroy
10
- has_many :sequence_flow_styles, dependent: :destroy
11
- has_many :arrangement_styles, dependent: :destroy
10
+ has_many :free_form_section_types, through: :published_type_version
11
+ has_many :layouts, through: :published_type_version
12
12
 
13
13
  scope :templates, -> { where(kind: Pulitzer::PostType.kinds[:template])}
14
14
  scope :partials, -> { where(kind: Pulitzer::PostType.kinds[:partial])}
@@ -19,36 +19,7 @@ class Pulitzer::PostType < ActiveRecord::Base
19
19
  self.find_by(name: label)
20
20
  end
21
21
 
22
- def singular?
23
- !plural
24
- end
25
-
26
- def singleton_post
27
- posts.first
28
- end
29
-
30
- def singleton_post?
31
- !plural
32
- end
33
-
34
- def has_display?
35
- background_styles.any? || justification_styles.any? || sequence_flow_styles.any? || arrangement_styles.any?
36
- end
37
-
38
- def has_templated_content_elements?
39
- content_element_types.any?
40
- end
41
-
42
- def has_free_form_sections?
43
- free_form_section_types.any?
44
- end
45
-
46
- def all_element_types
47
- (post_type_content_element_types.to_a + free_form_section_types.to_a)
48
- end
49
-
50
- def highest_element_sort
51
- last_element = all_element_types.max_by{ |e| e.sort_order || 0}
52
- last_element&.sort_order || 0
22
+ def published_type_version_id
23
+ published_type_version&.id
53
24
  end
54
25
  end
@@ -2,7 +2,7 @@ module Pulitzer
2
2
  class PostTypeContentElementType < ActiveRecord::Base
3
3
  include Pulitzer::PostTypeElement
4
4
 
5
- belongs_to :post_type
5
+ belongs_to :post_type_version
6
6
  belongs_to :content_element_type
7
7
  has_many :styles
8
8
 
@@ -5,7 +5,7 @@ module Pulitzer
5
5
  end
6
6
 
7
7
  def highest_sibling_sort
8
- self.post_type.highest_element_sort
8
+ self.post_type_version.highest_element_sort
9
9
  end
10
10
 
11
11
  def handle_sort_order
@@ -0,0 +1,84 @@
1
+ class Pulitzer::PostTypeVersion < ActiveRecord::Base
2
+ include StateMachine::Model
3
+
4
+ belongs_to :post_type
5
+ has_many :posts, dependent: :destroy
6
+ has_many :partials, dependent: :destroy
7
+ has_many :post_type_content_element_types, dependent: :destroy
8
+ has_many :content_element_types, through: :post_type_content_element_types
9
+ has_many :free_form_section_types, dependent: :destroy
10
+ has_many :background_styles, dependent: :destroy
11
+ has_many :justification_styles, dependent: :destroy
12
+ has_many :sequence_flow_styles, dependent: :destroy
13
+ has_many :arrangement_styles, dependent: :destroy
14
+
15
+ delegate :name, :kind, :partial?, :template?, :plural, :plural?, to: :post_type
16
+
17
+ register_transitions({
18
+ previewing_service: Preview,
19
+ publishing_service: Publish,
20
+ retiring_service: Retire })
21
+
22
+ def full_name
23
+ "\"#{name}\" v#{version_number}"
24
+ end
25
+
26
+ def singular?
27
+ !plural
28
+ end
29
+
30
+ def singleton_post
31
+ posts.first
32
+ end
33
+
34
+ def singleton_post?
35
+ !plural
36
+ end
37
+
38
+ def arity_display
39
+ plural? ? 'Many Posts' : 'Single Post'
40
+ end
41
+
42
+ def has_display?
43
+ background_styles.any? || justification_styles.any? || sequence_flow_styles.any? || arrangement_styles.any?
44
+ end
45
+
46
+ def has_templated_content_elements?
47
+ content_element_types.any?
48
+ end
49
+
50
+ def has_free_form_sections?
51
+ free_form_section_types.any?
52
+ end
53
+
54
+ def all_element_types
55
+ (post_type_content_element_types.to_a + free_form_section_types.to_a)
56
+ end
57
+
58
+ def highest_element_sort
59
+ last_element = all_element_types.max_by{ |e| e.sort_order || 0}
60
+ last_element&.sort_order || 0
61
+ end
62
+
63
+ def locked?
64
+ published? || retired?
65
+ end
66
+
67
+ def status_display
68
+ {'incomplete' => 'Not Ready',
69
+ 'preview' => 'Previewing',
70
+ 'published' => 'Published',
71
+ 'retired' => 'Retired'}[status]
72
+ end
73
+
74
+ def state_change
75
+ {'incomplete' => :preview,
76
+ 'preview' => :publish,
77
+ 'published' => :retire,
78
+ 'retired' => :publish}[status]
79
+ end
80
+
81
+ def state_change_display
82
+ state_change.to_s.humanize
83
+ end
84
+ end
@@ -1,6 +1,6 @@
1
1
  module Pulitzer
2
2
  class SequenceFlowStyle < ActiveRecord::Base
3
- belongs_to :post_type
3
+ belongs_to :post_type_version
4
4
  has_many :partials
5
5
  validates :display_name, presence: true
6
6
  validates :css_class_name, presence: true
@@ -0,0 +1,30 @@
1
+ class Pulitzer::PostTypeVersion::Preview
2
+ include StateMachine::Transition
3
+
4
+ self.action_name = :preview
5
+ self.target_state = 'preview'
6
+ self.valid_from_states = [:incomplete]
7
+
8
+ def initialize(post_type_version)
9
+ @post_type_version = post_type_version
10
+ self.object = @post_type_version
11
+ self.errors = ActiveModel::Errors.new(self)
12
+ end
13
+
14
+ def preview
15
+ self.validate_transition!
16
+ validate_elements or return false
17
+ update_status
18
+ return true
19
+ end
20
+
21
+ def validate_elements
22
+ if @post_type_version.post_type_content_element_types.empty? &&
23
+ @post_type_version.free_form_section_types.empty?
24
+ @post_type_version.errors.add(:base, 'You must set up all the content elements and free form sections before previewing the post type')
25
+ return false
26
+ end
27
+ return true
28
+ end
29
+
30
+ end
@@ -0,0 +1,38 @@
1
+ class Pulitzer::PostTypeVersion::Publish
2
+ include StateMachine::Transition
3
+
4
+ self.action_name = :publish
5
+ self.target_state = 'published'
6
+ self.valid_from_states = [:preview,:retired]
7
+
8
+ def initialize(post_type_version)
9
+ @post_type_version = post_type_version
10
+ self.object = @post_type_version
11
+ self.errors = ActiveModel::Errors.new(self)
12
+ @old_published = get_old_published_version
13
+ end
14
+
15
+ def publish
16
+ self.validate_transition!
17
+ validate_published_post or return false
18
+ update_status
19
+ archive_old_version
20
+ return true
21
+ end
22
+
23
+ def archive_old_version
24
+ @old_published.update(status: 'archived') if @old_published.present?
25
+ end
26
+
27
+ def get_old_published_version
28
+ @post_type_version.post_type.published_type_version
29
+ end
30
+
31
+ def validate_published_post
32
+ if @post_type_version.posts.none?{|post| post.active_version.present?}
33
+ @post_type_version.errors.add(:base, 'You must publish a post before publishing the post type')
34
+ return false
35
+ end
36
+ return true
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ class Pulitzer::PostTypeVersion::Retire
2
+ include StateMachine::Transition
3
+
4
+ self.action_name = :retire
5
+ self.target_state = 'retired'
6
+ self.valid_from_states = [:published]
7
+
8
+ def initialize(post_type_version)
9
+ @post_type_version = post_type_version
10
+ self.object = @post_type_version
11
+ self.errors = ActiveModel::Errors.new(self)
12
+ end
13
+
14
+ def retire
15
+ self.validate_transition!
16
+ update_status
17
+ return true
18
+ end
19
+
20
+ end
@@ -1,12 +1,12 @@
1
1
  <div class="pulitzer-row">
2
- <%= form_for arrangement_style, html: ajax_form_hash(dom_target(arrangement_style.post_type, :arrangement_styles_container), insert_method: 'append', reset_on_success: true) do |f| %>
3
- <%= f.hidden_field :post_type_id %>
2
+ <%= form_for arrangement_style, html: ajax_form_hash(dom_target(arrangement_style.post_type_version, :arrangement_styles_container), insert_method: 'append', reset_on_success: true) do |f| %>
3
+ <%= f.hidden_field :post_type_version_id %>
4
4
  <%= render partial: 'form_fields', locals: { f: f, arrangement_style: arrangement_style } %>
5
5
  <div class="pulitzer-span ten-percent">
6
6
  <%= f.submit "Create", data: {disable_with: false} %>
7
7
  </div>
8
8
  <div class="pulitzer-span ten-percent">
9
- <a class="button" data-emptier="true" data-target="<%= dom_target(arrangement_style.post_type, :new_arrangement_style)%>">Close</a>
9
+ <a class="button" data-emptier="true" data-target="<%= dom_target(arrangement_style.post_type_version, :new_arrangement_style)%>">Close</a>
10
10
  </div>
11
11
  <% end %>
12
12
  </div>