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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -2
  3. data/app/assets/javascripts/admin/blog/posts.js +42 -0
  4. data/app/controllers/admin/post_categories_controller.rb +57 -57
  5. data/app/controllers/admin/posts_controller.rb +110 -101
  6. data/app/controllers/concerns/blog_url_helpers.rb +22 -18
  7. data/app/controllers/concerns/post_view_for_action.rb +11 -0
  8. data/app/controllers/posts_controller.rb +23 -34
  9. data/app/helpers/admin/posts_helper.rb +20 -20
  10. data/app/helpers/blog_helper.rb +21 -21
  11. data/app/models/spud/spud_post_model.rb +43 -51
  12. data/app/models/spud_blog_config.rb +2 -2
  13. data/app/models/spud_post.rb +1 -1
  14. data/app/models/spud_post_categories_post.rb +1 -1
  15. data/app/models/spud_post_category.rb +18 -20
  16. data/app/models/spud_post_site.rb +1 -1
  17. data/app/views/admin/posts/_form.html.erb +4 -3
  18. data/app/views/admin/posts/edit.html.erb +10 -2
  19. data/app/views/admin/posts/new.html.erb +9 -1
  20. data/app/views/admin/posts/show.html.erb +0 -0
  21. data/config/routes.rb +3 -1
  22. data/lib/generators/spud/blog/blog_generator.rb +5 -5
  23. data/lib/generators/spud/blog/random_posts_generator.rb +12 -14
  24. data/lib/generators/spud/blog/views_generator.rb +1 -1
  25. data/lib/spud_blog/configuration.rb +1 -2
  26. data/lib/spud_blog/engine.rb +12 -16
  27. data/lib/spud_blog/version.rb +3 -3
  28. data/lib/tasks/spud_blog_tasks.rake +1 -1
  29. data/lib/tb_blog.rb +2 -2
  30. data/spec/controllers/admin/posts_controller_spec.rb +28 -7
  31. data/spec/controllers/posts_controller_spec.rb +7 -7
  32. data/spec/dummy/config/application.rb +2 -3
  33. data/spec/dummy/config/boot.rb +1 -1
  34. data/spec/dummy/config/environment.rb +2 -2
  35. data/spec/dummy/config/environments/test.rb +3 -3
  36. data/spec/dummy/config/routes.rb +1 -1
  37. data/spec/dummy/config.ru +1 -1
  38. data/spec/dummy/db/migrate/{20120610130206_create_spud_admin_permissions.spud_core.rb → 20161020155425_create_spud_admin_permissions.tb_core.rb} +1 -1
  39. data/spec/dummy/db/migrate/20161020155426_create_spud_users.tb_core.rb +30 -0
  40. 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
  41. 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
  42. data/spec/dummy/db/migrate/{20120610130210_create_spud_user_settings.spud_core.rb → 20161020155429_create_spud_user_settings.tb_core.rb} +1 -1
  43. data/spec/dummy/db/migrate/{20140110180411_create_spud_roles.tb_core.rb → 20161020155430_create_spud_roles.tb_core.rb} +0 -0
  44. data/spec/dummy/db/migrate/{20140110180412_create_spud_permissions.tb_core.rb → 20161020155431_create_spud_permissions.tb_core.rb} +3 -3
  45. data/spec/dummy/db/migrate/{20140110180413_create_spud_role_permissions.tb_core.rb → 20161020155432_create_spud_role_permissions.tb_core.rb} +2 -2
  46. data/spec/dummy/db/migrate/{20140110180414_drop_spud_admin_permissions.tb_core.rb → 20161020155433_drop_spud_admin_permissions.tb_core.rb} +0 -0
  47. 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
  48. data/spec/dummy/db/migrate/{20160215174633_create_tb_redirects.tb_redirects.rb → 20161020155435_create_tb_redirects.tb_redirects.rb} +3 -3
  49. 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
  50. data/spec/dummy/db/migrate/{20140110180418_create_spud_posts.tb_blog.rb → 20161020155437_create_spud_posts.tb_blog.rb} +3 -3
  51. data/spec/dummy/db/migrate/{20140110180419_create_spud_post_categories.tb_blog.rb → 20161020155438_create_spud_post_categories.tb_blog.rb} +4 -4
  52. 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
  53. data/spec/dummy/db/migrate/20161020155440_add_url_to_spud_post_categories.tb_blog.rb +9 -0
  54. 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
  55. data/spec/dummy/db/migrate/{20140110180424_add_meta_to_posts.tb_blog.rb → 20161020155442_add_meta_to_posts.tb_blog.rb} +0 -0
  56. data/spec/dummy/db/migrate/{20140110180426_create_spud_post_sites.tb_blog.rb → 20161020155443_create_spud_post_sites.tb_blog.rb} +3 -3
  57. 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
  58. 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
  59. 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
  60. 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
  61. 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
  62. 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
  63. data/spec/dummy/db/migrate/{20150116195007_drop_spud_post_sites.tb_blog.rb → 20161020155450_drop_spud_post_sites.tb_blog.rb} +4 -3
  64. 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
  65. 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
  66. data/spec/dummy/db/schema.rb +106 -118
  67. data/spec/dummy/script/rails +2 -2
  68. data/spec/factories/spud_post_factories.rb +2 -2
  69. data/spec/helpers/admin/posts_helper_spec.rb +1 -1
  70. data/spec/models/spud_post_spec.rb +4 -4
  71. data/spec/rails_helper.rb +5 -5
  72. data/spec/spec_helper.rb +42 -44
  73. metadata +77 -79
  74. data/spec/dummy/db/migrate/20120610130207_create_spud_users.spud_core.rb +0 -30
  75. data/spec/dummy/db/migrate/20140110180415_create_spud_permalinks.tb_permalinks.rb +0 -12
  76. data/spec/dummy/db/migrate/20140110180416_add_site_id_to_spud_permalinks.tb_permalinks.rb +0 -7
  77. data/spec/dummy/db/migrate/20140110180417_modify_site_id_for_spud_permalinks.tb_permalinks.rb +0 -12
  78. data/spec/dummy/db/migrate/20140110180420_create_spud_post_comments.tb_blog.rb +0 -14
  79. data/spec/dummy/db/migrate/20140110180422_add_url_to_spud_post_categories.tb_blog.rb +0 -9
  80. data/spec/dummy/db/migrate/20140110180425_add_comments_counter_to_spud_posts.tb_blog.rb +0 -13
  81. data/spec/dummy/db/migrate/20140110180427_add_spam_fields_to_spud_post_comments.tb_blog.rb +0 -9
  82. data/spec/dummy/db/migrate/20140110180428_add_permalink_to_spud_post_comments.tb_blog.rb +0 -6
  83. data/spec/dummy/db/migrate/20140811161503_add_blog_key_to_spud_post_comments.tb_blog.rb +0 -7
  84. 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
- def options_for_parent_category(parent_id = 0)
4
- if @categories[parent_id]
5
- return @categories[parent_id].collect{ |c|
6
- opts = [c.name, c.id]
7
- opts += options_for_parent_category(c.id)
8
- }
9
- else
10
- return []
11
- end
12
- end
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
- 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
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
@@ -1,30 +1,30 @@
1
1
  module BlogHelper
2
2
 
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
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
- def options_for_post_archive_select
8
- return options_for_select(SpudPost.months_with_public_posts.collect{ |d|
9
- [d.strftime('%B %Y'), d.strftime('%Y-%b').downcase]
10
- }, params[:archive_date])
11
- end
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
- 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
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
- 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
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
- 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
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
- 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
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, :foreign_key => 'spud_post_id'
8
+ has_many :spud_post_categories_posts, foreign_key: 'spud_post_id'
9
9
  has_many :categories,
10
- :class_name => 'SpudPostCategory',
11
- :through => :spud_post_categories_posts,
12
- :source => :spud_post_category
10
+ class_name: 'SpudPostCategory',
11
+ through: :spud_post_categories_posts,
12
+ source: :spud_post_category
13
13
 
14
- belongs_to :author, :class_name => 'SpudUser', :foreign_key => 'spud_user_id'
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(:blog_key => key) }
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
- validates_presence_of :title, :content, :published_at, :spud_user_id
32
- validates :url_name, :presence => true, :uniqueness => true, :format => {:with => /\A[\w\-]+\z/, :message => 'must contain only letters, numbers, and dashes'}
33
- validates_uniqueness_of :url_name
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(spud_site_id)
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 self.blog_posts.recent_posts(limit)
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 self.news_posts.recent_posts(limit)
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
- begin
58
- date = Date.strptime(date_string, "%Y-%b")
59
- return where(:published_at => date..date.end_of_month)
60
- rescue
61
- logger.debug 'fallback'
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 ":is_news is deprecated. Please rely on the :blog_key column stead.", caller
68
- return self.read_attribute(:is_news)
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.to_s}"
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(self.content)
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 read_attribute(:content_processed).blank?
88
- postprocess_content
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
- write_attribute(:content_processed,content)
90
+ self[:content_processed] = content
95
91
  end
96
92
 
97
93
  def display_date
98
- return published_at.strftime("%b %d, %Y")
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 self.categories.collect{ |c| c.name }.join(', ')
106
+ return categories.collect(&:name).join(', ')
111
107
  end
112
108
 
113
109
  def author_name
114
- if self.custom_author.present?
115
- self.custom_author
116
- else
117
- self.author.full_name
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
@@ -1,3 +1,3 @@
1
1
  class SpudPost < Spud::SpudPostModel
2
- # Copy this file to your app to extend the base SpudPost model
2
+ # Copy this file to your app to extend the base SpudPost model
3
3
  end
@@ -1,4 +1,4 @@
1
1
  class SpudPostCategoriesPost < ActiveRecord::Base
2
- belongs_to :spud_post, :touch => true
2
+ belongs_to :spud_post, touch: true
3
3
  belongs_to :spud_post_category
4
4
  end
@@ -1,30 +1,28 @@
1
1
  class SpudPostCategory < ActiveRecord::Base
2
- spud_searchable
2
+ spud_searchable
3
3
 
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'
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
- validates_presence_of :name, :url_name
10
- validates_uniqueness_of :name, :url_name
11
- before_validation :set_url_name
9
+ validates :name, :url_name, presence: true
10
+ validates :name, :url_name, uniqueness: true
11
+ before_validation :set_url_name
12
12
 
13
- after_update :touch_posts
14
- after_destroy :touch_posts
13
+ after_update :touch_posts
14
+ after_destroy :touch_posts
15
15
 
16
- scope :ordered, ->{ order('name asc') }
16
+ scope :ordered, -> { order('name asc') }
17
17
 
18
- private
18
+ private
19
19
 
20
- def set_url_name
21
- self.url_name = self.name.parameterize
22
- end
20
+ def set_url_name
21
+ self.url_name = name.parameterize
22
+ end
23
23
 
24
- def touch_posts
25
- if self.name_changed?
26
- self.posts.update_all(:updated_at => Time.now)
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
@@ -4,5 +4,5 @@ class SpudPostSite < ActiveRecord::Base
4
4
  def spud_site
5
5
  return Spud::Core.site_config_for_id(spud_site_id)
6
6
  end
7
-
7
+
8
8
  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, :url => admin_post_path(@post), :html => {:class => 'form-horizontal'}, :remote => true, :data => {:errors => :inline, :success => admin_posts_path} do |f| %>
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
- <%= tb_form_for @post, :url => admin_posts_path, :html => {:class => 'form-horizontal'}, :remote => true, :data => {:errors => :inline, :success => admin_posts_path} do |f| %>
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, :type => :string
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("What is your blog path?", :default => '/'+@name.parameterize)
11
- @layout = ask("What layout should your blog use?", :default => 'application')
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("Do you want to use custom views?", :limited_to => ['y', 'n']) == 'y'
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{ |c| c.id }
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
- :title => random_title,
29
- :content => random_content,
30
- :published_at => random_time,
31
- :visible => 1,
32
- :spud_user_id => 1,
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 |i|
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
@@ -1,7 +1,7 @@
1
1
  require 'rails/generators/migration'
2
2
 
3
3
  class Spud::Blog::ViewsGenerator < ::Rails::Generators::Base
4
-
4
+
5
5
  source_root File.join(Spud::Blog::Engine.root, 'app/views')
6
6
 
7
7
  def install
@@ -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
@@ -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
- :key => 'blog',
30
- :name => 'Blog',
31
- :path => Spud::Blog.config.blog_path,
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
- :key => 'news',
38
- :name => 'News',
39
- :path => Spud::Blog.config.news_path,
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
- :name => "#{config.name} Posts",
50
- :url => "admin/#{config.key}",
51
- :thumbnail => 'admin/posts_thumb.png'
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
@@ -1,5 +1,5 @@
1
1
  module Spud
2
- module Blog
3
- VERSION = "1.3.3"
4
- end
2
+ module Blog
3
+ VERSION = '1.3.4'.freeze
4
+ end
5
5
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  namespace :tb_blog do
7
7
 
8
- task :apply_blog_keys => :environment do
8
+ task apply_blog_keys: :environment do
9
9
  SpudPost.all.each do |post|
10
10
  if post.is_news?
11
11
  post.update_column(:blog_key, 'news')
data/lib/tb_blog.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Spud
2
2
  module Blog
3
- require 'spud_blog/configuration'
4
- require 'spud_blog/engine' if defined?(Rails)
3
+ require 'spud_blog/configuration'
4
+ require 'spud_blog/engine' if defined?(Rails)
5
5
  end
6
6
  end