Skip to content

Commit

Permalink
Merge pull request #61 from osbridge/asset_pipeline
Browse files Browse the repository at this point in the history
Use the Rails asset pipeline to process JS/CSS assets
  • Loading branch information
reidab committed Dec 3, 2013
2 parents 24dba04 + 4fc2fd5 commit 545479c
Show file tree
Hide file tree
Showing 138 changed files with 608 additions and 10,480 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
/public/themes/*
/rerun.txt
/tags
/public/stylesheets/common_css/*
/app/assets/stylesheets/common_css/*
/tmp/*
.ruby-version
.ruby-gemset
credentials.yml
.bundle
.sass-cache/
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ gem 'memcache-client'
gem "dynamic_form"
gem 'rinku', :require => 'rails_rinku'

# Assets
gem 'jquery-rails'
gem 'sass-rails', " ~> 3.2.0"
gem 'coffee-rails', " ~> 3.2.0"
gem 'uglifier'

group :production do
gem 'exception_notification'
end
Expand Down
23 changes: 23 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ GEM
cocaine (0.5.3)
climate_control (>= 0.0.3, < 1.0)
coderay (1.1.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.4.0)
color (1.4.2)
columnize (0.3.6)
comma (3.2.0)
Expand Down Expand Up @@ -113,6 +120,7 @@ GEM
exception_notification (4.0.1)
actionmailer (>= 3.0.4)
activesupport (>= 3.0.4)
execjs (2.0.2)
factory_girl (4.3.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.3.0)
Expand Down Expand Up @@ -140,6 +148,9 @@ GEM
hike (1.2.3)
i18n (0.6.5)
journey (1.0.4)
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
launchy (2.4.2)
addressable (~> 2.3)
Expand Down Expand Up @@ -249,6 +260,11 @@ GEM
rspec-mocks (~> 2.14.0)
ruby-openid (2.3.0)
ruby-rc4 (0.1.5)
sass (3.2.12)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
Expand All @@ -272,6 +288,9 @@ GEM
polyglot (>= 0.3.1)
ttfunk (1.0.3)
tzinfo (0.3.38)
uglifier (2.2.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
valise (1.0.0)
xml-simple (1.1.2)
xpath (2.0.0)
Expand All @@ -289,6 +308,7 @@ DEPENDENCIES
capistrano (~> 2.15.0)
capistrano-ext
capybara
coffee-rails (~> 3.2.0)
color
comma (~> 3.0)
coveralls
Expand All @@ -301,6 +321,7 @@ DEPENDENCIES
gchartrb (~> 0.8.0)
guard-rspec
hashery
jquery-rails
launchy
memcache-client
mysql2
Expand All @@ -316,6 +337,8 @@ DEPENDENCIES
rinku
rspec-rails
rwikibot!
sass-rails (~> 3.2.0)
simplecov
sqlite3
uglifier
vpim-rails!
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
18 changes: 18 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//= require jquery
//= require jquery_ujs
//= require jquery-migrate-1.2.1
//= require jquery.scrollTo
//= require jquery.localScroll
//= require farbtastic
//= require audiojs/audio.min
//= require bootstrap
//= require base
//= require util
//= require favorites
//= require menu
//= require persona
//= require proposals
//= require schedule
//= require spinner

/*===[ fin ]==========================================================*/
15 changes: 15 additions & 0 deletions app/assets/javascripts/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Set up jQuery ajax request to include the CSRF token
$.ajaxSetup({
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
}
});

// app object used to expose rails variables to javascript
var app = new Object;

// Is a user logged in?
function logged_in() {
return !app.current_user == false;
}

76 changes: 76 additions & 0 deletions app/assets/javascripts/favorites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*---[ user favorites ]----------------------------------------------*/

// Return the proposal_id (e.g., "266") bound to a user favorite control, which
// is a JQuery +element+ object.
var proposal_id_pattern = /^favorite_(\d+)$/;
function proposal_id_for(element) {
var klasses = element.attr('class').split(' ');
for (i in klasses) {
klass = klasses[i];
var matcher = klass.match(proposal_id_pattern);
if (matcher) {
return matcher[1];
}
}
return null;
}

function bind_user_favorite_controls() {
$('.favorite').each(function() {
if( !logged_in() ) {
$(this).addClass('disabled');
}
}).click(function(event) {
target = $(this);

if( !logged_in() ) {
alert("You must be logged in to add items to your favorites.");
} else {
target.addClass('working');

mode = target.hasClass('checked') ? 'remove' : 'add';
proposal_id = proposal_id_for(target);

$.ajax({
'type': 'PUT',
'url': app.favorites_path + '/modify.json',
'dataType': 'json',
'data': {
'authenticity_token': app.authenticity_token,
'proposal_id': proposal_id,
'mode': mode
},
'complete': function(request,status){
target.removeClass('working');
},
'success': function(data, status) {
nodes = $('.favorite_'+proposal_id);
switch(mode) {
case 'add':
nodes.addClass('checked');
break;
case 'remove':
nodes.removeClass('checked');
break;
}
},
'error': function(request, status, error) {
alert('There was an error! Status: ' + status + ". Error: " + error);
}
});
}
return false;
});
}

function populate_user_favorites() {
if( logged_in() ) {
$.getJSON( app.favorites_path + '.json?join=1',
function(data) {
jQuery.each( data, function(i, proposal_id) {
$( '.favorite_' + proposal_id ).addClass('checked');
});
}
)
}
}
2 changes: 2 additions & 0 deletions app/assets/javascripts/ie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//= require html5shiv
//= require respond.min
47 changes: 47 additions & 0 deletions app/assets/javascripts/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Highlight the active menu item. Works by adding an 'active' class to a
// menu item based on the current URL. Status can be reported via 'console.log'
// if the JavaScript interpreter provides one.
function activate_menu_item () {
var should_log = false;

var debug = function (message) {
if(should_log && (typeof console == "object")) console.log('activate_menu_item: ' + message);
};

// Names of menu item classes and regexp fragments that activate them:
var menu_items_and_activation_patterns = [
["bofs", "events/.+?bof/.+"],
["proposals_or_sessions", "(events/.+?/)?(proposals|sessions)"],
["schedule", "events/.+?/schedule"],
["speakers", "events/.+?/speakers"]
];

// Get the URL pathname from the browser:
var pathname = window.location.pathname;
// Or set a specific one when developing:
// var pathname = "/events/2009/speakers";
var menu_item_matched = null;

// Match the first pattern:
for (var i in menu_items_and_activation_patterns) {
var menu_item = menu_items_and_activation_patterns[i][0];
var pattern = menu_items_and_activation_patterns[i][1];
var re = new RegExp("^/" + pattern + "(?:/.*)?$");
if (pathname.match(re)) {
menu_item_matched = menu_item;
debug('Matched menu item "'+menu_item+'" based on pattern: '+ pattern);
break;
}
}

// Activate the menu item:
if (menu_item_matched) {
$('#header .'+menu_item_matched).parent().addClass('active');
} else {
debug("No match for pathname: " + pathname);
}
}

$(document).ready(function () {
activate_menu_item();
});
10 changes: 10 additions & 0 deletions app/assets/javascripts/persona.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function personaLogin() {
navigator.id.get(function(assertion) {
if (assertion) {
$('#persona_form input[name=assertion]').val(assertion);
$('#persona_form').submit();
} else {
window.location = "#{failure_path}"
}
});
}

0 comments on commit 545479c

Please sign in to comment.