effective_posts 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0adec48b907d17f506e2176b161e53daf59a86d5
4
- data.tar.gz: 5a2c2158ae1cdcc9f6fd1a7391fa3675c28a6531
3
+ metadata.gz: bcee40dabd2d40c4e60bd0ccab3756febf11c0a2
4
+ data.tar.gz: 49f930577bf1825eab1e9d4b00f8b26f3bc7c5a9
5
5
  SHA512:
6
- metadata.gz: 64f861165de83fe29bae345c5e114fdb870bf5c842830ae8b63845e715fa3f7a26b05210b1aea63e4f0cc36fada2f1196707dea8cd59133c6460cd1104e88414
7
- data.tar.gz: 89633a7b7e1d03069005ab164d8815024446cdd16e83696e3911d752ba00472a66836f8ab15c39385a63e960050ab669247278849263b180440194950cf03b37
6
+ metadata.gz: 6237cd9d8c3ae23d41133ce4a4a866cf54f189e90f1cf5de1a2d5ea94129615c24d94db8d59bd2ab5de80a7331b3b628201c3fc02d3e9cc4d0870fb33ff9fdb2
7
+ data.tar.gz: 9fef710e83c802feae9981b056497109cdccf99ddcd8c9ee6c5eb170c7b66c773d76c2b0daa940d7a69724d7f580a2003ef3d394e162c785ee7c99574964207f
@@ -66,6 +66,17 @@ module Admin
66
66
  elsif params[:commit] == 'Save and Add New'
67
67
  flash[:success] = 'Successfully updated post'
68
68
  redirect_to effective_posts.new_admin_post_path
69
+ elsif params[:commit] == 'Save and Duplicate'
70
+ begin
71
+ post = @post.duplicate!
72
+ flash[:success] = 'Successfully saved and duplicated post.'
73
+ flash[:info] = "You are now editting the duplicated post. This new post has been created as a Draft."
74
+ rescue => e
75
+ flash.delete(:success)
76
+ flash[:danger] = "Unable to duplicate post: #{e.message}"
77
+ end
78
+
79
+ redirect_to effective_posts.edit_admin_post_path(post || @post)
69
80
  else
70
81
  flash[:success] = 'Successfully updated post'
71
82
  redirect_to effective_posts.edit_admin_post_path(@post)
@@ -91,6 +91,24 @@ module Effective
91
91
  send_email(:post_submitted_to_admin, to_param)
92
92
  end
93
93
 
94
+ # Returns a duplicated post object, or throws an exception
95
+ def duplicate!
96
+ Post.new(attributes.except('id', 'updated_at', 'created_at')).tap do |post|
97
+ post.title = post.title + ' (Copy)'
98
+ post.draft = true
99
+
100
+ if defined?(EffectiveAssets) && image.present?
101
+ post.add_to_asset_box(:image, image)
102
+ end
103
+
104
+ regions.each do |region|
105
+ post.regions.build(region.attributes.except('id', 'updated_at', 'created_at'))
106
+ end
107
+
108
+ post.save!
109
+ end
110
+ end
111
+
94
112
  private
95
113
 
96
114
  def send_email(email, *mailer_args)
@@ -32,4 +32,5 @@
32
32
  - if defined?(EffectiveRegions)
33
33
  = f.button :submit, 'Save and Edit Content', data: { disable_with: 'Saving...' }
34
34
  = f.button :submit, 'Save and Add New', data: { disable_with: 'Saving...' }
35
+ = f.button :submit, 'Save and Duplicate', data: { disable_with: 'Saving...' }
35
36
  = link_to 'Cancel', effective_posts.admin_posts_path
@@ -1,3 +1,3 @@
1
1
  module EffectivePosts
2
- VERSION = '0.5.2'.freeze
2
+ VERSION = '0.5.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_posts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-05 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails