Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CocoaPush support to CocoaPods.org #36

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion Gemfile
@@ -1,5 +1,10 @@
# If you have OpenSSL installed, we recommend updating # If you have OpenSSL installed, we recommend updating
# the following line to use "https" # the following line to use "https"

# RVM support
#ruby=ruby-2.1.0
#ruby-gemset=cocoapods.org

source 'https://rubygems.org' source 'https://rubygems.org'


gem "middleman", "~>3.0.13" gem "middleman", "~>3.0.13"
Expand All @@ -21,4 +26,4 @@ gem 'pygments.rb'
gem 'github-markup' gem 'github-markup'


gem "rest" gem "rest"
gem "twitter" gem "twitter"
2 changes: 1 addition & 1 deletion shared
Submodule shared updated 1 files
+91 −84 sass/search.scss.erb
13 changes: 9 additions & 4 deletions source/_search-templates.html.slim
Expand Up @@ -3,24 +3,29 @@
ruby: ruby:
popover_html = "<h4 class='has-flash'>Copy to clipboard</h4><h4 class='no-flash'>For your <a href='http://guides.cocoapods.org/using/the-podfile.html'>Podfile</a></h4><pre><code>pod '{{ id }}', '~> {{ version }}'</code></pre><input class='no-flash' value=\"pod '{{ id }}', '~> {{ version }}'\" type=text>" popover_html = "<h4 class='has-flash'>Copy to clipboard</h4><h4 class='no-flash'>For your <a href='http://guides.cocoapods.org/using/the-podfile.html'>Podfile</a></h4><pre><code>pod '{{ id }}', '~> {{ version }}'</code></pre><input class='no-flash' value=\"pod '{{ id }}', '~> {{ version }}'\" type=text>"


fave_info = "<h4 class='has-safari-push'>Get Push Notifications for this pod</h4>"
fave_selected = "<h4 class='has-enabled-push-here'></h4>"

script id="search_result" type="text/html" script id="search_result" type="text/html"


li.result li.result
div.infos.col-lg-8.col-sm-7.col-xs-12 div.infos.col-lg-8.col-sm-7.col-xs-12
h3 h3
a href="{{ link }}" {{ id }} a href="{{ link }}" {{ id }}
span.version {{ version }} span.version {{ version }}
img.copy src="./images/copy-to-clipboard.png" data-clipboard-text="pod '{{ id }}', '~> {{ version }}'" data-toggle="popover" data-placement="top" data-container="body" data-html="true" data-content=popover_html img.fave src="./images/star-hollow.png" data-toggle="popover" data-placement="top" data-container="body" data-html="true" data-content=fave_info pod-name="{{ id }}" is_faved="{{ is_faved }}"

img.copy src="./images/copy-to-clipboard.png" data-clipboard-text="pod '{{ id }}', '~> {{ version }}'" data-toggle="popover" data-placement="top" data-container="body" data-html="true" data-content=popover_html


| {{#platform}} | {{#platform}}
span.os {{ platform }} span.os {{ platform }}
| {{/platform}} | {{/platform}}

p {{ summary }} p {{ summary }}
p.author {{ authors }} p.author {{ authors }}

div.actions.col-lg-4.col-sm-5.col-xs-12 div.actions.col-lg-4.col-sm-5.col-xs-12
div.action-wrapper div.action-wrapper
a href="{{ site_link }}" Site a href="{{ site_link }}" Site
a href="{{ docs_link }}" Docs a href="{{ docs_link }}" Docs
a href="{{ spec_link }}" Spec a href="{{ spec_link }}" Spec
Binary file added source/images/star-filled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/star-hollow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions source/javascripts/application.js
Expand Up @@ -7,6 +7,7 @@
*= require history.adapter.jquery.min.js *= require history.adapter.jquery.min.js
*= require picky.min.js *= require picky.min.js
*= require search.config.js *= require search.config.js
*= require cocoapush.js
*= require zero-clipboard.min.js *= require zero-clipboard.min.js
*= require has_flash.js *= require has_flash.js
*= require ICanHaz.js *= require ICanHaz.js
Expand All @@ -21,14 +22,14 @@ $(document).bind("touchmove", function(e){


$( document ).ready( function(){ $( document ).ready( function(){
$('.underscore a[data-toggle="tab"]').on('show.bs.tab', function (e) { $('.underscore a[data-toggle="tab"]').on('show.bs.tab', function (e) {

var index = $(e.target.parentElement).index() var index = $(e.target.parentElement).index()
var width = $(window).width(); var width = $(window).width();
var constant = (width < 768) ? 33: 40; var constant = (width < 768) ? 33: 40;
var percent = (index * constant).toString() var percent = (index * constant).toString()
$("#homepage-tab-indicator").css("margin-left", percent + "%"); $("#homepage-tab-indicator").css("margin-left", percent + "%");
}) })

if( hasFlash() ) { if( hasFlash() ) {
$("html").addClass("flash") $("html").addClass("flash")
} }
Expand Down
100 changes: 100 additions & 0 deletions source/javascripts/cocoapush.js
@@ -0,0 +1,100 @@
//singleton representing the CocoaPush webservice.
//If push notifications are not supported, returns 'NOT SUPPORTED'
//If push notifications have been requested and denied, returns 'NOT ALLOWED'
//Consumer of this singleton is responsible for updating UI in response to the former two cases
var CocoaPush = new function () {
this.enabled = true;

//param: callback taking permission data as parameter
//return: null
this.permissionData = function(cb) {
var permissionData = ('safari' in window && 'pushNotification' in window.safari) ? window.safari.pushNotification.permission('web.org.cocoapods.push') : { permission: 'denied', deviceToken: null };
if (permissionData.permission === 'default') {
// This is a new web service URL and its validity is unknown.
window.safari.pushNotification.requestPermission(
'https://localhost:3000/push', // The web service URL.
'web.org.cocoapods.push', // The Website Push ID.
{}, // Data that you choose to send to your server to help you identify the user.
function (permission) { // The callback function.
permissionData = permission; //update the object var with new info to fall through to bottom two cases
cb(permission);
}
);
} else {
cb(permissionData);
}
return;
};

this.pods = [];
var podsInitialized = false;
// get pods. takes a callback which has one parameter, the array of pods
this.getPods = function (cb) {
if (!podsInitialized) {
this.permissionData(function(permission) {
$.get("https://localhost:3000/push/v1/settingsForDeviceToken/" + permission.deviceToken, null, null, 'JSON')
.done(function(settings) {
CocoaPush.pods = settings["pods"];
podsInitialized = true;
cb(CocoaPush.pods);
})
.fail(function() {
cb(CocoaPush.pods);
});
});
} else {
cb(this.pods);
}
};

//function to upload new pod settings array, and keep state of CocoaPush consistent
//takes the array to upload, the array to store in case it fails, and a callback that is supplied with true or false depending on success or fail
function uploadPodSettings(cb, newPodArray, oldPodArray) {
CocoaPush.permissionData(function (permission) {
$.ajax("https://localhost:3000/push/v1/settingsForDeviceToken/" + permission.deviceToken, //send up and
{
data: JSON.stringify({"pods": newPodArray}),
type: 'POST',
processData: false,
error: function () {
CocoaPush.pods = oldPodArray;
cb(false);
},
success: function () {
CocoaPush.pods = newPodArray;
cb(true);
}
}
)
});
}

// add pod to remote webservice, update local cache
// takes the pod name as a string, and a callback receiving a boolean value indicating whether it was successfully stored
this.addPod = function (pod, cb) {
this.getPods(function(pods) {
if (pods.indexOf(pod) != -1) { //already present locally, so no worries
cb(true);
} else {
var newPodArray = CocoaPush.pods.slice(0);
newPodArray.push(pod);
uploadPodSettings(cb, newPodArray, CocoaPush.pods.slice(0));
}
})
};

// remove pod from CocoaPush, update local cache
// takes the pod name as a string, and a callback receiving a boolean value indicating whether it was successfully removed
this.removePod = function (pod, cb) {
this.getPods(function(pods) {
if (pods.indexOf(pod) == -1) {
cb(true);
} else {
var oldPodArray = CocoaPush.pods.slice(0);
var newPodArray = oldPodArray.filter(function (obj) { return (obj !== pod); });
uploadPodSettings(cb, newPodArray, oldPodArray);
}
})
}

};