diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/stylesheets/admin/layout.scss | 10 | ||||
-rw-r--r-- | app/controllers/admin/blogs_controller.rb | 10 | ||||
-rw-r--r-- | app/controllers/blogs_controller.rb | 2 | ||||
-rw-r--r-- | app/models/blog.rb | 18 | ||||
-rw-r--r-- | app/views/admin/blogs/_form.html.haml | 6 | ||||
-rw-r--r-- | app/views/admin/blogs/drafts.html.haml | 5 | ||||
-rw-r--r-- | app/views/admin/blogs/index.html.haml | 5 | ||||
-rw-r--r-- | app/views/admin/blogs/show.html.haml | 5 | ||||
-rw-r--r-- | app/views/blogs/show.html.haml | 2 |
9 files changed, 50 insertions, 13 deletions
diff --git a/app/assets/stylesheets/admin/layout.scss b/app/assets/stylesheets/admin/layout.scss index f68cf6a..b825c25 100644 --- a/app/assets/stylesheets/admin/layout.scss +++ b/app/assets/stylesheets/admin/layout.scss | |||
@@ -227,6 +227,16 @@ body { | |||
227 | } | 227 | } |
228 | } | 228 | } |
229 | 229 | ||
230 | #entry-preview-link { | ||
231 | a { | ||
232 | text-decoration: none; | ||
233 | |||
234 | &:hover { | ||
235 | text-decoration: underline; | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | |||
230 | #flash { | 240 | #flash { |
231 | display: inline-block; | 241 | display: inline-block; |
232 | color: black; | 242 | color: black; |
diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index 9706df3..1035c12 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb | |||
@@ -9,6 +9,16 @@ class Admin::BlogsController < Admin::AdminController | |||
9 | @blogs = Blog.where(published: false).order(updated_at: :desc) | 9 | @blogs = Blog.where(published: false).order(updated_at: :desc) |
10 | end | 10 | end |
11 | 11 | ||
12 | def show | ||
13 | @blog = Blog.find(params[:id]) | ||
14 | |||
15 | if @blog.published | ||
16 | redirect_to blog_url(@blog.slug) | ||
17 | else | ||
18 | render layout: "application" | ||
19 | end | ||
20 | end | ||
21 | |||
12 | def new | 22 | def new |
13 | @blog = Blog.new | 23 | @blog = Blog.new |
14 | end | 24 | end |
diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index f31287b..8ee472e 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb | |||
@@ -4,7 +4,7 @@ class BlogsController < ApplicationController | |||
4 | @blog = Blog.find_by_slug(params[:slug]) | 4 | @blog = Blog.find_by_slug(params[:slug]) |
5 | 5 | ||
6 | raise ActiveRecord::RecordNotFound unless @blog | 6 | raise ActiveRecord::RecordNotFound unless @blog |
7 | raise ActiveRecord::RecordNotFound unless @blog.published or user_signed_in? | 7 | raise ActiveRecord::RecordNotFound unless @blog.published |
8 | end | 8 | end |
9 | 9 | ||
10 | end | 10 | end |
diff --git a/app/models/blog.rb b/app/models/blog.rb index 495c6eb..322a808 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb | |||
@@ -1,26 +1,26 @@ | |||
1 | class Blog < ApplicationRecord | 1 | class Blog < ApplicationRecord |
2 | has_many :records, as: :recordable, inverse_of: :recordable | 2 | has_many :records, as: :recordable, inverse_of: :recordable |
3 | 3 | ||
4 | validates :title, :body, presence: true | 4 | validates :title, presence: true |
5 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ | 5 | validates :body, presence: true, if: :published |
6 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published | ||
6 | 7 | ||
7 | accepts_nested_attributes_for :records, allow_destroy: true | 8 | accepts_nested_attributes_for :records, allow_destroy: true |
8 | 9 | ||
10 | before_validation :set_draft_title | ||
9 | before_save :set_published_at | 11 | before_save :set_published_at |
10 | 12 | ||
11 | def path | 13 | def path |
12 | "/says/#{slug}" | 14 | "/says/#{slug}" |
13 | end | 15 | end |
14 | 16 | ||
15 | def posted_at | 17 | private |
16 | if published | 18 | def set_draft_title |
17 | published_at | 19 | if self.title.blank? and not self.published |
18 | else | 20 | self.title = "Untitled draft" |
19 | updated_at | 21 | end |
20 | end | 22 | end |
21 | end | ||
22 | 23 | ||
23 | private | ||
24 | def set_published_at | 24 | def set_published_at |
25 | if self.published | 25 | if self.published |
26 | if self.published_at.blank? | 26 | if self.published_at.blank? |
diff --git a/app/views/admin/blogs/_form.html.haml b/app/views/admin/blogs/_form.html.haml index 2066aed..12f7a82 100644 --- a/app/views/admin/blogs/_form.html.haml +++ b/app/views/admin/blogs/_form.html.haml | |||
@@ -15,6 +15,12 @@ | |||
15 | %ul | 15 | %ul |
16 | - f.object.errors.full_messages.each do |error| | 16 | - f.object.errors.full_messages.each do |error| |
17 | %li= error | 17 | %li= error |
18 | - unless f.object.new_record? | ||
19 | #entry-preview-link.details-module | ||
20 | - if f.object.published | ||
21 | = link_to "View post", blog_url(f.object.slug_was), target: "entry-preview" | ||
22 | - else | ||
23 | = link_to "Preview post", admin_blog_url(f.object), target: "entry-preview" | ||
18 | .details-module | 24 | .details-module |
19 | .published-field | 25 | .published-field |
20 | = f.check_box :published | 26 | = f.check_box :published |
diff --git a/app/views/admin/blogs/drafts.html.haml b/app/views/admin/blogs/drafts.html.haml index 91d3214..8f2d369 100644 --- a/app/views/admin/blogs/drafts.html.haml +++ b/app/views/admin/blogs/drafts.html.haml | |||
@@ -7,4 +7,7 @@ | |||
7 | %tr{ class: cycle("even", "odd") } | 7 | %tr{ class: cycle("even", "odd") } |
8 | %td= blog.title | 8 | %td= blog.title |
9 | %td= blog.updated_at.strftime("%B %d, %Y, %l:%M%P") | 9 | %td= blog.updated_at.strftime("%B %d, %Y, %l:%M%P") |
10 | %td= link_to "Edit", edit_admin_blog_url(blog) | 10 | %td |
11 | %ul.admin-actions | ||
12 | %li= link_to "Preview", admin_blog_url(blog) | ||
13 | %li= link_to "Edit", edit_admin_blog_url(blog) | ||
diff --git a/app/views/admin/blogs/index.html.haml b/app/views/admin/blogs/index.html.haml index c5db4f1..427d922 100644 --- a/app/views/admin/blogs/index.html.haml +++ b/app/views/admin/blogs/index.html.haml | |||
@@ -7,4 +7,7 @@ | |||
7 | %tr{ class: cycle("even", "odd") } | 7 | %tr{ class: cycle("even", "odd") } |
8 | %td= blog.title | 8 | %td= blog.title |
9 | %td= blog.published_at.strftime("%B %d, %Y, %l:%M%P") | 9 | %td= blog.published_at.strftime("%B %d, %Y, %l:%M%P") |
10 | %td= link_to "Edit", edit_admin_blog_url(blog) | 10 | %td |
11 | %ul.admin-actions | ||
12 | %li= link_to "View", blog_url(blog.slug) | ||
13 | %li= link_to "Edit", edit_admin_blog_url(blog) | ||
diff --git a/app/views/admin/blogs/show.html.haml b/app/views/admin/blogs/show.html.haml new file mode 100644 index 0000000..7875cab --- /dev/null +++ b/app/views/admin/blogs/show.html.haml | |||
@@ -0,0 +1,5 @@ | |||
1 | = render partial: "blogs/blog", object: @blog | ||
2 | %footer#blog-footer | ||
3 | This draft was last updated on | ||
4 | = succeed "." do | ||
5 | %time= @blog.updated_at.strftime("%B #{@blog.updated_at.day.ordinalize}, %Y at %-I:%M:%S%P") | ||
diff --git a/app/views/blogs/show.html.haml b/app/views/blogs/show.html.haml index 48c07dc..8ab4523 100644 --- a/app/views/blogs/show.html.haml +++ b/app/views/blogs/show.html.haml | |||
@@ -3,4 +3,4 @@ | |||
3 | %footer#blog-footer | 3 | %footer#blog-footer |
4 | This entry was posted on | 4 | This entry was posted on |
5 | = succeed "." do | 5 | = succeed "." do |
6 | %time= @blog.posted_at.strftime("%B #{@blog.posted_at.day.ordinalize}, %Y at %-I:%M:%S%P") | 6 | %time= @blog.published_at.strftime("%B #{@blog.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") |