Skip to content

Commit

Permalink
Bye bye hash rockets.
Browse files Browse the repository at this point in the history
  • Loading branch information
futhr committed Nov 25, 2014
1 parent 30235ae commit cbe817f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require 'spree/testing_support/common_rake'

RSpec::Core::RakeTask.new

task :default => [:spec]
task default: [:spec]

desc "Generates a dummy app for testing"
desc 'Generates a dummy app for testing'
task :test_app do
ENV['LIB_NAME'] = 'spree_email_to_friend'
Rake::Task['common:test_app'].invoke
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/spree/email_sender_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Spree::EmailSenderController < Spree::StoreController

def send_mail
if request.get?
@mail_to_friend = Spree::MailToFriend.new(:sender_email => spree_current_user.try(:email))
@mail_to_friend = Spree::MailToFriend.new(sender_email: spree_current_user.try(:email))
else
mail_to_friend
end
Expand All @@ -19,9 +19,9 @@ def mail_to_friend
@mail_to_friend.host = request.env['HTTP_HOST']
respond_to do |format|
format.html do
captcha_passed = !Spree::Captcha::Config[:use_captcha] || verify_recaptcha(:private_key => Spree::Captcha::Config[:private_key])
captcha_passed = !Spree::Captcha::Config[:use_captcha] || verify_recaptcha(private_key: Spree::Captcha::Config[:private_key])
if @mail_to_friend.valid? && captcha_passed
flash[:notice] = Spree.t('email_to_friend.mail_sent_to', :email => @mail_to_friend.recipients.join(", ")).html_safe
flash[:notice] = Spree.t('email_to_friend.mail_sent_to', email: @mail_to_friend.recipients.join(', '))

send_message(@object, @mail_to_friend)

Expand All @@ -30,7 +30,7 @@ def mail_to_friend

redirect_to @object
else
render :action => :send_mail
render action: :send_mail
end
end
end
Expand Down Expand Up @@ -58,5 +58,4 @@ def find_object
# Display 404 page if object is not found.
raise ActiveRecord::RecordNotFound if @object.nil?
end

end
2 changes: 1 addition & 1 deletion app/mailers/spree/to_friend_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Spree::ToFriendMailer < ActionMailer::Base
default :from => Spree::Config[:mails_from] || ''
default from: Spree::Config[:mails_from] || ''


def mail_to_friend(object, mail)
Expand Down
12 changes: 6 additions & 6 deletions app/models/spree/captcha_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Spree::CaptchaConfiguration < Spree::Preferences::Configuration
THEMES = ['red', 'white', 'blackglass', 'clean', 'custom']
THEMES = %w(red white blackglass clean custom)

# this keys works for localhost
preference :private_key, :string, :default => '6LfIsgEAAAAAAGfB6Z0lEUtdL3GVuBkRa9cYlMZz'
preference :public_key, :string, :default => '6LfIsgEAAAAAALpT20eiC3RslZQmmCbiNS-AUvSe'
preference :theme, :string, :default => 'red'
preference :use_captcha, :boolean, :default => true
# These keys works for localhost.
preference :private_key, :string, default: '6LfIsgEAAAAAAGfB6Z0lEUtdL3GVuBkRa9cYlMZz'
preference :public_key, :string, default: '6LfIsgEAAAAAALpT20eiC3RslZQmmCbiNS-AUvSe'
preference :theme, :string, default: 'red'
preference :use_captcha, :boolean, default: true
end
10 changes: 5 additions & 5 deletions app/models/spree/mail_to_friend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class Spree::MailToFriend

EMAILREGEX = /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,8}\z/i

validates :subject, :sender_name, :presence => true
validates :recipient_name, :presence => true, :unless => :is_multi
validates :sender_email, :format => { :with => EMAILREGEX }
validates :recipients, :length => {:minimum => 1, :message => Spree.t(:recipients, scope: :validation) }
validates :invalid_recipients, :length => {:maximum => 0, :message => Spree.t(:invalid_recipients, scope: :validation) }
validates :subject, :sender_name, presence: true
validates :recipient_name, presence: true, unless: :is_multi
validates :sender_email, format: { with: EMAILREGEX }
validates :recipients, length: {minimum: 1, message: Spree.t(:recipients, scope: :validation) }
validates :invalid_recipients, length: {maximum: 0, message: Spree.t(:invalid_recipients, scope: :validation) }

def initialize(opts = {})
@sender_email = opts[:sender_email] || ' '
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Deface::Override.new(:virtual_path => "spree/admin/shared/_configuration_menu",
:name => "add_captcha_admin_option",
:insert_bottom => "[data-hook='admin_configurations_sidebar_menu']",
:text => "<%= configurations_sidebar_menu_item Spree.t('captcha.captcha_settings'), edit_admin_captcha_settings_path %>",
:disabled => false)
Deface::Override.new(virtual_path: "spree/admin/shared/_configuration_menu",
name: "add_captcha_admin_option",
insert_bottom: "[data-hook='admin_configurations_sidebar_menu']",
text: "<%= configurations_sidebar_menu_item Spree.t('captcha.captcha_settings'), edit_admin_captcha_settings_path %>",
disabled: false)
14 changes: 6 additions & 8 deletions app/overrides/add_email_to_friend_link_to_products.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Deface::Override.new(:virtual_path => "spree/products/show",
:name => "converted_product_description_351026984",
:insert_bottom => "[data-hook='product_description'], #product_description[data-hook]",
:text => "<p class=\"email_to_friend\">
<%= link_to Spree.t('email_to_friend.send_to_friend'), email_to_friend_url('product', @product) %>
</p>",
:disabled => false,
:original => "23a81432df67f93cad7563f7b118d6f901b8e42b")
Deface::Override.new(virtual_path: "spree/products/show",
name: "converted_product_description_351026984",
insert_bottom: "[data-hook='product_description'], #product_description[data-hook]",
text: "<p class=\"email_to_friend\"><%= link_to Spree.t('email_to_friend.send_to_friend'), email_to_friend_path('product', @product) %></p>",
disabled: false,
original: "23a81432df67f93cad7563f7b118d6f901b8e42b")
10 changes: 5 additions & 5 deletions app/views/spree/admin/captcha_settings/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
<%= render partial: 'spree/admin/shared/configuration_menu' %>
<% content_for :page_title do %>
<%= Spree.t('captcha.captcha_settings') %>
<% end %>
<%= form_tag(admin_captcha_settings_path, :method => :put) do |f| -%>
<%= form_tag(admin_captcha_settings_path, method: :put) do |f| -%>

<fieldset class="no-border-top">
<div data-hook="admin_captcha_settings" class="row">
Expand All @@ -24,17 +24,17 @@

<div data-hook="public_key" class="field">
<label><%= Spree.t('captcha.public_key') %></label><br>
<%= text_field_tag('preferences[public_key]', Spree::Captcha::Config[:public_key], :size => 40) %>
<%= text_field_tag('preferences[public_key]', Spree::Captcha::Config[:public_key], size: 40) %>
</div>

<div data-hook="private_key" class="field">
<label><%= Spree.t('captcha.private_key') %></label><br>
<%= text_field_tag('preferences[private_key]', Spree::Captcha::Config[:private_key], :size => 40) %>
<%= text_field_tag('preferences[private_key]', Spree::Captcha::Config[:private_key], size: 40) %>
</div>

<div data-hook="private_key" class="field">
<label><%= Spree.t('captcha.theme') %>:</label><br>
<%= select_tag('preferences[theme]', options_for_select(Spree::CaptchaConfiguration::THEMES, Spree::Captcha::Config[:theme]), class: "select2") %>
<%= select_tag('preferences[theme]', options_for_select(Spree::CaptchaConfiguration::THEMES, Spree::Captcha::Config[:theme]), class: 'select2') %>
</div>

</div>
Expand Down
10 changes: 5 additions & 5 deletions app/views/spree/email_sender/send_mail.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1><%= Spree.t('email_to_friend.tell_about', :product => @object.name) %></h1>
<h1><%= Spree.t('email_to_friend.tell_about', product: @object.name) %></h1>

<%= form_for(@mail_to_friend, :url => email_to_friend_path(params[:type], @object)) do |f| -%>
<%= render 'spree/shared/error_messages', :target => @mail_to_friend %>
<%= form_for(@mail_to_friend, url: email_to_friend_path(params[:type], @object)) do |f| -%>
<%= render 'spree/shared/error_messages', target: @mail_to_friend %>
<p>
<%= f.label(:sender_name, Spree.t('email_to_friend.sender_name')) %><br/>
<%= f.text_field(:sender_name) %>
Expand All @@ -23,9 +23,9 @@
<%= f.text_area(:message) %>
</p>
<% if Spree::Captcha::Config[:use_captcha] %>
<%= recaptcha_tags :public_key => Spree::Captcha::Config[:public_key], :display => {:theme => Spree::Captcha::Config[:theme]} %>
<%= recaptcha_tags public_key: Spree::Captcha::Config[:public_key], display: { theme: Spree::Captcha::Config[:theme] } %>
<% end %>
<p>
<%= f.submit Spree.t('email_to_friend.send_message') %>
</p>
<% end -%>
<% end -%>
3 changes: 1 addition & 2 deletions app/views/spree/to_friend_mailer/mail_to_friend.text.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<% object_sym = @object.class.name.tableize %>
<%= render :partial => "#{object_sym}/mail_to_friend",
:locals => {:object => @object, :mail => @mail} %>
<%= render partial: "#{object_sym}/mail_to_friend", locals: { object: @object, mail: @mail } %>
6 changes: 3 additions & 3 deletions lib/spree_email_to_friend/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class Engine < Rails::Engine

config.autoload_paths += %W(#{config.root}/lib)

initializer "spree.email_to_friend.preferences", :after => "spree.environment" do |app|
initializer 'spree.email_to_friend.preferences', after: 'spree.environment' do |app|
Spree::Captcha::Config = Spree::CaptchaConfiguration.new
end

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end

Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
Dir.glob(File.join(File.dirname(__FILE__), '../../app/overrides/*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end
Expand Down

0 comments on commit cbe817f

Please sign in to comment.