cartoonist-blog 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/controllers/{blog_admin_controller.rb → admin/blog_controller.rb} +8 -8
- data/app/helpers/{blog_admin_helper.rb → admin/blog_helper.rb} +1 -1
- data/app/helpers/blog_helper.rb +2 -2
- data/app/models/blog_post.rb +25 -64
- data/app/views/{blog_admin → admin/blog}/edit.html.erb +14 -13
- data/app/views/{blog_admin → admin/blog}/index.html.erb +4 -4
- data/app/views/{blog_admin → admin/blog}/new.html.erb +2 -2
- data/app/views/layouts/{blog_admin.html.erb → admin/blog.html.erb} +3 -3
- data/app/views/layouts/blog.html.erb +3 -3
- data/config/locales/en.yml +2 -0
- data/db/migrate/20120308064117_create_blog_posts.rb +0 -2
- data/lib/cartoonist-blog/engine.rb +15 -12
- metadata +11 -11
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class Admin::BlogController < CartoonistController
|
2
2
|
helper :blog
|
3
3
|
before_filter :preview!, :only => [:preview]
|
4
4
|
before_filter :ensure_ssl!
|
@@ -9,7 +9,7 @@ class BlogAdminController < CartoonistController
|
|
9
9
|
begin
|
10
10
|
@post = BlogPost.preview_from_url_title params[:id]
|
11
11
|
rescue
|
12
|
-
redirect_to "/
|
12
|
+
redirect_to "/admin/blog/preview"
|
13
13
|
end
|
14
14
|
|
15
15
|
if @post.posted_at
|
@@ -33,34 +33,34 @@ class BlogAdminController < CartoonistController
|
|
33
33
|
|
34
34
|
def index
|
35
35
|
@unposted = BlogPost.unposted.chronological
|
36
|
-
@posted = BlogPost.posted.
|
36
|
+
@posted = BlogPost.posted.reverse_chronological
|
37
37
|
end
|
38
38
|
|
39
39
|
def create
|
40
40
|
post = BlogPost.create_post current_user, params
|
41
|
-
redirect_to "/
|
41
|
+
redirect_to "/admin/blog/#{post.id}/edit"
|
42
42
|
end
|
43
43
|
|
44
44
|
def edit
|
45
45
|
@post = BlogPost.find params[:id].to_i
|
46
46
|
rescue ActiveRecord::RecordNotFound
|
47
|
-
redirect_to "/
|
47
|
+
redirect_to "/admin/blog/new"
|
48
48
|
end
|
49
49
|
|
50
50
|
def update
|
51
51
|
post = BlogPost.update_post params
|
52
|
-
redirect_to "/
|
52
|
+
redirect_to "/admin/blog/#{post.id}/edit"
|
53
53
|
end
|
54
54
|
|
55
55
|
def lock
|
56
56
|
post = BlogPost.find params[:id].to_i
|
57
57
|
post.lock!
|
58
|
-
redirect_to "/
|
58
|
+
redirect_to "/admin/blog/#{post.id}/edit"
|
59
59
|
end
|
60
60
|
|
61
61
|
def unlock
|
62
62
|
post = BlogPost.find params[:id].to_i
|
63
63
|
post.unlock!
|
64
|
-
redirect_to "/
|
64
|
+
redirect_to "/admin/blog/#{post.id}/edit"
|
65
65
|
end
|
66
66
|
end
|
data/app/helpers/blog_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module BlogHelper
|
2
2
|
def blog_current_url
|
3
3
|
if preview?
|
4
|
-
"/
|
4
|
+
"/admin/blog/preview"
|
5
5
|
else
|
6
6
|
"/blog"
|
7
7
|
end
|
@@ -9,7 +9,7 @@ module BlogHelper
|
|
9
9
|
|
10
10
|
def blog_post_url(url_title)
|
11
11
|
if preview?
|
12
|
-
"/
|
12
|
+
"/admin/blog/#{url_title}/preview"
|
13
13
|
else
|
14
14
|
"/blog/#{url_title}"
|
15
15
|
end
|
data/app/models/blog_post.rb
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
class BlogPost < ActiveRecord::Base
|
2
|
-
include
|
2
|
+
include Postable
|
3
|
+
include Entity
|
4
|
+
entity_type :blog
|
5
|
+
entity_global_url "/blog"
|
6
|
+
entity_url &:url
|
7
|
+
entity_edit_url &:edit_url
|
8
|
+
entity_description &:title
|
3
9
|
attr_accessor :for_preview
|
4
|
-
attr_accessible :title, :url_title, :author, :posted_at, :content, :
|
10
|
+
attr_accessible :title, :url_title, :author, :posted_at, :content, :locked
|
11
|
+
|
12
|
+
def url
|
13
|
+
"/blog/#{url_title}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit_url
|
17
|
+
"/admin/blog/#{id}/edit"
|
18
|
+
end
|
5
19
|
|
6
20
|
def lock!
|
7
21
|
self.locked = true
|
@@ -13,22 +27,6 @@ class BlogPost < ActiveRecord::Base
|
|
13
27
|
save!
|
14
28
|
end
|
15
29
|
|
16
|
-
def posted?
|
17
|
-
posted_at && posted_at <= Time.now
|
18
|
-
end
|
19
|
-
|
20
|
-
def expected_tweet_time
|
21
|
-
posted_at
|
22
|
-
end
|
23
|
-
|
24
|
-
def formatted_posted_at(default_msg = "not yet posted")
|
25
|
-
if posted_at
|
26
|
-
posted_at.localtime.strftime "%-m/%-d/%Y at %-l:%M %P"
|
27
|
-
else
|
28
|
-
default_msg
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
30
|
def first_post
|
33
31
|
return @first_post if @first_post_retrieved
|
34
32
|
@first_post_retrieved = true
|
@@ -104,32 +102,22 @@ class BlogPost < ActiveRecord::Base
|
|
104
102
|
url_title
|
105
103
|
end
|
106
104
|
|
107
|
-
def absolute_url
|
108
|
-
"http://#{Setting[:domain]}/blog/#{url_title}"
|
109
|
-
end
|
110
|
-
|
111
105
|
class << self
|
112
106
|
def create_post(current_user, params)
|
113
107
|
url_title = url_titlize params[:title]
|
114
|
-
create :title => params[:title], :url_title => url_title, :content => params[:content], :author => current_user.name, :
|
108
|
+
create :title => params[:title], :url_title => url_title, :content => params[:content], :author => current_user.name, :locked => true
|
115
109
|
end
|
116
110
|
|
117
111
|
def update_post(params)
|
118
112
|
post = find params[:id].to_i
|
119
113
|
raise "Cannot update locked post!" if post.locked
|
120
|
-
original_tweet = post.tweet
|
121
114
|
original_url_title = post.url_title
|
122
115
|
post.title = params[:title]
|
123
116
|
post.url_title = url_titlize params[:title]
|
124
117
|
post.author = params[:author]
|
125
|
-
post.tweet = params[:tweet]
|
126
118
|
post.content = params[:content]
|
127
119
|
post.locked = true
|
128
120
|
|
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
121
|
if params[:post_now].present? && !post.posted?
|
134
122
|
post.posted_at = Time.now
|
135
123
|
elsif params[:post_in_hour].present? && !post.posted?
|
@@ -154,45 +142,29 @@ class BlogPost < ActiveRecord::Base
|
|
154
142
|
end
|
155
143
|
|
156
144
|
def newest_preview_post
|
157
|
-
|
145
|
+
reverse_chronological.first || new(:title => "No Posts Yet", :content => "There are no blog posts yet.")
|
158
146
|
end
|
159
147
|
|
160
148
|
def newest_post
|
161
|
-
posted.
|
149
|
+
posted.reverse_chronological.first || new(:title => "No Posts Yet", :content => "There are no blog posts yet.")
|
162
150
|
end
|
163
151
|
|
164
152
|
def first_post
|
165
153
|
posted.chronological.first || new(:title => "No Posts Yet", :content => "There are no blog posts yet.")
|
166
154
|
end
|
167
155
|
|
168
|
-
def posted
|
169
|
-
where "blog_posts.posted_at IS NOT NULL AND blog_posts.posted_at <= ?", Time.now
|
170
|
-
end
|
171
|
-
|
172
|
-
def unposted
|
173
|
-
where "blog_posts.posted_at IS NULL OR blog_posts.posted_at > ?", Time.now
|
174
|
-
end
|
175
|
-
|
176
|
-
def chronological
|
177
|
-
order "blog_posts.posted_at ASC"
|
178
|
-
end
|
179
|
-
|
180
|
-
def reversed
|
181
|
-
order "blog_posts.posted_at DESC"
|
182
|
-
end
|
183
|
-
|
184
156
|
def all_columns
|
185
157
|
select "blog_posts.*"
|
186
158
|
end
|
187
159
|
|
188
160
|
def current
|
189
|
-
post = posted.
|
161
|
+
post = posted.reverse_chronological.first
|
190
162
|
post = new :title => "No Posts Yet", :content => "There are no blog posts yet." unless post
|
191
163
|
post
|
192
164
|
end
|
193
165
|
|
194
166
|
def preview_current
|
195
|
-
post =
|
167
|
+
post = reverse_chronological.first
|
196
168
|
post = new :title => "No Posts Yet", :content => "There are no blog posts yet." unless post
|
197
169
|
post.for_preview = true
|
198
170
|
post
|
@@ -201,7 +173,7 @@ class BlogPost < ActiveRecord::Base
|
|
201
173
|
def previous_post(post)
|
202
174
|
context = BlogPost
|
203
175
|
context = posted unless post.for_preview
|
204
|
-
context.where("blog_posts.posted_at < ?", post.posted_at).
|
176
|
+
context.where("blog_posts.posted_at < ?", post.posted_at).reverse_chronological.first
|
205
177
|
end
|
206
178
|
|
207
179
|
def next_post(post)
|
@@ -224,26 +196,15 @@ class BlogPost < ActiveRecord::Base
|
|
224
196
|
end
|
225
197
|
|
226
198
|
def archives
|
227
|
-
posted.
|
228
|
-
end
|
229
|
-
|
230
|
-
def untweeted
|
231
|
-
posted.where(:tweeted_at => nil).all
|
199
|
+
posted.reverse_chronological.select([:url_title, :title, :posted_at]).all
|
232
200
|
end
|
233
201
|
|
234
202
|
def feed
|
235
|
-
posted.
|
203
|
+
posted.reverse_chronological.take 10
|
236
204
|
end
|
237
205
|
|
238
206
|
def sitemap
|
239
|
-
posted.
|
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
|
207
|
+
posted.reverse_chronological.all
|
247
208
|
end
|
248
209
|
end
|
249
210
|
end
|
@@ -1,14 +1,19 @@
|
|
1
|
+
<% Cartoonist::Entity.hooks_with(:edit_entity_before_partial).each do |hook| %>
|
2
|
+
<%= render :partial => hook.edit_entity_before_partial, :locals => { :entity => @post } %>
|
3
|
+
<hr />
|
4
|
+
<% end %>
|
5
|
+
|
1
6
|
<p>
|
2
|
-
<a href="/
|
7
|
+
<a href="/admin/blog/<%= @post.url_title %>/preview">Preview this post</a>
|
3
8
|
</p>
|
4
9
|
|
5
10
|
<p>
|
6
|
-
<%= form_tag "/
|
11
|
+
<%= form_tag "/admin/blog/#{@post.id}/#{lock_toggle_target}", :method => :post do %>
|
7
12
|
<input type="submit" value="<%= lock_toggle_target %>" />
|
8
13
|
<% end %>
|
9
14
|
</p>
|
10
15
|
|
11
|
-
<%= form_tag "/
|
16
|
+
<%= form_tag "/admin/blog/#{@post.id}", :method => :put do %>
|
12
17
|
<p>
|
13
18
|
<label><input type="checkbox" name="posted" value="true" <%= checked="checked".html_safe if @post.posted_at %> <%= lock_disabled %> />Posted at</label>
|
14
19
|
<input type="text" name="posted_at_date" value="<%= format_posted_at "%Y-%m-%d" %>" <%= lock_disabled %> />
|
@@ -44,15 +49,6 @@
|
|
44
49
|
<input type="text" name="author" size="20" value="<%= @post.author %>" <%= lock_disabled %> />
|
45
50
|
</p>
|
46
51
|
|
47
|
-
<p>
|
48
|
-
Tweet:
|
49
|
-
<% if @post.tweeted_at %>
|
50
|
-
<em>(sent <%= @post.tweeted_at.strftime "%-m/%-d/%Y %-l:%M %P" %>)</em>
|
51
|
-
<% end %>
|
52
|
-
<br />
|
53
|
-
<textarea name="tweet" rows="2" cols="100" tabindex="5" <%= lock_disabled %>><%= @post.tweet %></textarea>
|
54
|
-
</p>
|
55
|
-
|
56
52
|
<p>
|
57
53
|
<input type="submit" value="Save" <%= lock_disabled %> />
|
58
54
|
<input type="button" value="Preview" class="preview-content" />
|
@@ -83,7 +79,7 @@
|
|
83
79
|
$(".preview-content").click(function() {
|
84
80
|
var $this = $(this).attr("disabled", "disabled");
|
85
81
|
$.ajax({
|
86
|
-
url: "/
|
82
|
+
url: "/admin/blog/preview_content",
|
87
83
|
type: "post",
|
88
84
|
data: {
|
89
85
|
authenticity_token: $("form input[name='authenticity_token']").val(),
|
@@ -103,3 +99,8 @@
|
|
103
99
|
});
|
104
100
|
});
|
105
101
|
<% end %>
|
102
|
+
|
103
|
+
<% Cartoonist::Entity.hooks_with(:edit_entity_after_partial).each do |hook| %>
|
104
|
+
<hr />
|
105
|
+
<%= render :partial => hook.edit_entity_after_partial, :locals => { :entity => @post } %>
|
106
|
+
<% end %>
|
@@ -4,8 +4,8 @@
|
|
4
4
|
<% @unposted.each do |post| %>
|
5
5
|
<li>
|
6
6
|
<%= post.formatted_posted_at "" %>
|
7
|
-
<a href="/
|
8
|
-
(<a href="/
|
7
|
+
<a href="/admin/blog/<%= post.id %>/edit"><%= post.title %></a>
|
8
|
+
(<a href="/admin/blog/<%= post.url_title %>/preview"><%= t "admin.blog.index.preview" %></a>)
|
9
9
|
</li>
|
10
10
|
<% end %>
|
11
11
|
</ul>
|
@@ -16,8 +16,8 @@
|
|
16
16
|
<% @posted.each do |post| %>
|
17
17
|
<li>
|
18
18
|
<%= post.formatted_posted_at "" %>
|
19
|
-
<a href="/
|
20
|
-
(<a href="/
|
19
|
+
<a href="/admin/blog/<%= post.id %>/edit"><%= post.title %></a>
|
20
|
+
(<a href="/admin/blog/<%= post.url_title %>/preview"><%= t "admin.blog.index.preview" %></a>)
|
21
21
|
</li>
|
22
22
|
<% end %>
|
23
23
|
</ul>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= form_tag "/
|
1
|
+
<%= form_tag "/admin/blog", :method => :post do %>
|
2
2
|
<p>
|
3
3
|
Title: <input type="text" name="title" autofocus="autofocus" size="100" /><br />
|
4
4
|
</p>
|
@@ -25,7 +25,7 @@
|
|
25
25
|
$(".preview-content").click(function() {
|
26
26
|
var $this = $(this).attr("disabled", "disabled");
|
27
27
|
$.ajax({
|
28
|
-
url: "/
|
28
|
+
url: "/admin/blog/preview_content",
|
29
29
|
type: "post",
|
30
30
|
data: {
|
31
31
|
authenticity_token: $("form input[name='authenticity_token']").val(),
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<% content_for :subtabs do %>
|
2
2
|
<a class="subtab" href="/blog"><%= t "admin.blog.layout.latest" %></a>
|
3
|
-
<a class="subtab" href="/
|
4
|
-
<a class="subtab" href="/
|
5
|
-
<a class="subtab" href="/
|
3
|
+
<a class="subtab" href="/admin/blog"><%= t "admin.blog.layout.list" %></a>
|
4
|
+
<a class="subtab" href="/admin/blog/new"><%= t "admin.blog.layout.new" %></a>
|
5
|
+
<a class="subtab" href="/admin/blog/preview"><%= t "admin.blog.layout.preview" %></a>
|
6
6
|
<% end %>
|
7
7
|
|
8
8
|
<% content_for :page_title, t("admin.blog.layout.section") %>
|
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
<% content_for :small_buttons do %>
|
6
6
|
<% if @post.real? %>
|
7
|
-
<a class="facebook" href="https://www.facebook.com/sharer.php?u=<%= u @post.
|
8
|
-
<a class="twitter" href="https://twitter.com/intent/tweet?source=<%= u Setting[:domain] %>&text=<%= u t("blog.layout.twitter_text_message", :url => @post.
|
9
|
-
<a class="google-plus" href="https://plus.google.com/share?url=<%= u @post.
|
7
|
+
<a class="facebook" href="https://www.facebook.com/sharer.php?u=<%= u @post.entity_absolute_url %>&t=<%= u t("blog.layout.facebook_text_message", :title => @post.title) %>" title="<%= t "blog.layout.facebook_title" %>"><%= t "blog.layout.facebook" %></a>
|
8
|
+
<a class="twitter" href="https://twitter.com/intent/tweet?source=<%= u Setting[:domain] %>&text=<%= u t("blog.layout.twitter_text_message", :url => @post.entity_absolute_url) %>" title="<%= t "blog.layout.twitter_title" %>"><%= t "blog.layout.twitter" %></a>
|
9
|
+
<a class="google-plus" href="https://plus.google.com/share?url=<%= u @post.entity_absolute_url %>" title="<%= t "blog.layout.google_plus_title" %>"><%= t "blog.layout.google_plus" %></a>
|
10
10
|
<a class="rss" href="<%= rss_path %>" title="<%= rss_title %>"><%= t "blog.layout.rss" %></a>
|
11
11
|
<% end %>
|
12
12
|
<% end %>
|
data/config/locales/en.yml
CHANGED
@@ -6,8 +6,6 @@ class CreateBlogPosts < ActiveRecord::Migration
|
|
6
6
|
t.string :author, :null => false
|
7
7
|
t.datetime :posted_at
|
8
8
|
t.text :content, :null => false
|
9
|
-
t.string :tweet, :null => false, :length => 140
|
10
|
-
t.datetime :tweeted_at
|
11
9
|
t.boolean :locked, :null => false, :default => false
|
12
10
|
t.timestamps
|
13
11
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module CartoonistBlog
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
Cartoonist::
|
3
|
+
Cartoonist::Entity.add :blog, "BlogPost"
|
4
|
+
Cartoonist::Admin::Tab.add :blog, :url => "/admin/blog", :order => 1
|
4
5
|
Cartoonist::RootPath.add :blog, "blog#index"
|
5
|
-
Cartoonist::Navigation::Link.add :url => "/blog", :preview_url => "/
|
6
|
+
Cartoonist::Navigation::Link.add :url => "/blog", :preview_url => "/admin/blog/preview", :class => "blog", :label => "cartoonist.layout.navigation.blog", :order => 1
|
6
7
|
Cartoonist::Migration.add_for self
|
7
8
|
|
8
9
|
Cartoonist::Backup.for :blog_posts do
|
@@ -32,16 +33,18 @@ module CartoonistBlog
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
namespace :admin do
|
37
|
+
resources :blog do
|
38
|
+
member do
|
39
|
+
post "lock"
|
40
|
+
get "preview"
|
41
|
+
post "unlock"
|
42
|
+
end
|
43
|
+
|
44
|
+
collection do
|
45
|
+
get "preview"
|
46
|
+
post "preview_content"
|
47
|
+
end
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
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.9
|
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-
|
12
|
+
date: 2012-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cartoonist
|
16
|
-
requirement: &
|
16
|
+
requirement: &15371600 !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.9
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *15371600
|
25
25
|
description: This core plugin for Cartoonist adds a simple blog.
|
26
26
|
email: reasonnumber@gmail.com
|
27
27
|
executables: []
|
@@ -29,20 +29,20 @@ extensions: []
|
|
29
29
|
extra_rdoc_files: []
|
30
30
|
files:
|
31
31
|
- .gitignore
|
32
|
-
- app/controllers/
|
32
|
+
- app/controllers/admin/blog_controller.rb
|
33
33
|
- app/controllers/blog_controller.rb
|
34
|
-
- app/helpers/
|
34
|
+
- app/helpers/admin/blog_helper.rb
|
35
35
|
- app/helpers/blog_helper.rb
|
36
36
|
- app/models/blog_feed.rb
|
37
37
|
- app/models/blog_post.rb
|
38
|
+
- app/views/admin/blog/edit.html.erb
|
39
|
+
- app/views/admin/blog/index.html.erb
|
40
|
+
- app/views/admin/blog/new.html.erb
|
38
41
|
- app/views/blog/archives.html.erb
|
39
42
|
- app/views/blog/feed.rss.erb
|
40
43
|
- app/views/blog/show.html.erb
|
41
|
-
- app/views/
|
42
|
-
- app/views/blog_admin/index.html.erb
|
43
|
-
- app/views/blog_admin/new.html.erb
|
44
|
+
- app/views/layouts/admin/blog.html.erb
|
44
45
|
- app/views/layouts/blog.html.erb
|
45
|
-
- app/views/layouts/blog_admin.html.erb
|
46
46
|
- app/views/layouts/blog_archives.html.erb
|
47
47
|
- cartoonist-blog.gemspec
|
48
48
|
- config/locales/en.yml
|