Skip to content

Commit

Permalink
Integrated the sendgrid and redactor ref #7,#8
Browse files Browse the repository at this point in the history
  • Loading branch information
kanhaiyasharma007 committed Jul 15, 2014
1 parent 0f9eeca commit 4e0a440
Show file tree
Hide file tree
Showing 42 changed files with 467 additions and 15 deletions.
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ gem 'devise_invitable'

# Use bootstrap to generate quick, elegent and responsive layouts
gem 'bootstrap-sass'
gem 'bootstrap-datepicker-rails'

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

gem 'simple_form'
# Use to add redactor editor
gem 'redactor-rails'
gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem 'mini_magick'
gem 'redis-rails'
gem 'redis-namespace'
44 changes: 44 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@ GEM
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
bcrypt (3.1.7)
bootstrap-datepicker-rails (1.3.0.2)
railties (>= 3.0)
bootstrap-sass (3.2.0.0)
sass (~> 3.2)
bson (2.3.0)
builder (3.2.2)
carrierwave (0.10.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
carrierwave-mongoid (0.7.1)
carrierwave (>= 0.8.0, < 0.11.0)
mongoid (>= 3.0, < 5.0)
mongoid-grid_fs (>= 1.3, < 3.0)
celluloid (0.15.2)
timers (~> 1.1.0)
coffee-rails (4.0.1)
Expand Down Expand Up @@ -97,13 +108,18 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
mini_magick (3.7.0)
subexec (~> 0.2.1)
mini_portile (0.6.0)
minitest (5.3.5)
mongoid (4.0.0)
activemodel (~> 4.0)
moped (~> 2.0.0)
origin (~> 2.1)
tzinfo (>= 0.3.37)
mongoid-grid_fs (2.1.0)
mime-types (>= 1.0, < 3.0)
mongoid (>= 3.0, < 5.0)
moped (2.0.0)
bson (~> 2.2)
connection_pool (~> 2.0)
Expand Down Expand Up @@ -145,9 +161,29 @@ GEM
rake (10.3.2)
rdoc (4.1.1)
json (~> 1.4)
redactor-rails (0.4.5)
devise
mime-types
orm_adapter
redis (3.1.0)
redis-actionpack (4.0.0)
actionpack (~> 4)
redis-rack (~> 1.5.0)
redis-store (~> 1.1.0)
redis-activesupport (4.0.0)
activesupport (~> 4)
redis-store (~> 1.1.0)
redis-namespace (1.5.0)
redis (~> 3.0, >= 3.0.4)
redis-rack (1.5.0)
rack (~> 1.5)
redis-store (~> 1.1.0)
redis-rails (4.0.0)
redis-actionpack (~> 4)
redis-activesupport (~> 4)
redis-store (~> 1.1.0)
redis-store (1.1.4)
redis (>= 2.2)
ref (1.0.5)
rspec-core (3.0.2)
rspec-support (~> 3.0.0)
Expand Down Expand Up @@ -201,6 +237,7 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
subexec (0.2.3)
therubyracer (0.12.1)
libv8 (~> 3.16.14.0)
ref
Expand All @@ -225,7 +262,10 @@ PLATFORMS
ruby

DEPENDENCIES
bootstrap-datepicker-rails
bootstrap-sass
carrierwave
carrierwave-mongoid
coffee-rails (~> 4.0.0)
database_cleaner
devise
Expand All @@ -238,8 +278,12 @@ DEPENDENCIES
jbuilder (~> 2.0)
jquery-rails
linkedin
mini_magick
mongoid
rails (= 4.1.2)
redactor-rails
redis-namespace
redis-rails
rspec-rails
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require bootstrap-datepicker
// require bootstrap-datepicker-rails
//= require redactor-rails
//= require redactor-rails/plugins
//= require_tree .


1 change: 1 addition & 0 deletions app/assets/javascripts/users.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$('.datepicker').datepicker()
3 changes: 3 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*
*= require_tree .
*= require_self
*= require bootstrap-datepicker
*= require redactor-rails
*= redactor-rails/plugins
*/

@import "bootstrap";
3 changes: 3 additions & 0 deletions app/assets/stylesheets/newsletters.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the newsletters controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
45 changes: 45 additions & 0 deletions app/controllers/newsletters_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
class NewslettersController < ApplicationController

def index
@newsletters = Newsletter.order_by([:sent_on, :asc])
end

def show
@newsletter = Newsletter.find(params[:id])
end

def new
@newsletter = Newsletter.new
end

def newsletters_params
params.require(:newsletter).permit(:id, :content, :sent_on, :users_count)
end

def create
@newsletter = Newsletter.new(newsletters_params)
if @newsletter.save
redirect_to newsletters_path
else
render action: 'new'
end
end

def edit
@newsletter = Newsletter.find(params[:id])
end

def update
@newsletter = Newsletter.find(params[:id])
if @newsletter.update_attributes(newsletters_params)
redirect_to newsletters_path
else
render action: 'edit'
end
end

def destroy
@newsletter = Newsletter.find(params[:id])
@newsletter.destroy
redirect_to newsletters_path
end

end
25 changes: 23 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,36 @@ def new

def create
@user = User.new(users_params)
# @news = Newsletter.last

#respond_to do |format|
if @user.save
redirect_to users_path
redirect_to users_path
# UserMailer.welcome_message(@user,@news.content).deliver
# format.html { redirect_to(@user, notice: 'User was successfully created.')}
# format.json { render json: @user, status: :created, locaton: @user}
else
render action: 'new'
# format.html {render action: 'new'}
# format.json {render json: @user.errors, status: :unprocessable_entity }
end
#end
end

def subscribe
@user = User.find(params[:id])
@user.update(is_subscribed: 'false')
end

def sendmailer
#@user = User.where(is_subscribed: 'true')
#@news = Newsletter.last
HardWorker.perform_async()
redirect_to users_path
end

def users_params
params.require(:user).permit(:id, :email_id, :is_subscribed, :joined_on, :source)
params.require(:user).permit(:id, :email_id, :is_subscribed, :joined_on, :source, :username)
end

def edit
Expand Down
22 changes: 22 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class UserMailer < ActionMailer::Base
include SendGrid
sendgrid_category :use_subject_lines
sendgrid_enable :ganalytics, :opentrack
sendgrid_unique_args :key1 => "value1", :key2 => "value2"

def welcome_message(email, newsletter_content,id,name)
sendgrid_category "Welcome"
sendgrid_unique_args :key2 => "newvalue2", :key3 => "value3"

content = ERB.new(newsletter_content)
object_id = id
#headers['X-SMTPAPI'] = { :to => user.pluck(:email_id) }.to_json

mail( to: email,
category: "newuser",
subject: "Welcome #{name}",
body: content.result(binding),
content_type: "text/html"
)
end
end
9 changes: 9 additions & 0 deletions app/models/redactor_rails/asset.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class RedactorRails::Asset
include Mongoid::Document
include Mongoid::Timestamps

include RedactorRails::Orm::Mongoid::AssetBase

delegate :url, :current_path, :size, :content_type, :filename, :to => :data
validates_presence_of :data
end
14 changes: 14 additions & 0 deletions app/models/redactor_rails/document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class RedactorRails::Document < RedactorRails::Asset
mount_uploader :data, RedactorRailsDocumentUploader, :mount_on => :data_file_name

def url_content
url(:content)
end

def thumb
# Could theoretically provide an icon set here
# to match against the extensions
# but for now it's nil to address the bug
nil
end
end
7 changes: 7 additions & 0 deletions app/models/redactor_rails/picture.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class RedactorRails::Picture < RedactorRails::Asset
mount_uploader :data, RedactorRailsPictureUploader, :mount_on => :data_file_name

def url_content
url(:content)
end
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ class User
include Mongoid::Document

field :email_id, type: String
field :username, type: String
field :is_subscribed, type: Boolean
field :joined_on, type: Date
field :source, type: String

validates :email_id, presence: true
validates :username, presence: true
validates :is_subscribed, presence: true
validates :joined_on, presence: true
validates :source, presence: true
Expand Down
15 changes: 15 additions & 0 deletions app/uploaders/redactor_rails_document_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# encoding: utf-8
class RedactorRailsDocumentUploader < CarrierWave::Uploader::Base
include RedactorRails::Backend::CarrierWave

# storage :fog
storage :file

def store_dir
"system/redactor_assets/documents/#{model.id}"
end

def extension_white_list
RedactorRails.document_file_types
end
end
53 changes: 53 additions & 0 deletions app/uploaders/redactor_rails_picture_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# encoding: utf-8
class RedactorRailsPictureUploader < CarrierWave::Uploader::Base
include RedactorRails::Backend::CarrierWave

# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
# include CarrierWave::ImageScience

# Choose what kind of storage to use for this uploader:
storage :file

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"system/redactor_assets/pictures/#{model.id}"
end

# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end

# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end

process :read_dimensions

# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fill => [118, 100]
end

version :content do
process :resize_to_limit => [800, 800]
end

# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
RedactorRails.image_file_types
end

# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
Loading

0 comments on commit 4e0a440

Please sign in to comment.