diff --git a/Gemfile b/Gemfile index 1d53138..6808609 100644 --- a/Gemfile +++ b/Gemfile @@ -70,7 +70,7 @@ gem 'kaminari' gem "image_processing", "~> 1.2" # run cron jobs -gem 'whenever', require: false +gem 'rufus-scheduler' # mailer service gem 'sendgrid-ruby' diff --git a/Gemfile.lock b/Gemfile.lock index f5d5fad..2b3ddec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,7 +89,6 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - chronic (0.10.2) coercible (1.0.0) descendants_tracker (~> 0.0.1) concurrent-ruby (1.2.2) @@ -118,6 +117,8 @@ GEM rails erubi (1.12.0) erubis (2.7.0) + et-orbi (1.2.7) + tzinfo execjs (2.7.0) factory_bot (6.2.1) activesupport (>= 5.0.0) @@ -134,6 +135,9 @@ GEM path_expander (~> 1.0) ruby_parser (~> 3.1, > 3.1.0) sexp_processor (~> 4.8) + fugit (1.9.0) + et-orbi (~> 1, >= 1.2.7) + raabro (~> 1.4) globalid (1.1.0) activesupport (>= 5.0) haml (6.1.1) @@ -241,6 +245,7 @@ GEM public_suffix (5.0.3) puma (5.6.6) nio4r (~> 2.0) + raabro (1.4.0) racc (1.7.1) rack (2.2.8) rack-test (2.1.0) @@ -351,6 +356,8 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) + rufus-scheduler (3.9.1) + fugit (~> 1.1, >= 1.1.6) sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) @@ -403,8 +410,6 @@ GEM websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - whenever (1.0.0) - chronic (>= 0.6.3) xpath (3.2.0) nokogiri (~> 1.8) zeitwerk (2.6.11) @@ -446,6 +451,7 @@ DEPENDENCIES rubocop-performance rubocop-rails rubycritic + rufus-scheduler sassc-rails sendgrid-ruby shoulda-matchers (~> 5.0) @@ -453,7 +459,6 @@ DEPENDENCIES stimulus-rails tzinfo-data web-console - whenever RUBY VERSION ruby 3.0.6p216 diff --git a/app/assets/stylesheets/general/_colors.scss b/app/assets/stylesheets/general/_colors.scss index 3ae089b..dc800f5 100644 --- a/app/assets/stylesheets/general/_colors.scss +++ b/app/assets/stylesheets/general/_colors.scss @@ -11,4 +11,5 @@ $light-gray: #f2f2f2; $link-color: #0E91A1; $gray: gray; $card-color: #CCCCCC; -$tomato: #ff6347; \ No newline at end of file +$tomato: #ff6347; +$text-gray: #8f8f8f; diff --git a/app/assets/stylesheets/posts/_post.scss b/app/assets/stylesheets/posts/_post.scss index 95619fa..dbc96b2 100644 --- a/app/assets/stylesheets/posts/_post.scss +++ b/app/assets/stylesheets/posts/_post.scss @@ -44,9 +44,10 @@ } .user-email { + color: $black !important; display: flex; + font-weight: 500; width: fit-content; - color: $tomato !important; } .card-container { @@ -117,6 +118,10 @@ display: flex; flex-direction: row; justify-content: space-between; + + &__author > span { + color: $text-gray; + } } #copyPathButton { diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index d8aa9d4..9535112 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -3,8 +3,8 @@ class UserMailer < ApplicationMailer def newsletter_mailer @newsletter = Newsletter.all - @post = Post.last(5) + @post = Post.order('RANDOM()').limit(5) emails = @newsletter.collect(&:email).join(", ") - mail(to: emails, subject: "Hi, this is a test mail.") + mail(to: emails, subject: "Weekly Today I Learn Posts.") end end diff --git a/app/views/user_mailer/newsletter_mailer.html.haml b/app/views/user_mailer/newsletter_mailer.html.haml index df352ec..22a34d4 100644 --- a/app/views/user_mailer/newsletter_mailer.html.haml +++ b/app/views/user_mailer/newsletter_mailer.html.haml @@ -1,9 +1,60 @@ -%p Dear Followers: -%p Those are the lastest entries to our blog. We invite you to read and share everything we did on this week. -%br/ -%table - - @post.each do |post| - %tr{style: "display:flex; float:left; clear:both;"} - %td{style: "display:flex; float:left; clear:both; height: 80px; width: 100px;"} - %p= post.title - %td{style: "display:flex; float:left; clear:both;"} +%html + %head + %title Email Newsletter + %body + %meta{:http_equiv => "Content-type", :name => "viewport", :content => "initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width"} + + %table{:dir => "ltr", :style => "background-color:#ffffff;width:100%;"} + %tr + %td{:align => "center", :style => "text-align: center;padding: 20px 0; font-family:Helvetica,Arial,sans-serif;background: #D1F6FE;"} + %a{:href => "https://www.til-dev.com", :style => "text-decoration: none; font-weight: bold; color: #006699;; color:#888888;font-size:22px;text-decoration:none;"} + %img{:src => "https://www.til-dev.com/assets/logo-header-blank-d54ec403d53aba7529bce8df61b73baf93213da263a9c081f63b3e4735e6fa15.png", :alt => "Today I Learned logo", :style => "width: 12rem;"} + + - @post.each do |post| + %table{:dir => "ltr", :style => "width:100%;background:white;padding:0;border-spacing:0;font-family:Helvetica,Arial,sans-serif;font-size:14px;font-weight:200;line-height:1.3;vertical-align:top;"} + %td{:style => "vertical-align:top;padding:0;font-family:Helvetica,Arial,sans-serif;"} + %table{:dir => "ltr", :align => "center", :style => "border-spacing:0;background:#CCCCCC;margin:10px auto;padding:0;text-align:center;vertical-align:top;width:100%;max-width: 700px;"} + %tbody + %tr + %td{:style => "-moz-hyphens:auto;-webkit-hyphens:auto;border-collapse:collapse!important;color:#0a0a0a;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:normal"} + + %table{:dir => "ltr", :style => "width:100%"} + %tbody + %tr + %td{:style => "margin:0;padding:0 0 0 16px;text-align:left;vertical-align:top;"} + %p{:style => "color:#8f8f8f;line-height:1.3;margin: 20px 0 0 0;"} + - post.labels.each do |label| + %span{:style => "background: #2a2a2a;border-radius: 8px;text-wrap: nowrap;color: #fff;padding: 5px;", :data_drop_close => "true"}= label.name + %td{:style => "margin:0;padding:0 16px 0 0;text-align:right;vertical-align:top;"} + %p{:style => "color:#8f8f8f;line-height:1.3;margin:20px 0 0 0;font-weight:400;"}= post.created_at.strftime("%B %d, %Y") + + %table{:dir => "ltr", :style => "vertical-align:top;width:100%"} + %tbody + %tr + %td{:style => "padding:0 8px 8px 16px; text-align:left; width:100%;max-width: 600px;overflow: auto;"} + %h2{:style => "font-size:24px;font-weight:400;line-height:1.3;margin:0;padding:0;word-wrap:normal"} + %strong= post.title + + %table{:dir => "ltr", :style => "border-bottom:1px solid #f3f3f3;padding:0;text-align:left;vertical-align:top;width:100%"} + %tbody + %tr + %td{:style => "color:#0a0a0a;font-size:14px;padding:0 16px 0 16px;text-align:left;width:100%;font-weight:normal;"} + %p= truncate(post.content.to_plain_text, length: 100) # Adjust the length as per your requirement + + %table{:dir => "ltr", :style => "padding:0;text-align:left;vertical-align:top;width:100%; margin-top:20px;"} + %tbody + %tr + %td{:style => "padding:0 8px 16px 16px;text-align:left;white-space:nowrap;vertical-align:top;width:75px"} + %a{href: "http://www.til-dev.com/posts/#{post.id}", :style => "text-decoration: none; font-weight: bold; color: #006699;; background-color: #2F70AC; color: #FFFFFF;; width:100%;text-decoration:none;padding:8px 16px;white-space:nowrap;"} + Read More + + %td{:style => "line-height:1.3;padding:0 16px 0 8px;text-align:right;white-space:nowrap;vertical-align:top;"} + + + %div{:dir => "ltr", :style => "color:#666; font-size:95%; text-align:center; padding-top:15px;"} + This summary is sent from + %a{:href => "https://www.til-dev.com", :style => "text-decoration: none; font-weight: bold; color: #006699;; color: #0088cc"} + TIL-Dev + every Monday + %a{:href => "https://forum.sublimetext.com/email/unsubscribe/dummytext", :style => "text-decoration: none; font-weight: bold; color: #006699;; color: #0088cc"} + click here to unsubscribe. diff --git a/config/initializers/scheduler.rb b/config/initializers/scheduler.rb new file mode 100644 index 0000000..ce07b43 --- /dev/null +++ b/config/initializers/scheduler.rb @@ -0,0 +1,7 @@ +require 'rufus-scheduler' + +scheduler = Rufus::Scheduler.new + +scheduler.cron('0 8 * * 1') do + UserMailer.newsletter_mailer.deliver! +end diff --git a/config/schedule.rb b/config/schedule.rb deleted file mode 100644 index 6e4521c..0000000 --- a/config/schedule.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -# Use this file to easily define all of your cron jobs. -# -# It's helpful, but not entirely necessary to understand cron before proceeding. -# http://en.wikipedia.org/wiki/Cron - -# Example: -# -# set :output, "/path/to/my/cron_log.log" -# -# every 2.hours do -# command "/usr/bin/some_great_command" -# runner "MyModel.some_method" -# rake "some:great:rake:task" -# end -# -# every 4.days do -# runner "AnotherModel.prune_old_records" -# end - -# Learn more: http://github.com/javan/whenever - -every 1.day, at: '12:35am' do - rake 'weekly_newsletter_email' -end diff --git a/lib/tasks/schedule.rake b/lib/tasks/schedule.rake deleted file mode 100644 index 10a593c..0000000 --- a/lib/tasks/schedule.rake +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -desc 'weekly newsletter email' - -task weekly_newsletter_email: :environment do - UserMailer.newsletter_mailer.deliver! -end