Skip to content

Commit 7db9f6f

Browse files
Integrated the sendgrid and redactor ref #7,#8
1 parent 1058cf0 commit 7db9f6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+467
-15
lines changed

Gemfile

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ gem 'devise_invitable'
6464

6565
# Use bootstrap to generate quick, elegent and responsive layouts
6666
gem 'bootstrap-sass'
67+
gem 'bootstrap-datepicker-rails'
6768

6869
# The following gems for testing purpose in development and testing environment
6970
group :development, :test do
@@ -80,3 +81,10 @@ group :development, :test do
8081
end
8182

8283
gem 'simple_form'
84+
# Use to add redactor editor
85+
gem 'redactor-rails'
86+
gem 'carrierwave'
87+
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
88+
gem 'mini_magick'
89+
gem 'redis-rails'
90+
gem 'redis-namespace'

Gemfile.lock

+44
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,21 @@ GEM
2929
tzinfo (~> 1.1)
3030
arel (5.0.1.20140414130214)
3131
bcrypt (3.1.7)
32+
bootstrap-datepicker-rails (1.3.0.2)
33+
railties (>= 3.0)
3234
bootstrap-sass (3.2.0.0)
3335
sass (~> 3.2)
3436
bson (2.3.0)
3537
builder (3.2.2)
38+
carrierwave (0.10.0)
39+
activemodel (>= 3.2.0)
40+
activesupport (>= 3.2.0)
41+
json (>= 1.7)
42+
mime-types (>= 1.16)
43+
carrierwave-mongoid (0.7.1)
44+
carrierwave (>= 0.8.0, < 0.11.0)
45+
mongoid (>= 3.0, < 5.0)
46+
mongoid-grid_fs (>= 1.3, < 3.0)
3647
celluloid (0.15.2)
3748
timers (~> 1.1.0)
3849
coffee-rails (4.0.1)
@@ -97,13 +108,18 @@ GEM
97108
mime-types (~> 1.16)
98109
treetop (~> 1.4.8)
99110
mime-types (1.25.1)
111+
mini_magick (3.7.0)
112+
subexec (~> 0.2.1)
100113
mini_portile (0.6.0)
101114
minitest (5.3.5)
102115
mongoid (4.0.0)
103116
activemodel (~> 4.0)
104117
moped (~> 2.0.0)
105118
origin (~> 2.1)
106119
tzinfo (>= 0.3.37)
120+
mongoid-grid_fs (2.1.0)
121+
mime-types (>= 1.0, < 3.0)
122+
mongoid (>= 3.0, < 5.0)
107123
moped (2.0.0)
108124
bson (~> 2.2)
109125
connection_pool (~> 2.0)
@@ -145,9 +161,29 @@ GEM
145161
rake (10.3.2)
146162
rdoc (4.1.1)
147163
json (~> 1.4)
164+
redactor-rails (0.4.5)
165+
devise
166+
mime-types
167+
orm_adapter
148168
redis (3.1.0)
169+
redis-actionpack (4.0.0)
170+
actionpack (~> 4)
171+
redis-rack (~> 1.5.0)
172+
redis-store (~> 1.1.0)
173+
redis-activesupport (4.0.0)
174+
activesupport (~> 4)
175+
redis-store (~> 1.1.0)
149176
redis-namespace (1.5.0)
150177
redis (~> 3.0, >= 3.0.4)
178+
redis-rack (1.5.0)
179+
rack (~> 1.5)
180+
redis-store (~> 1.1.0)
181+
redis-rails (4.0.0)
182+
redis-actionpack (~> 4)
183+
redis-activesupport (~> 4)
184+
redis-store (~> 1.1.0)
185+
redis-store (1.1.4)
186+
redis (>= 2.2)
151187
ref (1.0.5)
152188
rspec-core (3.0.2)
153189
rspec-support (~> 3.0.0)
@@ -201,6 +237,7 @@ GEM
201237
actionpack (>= 3.0)
202238
activesupport (>= 3.0)
203239
sprockets (~> 2.8)
240+
subexec (0.2.3)
204241
therubyracer (0.12.1)
205242
libv8 (~> 3.16.14.0)
206243
ref
@@ -225,7 +262,10 @@ PLATFORMS
225262
ruby
226263

227264
DEPENDENCIES
265+
bootstrap-datepicker-rails
228266
bootstrap-sass
267+
carrierwave
268+
carrierwave-mongoid
229269
coffee-rails (~> 4.0.0)
230270
database_cleaner
231271
devise
@@ -238,8 +278,12 @@ DEPENDENCIES
238278
jbuilder (~> 2.0)
239279
jquery-rails
240280
linkedin
281+
mini_magick
241282
mongoid
242283
rails (= 4.1.2)
284+
redactor-rails
285+
redis-namespace
286+
redis-rails
243287
rspec-rails
244288
sass-rails (~> 4.0.3)
245289
sdoc (~> 0.4.0)

app/assets/javascripts/application.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
//= require jquery_ujs
1515
//= require turbolinks
1616
//= require bootstrap
17+
//= require bootstrap-datepicker
18+
// require bootstrap-datepicker-rails
19+
//= require redactor-rails
20+
//= require redactor-rails/plugins
1721
//= require_tree .
1822

1923

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Place all the behaviors and hooks related to the matching controller here.
22
# All this logic will automatically be available in application.js.
33
# You can use CoffeeScript in this file: http://coffeescript.org/
4+
$('.datepicker').datepicker()

app/assets/stylesheets/application.scss

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
*
1313
*= require_tree .
1414
*= require_self
15+
*= require bootstrap-datepicker
16+
*= require redactor-rails
17+
*= redactor-rails/plugins
1518
*/
1619

1720
@import "bootstrap";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the newsletters controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
+45
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,47 @@
11
class NewslettersController < ApplicationController
2+
3+
def index
4+
@newsletters = Newsletter.order_by([:sent_on, :asc])
5+
end
6+
7+
def show
8+
@newsletter = Newsletter.find(params[:id])
9+
end
10+
11+
def new
12+
@newsletter = Newsletter.new
13+
end
14+
15+
def newsletters_params
16+
params.require(:newsletter).permit(:id, :content, :sent_on, :users_count)
17+
end
18+
19+
def create
20+
@newsletter = Newsletter.new(newsletters_params)
21+
if @newsletter.save
22+
redirect_to newsletters_path
23+
else
24+
render action: 'new'
25+
end
26+
end
27+
28+
def edit
29+
@newsletter = Newsletter.find(params[:id])
30+
end
31+
32+
def update
33+
@newsletter = Newsletter.find(params[:id])
34+
if @newsletter.update_attributes(newsletters_params)
35+
redirect_to newsletters_path
36+
else
37+
render action: 'edit'
38+
end
39+
end
40+
41+
def destroy
42+
@newsletter = Newsletter.find(params[:id])
43+
@newsletter.destroy
44+
redirect_to newsletters_path
45+
end
46+
247
end

app/controllers/users_controller.rb

+23-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,36 @@ def new
1313

1414
def create
1515
@user = User.new(users_params)
16+
# @news = Newsletter.last
17+
18+
#respond_to do |format|
1619
if @user.save
17-
redirect_to users_path
20+
redirect_to users_path
21+
# UserMailer.welcome_message(@user,@news.content).deliver
22+
# format.html { redirect_to(@user, notice: 'User was successfully created.')}
23+
# format.json { render json: @user, status: :created, locaton: @user}
1824
else
1925
render action: 'new'
26+
# format.html {render action: 'new'}
27+
# format.json {render json: @user.errors, status: :unprocessable_entity }
2028
end
29+
#end
2130
end
2231

32+
def subscribe
33+
@user = User.find(params[:id])
34+
@user.update(is_subscribed: 'false')
35+
end
36+
37+
def sendmailer
38+
#@user = User.where(is_subscribed: 'true')
39+
#@news = Newsletter.last
40+
HardWorker.perform_async()
41+
redirect_to users_path
42+
end
43+
2344
def users_params
24-
params.require(:user).permit(:id, :email_id, :is_subscribed, :joined_on, :source)
45+
params.require(:user).permit(:id, :email_id, :is_subscribed, :joined_on, :source, :username)
2546
end
2647

2748
def edit

app/mailers/user_mailer.rb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class UserMailer < ActionMailer::Base
2+
include SendGrid
3+
sendgrid_category :use_subject_lines
4+
sendgrid_enable :ganalytics, :opentrack
5+
sendgrid_unique_args :key1 => "value1", :key2 => "value2"
6+
7+
def welcome_message(email, newsletter_content,id,name)
8+
sendgrid_category "Welcome"
9+
sendgrid_unique_args :key2 => "newvalue2", :key3 => "value3"
10+
11+
content = ERB.new(newsletter_content)
12+
object_id = id
13+
#headers['X-SMTPAPI'] = { :to => user.pluck(:email_id) }.to_json
14+
15+
mail( to: email,
16+
category: "newuser",
17+
subject: "Welcome #{name}",
18+
body: content.result(binding),
19+
content_type: "text/html"
20+
)
21+
end
22+
end

app/models/redactor_rails/asset.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class RedactorRails::Asset
2+
include Mongoid::Document
3+
include Mongoid::Timestamps
4+
5+
include RedactorRails::Orm::Mongoid::AssetBase
6+
7+
delegate :url, :current_path, :size, :content_type, :filename, :to => :data
8+
validates_presence_of :data
9+
end

app/models/redactor_rails/document.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class RedactorRails::Document < RedactorRails::Asset
2+
mount_uploader :data, RedactorRailsDocumentUploader, :mount_on => :data_file_name
3+
4+
def url_content
5+
url(:content)
6+
end
7+
8+
def thumb
9+
# Could theoretically provide an icon set here
10+
# to match against the extensions
11+
# but for now it's nil to address the bug
12+
nil
13+
end
14+
end

app/models/redactor_rails/picture.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class RedactorRails::Picture < RedactorRails::Asset
2+
mount_uploader :data, RedactorRailsPictureUploader, :mount_on => :data_file_name
3+
4+
def url_content
5+
url(:content)
6+
end
7+
end

app/models/user.rb

+2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ class User
22
include Mongoid::Document
33

44
field :email_id, type: String
5+
field :username, type: String
56
field :is_subscribed, type: Boolean
67
field :joined_on, type: Date
78
field :source, type: String
89

910
validates :email_id, presence: true
11+
validates :username, presence: true
1012
validates :is_subscribed, presence: true
1113
validates :joined_on, presence: true
1214
validates :source, presence: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# encoding: utf-8
2+
class RedactorRailsDocumentUploader < CarrierWave::Uploader::Base
3+
include RedactorRails::Backend::CarrierWave
4+
5+
# storage :fog
6+
storage :file
7+
8+
def store_dir
9+
"system/redactor_assets/documents/#{model.id}"
10+
end
11+
12+
def extension_white_list
13+
RedactorRails.document_file_types
14+
end
15+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# encoding: utf-8
2+
class RedactorRailsPictureUploader < CarrierWave::Uploader::Base
3+
include RedactorRails::Backend::CarrierWave
4+
5+
# Include RMagick or ImageScience support:
6+
# include CarrierWave::RMagick
7+
include CarrierWave::MiniMagick
8+
# include CarrierWave::ImageScience
9+
10+
# Choose what kind of storage to use for this uploader:
11+
storage :file
12+
13+
# Override the directory where uploaded files will be stored.
14+
# This is a sensible default for uploaders that are meant to be mounted:
15+
def store_dir
16+
"system/redactor_assets/pictures/#{model.id}"
17+
end
18+
19+
# Provide a default URL as a default if there hasn't been a file uploaded:
20+
# def default_url
21+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
22+
# end
23+
24+
# Process files as they are uploaded:
25+
# process :scale => [200, 300]
26+
#
27+
# def scale(width, height)
28+
# # do something
29+
# end
30+
31+
process :read_dimensions
32+
33+
# Create different versions of your uploaded files:
34+
version :thumb do
35+
process :resize_to_fill => [118, 100]
36+
end
37+
38+
version :content do
39+
process :resize_to_limit => [800, 800]
40+
end
41+
42+
# Add a white list of extensions which are allowed to be uploaded.
43+
# For images you might use something like this:
44+
def extension_white_list
45+
RedactorRails.image_file_types
46+
end
47+
48+
# Override the filename of the uploaded files:
49+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
50+
# def filename
51+
# "something.jpg" if original_filename
52+
# end
53+
end

0 commit comments

Comments
 (0)