diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-17 15:05:36 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-17 15:05:36 -0400 |
commit | 95e7c215df89608a5b10bebb87968c9a713bbf3d (patch) | |
tree | b21785e6483b0286a812dda44082bc735264fb27 | |
parent | 8d039903f630db0b89f2df44a94f4e5c938bd7bf (diff) | |
download | thoughts-95e7c215df89608a5b10bebb87968c9a713bbf3d.tar.gz thoughts-95e7c215df89608a5b10bebb87968c9a713bbf3d.tar.bz2 thoughts-95e7c215df89608a5b10bebb87968c9a713bbf3d.zip |
Added uploading images to blog posts
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 13 | ||||
-rw-r--r-- | app/assets/javascripts/admin/records.coffee | 2 | ||||
-rw-r--r-- | app/assets/stylesheets/admin/layout.scss | 25 | ||||
-rw-r--r-- | app/controllers/admin/blogs_controller.rb | 2 | ||||
-rw-r--r-- | app/models/blog.rb | 7 | ||||
-rw-r--r-- | app/views/admin/blogs/_form.html.haml | 8 | ||||
-rw-r--r-- | config/deploy.rb | 2 |
9 files changed, 52 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore index ae472fd..7e20915 100644 --- a/.gitignore +++ b/.gitignore | |||
@@ -29,5 +29,6 @@ tags | |||
29 | *.swo | 29 | *.swo |
30 | /public/uploads | 30 | /public/uploads |
31 | config/database.yml | 31 | config/database.yml |
32 | /storage | ||
32 | 33 | ||
33 | misc | 34 | misc |
diff --git a/Gemfile b/Gemfile index 47c1ffa..3044a2f 100644 --- a/Gemfile +++ b/Gemfile | |||
@@ -80,3 +80,5 @@ gem 'will_paginate', '~> 4.0' | |||
80 | gem 'redcarpet' | 80 | gem 'redcarpet' |
81 | gem 'rouge' | 81 | gem 'rouge' |
82 | gem 'akismet' | 82 | gem 'akismet' |
83 | gem 'active_storage_validations' | ||
84 | gem "image_processing", ">= 1.2" | ||
diff --git a/Gemfile.lock b/Gemfile.lock index f60e3d6..4ba3db9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock | |||
@@ -73,6 +73,11 @@ GEM | |||
73 | erubi (~> 1.4) | 73 | erubi (~> 1.4) |
74 | rails-dom-testing (~> 2.0) | 74 | rails-dom-testing (~> 2.0) |
75 | rails-html-sanitizer (~> 1.1, >= 1.2.0) | 75 | rails-html-sanitizer (~> 1.1, >= 1.2.0) |
76 | active_storage_validations (1.0.4) | ||
77 | activejob (>= 5.2.0) | ||
78 | activemodel (>= 5.2.0) | ||
79 | activestorage (>= 5.2.0) | ||
80 | activesupport (>= 5.2.0) | ||
76 | activejob (7.0.8) | 81 | activejob (7.0.8) |
77 | activesupport (= 7.0.8) | 82 | activesupport (= 7.0.8) |
78 | globalid (>= 0.3.6) | 83 | globalid (>= 0.3.6) |
@@ -166,6 +171,9 @@ GEM | |||
166 | highline (2.1.0) | 171 | highline (2.1.0) |
167 | i18n (1.14.1) | 172 | i18n (1.14.1) |
168 | concurrent-ruby (~> 1.0) | 173 | concurrent-ruby (~> 1.0) |
174 | image_processing (1.12.2) | ||
175 | mini_magick (>= 4.9.5, < 5) | ||
176 | ruby-vips (>= 2.0.17, < 3) | ||
169 | jbuilder (2.11.5) | 177 | jbuilder (2.11.5) |
170 | actionview (>= 5.0.0) | 178 | actionview (>= 5.0.0) |
171 | activesupport (>= 5.0.0) | 179 | activesupport (>= 5.0.0) |
@@ -197,6 +205,7 @@ GEM | |||
197 | mimemagic (0.3.10) | 205 | mimemagic (0.3.10) |
198 | nokogiri (~> 1) | 206 | nokogiri (~> 1) |
199 | rake | 207 | rake |
208 | mini_magick (4.12.0) | ||
200 | mini_mime (1.1.5) | 209 | mini_mime (1.1.5) |
201 | mini_portile2 (2.8.4) | 210 | mini_portile2 (2.8.4) |
202 | mini_racer (0.8.0) | 211 | mini_racer (0.8.0) |
@@ -272,6 +281,8 @@ GEM | |||
272 | railties (>= 5.2) | 281 | railties (>= 5.2) |
273 | rexml (3.2.6) | 282 | rexml (3.2.6) |
274 | rouge (4.1.3) | 283 | rouge (4.1.3) |
284 | ruby-vips (2.1.4) | ||
285 | ffi (~> 1.12) | ||
275 | rubyzip (2.3.2) | 286 | rubyzip (2.3.2) |
276 | sassc (2.4.0) | 287 | sassc (2.4.0) |
277 | ffi (~> 1.9) | 288 | ffi (~> 1.9) |
@@ -339,6 +350,7 @@ PLATFORMS | |||
339 | ruby | 350 | ruby |
340 | 351 | ||
341 | DEPENDENCIES | 352 | DEPENDENCIES |
353 | active_storage_validations | ||
342 | acts-as-taggable-on | 354 | acts-as-taggable-on |
343 | akismet | 355 | akismet |
344 | audited (~> 5.0) | 356 | audited (~> 5.0) |
@@ -354,6 +366,7 @@ DEPENDENCIES | |||
354 | enumerize | 366 | enumerize |
355 | haml | 367 | haml |
356 | highline | 368 | highline |
369 | image_processing (>= 1.2) | ||
357 | jbuilder (~> 2.5) | 370 | jbuilder (~> 2.5) |
358 | jquery-rails | 371 | jquery-rails |
359 | jquery-ui-rails | 372 | jquery-ui-rails |
diff --git a/app/assets/javascripts/admin/records.coffee b/app/assets/javascripts/admin/records.coffee index 27cdb78..3862b09 100644 --- a/app/assets/javascripts/admin/records.coffee +++ b/app/assets/javascripts/admin/records.coffee | |||
@@ -28,3 +28,5 @@ $(document).on "turbolinks:load", -> | |||
28 | $(".tags-input input[type=text]").autocomplete({ | 28 | $(".tags-input input[type=text]").autocomplete({ |
29 | source: Routes.suggest_tags_path() | 29 | source: Routes.suggest_tags_path() |
30 | }) | 30 | }) |
31 | $(".image-uploads pre").click -> | ||
32 | navigator.clipboard.writeText($(this).text()); | ||
diff --git a/app/assets/stylesheets/admin/layout.scss b/app/assets/stylesheets/admin/layout.scss index bf15b0d..9585414 100644 --- a/app/assets/stylesheets/admin/layout.scss +++ b/app/assets/stylesheets/admin/layout.scss | |||
@@ -82,19 +82,16 @@ body { | |||
82 | } | 82 | } |
83 | 83 | ||
84 | #entry-form { | 84 | #entry-form { |
85 | display: flex; | 85 | display: grid; |
86 | grid-template-columns: 73% 27%; | ||
86 | height: 100%; | 87 | height: 100%; |
87 | 88 | ||
88 | fieldset { | 89 | fieldset { |
89 | border: 0; | 90 | border: 0; |
90 | } | 91 | } |
91 | 92 | ||
92 | #content { | ||
93 | width: 77%; | ||
94 | } | ||
95 | |||
96 | #details { | 93 | #details { |
97 | width: 23%; | 94 | min-width: 0; |
98 | display: flex; | 95 | display: flex; |
99 | flex-direction: column; | 96 | flex-direction: column; |
100 | padding-left: 0; | 97 | padding-left: 0; |
@@ -201,6 +198,22 @@ body { | |||
201 | border-radius: 5px; | 198 | border-radius: 5px; |
202 | padding: .5em; | 199 | padding: .5em; |
203 | margin-bottom: 1em; | 200 | margin-bottom: 1em; |
201 | |||
202 | h4 { | ||
203 | margin-top: 0; | ||
204 | margin-bottom: 0.5em; | ||
205 | } | ||
206 | |||
207 | img { | ||
208 | max-width: 100%; | ||
209 | } | ||
210 | } | ||
211 | |||
212 | .image-uploads { | ||
213 | pre { | ||
214 | overflow: auto; | ||
215 | max-width: 100%; | ||
216 | } | ||
204 | } | 217 | } |
205 | 218 | ||
206 | .should-create-record-field { | 219 | .should-create-record-field { |
diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index f0ce519..35f3514 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb | |||
@@ -57,7 +57,7 @@ class Admin::BlogsController < Admin::AdminController | |||
57 | private | 57 | private |
58 | 58 | ||
59 | def blog_params | 59 | def blog_params |
60 | params.require(:blog).permit(:title, :body, :slug, :published, :published_at, :tag_list, records_attributes: [:description, :_destroy]) | 60 | params.require(:blog).permit(:title, :body, :slug, :published, :published_at, :tag_list, images: [], records_attributes: [:description, :_destroy]) |
61 | end | 61 | end |
62 | 62 | ||
63 | def set_section | 63 | def set_section |
diff --git a/app/models/blog.rb b/app/models/blog.rb index 362f69f..6db75ec 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb | |||
@@ -6,12 +6,15 @@ class Blog < ApplicationRecord | |||
6 | has_many :comments | 6 | has_many :comments |
7 | belongs_to :user | 7 | belongs_to :user |
8 | 8 | ||
9 | has_many_attached :images do |attachable| | ||
10 | attachable.variant :thumb, resize_to_limit: [300, 300] | ||
11 | end | ||
12 | |||
9 | validates :title, presence: true | 13 | validates :title, presence: true |
10 | validates :body, presence: true, if: :published | 14 | validates :body, presence: true, if: :published |
11 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published | 15 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published |
12 | validates :user, presence: true | 16 | validates :user, presence: true |
13 | 17 | validates :images, content_type: ['image/png', 'image/jpeg'] | |
14 | has_many_attached :images | ||
15 | 18 | ||
16 | before_validation :set_draft_title | 19 | before_validation :set_draft_title |
17 | before_save :set_published_at | 20 | before_save :set_published_at |
diff --git a/app/views/admin/blogs/_form.html.haml b/app/views/admin/blogs/_form.html.haml index 625c85e..c3720ba 100644 --- a/app/views/admin/blogs/_form.html.haml +++ b/app/views/admin/blogs/_form.html.haml | |||
@@ -39,4 +39,12 @@ | |||
39 | = builder.label :_destroy, "Create record?" | 39 | = builder.label :_destroy, "Create record?" |
40 | .record-description-field | 40 | .record-description-field |
41 | = builder.text_area :description, placeholder: "record text" | 41 | = builder.text_area :description, placeholder: "record text" |
42 | .details-module.image-uploads | ||
43 | %h4 Images | ||
44 | - f.object.images.each do |image| | ||
45 | = image_tag image.variant(:thumb) | ||
46 | = f.hidden_field :images, multiple: true, value: image.signed_id | ||
47 | %pre= url_for image | ||
48 | %hr | ||
49 | = f.file_field :images, multiple: true | ||
42 | .details-module= f.submit | 50 | .details-module= f.submit |
diff --git a/config/deploy.rb b/config/deploy.rb index 05b137d..6c15029 100644 --- a/config/deploy.rb +++ b/config/deploy.rb | |||
@@ -24,7 +24,7 @@ set :deploy_to, "/srv/www/thoughts" | |||
24 | append :linked_files, "config/database.yml", "config/secrets.yml", "config/lingo.yml", "config/akismet.yml", "config/mail.yml" | 24 | append :linked_files, "config/database.yml", "config/secrets.yml", "config/lingo.yml", "config/akismet.yml", "config/mail.yml" |
25 | 25 | ||
26 | # Default value for linked_dirs is [] | 26 | # Default value for linked_dirs is [] |
27 | append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/uploads" | 27 | append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/uploads", "storage" |
28 | 28 | ||
29 | # Default value for default_env is {} | 29 | # Default value for default_env is {} |
30 | # set :default_env, { path: "/opt/ruby/bin:$PATH" } | 30 | # set :default_env, { path: "/opt/ruby/bin:$PATH" } |