tb_blog 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -2
- data/app/assets/javascripts/admin/blog/posts.js +42 -0
- data/app/controllers/admin/post_categories_controller.rb +57 -57
- data/app/controllers/admin/posts_controller.rb +110 -101
- data/app/controllers/concerns/blog_url_helpers.rb +22 -18
- data/app/controllers/concerns/post_view_for_action.rb +11 -0
- data/app/controllers/posts_controller.rb +23 -34
- data/app/helpers/admin/posts_helper.rb +20 -20
- data/app/helpers/blog_helper.rb +21 -21
- data/app/models/spud/spud_post_model.rb +43 -51
- data/app/models/spud_blog_config.rb +2 -2
- data/app/models/spud_post.rb +1 -1
- data/app/models/spud_post_categories_post.rb +1 -1
- data/app/models/spud_post_category.rb +18 -20
- data/app/models/spud_post_site.rb +1 -1
- data/app/views/admin/posts/_form.html.erb +4 -3
- data/app/views/admin/posts/edit.html.erb +10 -2
- data/app/views/admin/posts/new.html.erb +9 -1
- data/app/views/admin/posts/show.html.erb +0 -0
- data/config/routes.rb +3 -1
- data/lib/generators/spud/blog/blog_generator.rb +5 -5
- data/lib/generators/spud/blog/random_posts_generator.rb +12 -14
- data/lib/generators/spud/blog/views_generator.rb +1 -1
- data/lib/spud_blog/configuration.rb +1 -2
- data/lib/spud_blog/engine.rb +12 -16
- data/lib/spud_blog/version.rb +3 -3
- data/lib/tasks/spud_blog_tasks.rake +1 -1
- data/lib/tb_blog.rb +2 -2
- data/spec/controllers/admin/posts_controller_spec.rb +28 -7
- data/spec/controllers/posts_controller_spec.rb +7 -7
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environment.rb +2 -2
- data/spec/dummy/config/environments/test.rb +3 -3
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/db/migrate/{20120610130206_create_spud_admin_permissions.spud_core.rb → 20161020155425_create_spud_admin_permissions.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/20161020155426_create_spud_users.tb_core.rb +30 -0
- data/spec/dummy/db/migrate/{20120610130208_add_time_zone_to_spud_user.spud_core.rb → 20161020155427_add_time_zone_to_spud_user.tb_core.rb} +1 -2
- data/spec/dummy/db/migrate/{20120610130209_add_scope_to_spud_admin_permissions.spud_core.rb → 20161020155428_add_scope_to_spud_admin_permissions.tb_core.rb} +1 -2
- data/spec/dummy/db/migrate/{20120610130210_create_spud_user_settings.spud_core.rb → 20161020155429_create_spud_user_settings.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/{20140110180411_create_spud_roles.tb_core.rb → 20161020155430_create_spud_roles.tb_core.rb} +0 -0
- data/spec/dummy/db/migrate/{20140110180412_create_spud_permissions.tb_core.rb → 20161020155431_create_spud_permissions.tb_core.rb} +3 -3
- data/spec/dummy/db/migrate/{20140110180413_create_spud_role_permissions.tb_core.rb → 20161020155432_create_spud_role_permissions.tb_core.rb} +2 -2
- data/spec/dummy/db/migrate/{20140110180414_drop_spud_admin_permissions.tb_core.rb → 20161020155433_drop_spud_admin_permissions.tb_core.rb} +0 -0
- data/spec/dummy/db/migrate/{20160215174632_add_requires_password_change_to_spud_users.tb_core.rb → 20161020155434_add_requires_password_change_to_spud_users.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/{20160215174633_create_tb_redirects.tb_redirects.rb → 20161020155435_create_tb_redirects.tb_redirects.rb} +3 -3
- data/spec/dummy/db/migrate/{20140113162805_create_tb_liquid_spud_liquid_tags.tb_liquid.rb → 20161020155436_create_tb_liquid_spud_liquid_tags.tb_liquid.rb} +0 -0
- data/spec/dummy/db/migrate/{20140110180418_create_spud_posts.tb_blog.rb → 20161020155437_create_spud_posts.tb_blog.rb} +3 -3
- data/spec/dummy/db/migrate/{20140110180419_create_spud_post_categories.tb_blog.rb → 20161020155438_create_spud_post_categories.tb_blog.rb} +4 -4
- data/spec/dummy/db/migrate/{20140110180421_add_url_to_spud_posts.tb_blog.rb → 20161020155439_add_url_to_spud_posts.tb_blog.rb} +2 -2
- data/spec/dummy/db/migrate/20161020155440_add_url_to_spud_post_categories.tb_blog.rb +9 -0
- data/spec/dummy/db/migrate/{20140110180423_add_is_news_to_spud_posts.tb_blog.rb → 20161020155441_add_is_news_to_spud_posts.tb_blog.rb} +2 -2
- data/spec/dummy/db/migrate/{20140110180424_add_meta_to_posts.tb_blog.rb → 20161020155442_add_meta_to_posts.tb_blog.rb} +0 -0
- data/spec/dummy/db/migrate/{20140110180426_create_spud_post_sites.tb_blog.rb → 20161020155443_create_spud_post_sites.tb_blog.rb} +3 -3
- data/spec/dummy/db/migrate/{20140110180429_add_nested_set_to_post_categories.tb_blog.rb → 20161020155444_add_nested_set_to_post_categories.tb_blog.rb} +1 -5
- data/spec/dummy/db/migrate/{20140110180430_add_content_format_to_spud_posts.tb_blog.rb → 20161020155445_add_content_format_to_spud_posts.tb_blog.rb} +1 -1
- data/spec/dummy/db/migrate/{20140110180431_add_content_processed_to_spud_post.tb_blog.rb → 20161020155446_add_content_processed_to_spud_post.tb_blog.rb} +0 -0
- data/spec/dummy/db/migrate/{20140730131549_add_primary_key_to_spud_post_categories_posts.tb_blog.rb → 20161020155447_add_primary_key_to_spud_post_categories_posts.tb_blog.rb} +0 -0
- data/spec/dummy/db/migrate/{20140730131550_remove_awesome_nested_set_columns_from_spud_post_categories.tb_blog.rb → 20161020155448_remove_awesome_nested_set_columns_from_spud_post_categories.tb_blog.rb} +2 -1
- data/spec/dummy/db/migrate/{20140811161502_add_blog_key_to_spud_posts.tb_blog.rb → 20161020155449_add_blog_key_to_spud_posts.tb_blog.rb} +0 -0
- data/spec/dummy/db/migrate/{20150116195007_drop_spud_post_sites.tb_blog.rb → 20161020155450_drop_spud_post_sites.tb_blog.rb} +4 -3
- data/spec/dummy/db/migrate/{20151015154040_add_custom_author_to_post.tb_blog.rb → 20161020155451_add_custom_author_to_post.tb_blog.rb} +1 -1
- data/spec/dummy/db/migrate/{20160216150847_add_identifier_to_spud_posts.tb_blog.rb → 20161020155452_add_identifier_to_spud_posts.tb_blog.rb} +1 -1
- data/spec/dummy/db/schema.rb +106 -118
- data/spec/dummy/script/rails +2 -2
- data/spec/factories/spud_post_factories.rb +2 -2
- data/spec/helpers/admin/posts_helper_spec.rb +1 -1
- data/spec/models/spud_post_spec.rb +4 -4
- data/spec/rails_helper.rb +5 -5
- data/spec/spec_helper.rb +42 -44
- metadata +77 -79
- data/spec/dummy/db/migrate/20120610130207_create_spud_users.spud_core.rb +0 -30
- data/spec/dummy/db/migrate/20140110180415_create_spud_permalinks.tb_permalinks.rb +0 -12
- data/spec/dummy/db/migrate/20140110180416_add_site_id_to_spud_permalinks.tb_permalinks.rb +0 -7
- data/spec/dummy/db/migrate/20140110180417_modify_site_id_for_spud_permalinks.tb_permalinks.rb +0 -12
- data/spec/dummy/db/migrate/20140110180420_create_spud_post_comments.tb_blog.rb +0 -14
- data/spec/dummy/db/migrate/20140110180422_add_url_to_spud_post_categories.tb_blog.rb +0 -9
- data/spec/dummy/db/migrate/20140110180425_add_comments_counter_to_spud_posts.tb_blog.rb +0 -13
- data/spec/dummy/db/migrate/20140110180427_add_spam_fields_to_spud_post_comments.tb_blog.rb +0 -9
- data/spec/dummy/db/migrate/20140110180428_add_permalink_to_spud_post_comments.tb_blog.rb +0 -6
- data/spec/dummy/db/migrate/20140811161503_add_blog_key_to_spud_post_comments.tb_blog.rb +0 -7
- data/spec/dummy/db/migrate/20160216153113_drop_spud_post_comments.rb +0 -29
@@ -1,25 +1,25 @@
|
|
1
1
|
module Admin::PostsHelper
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
def options_for_parent_category(parent_id = 0)
|
4
|
+
if @categories[parent_id]
|
5
|
+
return @categories[parent_id].collect do |c|
|
6
|
+
opts = [c.name, c.id]
|
7
|
+
opts += options_for_parent_category(c.id)
|
8
|
+
end
|
9
|
+
else
|
10
|
+
return []
|
11
|
+
end
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
def link_to_disqus_comment_count(post)
|
15
|
+
# TODO: It would be great to link directly to the thread
|
16
|
+
# ie: https://myblog.disqus.com/admin/moderate/#/all/search/thread:4584301535
|
17
|
+
#
|
18
|
+
# However, we do not know the thread ID at this time. We may be able to fetch it
|
19
|
+
# via the Disqus JavaScript API.
|
20
|
+
#
|
21
|
+
return link_to 'Comments', "https://#{Spud::Blog.disqus_shortname}.disqus.com/admin/moderate/#/all", target: :blank, class: 'disqus-comment-count',
|
22
|
+
data: { disqus_identifier: post.identifier }
|
23
|
+
end
|
24
24
|
|
25
25
|
end
|
data/app/helpers/blog_helper.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
module BlogHelper
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
def options_for_post_category_select
|
4
|
+
return options_from_collection_for_select(SpudPostCategory.ordered, :url_name, :name, params[:category_url_name])
|
5
|
+
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def options_for_post_archive_select
|
8
|
+
return options_for_select(SpudPost.months_with_public_posts.collect do |d|
|
9
|
+
[d.strftime('%B %Y'), d.strftime('%Y-%b').downcase]
|
10
|
+
end, params[:archive_date])
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def spud_post_category_select
|
14
|
+
return select_tag('category_url_name', options_for_post_category_select(), prompt: 'All Categories', class: 'form-control')
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def spud_post_archive_select
|
18
|
+
return select_tag 'archive_date', options_for_post_archive_select(), prompt: 'All Dates', rel: 'archive', class: 'form-control'
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def spud_blog_rss_link
|
22
|
+
return tag :link, rel: 'alternate', type: 'application/rss+xml', title: "#{Spud::Core.site_name} Blog RSS", href: posts_path(format: :rss)
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def disqus_comment_count_for_post(post)
|
26
|
+
return content_tag :span, 'Comments', class: 'disqus-comment-count',
|
27
|
+
data: { disqus_identifier: post.identifier }
|
28
|
+
end
|
29
29
|
|
30
30
|
end
|
@@ -5,22 +5,22 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
5
5
|
|
6
6
|
spud_searchable
|
7
7
|
|
8
|
-
has_many :spud_post_categories_posts, :
|
8
|
+
has_many :spud_post_categories_posts, foreign_key: 'spud_post_id'
|
9
9
|
has_many :categories,
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
10
|
+
class_name: 'SpudPostCategory',
|
11
|
+
through: :spud_post_categories_posts,
|
12
|
+
source: :spud_post_category
|
13
13
|
|
14
|
-
belongs_to :author, :
|
14
|
+
belongs_to :author, class_name: 'SpudUser', foreign_key: 'spud_user_id'
|
15
15
|
|
16
|
-
scope :blog_posts, ->{ for_blog('blog') }
|
17
|
-
scope :news_posts, ->{ for_blog('news') }
|
18
|
-
scope :for_blog, ->(key){ where(:
|
19
|
-
scope :visible, ->{ where('visible = true AND published_at <= ?', Time.now.utc) }
|
20
|
-
scope :ordered, ->{ order('published_at desc') }
|
16
|
+
scope :blog_posts, -> { for_blog('blog') }
|
17
|
+
scope :news_posts, -> { for_blog('news') }
|
18
|
+
scope :for_blog, ->(key) { where(blog_key: key) }
|
19
|
+
scope :visible, -> { where('visible = true AND published_at <= ?', Time.now.utc) }
|
20
|
+
scope :ordered, -> { order('published_at desc') }
|
21
21
|
|
22
|
-
scope :search, ->(term){ where('title LIKE ?', "%#{term}%") }
|
23
|
-
scope :for_user, ->(user){
|
22
|
+
scope :search, ->(term) { where('title LIKE ?', "%#{term}%") }
|
23
|
+
scope :for_user, ->(user) {
|
24
24
|
if Spud::Blog.query_for_user.present?
|
25
25
|
where(Spud::Blog.query_for_user.call(user))
|
26
26
|
else
|
@@ -28,74 +28,70 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
28
28
|
end
|
29
29
|
}
|
30
30
|
|
31
|
-
|
32
|
-
validates :url_name, :
|
33
|
-
|
31
|
+
validates :title, :content, :published_at, :spud_user_id, presence: true
|
32
|
+
validates :url_name, presence: true, uniqueness: true, format: { with: /\A[\w\-]+\z/, message: 'must contain only letters, numbers, and dashes' }
|
33
|
+
validates :url_name, uniqueness: true
|
34
34
|
before_validation :set_url_name
|
35
35
|
before_validation :set_identifier
|
36
36
|
|
37
37
|
acts_as_tb_liquid_content
|
38
38
|
|
39
|
-
def self.for_spud_site(
|
39
|
+
def self.for_spud_site(_spud_site_id)
|
40
40
|
ActiveSupport::Deprecation.warn 'SpudBlog.for_spud_site is deprecated and will be removed in the future'
|
41
41
|
return all()
|
42
42
|
end
|
43
43
|
|
44
|
-
def self.recent_posts(limit=5)
|
44
|
+
def self.recent_posts(limit = 5)
|
45
45
|
return where('visible = ? AND published_at <= ?', true, Time.now.utc).order('published_at desc').limit(limit)
|
46
46
|
end
|
47
47
|
|
48
|
-
def self.recent_blog_posts(limit=5)
|
49
|
-
return
|
48
|
+
def self.recent_blog_posts(limit = 5)
|
49
|
+
return blog_posts.recent_posts(limit)
|
50
50
|
end
|
51
51
|
|
52
|
-
def self.recent_news_posts(limit=5)
|
53
|
-
return
|
52
|
+
def self.recent_news_posts(limit = 5)
|
53
|
+
return news_posts.recent_posts(limit)
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.from_archive(date_string)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
return where('')
|
63
|
-
end
|
57
|
+
date = Date.strptime(date_string, '%Y-%b')
|
58
|
+
return where(published_at: date..date.end_of_month)
|
59
|
+
rescue
|
60
|
+
logger.debug 'fallback'
|
61
|
+
return where('')
|
64
62
|
end
|
65
63
|
|
66
64
|
def is_news
|
67
|
-
ActiveSupport::Deprecation.warn
|
68
|
-
return self
|
65
|
+
ActiveSupport::Deprecation.warn ':is_news is deprecated. Please rely on the :blog_key column stead.', caller
|
66
|
+
return self[:is_news]
|
69
67
|
end
|
70
68
|
|
71
69
|
def self.months_with_public_posts
|
72
70
|
records = SpudPost.select('Extract(Month from published_at) as published_month, Extract(Year from published_at) as published_year').where('visible = ? AND published_at < ?', true, DateTime.now).group('published_month, published_year').order('published_year desc, published_month desc')
|
73
71
|
begin
|
74
|
-
return records.collect{ |r| Date.new(r[:published_year].to_i, r[:published_month].to_i) }
|
72
|
+
return records.collect { |r| Date.new(r[:published_year].to_i, r[:published_month].to_i) }
|
75
73
|
rescue Exception => e
|
76
|
-
logger.fatal "Exception occurred while fetching post archive dates:\n #{e
|
74
|
+
logger.fatal "Exception occurred while fetching post archive dates:\n #{e}"
|
77
75
|
return []
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
81
79
|
def postprocess_content
|
82
|
-
template = Liquid::Template.parse(
|
80
|
+
template = Liquid::Template.parse(content)
|
83
81
|
self.content_processed = template.render()
|
84
82
|
end
|
85
83
|
|
86
84
|
def content_processed
|
87
|
-
if
|
88
|
-
|
89
|
-
end
|
90
|
-
read_attribute(:content_processed)
|
85
|
+
postprocess_content if self[:content_processed].blank?
|
86
|
+
self[:content_processed]
|
91
87
|
end
|
92
88
|
|
93
89
|
def content_processed=(content)
|
94
|
-
|
90
|
+
self[:content_processed] = content
|
95
91
|
end
|
96
92
|
|
97
93
|
def display_date
|
98
|
-
return published_at.strftime(
|
94
|
+
return published_at.strftime('%b %d, %Y')
|
99
95
|
end
|
100
96
|
|
101
97
|
def is_public?
|
@@ -107,29 +103,25 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
107
103
|
end
|
108
104
|
|
109
105
|
def category_names
|
110
|
-
return
|
106
|
+
return categories.collect(&:name).join(', ')
|
111
107
|
end
|
112
108
|
|
113
109
|
def author_name
|
114
|
-
if
|
115
|
-
|
116
|
-
else
|
117
|
-
|
110
|
+
if custom_author.present?
|
111
|
+
custom_author
|
112
|
+
else
|
113
|
+
author.full_name
|
118
114
|
end
|
119
115
|
end
|
120
116
|
|
121
|
-
private
|
117
|
+
private
|
122
118
|
|
123
119
|
def set_url_name
|
124
|
-
if url_name.blank?
|
125
|
-
self.url_name = title.parameterize
|
126
|
-
end
|
120
|
+
self.url_name = title.parameterize if url_name.blank?
|
127
121
|
end
|
128
122
|
|
129
123
|
def set_identifier
|
130
|
-
if identifier.blank?
|
131
|
-
self.identifier = SecureRandom.uuid
|
132
|
-
end
|
124
|
+
self.identifier = SecureRandom.uuid if identifier.blank?
|
133
125
|
return true
|
134
126
|
end
|
135
127
|
|
@@ -5,7 +5,7 @@ class SpudBlogConfig
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.find(key)
|
8
|
-
return Spud::Blog.config.blogs.find{ |it| it.key == key }
|
8
|
+
return Spud::Blog.config.blogs.find { |it| it.key == key }
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.each
|
@@ -16,7 +16,7 @@ class SpudBlogConfig
|
|
16
16
|
|
17
17
|
attr_accessor :name, :key, :path, :layout
|
18
18
|
|
19
|
-
def initialize(name:, key:, path:, layout:nil)
|
19
|
+
def initialize(name:, key:, path:, layout: nil)
|
20
20
|
@name = name
|
21
21
|
@key = key
|
22
22
|
@path = path
|
data/app/models/spud_post.rb
CHANGED
@@ -1,30 +1,28 @@
|
|
1
1
|
class SpudPostCategory < ActiveRecord::Base
|
2
|
-
|
2
|
+
spud_searchable
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
has_and_belongs_to_many :posts,
|
5
|
+
class_name: 'SpudPost',
|
6
|
+
join_table: 'spud_post_categories_posts',
|
7
|
+
foreign_key: 'spud_post_category_id'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
validates :name, :url_name, presence: true
|
10
|
+
validates :name, :url_name, uniqueness: true
|
11
|
+
before_validation :set_url_name
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
after_update :touch_posts
|
14
|
+
after_destroy :touch_posts
|
15
15
|
|
16
|
-
|
16
|
+
scope :ordered, -> { order('name asc') }
|
17
17
|
|
18
|
-
private
|
18
|
+
private
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def set_url_name
|
21
|
+
self.url_name = name.parameterize
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
24
|
+
def touch_posts
|
25
|
+
posts.update_all(updated_at: Time.now) if name_changed?
|
26
|
+
end
|
29
27
|
|
30
28
|
end
|
@@ -75,7 +75,7 @@
|
|
75
75
|
</div>
|
76
76
|
|
77
77
|
<%= render :partial => '/admin/posts/custom_fields', :locals => {:f => f} %>
|
78
|
-
|
78
|
+
|
79
79
|
<h4>Meta Data</h4>
|
80
80
|
|
81
81
|
<div class="form-group">
|
@@ -104,11 +104,12 @@
|
|
104
104
|
|
105
105
|
<div class="form-group">
|
106
106
|
<div class="col-sm-offset-2 col-sm-10">
|
107
|
-
<%= f.submit "Save Post", :class => "btn btn-primary", "data-loading-text" => "Saving..." %>
|
107
|
+
<%= f.submit "Save Post", :class => "btn btn-primary", "data-loading-text" => "Saving..." %>
|
108
|
+
<%= f.submit "Preview", :class => "btn btn-info btn-preview", data: { loading_text: 'Please Wait...' } %> or
|
108
109
|
<%= link_to "Cancel", request.referer, :class => "btn btn-default" %>
|
109
110
|
</div>
|
110
111
|
</div>
|
111
112
|
|
112
113
|
<script type="text/javascript">
|
113
114
|
$(document).ready(spud.admin.posts.edit);
|
114
|
-
</script>
|
115
|
+
</script>
|
@@ -1,3 +1,11 @@
|
|
1
|
-
<%= tb_form_for @post,
|
1
|
+
<%= tb_form_for @post,
|
2
|
+
url: admin_post_path(@post),
|
3
|
+
remote: true,
|
4
|
+
data: {
|
5
|
+
errors: :inline,
|
6
|
+
success: admin_posts_path,
|
7
|
+
preview_action: admin_post_preview_path(@post)
|
8
|
+
},
|
9
|
+
html: { :class => 'form-horizontal' } do |f| %>
|
2
10
|
<%= render :partial => 'form', :locals => {:f => f} %>
|
3
|
-
<% end %>
|
11
|
+
<% end %>
|
@@ -1,3 +1,11 @@
|
|
1
|
-
<%=
|
1
|
+
<%= form_for @post,
|
2
|
+
url: admin_posts_path(),
|
3
|
+
remote: true,
|
4
|
+
data: {
|
5
|
+
errors: :inline,
|
6
|
+
success: admin_posts_path,
|
7
|
+
preview_action: admin_post_preview_path(@post)
|
8
|
+
},
|
9
|
+
html: { class: "form-horizontal page_form" } do |f| %>
|
2
10
|
<%= render :partial => 'form', :locals => {:f => f} %>
|
3
11
|
<% end %>
|
File without changes
|
data/config/routes.rb
CHANGED
@@ -8,7 +8,9 @@ Rails.application.routes.draw do
|
|
8
8
|
blog_key = config.key
|
9
9
|
|
10
10
|
namespace :admin do
|
11
|
-
resources :posts, :path => blog_key, :blog_key => blog_key
|
11
|
+
resources :posts, :path => blog_key, :blog_key => blog_key do
|
12
|
+
match :preview, on: :collection, via: [:post, :patch]
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
scope config.path do
|
@@ -1,22 +1,22 @@
|
|
1
1
|
class Spud::Blog::BlogGenerator < ::Rails::Generators::Base
|
2
2
|
|
3
|
-
argument :blog_name, :
|
3
|
+
argument :blog_name, type: :string
|
4
4
|
|
5
5
|
source_root File.join(Spud::Blog::Engine.root, 'app/views/posts')
|
6
6
|
|
7
7
|
def generate
|
8
8
|
@name = blog_name
|
9
9
|
@key = blog_name.parameterize.underscore
|
10
|
-
@path = ask(
|
11
|
-
@layout = ask(
|
10
|
+
@path = ask('What is your blog path?', default: '/' + @name.parameterize)
|
11
|
+
@layout = ask('What layout should your blog use?', default: 'application')
|
12
12
|
environment(blog_config())
|
13
|
-
if ask(
|
13
|
+
if ask('Do you want to use custom views?', limited_to: ['y', 'n']) == 'y'
|
14
14
|
copy_file 'index.html.erb', Rails.root.join('app/views', @key, 'index.html.erb')
|
15
15
|
copy_file 'show.html.erb', Rails.root.join('app/views', @key, 'show.html.erb')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
private
|
19
|
+
private
|
20
20
|
|
21
21
|
def blog_config
|
22
22
|
return <<EOF
|
@@ -12,7 +12,7 @@ class Spud::Blog::RandomPostsGenerator < ::Rails::Generators::Base
|
|
12
12
|
random_posts(true)
|
13
13
|
end
|
14
14
|
puts 'Assigning categories...'
|
15
|
-
category_ids = SpudPostCategory.all.collect
|
15
|
+
category_ids = SpudPostCategory.all.collect(&:id)
|
16
16
|
SpudPost.all.each do |p|
|
17
17
|
p.category_ids = [category_ids[rand(category_ids.length)]]
|
18
18
|
p.save
|
@@ -24,31 +24,29 @@ class Spud::Blog::RandomPostsGenerator < ::Rails::Generators::Base
|
|
24
24
|
|
25
25
|
def random_posts(is_news)
|
26
26
|
100.times do
|
27
|
-
post = SpudPost.create(
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
:is_news => is_news
|
34
|
-
})
|
27
|
+
post = SpudPost.create(title: random_title,
|
28
|
+
content: random_content,
|
29
|
+
published_at: random_time,
|
30
|
+
visible: 1,
|
31
|
+
spud_user_id: 1,
|
32
|
+
is_news: is_news)
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
38
36
|
def random_word
|
39
37
|
chars = 'abcdefghjkmnpqrstuvwxyz'
|
40
38
|
length = rand(8) + 1
|
41
|
-
return (1..length).collect{ chars[rand(chars.length)] }.join('')
|
39
|
+
return (1..length).collect { chars[rand(chars.length)] }.join('')
|
42
40
|
end
|
43
41
|
|
44
42
|
def random_title
|
45
|
-
return (1..4).collect{ random_word.capitalize }.join(' ')
|
43
|
+
return (1..4).collect { random_word.capitalize }.join(' ')
|
46
44
|
end
|
47
45
|
|
48
46
|
def random_content
|
49
47
|
content = ''
|
50
|
-
3.times do |
|
51
|
-
content += '<p>' + (1..30).collect{ random_word }.join(' ').capitalize + '.</p>'
|
48
|
+
3.times do |_i|
|
49
|
+
content += '<p>' + (1..30).collect { random_word }.join(' ').capitalize + '.</p>'
|
52
50
|
end
|
53
51
|
return content
|
54
52
|
end
|
@@ -57,4 +55,4 @@ class Spud::Blog::RandomPostsGenerator < ::Rails::Generators::Base
|
|
57
55
|
return Time.at(1.year.ago + rand * (Time.now.to_f - 1.year.ago.to_f))
|
58
56
|
end
|
59
57
|
|
60
|
-
end
|
58
|
+
end
|
@@ -3,8 +3,7 @@ module Spud
|
|
3
3
|
include ActiveSupport::Configurable
|
4
4
|
config_accessor(
|
5
5
|
:base_layout, :news_layout, :blogs, :news_enabled, :blog_enabled, :blog_path, :news_path, :posts_per_page,
|
6
|
-
:permitted_attributes, :query_for_user,
|
7
|
-
:disqus_shortname
|
6
|
+
:permitted_attributes, :query_for_user, :disqus_shortname
|
8
7
|
)
|
9
8
|
self.base_layout = 'application'
|
10
9
|
self.posts_per_page = 5
|
data/lib/spud_blog/engine.rb
CHANGED
@@ -25,20 +25,16 @@ module Spud
|
|
25
25
|
# This provides support for the legacy :blog_enabled and :news_enabled config options
|
26
26
|
# Blog and News handle 90% of the typical use cases
|
27
27
|
if Spud::Blog.config.blog_enabled
|
28
|
-
SpudBlogConfig.push(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
:layout => Spud::Blog.config.base_layout
|
33
|
-
})
|
28
|
+
SpudBlogConfig.push(key: 'blog',
|
29
|
+
name: 'Blog',
|
30
|
+
path: Spud::Blog.config.blog_path,
|
31
|
+
layout: Spud::Blog.config.base_layout)
|
34
32
|
end
|
35
33
|
if Spud::Blog.config.news_enabled
|
36
|
-
SpudBlogConfig.push(
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
:layout => Spud::Blog.config.news_layout
|
41
|
-
})
|
34
|
+
SpudBlogConfig.push(key: 'news',
|
35
|
+
name: 'News',
|
36
|
+
path: Spud::Blog.config.news_path,
|
37
|
+
layout: Spud::Blog.config.news_layout)
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
@@ -46,12 +42,12 @@ module Spud
|
|
46
42
|
# Build admin modules for each configure blog
|
47
43
|
SpudBlogConfig.each do |config|
|
48
44
|
blog_app = {
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
45
|
+
name: "#{config.name} Posts",
|
46
|
+
url: "admin/#{config.key}",
|
47
|
+
thumbnail: 'admin/posts_thumb.png'
|
52
48
|
}
|
53
49
|
Spud::Core.config.admin_applications += [blog_app]
|
54
|
-
end
|
50
|
+
end
|
55
51
|
end
|
56
52
|
|
57
53
|
initializer 'tb_blog.assets' do
|
data/lib/spud_blog/version.rb
CHANGED
data/lib/tb_blog.rb
CHANGED