From 31d33054ef5145b037c829f1ad551a0d5460d0b9 Mon Sep 17 00:00:00 2001 From: maxwell <maxwell@joindiaspora.com> Date: Wed, 17 Nov 2010 21:51:35 -0800 Subject: [PATCH] added jammit, now js and css compress for production --- .gitignore | 1 + Gemfile | 2 +- Gemfile.lock | 6 + app/helpers/application_helper.rb | 4 + app/views/aspects/manage.html.haml | 3 +- app/views/js/_websocket_js.haml | 1 - app/views/layouts/application.html.haml | 21 +-- config/assets.yml | 33 +++++ public/javascripts/publisher.js | 173 ------------------------ script/websocket_server.rb | 6 + 10 files changed, 58 insertions(+), 192 deletions(-) create mode 100644 config/assets.yml delete mode 100644 public/javascripts/publisher.js diff --git a/.gitignore b/.gitignore index 49b150d1d8..ab2b27011a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ public/stylesheets/ui.css # Uploded files and local files public/uploads/* +public/assets/* public/source.tar* tmp/**/* db/*.sqlite3 diff --git a/Gemfile b/Gemfile index dc93891245..3ee073d24e 100644 --- a/Gemfile +++ b/Gemfile @@ -46,7 +46,7 @@ gem 'carrierwave', :git => 'git://github.com/rsofaer/carrierwave.git' , :branch gem 'mini_magick' gem 'aws' gem 'fastercsv', :require => false - +gem 'jammit' group :test, :development do gem 'factory_girl_rails' gem 'ruby-debug19' if RUBY_VERSION.include? "1.9" diff --git a/Gemfile.lock b/Gemfile.lock index 57d5b53d42..d938b6b611 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -141,6 +141,7 @@ GEM uuidtools childprocess (0.1.4) ffi (~> 0.6.3) + closure-compiler (0.3.3) columnize (0.3.2) configuration (1.1.0) crack (0.1.8) @@ -188,6 +189,9 @@ GEM httparty (0.6.1) crack (= 0.1.8) i18n (0.4.2) + jammit (0.5.4) + closure-compiler (>= 0.1.0) + yui-compressor (>= 0.9.1) json (1.4.6) json_pure (1.4.6) launchy (0.3.7) @@ -345,6 +349,7 @@ GEM crack (>= 0.1.7) will_paginate (3.0.pre2) xml-simple (1.0.12) + yui-compressor (0.9.1) PLATFORMS ruby @@ -369,6 +374,7 @@ DEPENDENCIES fastercsv haml http_accept_language! + jammit jasmine! json launchy diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cade35c04f..67f78c42e9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,6 +5,10 @@ module ApplicationHelper @@youtube_title_cache = Hash.new("no-title") + def modern_browser? + false + end + def current_aspect?(aspect) !@aspect.is_a?(Symbol) && @aspect.id == aspect.id end diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index fc35f143e9..d41d34c0b3 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -3,8 +3,7 @@ -# the COPYRIGHT file. - content_for :head do - = javascript_include_tag 'aspect-edit.js' - = javascript_include_tag 'vendor/jquery-ui-1.8.6.custom.min' + = include_javascripts :aspects #section_header %h2=t('.manage_aspects') diff --git a/app/views/js/_websocket_js.haml b/app/views/js/_websocket_js.haml index 94e3e95915..c136805129 100644 --- a/app/views/js/_websocket_js.haml +++ b/app/views/js/_websocket_js.haml @@ -2,7 +2,6 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -= javascript_include_tag 'vendor/FABridge', 'vendor/swfobject', 'vendor/web_socket' :javascript WebSocket.__swfLocation = "#{javascript_path 'vendor/WebSocketMain.swf'}"; $(document).ready(function(){ diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1140f62885..d6780ecef8 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -9,29 +9,20 @@ = "#{current_user.real_name} | diaspora" if current_user %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ - = stylesheet_link_tag "blueprint/screen", :media => 'screen' = stylesheet_link_tag "blueprint/print", :media => 'print' + = include_stylesheets :default, :media => 'all' - = stylesheet_link_tag "application", "ui" - = stylesheet_link_tag "vendor/jquery.fancybox-1.3.1" - = stylesheet_link_tag "vendor/fileuploader" - = stylesheet_link_tag "vendor/tipsy" - if current_user %link{:rel => "alternate", :href => "#{current_user.public_url}", :type => "application/atom+xml", :title => "Public Diaspora Feed for #{current_user.real_name}"} - /= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" - = javascript_include_tag 'vendor/jquery144.min', 'rails' - = javascript_include_tag 'vendor/jquery.infieldlabel' - = javascript_include_tag 'vendor/jquery.tipsy' - - = javascript_include_tag 'vendor/fancybox/jquery.fancybox-1.3.1.pack' - = javascript_include_tag 'vendor/fileuploader' - - = javascript_include_tag 'view', 'image-picker', 'stream' - + = javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" + + = include_javascripts :main + - if current_user + = include_javascripts :flash_socket unless modern_browser? = render 'js/websocket_js' = csrf_meta_tag diff --git a/config/assets.yml b/config/assets.yml new file mode 100644 index 0000000000..54796cb103 --- /dev/null +++ b/config/assets.yml @@ -0,0 +1,33 @@ +javascripts: + flash_socket: + - public/javascripts/vendor/FABridge.js + - public/javascripts/vendor/swfobject.js + - public/javascripts/vendor/web_socket.js + main: + - public/javascripts/rails.js + - public/javascripts/vendor/jquery.infieldlabel.js + - public/javascripts/vendor/jquery.tipsy.js + - public/javascripts/vendor/fancybox/jquery.fancybox-1.3.1.pack.js + - public/javascripts/vendor/fileuploader.js + - public/javascripts/vendor/jquery_mobile_a2.min.js + - public/javascripts/view.js + - public/javascripts/image-picker.js + - public/javascripts/stream.js + mobile: + - public/javascripts/vendor/jquery-ui-1.8.6.custom.min.js + - public/javascripts/vendor/jquery_mobile_a2.min.js + + photo: + - public/javascripts/photo.js + - public/javascripts/image-picker.js + aspects: + - public/javascripts/vendor/jquery-ui-1.8.6.custom.min.js + - public/javascripts/aspect-edit.js + +stylesheets: + default: + - public/stylesheets/application.css + - public/stylesheets/ui.css + - public/stylesheets/vendor/jquery.fancybox-1.3.1.css + - public/stylesheets/vendor/fileuploader.css + - public/stylesheets/vendor/tipsy.css diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js deleted file mode 100644 index df8f3a1b41..0000000000 --- a/public/javascripts/publisher.js +++ /dev/null @@ -1,173 +0,0 @@ -/* Copyright (c) 2010, Diaspora Inc. This file is - * licensed under the Affero General Public License version 3 or later. See - * the COPYRIGHT file. - */ - -var Publisher = { - - initialize: function() { - $("ul .person").draggable({ - revert: true, - start: AspectEdit.startDrag, - drag: AspectEdit.duringDrag, - stop: AspectEdit.stopDrag - }); - - $(".aspect ul.dropzone").droppable({ - hoverClass: 'active', - drop: AspectEdit.onDropMove - }); - - $(".delete").live("click", AspectEdit.deletePerson); - $(".aspect h3").live('focus', AspectEdit.changeName); - }, - - startDrag: function() { - AspectEdit.animateImage($(this).children("img").first()); - $(".draggable_info").fadeIn(100); - }, - - animateImage: function(image) { - image.animate({'height':80, 'width':80, 'opacity':0.8}, 200); - image.tipsy("hide"); - }, - - duringDrag: function(event, ui) { - $(this).children("img").tipsy("hide"); //ensure this is hidden - }, - - stopDrag: function(event, ui) { - $(this).children("img").animate({'height':70, 'width':70, 'opacity':1}, 200); - $(".draggable_info").fadeOut(100); - }, - - onDropMove: function(event, ui) { - var dropzone = $(this); - var person = ui.draggable; - - if (person.hasClass('request')) { - $.ajax({ - type: "DELETE", - url: "/requests/" + person.attr('data-guid'), - data: {"accept" : true, "aspect_id" : dropzone.attr('data-aspect_id') }, - success: function(data) { - AspectEdit.decrementRequestsCounter(); - person.removeClass('request'); - } - }); - } - - if (dropzone.attr('data-aspect_id') != person.attr('data-aspect_id')) { - $.ajax({ - url: "/aspects/move_contact/", - data: {"person_id" : person.attr('data-guid'), - "from" : person.attr('data-aspect_id'), - "to" : { "to" : dropzone.attr('data-aspect_id') }}, - success: function(data) { - person.attr('data-aspect_id', dropzone.attr('data-aspect_id')); - }}); - } - - dropzone.closest("ul").append(person); - }, - - deletePersonFromAspect: function(person) { - - var person_id = person.attr('data-guid'); - - if( $(".person[data-guid='"+ person_id +"']").length == 1) { - alert("You can not remove the person from the last aspect"); - - } else { - if (!person.hasClass('request')) { - - $.ajax({ - type: "POST", - url: "/aspects/remove_from_aspect", - data:{ - 'person_id' : person_id, - 'aspect_id' : person.attr('data-aspect_id') } - }); - } - person.fadeOut(400, function() { - person.remove(); - }); - } - }, - - changeName: function() { - - var $this = $(this); - var id = $this.closest("li.aspect").attr("data-guid"); - var link = "/aspects/" + id; - - $this.keypress(function(e) { - if (e.which == 13) { - e.preventDefault(); - $this.blur(); - - //save changes - $.ajax({ - type: "PUT", - url: link, - data: {"aspect" : {"name" : $this.text() }} - }); - } - //update all other aspect links - $this.keyup(function(e) { - $("#aspect_nav a[href='" + link + "']").text($this.text()); - }); - }); - }, - - deletePerson: function() { - var person = $(this).closest("li.person"); - - if (person.hasClass('request')) { - if (confirm("Ignore request?")) { - var request_id = person.attr("data-guid"); - - $.ajax({ - type: "DELETE", - url: "/requests/" + request_id, - success: function () { - AspectEdit.decrementRequestsCounter(); - } - }); - } - } else { - if (confirm("Also remove this person from all aspects?")) { - var person_id = $(this).closest("li.person").attr('data-guid'); - - $.ajax({ - type: "DELETE", - url: "/people/" + person_id, - success: function() { - $(".person[data-guid='"+ person_id +"']").fadeOut(200); - } - }); - } else { - AspectEdit.deletePersonFromAspect(person); - } - } - }, - - decrementRequestsCounter: function() { - var $new_requests = $(".new_requests"); - var request_html = $new_requests.html(); - var old_request_count = request_html.match(/\d+/); - - if (old_request_count == 1) { - $new_requests.html( - request_html.replace(/ \(\d+\)/, '') - ); - } else { - $new_requests.html( - request_html.replace(/\d+/, old_request_count - 1) - ); - } - } -}; - -$(document).ready(Publisher.initialize); - diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 129d977793..ddfd706030 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -41,8 +41,14 @@ def process_message end end +def package_js + require 'jammit' + Jammit.package! +end + begin EM.run { + package_js Diaspora::WebSocket.initialize_channels socket_params = { :host => APP_CONFIG[:socket_host], -- GitLab