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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c07afcec9d3eb4f9a2038a5dc331496148f6c40
4
- data.tar.gz: 5921d46580058b1faf06f56f81c2b700b48e2a27
3
+ metadata.gz: 7ea87e773003046128ce6898ed2d3503f4c3c356
4
+ data.tar.gz: f8ef87cc40c3c462b7b40078e66a916fc63c49c5
5
5
  SHA512:
6
- metadata.gz: 971e90879dde94f36ed70c28019f57c50610a4b8d829b93348a72e9af54d0e01d0f109aa35803d72f2cdf4290411b3fe3eaa11630ddf09179f30311073f59750
7
- data.tar.gz: 78244e37a50fcfbbd516554e8554047d9f9dbf01dfa6da0d887c0160ce0098613a429f4fa649358b8630f04b2acb817873a6efbb08157f52685493da2ce32e20
6
+ metadata.gz: 6f86f21e95dc402fc6d73df5f3caaf2cf6b550ce3473e51753d2192b310615cba3202cd9c764c2af8534c6765c72e3be1c4d222b314b10a29efb9248f4fa7dd9
7
+ data.tar.gz: 14d0eee6497a0ffc52d8d94f38ea820989ef477d777200c04e0d8ecdc78b46084efce791ea37a3270bb0491777e7f15b15e5b975a7e5017754b9a8adf136ba86
data/Rakefile CHANGED
@@ -20,10 +20,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
23
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
24
24
  load 'rails/tasks/engine.rake'
25
25
 
26
26
  Bundler::GemHelper.install_tasks
27
27
 
28
28
  require 'rake'
29
-
@@ -6,6 +6,7 @@ spud.admin.posts = {
6
6
  $('body').on('submit', '.spud-post-category-form', submittedPostCategoryForm);
7
7
  $('body').on('blur', '.spud-post-title', blurredPostTitle);
8
8
  $('body').on('click', '.spud-post-url-name-regen', clickedUrlNameRegen);
9
+ $(".btn-preview").on('click', clickedPreviewButton);
9
10
  }
10
11
  };
11
12
 
@@ -91,4 +92,45 @@ var encodeTitleForUrlName = function(title){
91
92
  return string;
92
93
  };
93
94
 
95
+ var clickedPreviewButton = function(e){
96
+ e.preventDefault();
97
+ var $button = $(this);
98
+ var $form = $button.parents('form');
99
+
100
+ // Build a temporary form
101
+ $previewForm = $('<form />', {
102
+ action: $form.data('previewAction'),
103
+ target: '_blank',
104
+ method: 'POST',
105
+ css: { display: 'none' }
106
+ });
107
+ $('body').append($previewForm);
108
+
109
+ // Tell tinymce to write out to the textarea
110
+ tinyMCE.triggerSave();
111
+
112
+ // Copy fields into our temp form
113
+ $form.find('input, select, textarea').each(function(i, el){
114
+ var input = document.createElement('input');
115
+ input.name = el.name;
116
+ input.value = el.value;
117
+ $previewForm.append(input);
118
+ });
119
+
120
+ // Cross site scripting tag
121
+ var csrf = document.createElement('input');
122
+ csrf.name = 'authenticity_token';
123
+ csrf.value = tb.util.getCsrfToken();
124
+ $previewForm.append(csrf);
125
+
126
+ // Submit it
127
+ $button.button('loading');
128
+ $previewForm.submit();
129
+
130
+ setTimeout(function(){
131
+ $previewForm.remove();
132
+ $button.button('reset');
133
+ }, 2000);
134
+ };
135
+
94
136
  })();
@@ -1,61 +1,61 @@
1
1
  class Admin::PostCategoriesController < Admin::ApplicationController
2
2
 
3
- layout false
4
- respond_to :html, :json
5
-
6
- before_filter :find_category, :only => [:show, :edit, :update, :destroy]
7
-
8
- def index
9
- @post_categories = SpudPostCategory.ordered
10
- respond_with @post_categories
11
- end
12
-
13
- def edit
14
- respond_with @post_category
15
- end
16
-
17
- def update
18
- if @post_category.update_attributes(category_params)
19
- flash.now[:notice] = 'Post Category was successfully updated'
20
- respond_with @post_category, :location => admin_post_categories_path
21
- else
22
- render 'new', :status => 422
23
- end
24
- end
25
-
26
- def new
27
- @post_category = SpudPostCategory.new
28
- respond_with @post_category
29
- end
30
-
31
- def create
32
- @post_category = SpudPostCategory.new(category_params)
33
- if @post_category.save
34
- flash.now[:notice] = 'Post Category was successfully created'
35
- respond_with @post_category, :location => admin_post_categories_path
36
- else
37
- render 'new', :status => 422
38
- end
39
- end
40
-
41
- def destroy
42
- if @post_category.destroy
43
- flash.now[:notice] = 'Post Category was successfully deleted'
44
- @post_categories = SpudPostCategory.ordered
45
- render 'index'
46
- else
47
- respond_with @post_category, :location => admin_post_categories_path
48
- end
49
- end
50
-
51
- private
52
-
53
- def find_category
54
- @post_category = SpudPostCategory.find(params[:id])
55
- end
56
-
57
- def category_params
58
- params.require(:spud_post_category).permit(:name)
59
- end
3
+ layout false
4
+ respond_to :html, :json
5
+
6
+ before_action :find_category, only: [:show, :edit, :update, :destroy]
7
+
8
+ def index
9
+ @post_categories = SpudPostCategory.ordered
10
+ respond_with @post_categories
11
+ end
12
+
13
+ def edit
14
+ respond_with @post_category
15
+ end
16
+
17
+ def update
18
+ if @post_category.update_attributes(category_params)
19
+ flash.now[:notice] = 'Post Category was successfully updated'
20
+ respond_with @post_category, location: admin_post_categories_path
21
+ else
22
+ render 'new', status: 422
23
+ end
24
+ end
25
+
26
+ def new
27
+ @post_category = SpudPostCategory.new
28
+ respond_with @post_category
29
+ end
30
+
31
+ def create
32
+ @post_category = SpudPostCategory.new(category_params)
33
+ if @post_category.save
34
+ flash.now[:notice] = 'Post Category was successfully created'
35
+ respond_with @post_category, location: admin_post_categories_path
36
+ else
37
+ render 'new', status: 422
38
+ end
39
+ end
40
+
41
+ def destroy
42
+ if @post_category.destroy
43
+ flash.now[:notice] = 'Post Category was successfully deleted'
44
+ @post_categories = SpudPostCategory.ordered
45
+ render 'index'
46
+ else
47
+ respond_with @post_category, location: admin_post_categories_path
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def find_category
54
+ @post_category = SpudPostCategory.find(params[:id])
55
+ end
56
+
57
+ def category_params
58
+ params.require(:spud_post_category).permit(:name)
59
+ end
60
60
 
61
61
  end
@@ -1,104 +1,113 @@
1
1
  class Admin::PostsController < Admin::ApplicationController
2
- include BlogUrlHelpers
3
-
4
- respond_to :html, :xml, :json
5
- before_action :load_blog
6
- before_action :find_post, :only => [:show, :edit, :update, :destroy]
7
- around_action :create_redirect_if_necessary, :only => :update
8
-
9
- def index
10
- @posts = SpudPost.for_blog(params[:blog_key]).ordered.paginate(:page => params[:page], :per_page => 15)
11
- if params[:search]
12
- @posts = @posts.search(params[:search])
13
- end
14
- respond_with @posts
15
- end
16
-
17
- def edit
18
- respond_with @post
19
- end
20
-
21
- def update
22
- if @post.update_attributes(post_params)
23
- flash[:notice] = 'Post was successfully updated.'
24
- end
25
- respond_with @post, :location => admin_posts_path
26
- end
27
-
28
- def new
29
- @categories = SpudPostCategory.ordered
30
- @post = SpudPost.new(:published_at => Time.zone.now, :spud_user_id => current_user.id)
31
- respond_with @post
32
- end
33
-
34
- def create
35
- @categories = SpudPostCategory.ordered
36
- @post = SpudPost.new(post_params)
37
- @post.blog_key = params[:blog_key]
38
- if @post.save
39
- flash[:notice] = 'Post was successfully created.'
40
- end
41
- respond_with @post, :location => admin_posts_path
42
- end
43
-
44
- def destroy
45
- if @post.destroy
46
- flash[:notice] = 'Post was successfully deleted.'
47
- end
48
- respond_with @post, :location => admin_posts_path
49
- end
50
-
51
- private
52
-
53
- def find_post
54
- @post = SpudPost.find(params[:id])
55
- if @post.blank?
56
- flash[:error] = "Post not found!"
57
- redirect_to admin_posts_path and return false
58
- end
59
- end
60
-
61
- def post_params
62
- permitted = [:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :custom_author, :category_ids => []]
63
- if Spud::Blog.permitted_attributes.present?
64
- permitted = permitted + Spud::Blog.permitted_attributes
65
- end
66
- p = params.require(:spud_post).permit(permitted)
67
- p[:updated_at] = DateTime.now
68
- return p
69
- end
70
-
71
- def load_blog
72
- @config = SpudBlogConfig.find(params[:blog_key])
73
- if @config.blank?
74
- redirect_to admin_root_path
75
- return false
76
- else
77
- act_as_app "#{@config.name} Posts".parameterize.underscore.to_sym
78
- add_breadcrumb "#{@config.name} Posts", admin_posts_path(blog_key: @config.key)
79
- end
80
- end
81
-
82
- # Create a redirect if the post URL has changed
83
- #
84
- # Normally this sort of thing might belong in a model after_update hook, but the model
85
- # layer has no knowledge of URL helpers.
86
- #
87
- def create_redirect_if_necessary
88
- @_redirect_source = post_path(@post.url_name, :blog_key => @post.blog_key, :only_path => true)
89
- yield
90
- ensure
91
- if @post.errors.empty?
92
- @_redirect_destination = post_path(@post.url_name, :blog_key => @post.blog_key, :only_path => true)
93
- if @_redirect_source != @_redirect_destination
94
- TbRedirect.create_smart({
95
- :source => @_redirect_source,
96
- :destination => @_redirect_destination,
97
- :created_by => 'blog',
98
- :owner => @post
99
- })
100
- end
101
- end
102
- end
2
+ include BlogUrlHelpers
3
+ include PostViewForAction
4
+
5
+ respond_to :html, :xml, :json
6
+ before_action :load_blog
7
+ before_action :find_post, only: [:edit, :update, :destroy]
8
+ around_action :create_redirect_if_necessary, only: :update
9
+
10
+ def index
11
+ @posts = SpudPost.for_blog(params[:blog_key]).ordered.paginate(page: params[:page], per_page: 15)
12
+ @posts = @posts.search(params[:search]) if params[:search]
13
+ respond_with @posts
14
+ end
15
+
16
+ def edit
17
+ respond_with @post
18
+ end
19
+
20
+ def show
21
+ end
22
+
23
+ def update
24
+ if @post.update_attributes(post_params)
25
+ flash[:notice] = 'Post was successfully updated.'
26
+ end
27
+ respond_with @post, location: admin_posts_path
28
+ end
29
+
30
+ def new
31
+ @post = SpudPost.new(published_at: Time.zone.now, spud_user_id: current_user.id)
32
+ respond_with @post
33
+ end
34
+
35
+ def create
36
+ @post = SpudPost.new(post_params)
37
+ @post.blog_key = params[:blog_key]
38
+ flash[:notice] = 'Post was successfully created.' if @post.save
39
+ respond_with @post, location: admin_posts_path
40
+ end
41
+
42
+ def destroy
43
+ flash[:notice] = 'Post was successfully deleted.' if @post.destroy
44
+ respond_with @post, location: admin_posts_path
45
+ end
46
+
47
+ def preview
48
+ @post = if params[:post_id]
49
+ SpudPost.find_by!(id: params[:post_id])
50
+ else
51
+ SpudPost.new
52
+ end
53
+ @post.assign_attributes(post_params)
54
+ @post.postprocess_content()
55
+ render template: post_view_for_action(:show), controller: :posts, layout: @config.layout
56
+ end
57
+
58
+ def render_preview
59
+ render template: post_view_for_action(:show), controller: :posts, layout: @config.layout
60
+ end
61
+
62
+ private
63
+
64
+ def find_post
65
+ @post = SpudPost.find(params[:id])
66
+ if @post.blank?
67
+ flash[:error] = 'Post not found!'
68
+ redirect_to(admin_posts_path) && (return false)
69
+ end
70
+ end
71
+
72
+ def post_params
73
+ permitted = [:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :custom_author, category_ids: []]
74
+ if Spud::Blog.permitted_attributes.present?
75
+ permitted += Spud::Blog.permitted_attributes
76
+ end
77
+ p = params.require(:spud_post).permit(permitted)
78
+ p[:updated_at] = DateTime.now
79
+ return p
80
+ end
81
+
82
+ def load_blog
83
+ @config = SpudBlogConfig.find(params[:blog_key])
84
+ if @config.blank?
85
+ redirect_to admin_root_path
86
+ return false
87
+ else
88
+ act_as_app "#{@config.name} Posts".parameterize.underscore.to_sym
89
+ add_breadcrumb "#{@config.name} Posts", admin_posts_path(blog_key: @config.key)
90
+ end
91
+ end
92
+
93
+ # Create a redirect if the post URL has changed
94
+ #
95
+ # Normally this sort of thing might belong in a model after_update hook, but the model
96
+ # layer has no knowledge of URL helpers.
97
+ #
98
+ def create_redirect_if_necessary
99
+ @_redirect_source = post_path(@post.url_name, blog_key: @post.blog_key, only_path: true)
100
+ yield
101
+ ensure
102
+ if @post.errors.empty?
103
+ @_redirect_destination = post_path(@post.url_name, blog_key: @post.blog_key, only_path: true)
104
+ if @_redirect_source != @_redirect_destination
105
+ TbRedirect.create_smart(source: @_redirect_source,
106
+ destination: @_redirect_destination,
107
+ created_by: 'blog',
108
+ owner: @post)
109
+ end
110
+ end
111
+ end
103
112
 
104
113
  end
@@ -3,49 +3,53 @@ module BlogUrlHelpers
3
3
 
4
4
  included do
5
5
  helper_method :posts_path, :post_path, :post_category_path, :post_archive_path,
6
- :admin_posts_path, :admin_post_path, :new_admin_post_path, :edit_admin_post_path
6
+ :admin_posts_path, :admin_post_path, :new_admin_post_path, :edit_admin_post_path,
7
+ :admin_post_preview_path
7
8
  end
8
9
 
9
- def posts_path(opts={})
10
- url_for opts.merge({:controller => '/posts', :action => 'index', :blog_key => params[:blog_key]})
10
+ def posts_path(opts = {})
11
+ url_for opts.merge(controller: '/posts', action: 'index', blog_key: params[:blog_key])
11
12
  end
12
13
 
13
- def post_path(url_name, opts={})
14
- url_for opts.merge({:controller => '/posts', :action => 'show', :id => url_name, :blog_key => params[:blog_key]})
14
+ def post_path(url_name, opts = {})
15
+ url_for opts.merge(controller: '/posts', action: 'show', id: url_name, blog_key: params[:blog_key])
15
16
  end
16
17
 
17
- def post_category_path(category_url_name, opts={})
18
- url_for opts.merge({:controller => '/posts', :action => 'category', :category_url_name => category_url_name, :blog_key => params[:blog_key]})
18
+ def post_category_path(category_url_name, opts = {})
19
+ url_for opts.merge(controller: '/posts', action: 'category', category_url_name: category_url_name, blog_key: params[:blog_key])
19
20
  end
20
21
 
21
- def post_archive_path(archive_date, opts={})
22
- url_for opts.merge({:controller => '/posts', :action => 'archive', :archive_date => archive_date, :blog_key => params[:blog_key]})
22
+ def post_archive_path(archive_date, opts = {})
23
+ url_for opts.merge(controller: '/posts', action: 'archive', archive_date: archive_date, blog_key: params[:blog_key])
23
24
  end
24
25
 
25
- def post_category_archive_path(category_url_name, archive_date, opts={})
26
- url_for opts.merge({:controller => '/posts', :action => 'category', :category_url_name => category_url_name, :archive_date => archive_date, :blog_key => params[:blog_key]})
26
+ def post_category_archive_path(category_url_name, archive_date, opts = {})
27
+ url_for opts.merge(controller: '/posts', action: 'category', category_url_name: category_url_name, archive_date: archive_date, blog_key: params[:blog_key])
27
28
  end
28
29
 
29
- #
30
- # Admin
31
- #
30
+ #
31
+ # Admin
32
+ #
32
33
 
33
34
  def admin_posts_path(blog_key: nil)
34
35
  blog_key ||= params[:blog_key]
35
- url_for :controller => '/admin/posts', :action => 'index', :blog_key => blog_key
36
+ url_for controller: '/admin/posts', action: 'index', blog_key: blog_key
36
37
  end
37
38
 
38
39
  def new_admin_post_path(blog_key: nil)
39
40
  blog_key ||= params[:blog_key]
40
- url_for :controller => '/admin/posts', :action => 'new', :blog_key => blog_key
41
+ url_for controller: '/admin/posts', action: 'new', blog_key: blog_key
41
42
  end
42
43
 
43
44
  def admin_post_path(post)
44
- url_for :controller => '/admin/posts', :action => 'show', :id => post.id, :blog_key => post.blog_key
45
+ url_for controller: '/admin/posts', action: 'show', id: post.id, blog_key: post.blog_key
45
46
  end
46
47
 
47
48
  def edit_admin_post_path(post)
48
- url_for :controller => '/admin/posts', :action => 'edit', :id => post.id, :blog_key => post.blog_key
49
+ url_for controller: '/admin/posts', action: 'edit', id: post.id, blog_key: post.blog_key
49
50
  end
50
51
 
52
+ def admin_post_preview_path(post)
53
+ url_for controller: '/admin/posts', action: :preview, post_id: post.id, blog_key: (post.blog_key || params[:blog_key])
54
+ end
51
55
  end
@@ -0,0 +1,11 @@
1
+ module PostViewForAction
2
+ extend ActiveSupport::Concern
3
+
4
+ def post_view_for_action(action)
5
+ if File.exist?(Rails.root.join("app/views/#{@config.key}/#{action}.html.erb"))
6
+ return "/#{@config.key}/#{action}"
7
+ else
8
+ return "/posts/#{action}"
9
+ end
10
+ end
11
+ end
@@ -1,21 +1,20 @@
1
1
  class PostsController < ApplicationController
2
2
  include BlogUrlHelpers
3
+ include PostViewForAction
3
4
 
4
- respond_to :html, :json, :rss
5
+ respond_to :html, :json, :rss
5
6
 
6
7
  before_action :load_blog
7
- before_action :load_page_number, :only => [:index, :archive, :category]
8
- before_action :find_post, :only => [:show, :create_comment]
8
+ before_action :load_page_number, only: [:index, :archive, :category]
9
+ before_action :find_post, only: [:show, :create_comment]
9
10
 
10
11
  def index
11
- @posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).ordered.paginate(:page => @page_number, :per_page => Spud::Blog.config.posts_per_page)
12
- if params[:search]
13
- @posts = @posts.search(params[:search])
14
- end
12
+ @posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).ordered.paginate(page: @page_number, per_page: Spud::Blog.config.posts_per_page)
13
+ @posts = @posts.search(params[:search]) if params[:search]
15
14
  respond_with @posts do |format|
16
- format.html{
17
- render view_for_action('index')
18
- }
15
+ format.html do
16
+ render post_view_for_action(:index)
17
+ end
19
18
  end
20
19
  end
21
20
 
@@ -33,37 +32,35 @@ class PostsController < ApplicationController
33
32
  end
34
33
 
35
34
  def category
36
- if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
37
- @posts = @post_category.posts.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(:page => @page_number, :per_page => Spud::Blog.config.posts_per_page)
35
+ if @post_category = SpudPostCategory.find_by(url_name: params[:category_url_name])
36
+ @posts = @post_category.posts.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(page: @page_number, per_page: Spud::Blog.config.posts_per_page)
38
37
  else
39
38
  redirect_to posts_path
40
39
  return
41
40
  end
42
41
  respond_with @posts do |format|
43
- format.html { render view_for_action 'index' }
42
+ format.html { render post_view_for_action :index }
44
43
  end
45
44
  end
46
45
 
47
46
  def archive
48
- @posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(:page => @page_number, :per_page => Spud::Blog.config.posts_per_page)
47
+ @posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(page: @page_number, per_page: Spud::Blog.config.posts_per_page)
49
48
  respond_with @posts do |format|
50
- format.html { render view_for_action 'index' }
49
+ format.html { render post_view_for_action :index }
51
50
  end
52
51
  end
53
52
 
54
53
  def show
55
- respond_with @post do |format|
56
- format.html { render view_for_action 'show' }
54
+ respond_with @post do |format|
55
+ format.html { render post_view_for_action :show }
57
56
  end
58
57
  end
59
58
 
60
- private
59
+ private
61
60
 
62
61
  def find_post
63
- @post = SpudPost.for_user(current_user).for_blog(params[:blog_key]).where(:url_name => params[:id]).first
64
- if @post.blank? || @post.is_private?
65
- raise Spud::NotFoundError.new(:item => 'post')
66
- end
62
+ @post = SpudPost.for_user(current_user).for_blog(params[:blog_key]).where(url_name: params[:id]).first
63
+ raise Spud::NotFoundError, item: 'post' if @post.blank? || @post.is_private?
67
64
  end
68
65
 
69
66
  def load_page_number
@@ -71,10 +68,10 @@ private
71
68
  if params[:page].present?
72
69
  page = params[:page].to_i
73
70
  if page.to_s != params[:page].to_s
74
- if(page > 1)
75
- redirect_to posts_path(:page => page), :status => :moved_permanently and return
71
+ if page > 1
72
+ redirect_to(posts_path(page: page), status: :moved_permanently) && return
76
73
  else
77
- redirect_to posts_path(:page => nil), :status => :moved_permanently and return
74
+ redirect_to(posts_path(page: nil), status: :moved_permanently) && return
78
75
  end
79
76
  end
80
77
  end
@@ -84,19 +81,11 @@ private
84
81
  def load_blog
85
82
  @config = SpudBlogConfig.find(params[:blog_key])
86
83
  if @config.blank?
87
- raise Spud::NotFoundError(:item => 'blog')
84
+ raise Spud::NotFoundError(item: 'blog')
88
85
  return false
89
86
  else
90
87
  self.class.layout(@config.layout)
91
88
  end
92
89
  end
93
90
 
94
- def view_for_action(action)
95
- if File.exist?(Rails.root.join("app/views/#{@config.key}/#{action}.html.erb"))
96
- return "#{@config.key}/#{action}"
97
- else
98
- return action
99
- end
100
- end
101
-
102
91
  end