trusty-rad-social-extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/README.md +5 -0
  2. data/Rakefile +109 -0
  3. data/app/assets/images/rad_social/ajax-loader-small.gif +0 -0
  4. data/app/assets/images/rad_social/ajax-loader.gif +0 -0
  5. data/app/assets/images/rad_social/bg_primary-btn.png +0 -0
  6. data/app/assets/images/rad_social/email.png +0 -0
  7. data/app/assets/images/rad_social/facebook.png +0 -0
  8. data/app/assets/images/rad_social/flickr.png +0 -0
  9. data/app/assets/images/rad_social/foursquare.png +0 -0
  10. data/app/assets/images/rad_social/googleplus.png +0 -0
  11. data/app/assets/images/rad_social/twitter.png +0 -0
  12. data/app/assets/javascripts/lib/rad_social/captcha.js +42 -0
  13. data/app/assets/javascripts/lib/rad_social/rad_ajax_form.js +82 -0
  14. data/app/assets/javascripts/lib/rad_social/rad_email_form.js +85 -0
  15. data/app/assets/javascripts/lib/rad_social/rad_email_validator.js +47 -0
  16. data/app/assets/javascripts/lib/rad_social/rad_widget.js +20 -0
  17. data/app/assets/stylesheets/rad_social/rad_screen.scss +141 -0
  18. data/app/controllers/filters/rad_captcha_filter.rb +27 -0
  19. data/app/controllers/social_mailer_controller.rb +31 -0
  20. data/app/helpers/rad_social_helper.rb +23 -0
  21. data/app/models/rad_social_mailer.rb +16 -0
  22. data/app/views/rad_social_mailer/social_mail.text.html.haml +5 -0
  23. data/app/views/rad_social_mailer/social_mail_form.html.haml +49 -0
  24. data/app/views/widget/_email_form.html.haml +27 -0
  25. data/app/views/widget/_horizontal_widget.html.haml +25 -0
  26. data/config/initializers/trusty_config.rb +4 -0
  27. data/config/locales/en.yml +3 -0
  28. data/config/routes.rb +5 -0
  29. data/cucumber.yml +1 -0
  30. data/features/support/env.rb +11 -0
  31. data/features/support/paths.rb +22 -0
  32. data/lib/rad_social/engine.rb +5 -0
  33. data/lib/tags/widget_tags.rb +21 -0
  34. data/lib/tasks/rad_social_extension_tasks.rake +47 -0
  35. data/lib/trusty-rad-social-extension.rb +8 -0
  36. data/rad_social_extension.rb +22 -0
  37. data/spec/spec.opts +6 -0
  38. data/spec/spec_helper.rb +36 -0
  39. data/trusty-rad-social-extension.gemspec +30 -0
  40. metadata +120 -0
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Rad Social
2
+
3
+ TrustyCMS is _so_ freaking awesome, but I made it better through this extension.
4
+
5
+ Created by Eric Sipple.
data/Rakefile ADDED
@@ -0,0 +1,109 @@
1
+ # Determine where the RSpec plugin is by loading the boot
2
+ unless defined? RADIANT_ROOT
3
+ ENV["RAILS_ENV"] = "test"
4
+ case
5
+ when ENV["RADIANT_ENV_FILE"]
6
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
7
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
8
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
9
+ else
10
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
11
+ end
12
+ end
13
+
14
+ require 'rake'
15
+ require 'rdoc/task'
16
+ require 'rake/testtask'
17
+
18
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
19
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
20
+ require 'spec/rake/spectask'
21
+ require 'cucumber'
22
+ require 'cucumber/rake/task'
23
+
24
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
25
+ Object.send(:remove_const, :RADIANT_ROOT)
26
+
27
+ extension_root = File.expand_path(File.dirname(__FILE__))
28
+
29
+ task :default => [:spec, :features]
30
+ task :stats => "spec:statsetup"
31
+
32
+ desc "Run all specs in spec directory"
33
+ Spec::Rake::SpecTask.new(:spec) do |t|
34
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
35
+ t.spec_files = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ task :features => 'spec:integration'
39
+
40
+ namespace :spec do
41
+ desc "Run all specs in spec directory with RCov"
42
+ Spec::Rake::SpecTask.new(:rcov) do |t|
43
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
44
+ t.spec_files = FileList['spec/**/*_spec.rb']
45
+ t.rcov = true
46
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
47
+ end
48
+
49
+ desc "Print Specdoc for all specs"
50
+ Spec::Rake::SpecTask.new(:doc) do |t|
51
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
52
+ t.spec_files = FileList['spec/**/*_spec.rb']
53
+ end
54
+
55
+ [:models, :controllers, :views, :helpers].each do |sub|
56
+ desc "Run the specs under spec/#{sub}"
57
+ Spec::Rake::SpecTask.new(sub) do |t|
58
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
59
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
60
+ end
61
+ end
62
+
63
+ desc "Run the Cucumber features"
64
+ Cucumber::Rake::Task.new(:integration) do |t|
65
+ t.fork = true
66
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
67
+ # t.feature_pattern = "#{extension_root}/features/**/*.feature"
68
+ t.profile = "default"
69
+ end
70
+
71
+ # Setup specs for stats
72
+ task :statsetup do
73
+ require 'code_statistics'
74
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
75
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
76
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
77
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
78
+ ::CodeStatistics::TEST_TYPES << "Model specs"
79
+ ::CodeStatistics::TEST_TYPES << "View specs"
80
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
81
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
82
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
83
+ end
84
+
85
+ namespace :db do
86
+ namespace :fixtures do
87
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
88
+ task :load => :environment do
89
+ require 'active_record/fixtures'
90
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
91
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
92
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ desc 'Generate documentation for the rad_social extension.'
100
+ RDoc::Task.new(:rdoc) do |rdoc|
101
+ rdoc.rdoc_dir = 'rdoc'
102
+ rdoc.title = 'RadSocialExtension'
103
+ rdoc.options << '--line-numbers' << '--inline-source'
104
+ rdoc.rdoc_files.include('README')
105
+ rdoc.rdoc_files.include('lib/**/*.rb')
106
+ end
107
+
108
+ # Load any custom rakefiles for extension
109
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,42 @@
1
+ function Captcha(element) {
2
+ var self = this;
3
+ var challengeFieldSelector = "#recaptcha_challenge_field";
4
+ var responseFieldSelector = "#recaptcha_response_field";
5
+
6
+ self.challengeValue = function() {
7
+ return $(element).find(challengeFieldSelector).val();
8
+ };
9
+
10
+ self.responseValue = function() {
11
+ return $(element).find(responseFieldSelector).val();
12
+ };
13
+
14
+ self.visible = function() {
15
+ return ($(element).find("#recaptcha_area").length > 0);
16
+ };
17
+
18
+ self.requestData = function() {
19
+ requestHash = {};
20
+ if(this.visible()) {
21
+ $.extend(requestHash, {
22
+ 'recaptcha_challenge_field': this.challengeValue(),
23
+ 'recaptcha_response_field': this.responseValue()
24
+ });
25
+ }
26
+ return requestHash;
27
+ };
28
+
29
+ self.isValid = function() {
30
+ if(this.visible()) {
31
+ return this.responseValue().length > 0;
32
+ }
33
+ return true;
34
+ };
35
+
36
+ self.reload = function() {
37
+ if(Recaptcha) {
38
+ Recaptcha.reload();
39
+ }
40
+ };
41
+
42
+ }
@@ -0,0 +1,82 @@
1
+ function RadAjaxForm(form) {
2
+ var self = this;
3
+ this.submitWithoutValidation = function(onSuccess, onError, onComplete) {
4
+ if (onError === undefined) {
5
+ onError = function() {
6
+ };
7
+ }
8
+ if (onComplete === undefined) {
9
+ onComplete = function() {
10
+ };
11
+ }
12
+
13
+ form.find(".loader").addClass('ajax-loader');
14
+ form.find(".loader-small").addClass('ajax-loader-small');
15
+ $.ajax({
16
+ type: "POST",
17
+ url: form.find('input[name=submit_url]').attr('value'),
18
+ data: form.serialize(),
19
+ beforeSend: function ( xhr ) {
20
+ xhr.setRequestHeader("X-CSRF-Token", $("#auth_token").attr('value'));
21
+ },
22
+ success: function(data, status, xhr) {
23
+ form.find(".loader").removeClass('ajax-loader');
24
+ form.find(".loader-small").removeClass('ajax-loader-small');
25
+ onSuccess(data, status, xhr);
26
+ },
27
+ error: function(data) {
28
+ form.find(".loader").removeClass('ajax-loader');
29
+ form.find(".loader-small").removeClass('ajax-loader-small');
30
+ form.find('.continue').attr('disabled', false);
31
+ onError(data);
32
+ },
33
+ complete: onComplete
34
+ });
35
+ form.find('.continue').attr('disabled', 'disabled');
36
+ return true;
37
+ };
38
+
39
+ this.defaultSubmitWithoutValidation = function() {
40
+ this.submitWithoutValidation(handleSuccess, handleFailure);
41
+ };
42
+
43
+ this.submit = function(onSuccess, onError, onComplete) {
44
+ if (onComplete === undefined) {
45
+ onComplete = function() {
46
+ };
47
+ }
48
+
49
+ if (onError === undefined) {
50
+ onError = handleFailure;
51
+ }
52
+
53
+ if (!form.valid()) {
54
+ onComplete();
55
+ return true;
56
+ }
57
+ return self.submitWithoutValidation(onSuccess, onError, onComplete);
58
+ };
59
+
60
+
61
+ function handleSuccess(data, status, xhr)
62
+ {
63
+ var url = xhr.getResponseHeader("BrowserRedirectTo");
64
+ if (!!url) {
65
+ location.href = url
66
+ }
67
+ }
68
+
69
+ function handleFailure(xhr) {
70
+ var errorMessage = xhr.getResponseHeader("ErrorMsg");
71
+ var errorMessageDialog = new ModalDialog('', function(element) {
72
+ return {
73
+ autoOpen: false,
74
+ minHeight: 20,
75
+ title: "We're Sorry!",
76
+ dialogClass: 'seat-error-dialog'
77
+ };
78
+ });
79
+ errorMessageDialog.show(errorMessage);
80
+ }
81
+
82
+ }
@@ -0,0 +1,85 @@
1
+ $(document).ready(function() {
2
+
3
+ var radModal;
4
+
5
+ function centeredPopup(url,w,h){
6
+ var popupWindow = null;
7
+ LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
8
+ TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
9
+ settings =
10
+ 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
11
+ popupWindow = window.open(url,"Share",settings);
12
+ }
13
+
14
+ $(".rad-window-close").click(function(event) {
15
+ event.preventDefault();
16
+ $("#rad-social-email-form").fadeToggle('slow');
17
+ });
18
+
19
+ $(".rad-popup-window").click(function(event){
20
+ event.preventDefault();
21
+ var url = $(this).attr("href");
22
+ centeredPopup(url, 625, 430)
23
+
24
+ });
25
+
26
+ var form = $("#rad-social-email-form");
27
+
28
+ validator = form.validate({
29
+ submitHandler: function(form) {
30
+ var button = $('#rad_email_submit');
31
+ button.attr('disabled', true);
32
+ button.removeClass('primary-button').addClass('disabled-button');
33
+ form.submit();
34
+ clear_form();
35
+ }
36
+ });
37
+
38
+
39
+ var radEmailValidator = new RadEmailValidator(form);
40
+ radEmailValidator.addRules();
41
+
42
+ form.find('#rad_email_submit').click(function(e) {
43
+ return new RadAjaxForm(form).submit(OnSuccess, OnError, OnComplete);
44
+ });
45
+
46
+ function OnSuccess(data) {
47
+ $("#rad-social-email-form").addClass('hidden');
48
+ $("#rad-confirmation").removeClass('hidden');
49
+
50
+ }
51
+
52
+ function OnError(xhr) {
53
+ processFailure(xhr);
54
+ }
55
+
56
+ function OnComplete() {
57
+ //$('#express_contact_form').find('.continue').attr('disabled', false);
58
+ //$('#express_contact_form').find(".loader").removeClass('ajax-loader');
59
+ }
60
+
61
+ function clear_form(){
62
+ $('#rs-from').val('');
63
+ $('#rs-from_name').val('');
64
+ $('#rs-to').val('');
65
+ $('#rs-message').val($('#rs-base-message').val());
66
+ var captcha = new Captcha("#recaptcha-container");
67
+ captcha.reload();
68
+ }
69
+
70
+ function processFailure(xhr)
71
+ {
72
+ var captcha = new Captcha("#recaptcha-container");
73
+ var error_msg = xhr.getResponseHeader("ErrorMsg");
74
+ displayErrorMessage(error_msg);
75
+ captcha.reload();
76
+ }
77
+
78
+ function displayErrorMessage(msg) {
79
+ var error_msg_div = $('.rad-email-error');
80
+ error_msg_div.text(msg);
81
+ error_msg_div.show();
82
+ }
83
+
84
+
85
+ });
@@ -0,0 +1,47 @@
1
+ function RadEmailValidator(parentElement) {
2
+ var rules = {
3
+ "rs-from": {
4
+ required: true,
5
+ email: true,
6
+ messages: {
7
+ required: "From email is required."
8
+ }
9
+ },
10
+ "rs-from_name": {
11
+ required: true,
12
+ messages: {
13
+ required: "From name is required."
14
+ }
15
+ },
16
+ "rs-to": {
17
+ required: true,
18
+ email: true,
19
+ messages: {
20
+ required: "To email is required"
21
+ }
22
+ },
23
+ "rs-message": {
24
+ required: true,
25
+ messages: {
26
+ required: "Email message is required."
27
+ }
28
+ }
29
+ };
30
+
31
+ this.addRules = function() {
32
+ for (var key in rules) {
33
+ $(parentElement).find("[id$=" + key + "]").rules("add", rules[key]);
34
+ }
35
+ };
36
+
37
+ this.removeRules = function() {
38
+ for (var key in rules) {
39
+ $(parentElement).find("[id$=" + key + "]").rules("remove");
40
+ }
41
+ };
42
+
43
+ function elementKeyFor(key) {
44
+ return "[id$=" + parentElement.attr('id') + '_' + key + ']';
45
+ }
46
+
47
+ }
@@ -0,0 +1,20 @@
1
+ $(document).ready(function() {
2
+
3
+ function centeredPopup(url,w,h){
4
+ var popupWindow = null;
5
+ LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
6
+ TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
7
+ settings =
8
+ 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
9
+ popupWindow = window.open(url,"Share",settings);
10
+ }
11
+
12
+ $(".rad-popup-window").click(function(event){
13
+ event.preventDefault();
14
+ var url = $(this).attr("href");
15
+ centeredPopup(url, 625, 430)
16
+
17
+ });
18
+
19
+
20
+ });
@@ -0,0 +1,141 @@
1
+ body {
2
+ font-family: Arial, Helvetica, sans-serif;
3
+ font-size: 12px;
4
+ }
5
+
6
+ .rad-icon {
7
+ float: left;
8
+ padding-right: 3px;
9
+ }
10
+ .rad-email-form {
11
+ position: relative;
12
+ padding: 15px;
13
+ }
14
+
15
+ .hidden {
16
+ display: none;
17
+ }
18
+
19
+ .rad-dialog-titlebar {
20
+ background: #EDEDED;
21
+ padding: .5em .3em .3em 1em;
22
+ height: 2em;
23
+ }
24
+
25
+ .rad-dialog-title {
26
+ float: left;
27
+ font-weight: bold;
28
+ margin: .3em 0 .2em;
29
+ }
30
+
31
+ #rad-social-email-form .form-row .form-fields {
32
+ width: 60%;
33
+ float: left;
34
+ }
35
+
36
+ #rad-social-email-form .form-row .input-textbox {
37
+ display: block;
38
+ font-size: 12px;
39
+ }
40
+
41
+
42
+ .rad-email-form #rad_email_submit {
43
+ float: right;
44
+ }
45
+
46
+ .rad-email-form .captcha-container {
47
+ padding: 10px 0px;
48
+ }
49
+
50
+ .rad-email-form input.std_input {
51
+ margin-bottom: 10px;
52
+ }
53
+
54
+ .rad-email-form select {
55
+ margin-bottom: 10px;
56
+ background-color: #fff;
57
+ border: 1px solid #ccc;
58
+ font: 14px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
59
+ color: #6e6e6e;
60
+ }
61
+
62
+ #rad-social-email-form .form-label {
63
+ width: 15%;
64
+ float: left;
65
+ display: block;
66
+ text-align: left;
67
+ padding: 5px 10px 0 0;
68
+ }
69
+
70
+ #rad-social-email-form .form-row {
71
+ padding: 5px;
72
+ clear: both;
73
+ overflow: auto;
74
+ }
75
+
76
+
77
+ .rad-email-form input.std_input,
78
+ .rad-email-form textarea {
79
+ border: 1px solid #ccc;
80
+ width: 97%;
81
+ font: 15px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
82
+ padding: 5px;
83
+ color: #6e6e6e;
84
+ }
85
+
86
+ .rad-email-form table {
87
+ width: 100%;
88
+ }
89
+
90
+ .rad-email-form table input.std_input {
91
+ width: 93%;
92
+ }
93
+
94
+ .rad-email-form table.three-col input.std_input {
95
+ width: 90%;
96
+ }
97
+
98
+ .rad-email-form input.form_but {
99
+ margin-top: 10px;
100
+ background-color: #93ba31;
101
+ border: 3px solid #afdd39;
102
+ color: #fff;
103
+ font: bold 15px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
104
+ -webkit-border-radius: 5px;
105
+ -moz-border-radius: 5px;
106
+ padding: 5px 10px;
107
+ }
108
+
109
+ input.error {
110
+ border: 1px solid #CD0A0A !important;
111
+ color: #CD0A0A !important;
112
+ font-family: Arial, Helvetica, sans-serif !important;
113
+ }
114
+
115
+ .rad-email-error, label.error{
116
+ padding: 5px 0px !important;
117
+ color: #CD0A0A !important;
118
+ font-family: Arial, Helvetica, sans-serif !important;
119
+ display: block;
120
+ }
121
+
122
+ #rad-confirmation {
123
+ font-weight: bold;
124
+ text-align: center;
125
+ padding-top: 25px;
126
+ }
127
+
128
+ body .ajax-loader {
129
+ background: transparent none no-repeat 50% 50%;
130
+ background-image: url("/assets/rad_social/ajax-loader.gif");
131
+ height: 35px;
132
+ }
133
+
134
+ body #rad-social-email-form .primary-button {
135
+ background: transparent none repeat-x scroll 0 0;
136
+ background-image: url("/assets/rad_social/bg_primary-btn.png") /* sprite-ref: cd-backgrounds-sprite; sprite-alignment: repeat; */;
137
+ color: white !important;
138
+ border: 1px solid #924900;
139
+ }
140
+
141
+ /* @end */
@@ -0,0 +1,27 @@
1
+ require 'recaptcha'
2
+
3
+ class Filters::RadCaptchaFilter
4
+
5
+ def initialize controller
6
+ @controller = controller
7
+ end
8
+
9
+ def self.filter controller
10
+ Filters::RadCaptchaFilter.new(controller).verify
11
+ end
12
+
13
+ def verify
14
+ unless verify_captcha
15
+ @controller.send :head, :bad_request, :ErrorMsg => "The security code that you entered does not match the one in the image. Please enter the security code again."
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def verify_captcha
22
+ @controller.extend Recaptcha::Verify
23
+ @controller.verify_recaptcha(:private_key => Rails.configuration.captcha_private_key)
24
+ end
25
+
26
+
27
+ end
@@ -0,0 +1,31 @@
1
+ class SocialMailerController < ApplicationController
2
+ trusty_layout "default", {:only => :create_social_mail}
3
+ before_filter Filters::RadCaptchaFilter, :only => :create_social_mail
4
+ no_login_required
5
+
6
+ def create_social_mail
7
+
8
+ mailer_options = {
9
+ :to => params[:to],
10
+ :from => params[:from],
11
+ :from_name => params[:from_name],
12
+ :message => params[:message],
13
+ :subject => params[:subject]
14
+ }
15
+
16
+ RadSocialMailer.deliver_social_mail(mailer_options)
17
+ head :ok
18
+
19
+ end
20
+
21
+ def social_mail_form
22
+ render :template => "rad_social_mailer/social_mail_form",
23
+ :layout => false,
24
+ :locals => {
25
+ :email_message => params[:email_message],
26
+ :email_subject => params[:email_subject],
27
+ :email_action_url => params[:email_action_url]
28
+ }
29
+ end
30
+
31
+ end
@@ -0,0 +1,23 @@
1
+ module RadSocialHelper
2
+
3
+ def rad_test_method
4
+ "SURPRISE SURPRISE SURPRISE"
5
+ end
6
+
7
+ def rad_share_widget(options)
8
+ url = options[:url].nil? ? request.url : options[:url]
9
+ message = options[:message].nil? ? "Check out #{options[:title]}." : options[:message]
10
+ email_subject = options[:email_subject].nil? ? options[:title] : options[:email_subject]
11
+ email_message = options[:email_message].nil? ? "I thought you might be interested in this: #{url}" : "#{options[:email_message]} #{url}"
12
+ email_action_url = options[:email_action_url].nil? ? "/rad_social/mail" : options[:email_action_url]
13
+
14
+ render :partial => "widget/horizontal_widget",
15
+ :locals => { :url => url,
16
+ :message => message,
17
+ :email_subject => email_subject,
18
+ :email_message => email_message,
19
+ :email_action_url => email_action_url
20
+ }
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+ class RadSocialMailer < ActionMailer::Base
2
+
3
+ def social_mail options
4
+
5
+ email_recipients = Rails.configuration.test_email_recipients ? Rails.configuration.test_email_recipients : options[:to]
6
+
7
+ recipients email_recipients
8
+ from options[:from]
9
+ subject options[:subject]
10
+ sent_on Time.now
11
+ content_type "text/html"
12
+ body :from_name => options[:from_name], :from_email => options[:from], :message => options[:message]
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,5 @@
1
+ %div
2
+ %p
3
+ = "From: #{@from_name} (#{@from_email})"
4
+ %p
5
+ = @message
@@ -0,0 +1,49 @@
1
+ = stylesheet_link_tag('rad_social/rad_screen')
2
+ = javascript_include_tag("externals/jquery")
3
+ = javascript_include_tag("externals/jquery.validate")
4
+ = javascript_include_tag("http://www.google.com/recaptcha/api/js/recaptcha_ajax.js")
5
+ = javascript_include_tag("lib/rad_social/rad_ajax_form")
6
+ = javascript_include_tag("lib/rad_social/captcha")
7
+ = javascript_include_tag("lib/rad_social/rad_email_validator")
8
+ = javascript_include_tag("lib/rad_social/rad_email_form")
9
+
10
+ .rad-dialog-titlebar
11
+ %span.rad-dialog-title
12
+ Email a Friend
13
+
14
+ %form{:id=>'rad-social-email-form', :class=>"rad-email-form"}
15
+ .rad-email-error
16
+ %input{:type=>'hidden', :id=> "auth_token", :value=>"#{form_authenticity_token}"}
17
+ %div.form-row
18
+ %label.form-label{:type=>"label", :for=>"from"}
19
+ From Email
20
+ %div.form-fields
21
+ %input{:class => "input-textbox", :type => "text", :id => "rs-from", :name => "from", :size => 30, :maxlength => 35}
22
+ %div.form-row
23
+ %label.form-label{:type=>"label", :for=>"from_name"}
24
+ From Name
25
+ %div.form-fields
26
+ %input{:class => "input-textbox", :type => "text", :id => "rs-from_name", :name => "from_name", :size => 30, :maxlength => 35}
27
+ %div.form-row
28
+ %label.form-label{:type=>"label", :for=>"to"}
29
+ To Email
30
+ %div.form-fields
31
+ %input{:class => "input-textbox", :type => "text", :id => "rs-to", :name => "to", :size => 30, :maxlength => 35}
32
+ %div.form-row
33
+ %label.form-label{:type=>"label", :for=>"message"}
34
+ Message
35
+ %div.form-fields
36
+ %textarea{:class => "input-textbox", :id => "rs-message", :name => "message", :rows => 5, :cols => 40}
37
+ = email_message
38
+ %input{:type=>"hidden", :name=>"subject", :value=> email_subject}
39
+ %input{:type=>"hidden", :id=>"rs-base-message", :value=> email_message}
40
+ #recaptcha-container.captcha-container
41
+ = recaptcha_tags :public_key => Rails.configuration.captcha_public_key, :display => {:theme => 'clean'}
42
+ #recaptcha_image
43
+ #recaptcha_response_field{:name => 'recaptcha_response_field'}
44
+ %input{:type=>"hidden", :name=>"submit_url", :value=> email_action_url}
45
+ %input.button.primary-button{:id => "rad_email_submit", :type=>:button ,:value=>"Submit"}
46
+ .loader
47
+
48
+ #rad-confirmation.hidden
49
+ Your message has been sent.
@@ -0,0 +1,27 @@
1
+ - javascript("lib/rad_social/captcha")
2
+
3
+ = form_tag
4
+ %form{:id=>'rad_social_email_form', :class=>"rad-email-form"}
5
+ %label{:for => "from"}
6
+ Your Email:
7
+ %input{:class => "std_input", :type => "text", :id => "rs-from", :name => "from", :size => 40, :maxlength => 35}
8
+ %label{:for => "from_name"}
9
+ Your Name:
10
+ %input{:class => "std_input", :type => "text", :id => "rs-from_name", :name => "from_name", :size => 40, :maxlength => 35}
11
+ %label{:for => "to"}
12
+ To:
13
+ %input{:class => "std_input", :type => "text", :id => "rs-to", :name => "to", :size => 40, :maxlength => 35}
14
+ %label{:for => "subject"}
15
+ To:
16
+ %input{:class => "std_input", :type => "text", :id => "rs-subject", :name => "subject", :size => 40, :maxlength => 35}
17
+ %label{:for => "Message"}
18
+ Message:
19
+ %textarea{:id => "rs-message", :rows => 18, :cols => 40}
20
+ %input{:type=>"hidden", :name=>"submit_url", :value=>'contact/email'}
21
+ %input.button.primary-button{:id => "email_submit", :type=>:button ,:value=>"Submit"}
22
+ .loader
23
+
24
+ #recaptcha-container.captcha-container
25
+ = recaptcha_tags :public_key => Rails.configuration.captcha_public_key, :display => {:theme => 'clean'}
26
+ #recaptcha_image
27
+ #recaptcha_response_field{:name => 'recaptcha_response_field'}
@@ -0,0 +1,25 @@
1
+ = stylesheet_link_tag('rad_social/rad_screen')
2
+ = javascript_include_tag("lib/rad_social/rad_widget")
3
+ - local_variables = defined?(locals) ? locals : local_assigns
4
+ - url = local_variables[:url]
5
+ - message = local_variables[:message]
6
+ - email_action_url = local_variables[:email_action_url]
7
+ - email_subject = local_variables[:email_subject]
8
+ - email_message = local_variables[:email_message]
9
+
10
+ .rad-widget
11
+ .rad-icon
12
+ %a{:class => "rad-popup-window rad-facebook", :href => "https://www.facebook.com/sharer/sharer.php?u=#{CGI::escape(url)}", :target=> "_blank"}
13
+ %img{:src => "/assets/rad_social/facebook.png", :alt => "Facebook", :title => "Share to Facebook", :height => "26", :width => "26"}
14
+ .rad-icon
15
+ %a{:class => "rad-popup-window rad-twitter", :href => "https://twitter.com/intent/tweet?text=#{CGI::escape(message + " " + url)}"}
16
+ %img{:src => "/assets/rad_social/twitter.png", :alt => "Twitter", :title => "Share to Twitter", :height => "26", :width => "26"}
17
+ .rad-icon
18
+ %a{:class => "rad-popup-window rad-email", :href => rad_social_mail_form_url(:email_subject => email_subject, :email_message => email_message, :email_action_url => email_action_url)}
19
+ %img{:src => "/assets/rad_social/email.png", :alt => "Email a Friend", :title => "Email a Friend", :height => "26", :width => "26"}
20
+ .rad-icon
21
+ %a{:class => "rad-popup-window rad-gplus", :href => "https://plus.google.com/share?url=#{CGI::escape(url)}"}
22
+ %img{:src => "/assets/rad_social/googleplus.png", :alt => "Google+", :title => "Share to Google+", :height => "26", :width => "26"}
23
+
24
+
25
+
@@ -0,0 +1,4 @@
1
+ require 'multi_site/engine'
2
+ TrustyCms.config do |config|
3
+ # config.define "setting.name", :default => 'value', :select_from => ['foo', 'bar']
4
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ en:
3
+ rad social: Rad Social
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+
2
+ TrustyCms::Application.routes.draw do
3
+ get '/rad_social/mail' => 'social_mailer#social_mail_form', as: :rad_social_mail_form
4
+ post '/rad_social/mail' => 'social_mailer#social_mail_form#create_social_mail', as: :rad_create_social_mail
5
+ end
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: --format progress features --tags ~@proposed,~@in_progress
@@ -0,0 +1,11 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV["RAILS_ENV"] = "test"
3
+ # Extension root
4
+ extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
5
+ require extension_env+'.rb'
6
+
7
+ Dir.glob(File.join(TRUSTY_CMS_ROOT, "features", "**", "*.rb")).each {|step| require step unless step =~ /datasets_loader\.rb$/}
8
+
9
+ Cucumber::Rails::World.class_eval do
10
+ dataset :rad_social
11
+ end
@@ -0,0 +1,22 @@
1
+ module NavigationHelpers
2
+
3
+ # Extend the standard PathMatchers with your own paths
4
+ # to be used in your features.
5
+ #
6
+ # The keys and values here may be used in your standard web steps
7
+ # Using:
8
+ #
9
+ # When I go to the "rad_social" admin page
10
+ #
11
+ # would direct the request to the path you provide in the value:
12
+ #
13
+ # admin_rad_social_path
14
+ #
15
+ PathMatchers = {} unless defined?(PathMatchers)
16
+ PathMatchers.merge!({
17
+ # /rad_social/i => 'admin_rad_social_path'
18
+ })
19
+
20
+ end
21
+
22
+ World(NavigationHelpers)
@@ -0,0 +1,5 @@
1
+ module RadSocial
2
+ class Engine < Rails::Engine
3
+ paths["app/helpers"] = []
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module Tags::WidgetTags
2
+ include TrustyCms::Taggable
3
+
4
+ desc "Widget of sharing icons"
5
+ tag "rad_share_widget" do |tag|
6
+ attributes = tag.attr.to_options
7
+ url = attributes[:url].nil? ? request.url : attributes[:url]
8
+ message = attributes[:message].nil? ? "Check out #{tag.locals.page.title}." : attributes[:message]
9
+ email_subject = attributes[:email_subject].nil? ? tag.locals.page.title : attributes[:email_subject]
10
+ email_message = attributes[:email_message].nil? ? "I thought you might be interested in this: #{url}" : "#{attributes[:email_message]} #{url}"
11
+ email_action_url = attributes[:email_action_url].nil? ? "/rad_social/mail" : attributes[:email_action_url]
12
+ request.env["action_controller.instance"].render_to_string :partial => "widget/horizontal_widget",
13
+ :locals => { :url => url,
14
+ :message => message,
15
+ :email_subject => email_subject,
16
+ :email_message => email_message,
17
+ :email_action_url => email_action_url
18
+ }
19
+ end
20
+
21
+ end
@@ -0,0 +1,47 @@
1
+ namespace :trusty do
2
+ namespace :extensions do
3
+ namespace :rad_social do
4
+
5
+ desc "Runs the migration of the Rad Social extension"
6
+ task :migrate => :environment do
7
+ require 'trusty_cms/extension_migrator'
8
+ if ENV["VERSION"]
9
+ RadSocialExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ Rake::Task['db:schema:dump'].invoke
11
+ else
12
+ RadSocialExtension.migrator.migrate
13
+ Rake::Task['db:schema:dump'].invoke
14
+ end
15
+ end
16
+
17
+ desc "Copies public assets of the Rad Social to the instance public/ directory."
18
+ task :update => :environment do
19
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
20
+ puts "Copying assets from RadSocialExtension"
21
+ Dir[RadSocialExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(RadSocialExtension.root, '')
23
+ directory = File.dirname(path)
24
+ mkdir_p RAILS_ROOT + directory, :verbose => false
25
+ cp file, RAILS_ROOT + path, :verbose => false
26
+ end
27
+ end
28
+
29
+ desc "Syncs all available translations for this ext to the English ext master"
30
+ task :sync => :environment do
31
+ # The main translation root, basically where English is kept
32
+ language_root = RadSocialExtension.root + "/config/locales"
33
+ words = TranslationSupport.get_translation_keys(language_root)
34
+
35
+ Dir["#{language_root}/*.yml"].each do |filename|
36
+ next if filename.match('_available_tags')
37
+ basename = File.basename(filename, '.yml')
38
+ puts "Syncing #{basename}"
39
+ (comments, other) = TranslationSupport.read_file(filename, basename)
40
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
41
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
42
+ TranslationSupport.write_file(filename, basename, comments, other)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,8 @@
1
+ module TrustyRadSocialExtension
2
+ VERSION = "1.0.0"
3
+ SUMMARY = "Rad Social for Trusty CMS"
4
+ DESCRIPTION = "Makes Trusty CMS better by adding rad_social!"
5
+ URL = "http://example.com/rad_social"
6
+ AUTHORS = ["Eric Sipple"]
7
+ EMAIL = ["sipple@trustarts.org"]
8
+ end
@@ -0,0 +1,22 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ # require_dependency "application_controller"
3
+ require "trusty-rad-social-extension"
4
+
5
+ class RadSocialExtension < TrustyCms::Extension
6
+ version TrustyRadSocialExtension::VERSION
7
+ description TrustyRadSocialExtension::DESCRIPTION
8
+ url TrustyRadSocialExtension::URL
9
+
10
+ # See your config/routes.rb file in this extension to define custom routes
11
+
12
+ extension_config do |config|
13
+ # config is the Radiant.configuration object
14
+ end
15
+
16
+ def activate
17
+ # tab 'Content' do
18
+ # add_item "Rad Social", "/admin/rad_social", :after => "Pages"
19
+ # end
20
+ Page.send :include, Tags::WidgetTags
21
+ end
22
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,36 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
15
+
16
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
17
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ # config.use_transactional_fixtures = true
22
+ # config.use_instantiated_fixtures = false
23
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
24
+
25
+ # You can declare fixtures for each behaviour like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so here, like so ...
31
+ #
32
+ # config.global_fixtures = :table_a, :table_b
33
+ #
34
+ # If you declare global fixtures, be aware that they will be declared
35
+ # for all of your examples, even those that don't use them.
36
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "trusty-rad-social-extension"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "trusty-rad-social-extension"
7
+ s.version = TrustyRadSocialExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = TrustyRadSocialExtension::AUTHORS
10
+ s.email = TrustyRadSocialExtension::EMAIL
11
+ s.homepage = TrustyRadSocialExtension::URL
12
+ s.summary = TrustyRadSocialExtension::SUMMARY
13
+ s.description = TrustyRadSocialExtension::DESCRIPTION
14
+
15
+ # Define gem dependencies here.
16
+ # Don't include a dependency on radiant itself: it causes problems when radiant is in vendor/radiant.
17
+ # s.add_dependency "something", "~> 1.0.0"
18
+ s.add_dependency "recaptcha", "~> 0.3.6"
19
+ s.add_dependency "trusty-cms", "~> 1.0.1"
20
+
21
+ ignores = if File.exist?('.gitignore')
22
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
23
+ else
24
+ []
25
+ end
26
+ s.files = Dir['**/*'] - ignores
27
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
28
+ # s.executables = Dir['bin/*'] - ignores
29
+ s.require_paths = ["lib"]
30
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trusty-rad-social-extension
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Sipple
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: recaptcha
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.3.6
30
+ - !ruby/object:Gem::Dependency
31
+ name: trusty-cms
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.1
46
+ description: Makes Trusty CMS better by adding rad_social!
47
+ email:
48
+ - sipple@trustarts.org
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - app/assets/images/rad_social/ajax-loader-small.gif
54
+ - app/assets/images/rad_social/ajax-loader.gif
55
+ - app/assets/images/rad_social/bg_primary-btn.png
56
+ - app/assets/images/rad_social/email.png
57
+ - app/assets/images/rad_social/facebook.png
58
+ - app/assets/images/rad_social/flickr.png
59
+ - app/assets/images/rad_social/foursquare.png
60
+ - app/assets/images/rad_social/googleplus.png
61
+ - app/assets/images/rad_social/twitter.png
62
+ - app/assets/javascripts/lib/rad_social/captcha.js
63
+ - app/assets/javascripts/lib/rad_social/rad_ajax_form.js
64
+ - app/assets/javascripts/lib/rad_social/rad_email_form.js
65
+ - app/assets/javascripts/lib/rad_social/rad_email_validator.js
66
+ - app/assets/javascripts/lib/rad_social/rad_widget.js
67
+ - app/assets/stylesheets/rad_social/rad_screen.scss
68
+ - app/controllers/filters/rad_captcha_filter.rb
69
+ - app/controllers/social_mailer_controller.rb
70
+ - app/helpers/rad_social_helper.rb
71
+ - app/models/rad_social_mailer.rb
72
+ - app/views/rad_social_mailer/social_mail.text.html.haml
73
+ - app/views/rad_social_mailer/social_mail_form.html.haml
74
+ - app/views/widget/_email_form.html.haml
75
+ - app/views/widget/_horizontal_widget.html.haml
76
+ - config/initializers/trusty_config.rb
77
+ - config/locales/en.yml
78
+ - config/routes.rb
79
+ - cucumber.yml
80
+ - features/support/env.rb
81
+ - features/support/paths.rb
82
+ - lib/rad_social/engine.rb
83
+ - lib/tags/widget_tags.rb
84
+ - lib/tasks/rad_social_extension_tasks.rake
85
+ - lib/trusty-rad-social-extension.rb
86
+ - rad_social_extension.rb
87
+ - Rakefile
88
+ - README.md
89
+ - spec/spec.opts
90
+ - spec/spec_helper.rb
91
+ - trusty-rad-social-extension.gemspec
92
+ homepage: http://example.com/rad_social
93
+ licenses: []
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.29
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Rad Social for Trusty CMS
116
+ test_files:
117
+ - spec/spec.opts
118
+ - spec/spec_helper.rb
119
+ - features/support/env.rb
120
+ - features/support/paths.rb