Skip to content

Commit

Permalink
Merge branch 'subscribe'
Browse files Browse the repository at this point in the history
  • Loading branch information
windy committed Apr 27, 2016
2 parents deaa69f + 8203757 commit d92ac0c
Show file tree
Hide file tree
Showing 29 changed files with 132 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ group :development do
gem 'guard-rails'
gem 'guard-rspec', require: false
gem 'guard-bundler', require: false
gem 'listen', '~> 3.0.5'
gem 'listen', '~> 3.x'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'

Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ GEM
coffee-script-source (1.10.0)
concurrent-ruby (1.0.1)
connection_pool (2.2.0)
database_cleaner (1.5.2)
database_cleaner (1.5.3)
diff-lcs (1.2.5)
docile (1.1.5)
domain_name (0.5.20160310)
Expand Down Expand Up @@ -142,7 +142,7 @@ GEM
js_cookie_rails (1.0.1)
railties (>= 3.1)
json (1.8.3)
listen (3.0.6)
listen (3.1.1)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9.7)
loofah (2.0.3)
Expand Down Expand Up @@ -354,7 +354,7 @@ DEPENDENCIES
jquery-rails
js_cookie_rails
kaminari!
listen (~> 3.0.5)
listen (~> 3.x)
mina
mina-multistage
mina-puma
Expand Down
11 changes: 9 additions & 2 deletions app/assets/stylesheets/aboutme_welcome.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
a {
word-wrap: break-word;
}
@media only screen and (min-width: 40.063em) {
//@media only screen and (min-width: 40.063em) {
@media screen and (max-width: 39.9375em) {
.top-bar-wrapper {
.top-bar, .top-bar-left, .top-bar-right {
width: auto !important;
}
}
}
.top-bar-wrapper {
background: 0 0;
transition: background .5s ease-in-out,padding .5s ease-in-out;
Expand Down Expand Up @@ -77,7 +84,7 @@
}
}
}
}
//}

p {
font-size: 1.275rem;
Expand Down
1 change: 0 additions & 1 deletion app/assets/stylesheets/blogs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
}

.recent-title {
border-bottom: 1px solid #DCDCDC;
margin-bottom: 1rem;
}

Expand Down
23 changes: 11 additions & 12 deletions app/controllers/subscribes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ class SubscribesController < ApplicationController
def index
end

def new
@subscribe = Subscribe.new
end

def create
subscribe = Subscribe.find_or_initialize_by(email: params[:email])
subscribe.enable = true
@subscribe = Subscribe.find_or_initialize_by(email: subscribe_params[:email])
@subscribe.enable = true

if subscribe.save
render :json => { success: true }
if @subscribe.save
redirect_to subscribes_path, notice: '订阅成功'
else
render :json => { success: false, message: subscribe.errors.full_messages.join(", ")}
render :new
end
end

def cancel
subscribe = Subscribe.find_or_initialize_by(email: params[:email])
subscribe.enable = false
subscribe.save

flash[:notice] = "退订成功: #{params[:email]}"
render :json => { success: true }
def subscribe_params
params.require(:subscribe).permit(:email)
end

end
17 changes: 17 additions & 0 deletions app/controllers/unsubscribes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class UnsubscribesController < ApplicationController
def index
end

def new
@subscribe = Subscribe.new
end

def create
subscribe = Subscribe.find_or_initialize_by(email: params[:email])
subscribe.enable = false
subscribe.save

flash[:notice] = "退订成功: #{params[:email]}"
redirect_to unsubscribes_path
end
end
2 changes: 1 addition & 1 deletion app/mailers/comment_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class CommentMailer < ActionMailer::Base

default from: "no-reply@#{domain}"

def new(comment_id, to)
def born(comment_id, to)
@comment = Comment.find(comment_id)
mail to: to, subject: '博主, 你的博客有新的评论'
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/post_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class PostMailer < ActionMailer::Base

default from: "no-reply@#{domain}"

def new(post_id, to)
def born(post_id, to)
@post = Post.find(post_id)
mail to: to, subject: '客官, 新博客来了'
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Comment < ApplicationRecord
validates :content, presence: true

def reply_emails
Comment.where(post_id: self.post_id).collect(&:email).uniq - [ self.email ] - Subscribe.unsubscribe_list
Comment.where(post_id: self.post_id).collect(&:email).uniq - [ self.email ] - Subscribe.unsubscribe_list - [ ENV['ADMIN_USER'] ]
end

after_create do
after_commit on: :create do
if ENV['MAIL_SERVER'].present? && ENV['ADMIN_USER'].present? && ENV['ADMIN_USER'] =~ /@/
Rails.logger.info 'comment created, comment worker start'
NewCommentWorker.perform_async(self.id.to_s, ENV['ADMIN_USER'])
Expand Down
2 changes: 1 addition & 1 deletion app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Post < ActiveRecord::Base
validates :title, :presence=>true, :uniqueness=> true
validates :content, :presence=>true, :length => { :minimum=> 30 }

after_create do
after_commit on: :create do
if ENV['MAIL_SERVER'].present?
NewPostWorker.perform_async(self.id.to_s)
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/blogs/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
.row
.small-12.medium-6.large-12.columns
ul.subscribe-ul
- if ENV['ADMIN_USER'].present? && ENV['ADMIN_USER'].include?('@')
li
= link_to t('subscribes.email'), new_subscribe_path
li
a data-toggle="qrcode-home" #{t('subscribes.wechat') }
#qrcode-home.weixin-subscribe.hide data-toggler='hide' data-url=root_url
Expand Down
File renamed without changes.
File renamed without changes.
32 changes: 15 additions & 17 deletions app/views/home/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
- content_for(:main) do
.about-page
.top-bar-wrapper.contain-to-grid.fixed
.row
.small-12.columns
nav#about-top-bar.top-bar
.top-bar-left
ul.menu
li
a.name href='/' 回到博客
.top-bar-right
ul.menu
li
a href='#about' 关于
li
a href='#skill' 技能
li
a href='#work' 作品
li
a href='#contact' 联系
nav#about-top-bar.top-bar
.top-bar-left
ul.menu
li
a.name href='/' 回到博客
.top-bar-right
ul.menu
li
a href='#about' 关于
li
a href='#skill' 技能
li
a href='#work' 作品
li
a href='#contact' 联系
#intro
header.intro
.intro-heading
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions app/views/subscribes/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.row
.large-9.large-centered.columns
h2 退订服务
hr
form action='' ng-controller='SubscribesController'
.row
.small-12.large-6.columns
= text_field_tag :email, nil, placeholder: '[email protected]', 'ng-model' => 'email'
button ng-click="cancel()" 退订
h2 订阅成功, 我们将提供:

ul
li 第一时间新博客邮件通知
li 有相关评论 @ 你的时候邮件通知

p 你可以随时取消订阅
7 changes: 7 additions & 0 deletions app/views/subscribes/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.row
.small-12.medium-12.large-9.columns
h2 订阅

= simple_form_for @subscribe do |f|
= f.input :email
= f.button :submit
5 changes: 5 additions & 0 deletions app/views/unsubscribes/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.row
.large-9.large-centered.columns
h4 退订成功

p 我们将不再向你发送任何邮件
9 changes: 9 additions & 0 deletions app/views/unsubscribes/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.row
.large-9.large-centered.columns
h2 退订服务
hr
= simple_form_for @subscribe, url: unsubscribes_path do |f|
.row
.small-12.large-6.columns
= f.input :email, placeholder: '[email protected]'
= f.submit
2 changes: 1 addition & 1 deletion app/workers/new_comment_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class NewCommentWorker

def perform(comment_id, to)
logger.info "new comment mail: #{comment_id}"
CommentMailer.new(comment_id.to_s, to).deliver
CommentMailer.born(comment_id.to_s, to).deliver
end
end

2 changes: 1 addition & 1 deletion app/workers/new_post_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NewPostWorker
def perform(post_id)
Subscribe.subscribe_list.each do |email|
Rails.logger.info "new post #{post_id}, send to #{email}"
PostMailer.new(post_id.to_s, email).deliver
PostMailer.born(post_id.to_s, email).deliver
end
end
end
Expand Down
1 change: 0 additions & 1 deletion app/workers/new_reply_post_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def perform(comment_id)
logger.info "new reply mail"
comment = Comment.find(comment_id.to_s)
comment.reply_emails.each do |email|
next if email == ENV['ADMIN_USER']
logger.info "new reply mail to #{email}"
CommentMailer.reply(comment_id.to_s, email).deliver
end
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# number of complex assets.
config.assets.debug = true

config.middleware.insert_before 0, "Rack::Cors" do
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
b.use :placeholder
b.use :label_input
b.use :hint, wrap_with: { tag: :span, class: :hint }
b.use :error, wrap_with: { tag: :span, class: :error }
b.use :error, wrap_with: { tag: :span, class: 'form-error is-visible' }

end

Expand Down
31 changes: 31 additions & 0 deletions config/locales/simple_form.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
en:
simple_form:
"yes": ''
"no": ''
required:
text: '必须的'
mark: '*'
# You can uncomment the line below if you need to overwrite the whole required html.
# When using html, text and mark won't be used.
# html: '<abbr title="required">*</abbr>'
error_notification:
default_message: "请检查以下问题:"
# Examples
# labels:
# defaults:
# password: 'Password'
# user:
# new:
# email: 'E-mail to sign in.'
# edit:
# email: 'E-mail.'
# hints:
# defaults:
# username: 'User name to sign in.'
# password: 'No special characters, please.'
# include_blanks:
# defaults:
# age: 'Rather not say'
# prompts:
# defaults:
# age: 'Select your age'
9 changes: 3 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@


resources :archives
resources :subscribes do
collection do
post :cancel
end
end
get '/unsubscribe' => 'subscribes#index'
resources :subscribes, only: [:index, :new, :create]

resources :unsubscribes, only: [:index, :new, :create]
# photos
resources :photos, only: [:create]
get '/qrcodes' => 'qrcodes#show'
Expand Down
Empty file modified lib/markdown.rb
100755 → 100644
Empty file.
6 changes: 2 additions & 4 deletions spec/controllers/subscribes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

describe "POST 'create'" do
it "post ok" do
post 'create', email: '[email protected]'
expect(JSON.parse(response.body)['success']).to be_truthy
post 'create', { subscribe: { email: '[email protected]' } }
expect(Subscribe.all.size).to eq(1)
end

it "post with disabled email" do
subscribe = Subscribe.create(email: '[email protected]', enable: false)
post 'create', email: '[email protected]'
expect(JSON.parse(response.body)['success']).to be_truthy
post 'create', { subscribe: { email: '[email protected]' } }
expect(subscribe.reload.enable).to be_truthy
end
end
Expand Down

0 comments on commit d92ac0c

Please sign in to comment.