Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix newsletter #61

Merged
merged 3 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 9 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -446,14 +451,14 @@ DEPENDENCIES
rubocop-performance
rubocop-rails
rubycritic
rufus-scheduler
sassc-rails
sendgrid-ruby
shoulda-matchers (~> 5.0)
sprockets-rails
stimulus-rails
tzinfo-data
web-console
whenever

RUBY VERSION
ruby 3.0.6p216
Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/general/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ $light-gray: #f2f2f2;
$link-color: #0E91A1;
$gray: gray;
$card-color: #CCCCCC;
$tomato: #ff6347;
$tomato: #ff6347;
$text-gray: #8f8f8f;
7 changes: 6 additions & 1 deletion app/assets/stylesheets/posts/_post.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
}

.user-email {
color: $black !important;
display: flex;
font-weight: 500;
width: fit-content;
color: $tomato !important;
}

.card-container {
Expand Down Expand Up @@ -117,6 +118,10 @@
display: flex;
flex-direction: row;
justify-content: space-between;

&__author > span {
color: $text-gray;
}
}

#copyPathButton {
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 60 additions & 9 deletions app/views/user_mailer/newsletter_mailer.html.haml
Original file line number Diff line number Diff line change
@@ -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"}
<!-- Beginning of Popular Topic -->
%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;"}
<!-- End of Popular Topic -->

%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.
7 changes: 7 additions & 0 deletions config/initializers/scheduler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new

scheduler.cron('0 8 * * 1') do
UserMailer.newsletter_mailer.deliver!
end
26 changes: 0 additions & 26 deletions config/schedule.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/tasks/schedule.rake

This file was deleted.