cartoonist-blog 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -37,8 +37,7 @@ class BlogAdminController < CartoonistController
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def create
|
40
|
-
|
41
|
-
post = BlogPost.create :title => params[:title], :url_title => url_title, :content => params[:content], :author => current_user.name, :tweet => tweet_message(url_title), :locked => true
|
40
|
+
post = BlogPost.create_post current_user, params
|
42
41
|
redirect_to "/blog_admin/#{post.id}/edit"
|
43
42
|
end
|
44
43
|
|
@@ -49,54 +48,19 @@ class BlogAdminController < CartoonistController
|
|
49
48
|
end
|
50
49
|
|
51
50
|
def update
|
52
|
-
post = BlogPost.
|
53
|
-
raise "Cannot update locked post!" if post.locked
|
54
|
-
original_tweet = post.tweet
|
55
|
-
original_url_title = post.url_title
|
56
|
-
post.title = params[:title]
|
57
|
-
post.url_title = BlogPost.url_titlize params[:title]
|
58
|
-
post.author = params[:author]
|
59
|
-
post.tweet = params[:tweet]
|
60
|
-
post.content = params[:content]
|
61
|
-
post.locked = true
|
62
|
-
|
63
|
-
if original_tweet == post.tweet && original_url_title != post.url_title && !post.tweeted?
|
64
|
-
post.tweet = tweet_message post.url_title
|
65
|
-
end
|
66
|
-
|
67
|
-
if params[:posted] && params[:posted_at_date].present?
|
68
|
-
time = "#{params[:posted_at_date]} #{params[:posted_at_hour]}:#{params[:posted_at_minute]} #{params[:posted_at_meridiem]}"
|
69
|
-
time = DateTime.parse time
|
70
|
-
time = Time.local time.year, time.month, time.day, time.hour, time.min
|
71
|
-
post.posted_at = time
|
72
|
-
elsif params[:posted]
|
73
|
-
post.posted_at = 1.hour.from_now
|
74
|
-
else
|
75
|
-
post.posted_at = nil
|
76
|
-
end
|
77
|
-
|
78
|
-
post.save!
|
51
|
+
post = BlogPost.update_post params
|
79
52
|
redirect_to "/blog_admin/#{post.id}/edit"
|
80
53
|
end
|
81
54
|
|
82
55
|
def lock
|
83
56
|
post = BlogPost.find params[:id].to_i
|
84
|
-
post.
|
85
|
-
post.save!
|
57
|
+
post.lock!
|
86
58
|
redirect_to "/blog_admin/#{post.id}/edit"
|
87
59
|
end
|
88
60
|
|
89
61
|
def unlock
|
90
62
|
post = BlogPost.find params[:id].to_i
|
91
|
-
post.
|
92
|
-
post.save!
|
63
|
+
post.unlock!
|
93
64
|
redirect_to "/blog_admin/#{post.id}/edit"
|
94
65
|
end
|
95
|
-
|
96
|
-
private
|
97
|
-
def tweet_message(url_title)
|
98
|
-
tweet = "New blog post: http://#{Setting[:domain]}/blog/#{url_title}"
|
99
|
-
tweet = "New blog post: http://#{Setting[:domain]}/blog" if tweet.length > 140
|
100
|
-
tweet
|
101
|
-
end
|
102
66
|
end
|
@@ -13,6 +13,12 @@ module BlogAdminHelper
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
def post_lock_disabled
|
17
|
+
if @post.locked || @post.posted?
|
18
|
+
'disabled="disabled"'.html_safe
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
16
22
|
def format_posted_at(fmt)
|
17
23
|
if @post && @post.posted_at
|
18
24
|
@post.posted_at.localtime.strftime fmt
|
data/app/models/blog_post.rb
CHANGED
@@ -3,6 +3,20 @@ class BlogPost < ActiveRecord::Base
|
|
3
3
|
attr_accessor :for_preview
|
4
4
|
attr_accessible :title, :url_title, :author, :posted_at, :content, :tweet, :tweeted_at, :locked
|
5
5
|
|
6
|
+
def lock!
|
7
|
+
self.locked = true
|
8
|
+
save!
|
9
|
+
end
|
10
|
+
|
11
|
+
def unlock!
|
12
|
+
self.locked = false
|
13
|
+
save!
|
14
|
+
end
|
15
|
+
|
16
|
+
def posted?
|
17
|
+
posted_at && posted_at <= Time.now
|
18
|
+
end
|
19
|
+
|
6
20
|
def expected_tweet_time
|
7
21
|
posted_at
|
8
22
|
end
|
@@ -95,6 +109,46 @@ class BlogPost < ActiveRecord::Base
|
|
95
109
|
end
|
96
110
|
|
97
111
|
class << self
|
112
|
+
def create_post(current_user, params)
|
113
|
+
url_title = url_titlize params[:title]
|
114
|
+
create :title => params[:title], :url_title => url_title, :content => params[:content], :author => current_user.name, :tweet => tweet_message(url_title), :locked => true
|
115
|
+
end
|
116
|
+
|
117
|
+
def update_post(params)
|
118
|
+
post = find params[:id].to_i
|
119
|
+
raise "Cannot update locked post!" if post.locked
|
120
|
+
original_tweet = post.tweet
|
121
|
+
original_url_title = post.url_title
|
122
|
+
post.title = params[:title]
|
123
|
+
post.url_title = url_titlize params[:title]
|
124
|
+
post.author = params[:author]
|
125
|
+
post.tweet = params[:tweet]
|
126
|
+
post.content = params[:content]
|
127
|
+
post.locked = true
|
128
|
+
|
129
|
+
if original_tweet == post.tweet && original_url_title != post.url_title && !post.tweeted?
|
130
|
+
post.tweet = tweet_message post.url_title
|
131
|
+
end
|
132
|
+
|
133
|
+
if params[:post_now].present? && !post.posted?
|
134
|
+
post.posted_at = Time.now
|
135
|
+
elsif params[:post_in_hour].present? && !post.posted?
|
136
|
+
post.posted_at = 1.hour.from_now
|
137
|
+
elsif params[:posted] && params[:posted_at_date].present?
|
138
|
+
time = "#{params[:posted_at_date]} #{params[:posted_at_hour]}:#{params[:posted_at_minute]} #{params[:posted_at_meridiem]}"
|
139
|
+
time = DateTime.parse time
|
140
|
+
time = Time.local time.year, time.month, time.day, time.hour, time.min
|
141
|
+
post.posted_at = time
|
142
|
+
elsif params[:posted]
|
143
|
+
post.posted_at = 1.hour.from_now
|
144
|
+
else
|
145
|
+
post.posted_at = nil
|
146
|
+
end
|
147
|
+
|
148
|
+
post.save!
|
149
|
+
post
|
150
|
+
end
|
151
|
+
|
98
152
|
def url_titlize(title)
|
99
153
|
title.downcase.gsub(" ", "-").gsub(/[^-_a-z0-9]/, "")
|
100
154
|
end
|
@@ -184,5 +238,12 @@ class BlogPost < ActiveRecord::Base
|
|
184
238
|
def sitemap
|
185
239
|
posted.reversed.all
|
186
240
|
end
|
241
|
+
|
242
|
+
private
|
243
|
+
def tweet_message(url_title)
|
244
|
+
tweet = "New blog post: http://#{Setting[:domain]}/blog/#{url_title}"
|
245
|
+
tweet = "New blog post: http://#{Setting[:domain]}/blog" if tweet.length > 140
|
246
|
+
tweet
|
247
|
+
end
|
187
248
|
end
|
188
249
|
end
|
@@ -26,6 +26,8 @@
|
|
26
26
|
<option value="am" <%= selected "am", format_posted_at("%P") %>>am</option>
|
27
27
|
<option value="pm" <%= selected "pm", format_posted_at("%P") %>>pm</option>
|
28
28
|
</select>
|
29
|
+
<input type="submit" name="post_now" value="Post Now" <%= post_lock_disabled %> />
|
30
|
+
<input type="submit" name="post_in_hour" value="Post in an Hour" <%= post_lock_disabled %> />
|
29
31
|
</p>
|
30
32
|
|
31
33
|
<p>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cartoonist-blog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,19 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cartoonist
|
16
|
-
requirement: &
|
16
|
+
requirement: &14804380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.0.
|
21
|
+
version: 0.0.8
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14804380
|
25
25
|
description: This core plugin for Cartoonist adds a simple blog.
|
26
26
|
email: reasonnumber@gmail.com
|
27
27
|
executables: []
|