Skip to content

Commit

Permalink
[webui] Add a new rake task to mimize static assets
Browse files Browse the repository at this point in the history
Initially, only minimize JavaScript code (with UglifyJS) and replace
all javascript_include_tag spead across our views with one in the
base layout.
  • Loading branch information
saschpe committed Mar 30, 2012
1 parent b7c776b commit 03e6d9f
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 855 deletions.
3 changes: 0 additions & 3 deletions src/webui/app/views/configuration/connect_instance.html.erb
@@ -1,6 +1,3 @@
<%= javascript_include_tag :defaults %>
<% content_for :head_javascript do %>
function useOpenSUSE(){
document.getElementById('name').value = "openSUSE.org";
Expand Down
1 change: 0 additions & 1 deletion src/webui/app/views/home/my_work.html.erb
Expand Up @@ -4,7 +4,6 @@
<% content_for :content_for_head do %>
<%= stylesheet_link_tag 'jquery.tooltip' %>
<% end %>
<%= javascript_include_tag 'jquery.tablesorter', 'jquery.tooltip.min' %>

<h3><%= @pagetitle %></h3>

Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/main/index.rhtml
@@ -1,8 +1,6 @@
<% @pagetitle = 'Welcome' %>
<% @layouttype = 'custom' %>

<%= javascript_include_tag 'jquery.flot.min' %>

<div class="grid_11 alpha">
<div class="box box-shadow">
<h1 class="mainhead">Welcome to <%= @configuration['title'] %></h1>
Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/monitor/_building_table.rhtml
Expand Up @@ -4,8 +4,6 @@
<p class="info filtered_by">Currently active filter <strong><%= h(@project_filter) %></strong> [<%= link_to 'Remove Filter', :controller => 'monitor', :action => :old %>]</p>
<% end %>
<%= javascript_include_tag 'jquery.tablesorter' %>
<% content_for :ready_function do %>
// call the tablesorter plugin
$(".tablesorter").tablesorter({
Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/monitor/_events.html.erb
@@ -1,5 +1,3 @@
<%= javascript_include_tag 'jquery.flot.min', 'jquery.flot.stack.min' %>

<h2>Statistical Plots</h2>

<div class="grid_7 prefix_1 alpha" >
Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/package/_submit_request_dialog.rhtml
@@ -1,5 +1,3 @@
<%= javascript_include_tag 'jquery.tablesorter' %>
<% javascript_tag do %>
function updateSupersedeAndDevelPackageDisplay() {
if ($('#targetproject')[0].value.length > 0) {
Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/package/files.html.erb
Expand Up @@ -3,8 +3,6 @@
<%= render :partial => "tabs" %>
<%= javascript_include_tag 'jquery.tablesorter' %>
<% content_for :head_javascript do %>
function insertRow() {
var name = document.getElementById('add_new_parameter').value;
Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/project/maintained_projects.html.erb
Expand Up @@ -3,8 +3,6 @@
<%= render :partial => 'tabs' %>

<%= javascript_include_tag 'jquery.tablesorter' %>

<h3>Maintained Projects</h3>
<% if @maintained_projects.length > 0 %>
<table cellspacing='1' id="maintained_projects_table" class="tablesorter">
Expand Down
1 change: 0 additions & 1 deletion src/webui/app/views/project/maintenance_incidents.html.erb
Expand Up @@ -6,7 +6,6 @@
<% content_for :content_for_head do %>
<%= stylesheet_link_tag 'jquery.tooltip' %>
<% end %>
<%= javascript_include_tag 'jquery.tablesorter', 'jquery.tooltip.min', 'jquery.expander.min' %>

<h3><%= @pagetitle %></h3>

Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/project/status.rhtml
Expand Up @@ -3,8 +3,6 @@
project_bread_crumb 'Status'
-%>
<%= javascript_include_tag 'jquery.tablesorter' %>
<% content_for :ready_function do %>
$('.tablesorter').tablesorter({widgets: ['zebra']});
<% end %>
Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/request/show.html.erb
Expand Up @@ -2,8 +2,6 @@
<% @layouttype = 'custom' %>
<% @crumb_list = [link_to('Requests', :controller => :home, :action => :requests), @id] %>
<%= javascript_include_tag 'jquery.expander.min' %>
<% content_for :ready_function do %>
$('#expandable_comment').expander({slicePoint: 320, expandText: '[+]', expandPrefix: ' ', userCollapseText: '[-]',});
<% end %>
Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/shared/_editor.html.erb
Expand Up @@ -5,7 +5,6 @@
<% no_border ||= false %>
<% content_for :content_for_head do %>
<%= stylesheet_link_tag 'cm2/suse' %>
<style type="text/css">
<% if no_border %>
.CodeMirror {
Expand All @@ -21,7 +20,6 @@
}
</style>
<% end %>
<%= javascript_include_tag 'cm2/codemirror', 'cm2/codemirror-ui', "cm2/mode/#{mode}" %>
<% uid = rand().to_s()[2..-1] # unique id to allow including multiple editors %>
<textarea id="editor_<%= uid %>" name="editor_<%= uid %>" style="display: none;" rows="0" cols="0"><%= force_utf8_and_transform_nonprintables(text) %></textarea>
Expand Down
2 changes: 0 additions & 2 deletions src/webui/app/views/shared/_involved_users.html.erb
@@ -1,5 +1,3 @@
<%= javascript_include_tag 'jquery.tablesorter' %>
<% if @user and @user.is_maintainer?(@project, @package) %>
<% content_for :head_javascript do %>
function change_role() {
Expand Down
1 change: 0 additions & 1 deletion src/webui/app/views/shared/_select_requests.html.erb
Expand Up @@ -3,7 +3,6 @@
<% content_for :content_for_head do %>
<%= stylesheet_link_tag 'jquery.tooltip' %>
<% end %>
<%= javascript_include_tag 'jquery.tablesorter', 'jquery.tooltip.min' %>
<% content_for :head_javascript do %>
function updateRequestDisplay() {
Expand Down
5 changes: 2 additions & 3 deletions src/webui/app/views/vendor/bento/layouts/application.html.erb
Expand Up @@ -15,12 +15,11 @@

<%= stylesheet_link_tag "/themes/bento/css/style", :media => "screen", :title => "Normal" %>
<%= stylesheet_link_tag "style", :media => "screen" %>
<%= stylesheet_link_tag 'cm2/suse' %>
<%= yield :content_for_head %>
<%= javascript_include_tag 'jquery-1.7.1.min', 'jquery-ui-1.8.18.custom.min', 'jrails', '/themes/bento/js/script', 'application', :cache => 'layout-squashed' %>
<%= javascript_include_tag 'obs.min' %>
<% javascript_tag do %>
<%= yield :head_javascript %>
<% if CONFIG['theme'] == 'bento' %>
Expand Down
107 changes: 107 additions & 0 deletions src/webui/lib/tasks/minimize.rake
@@ -0,0 +1,107 @@
require 'tempfile'

# Beware, order matters:
JAVASCRIPT_FILENAMES = [
'public/javascripts/jquery-1.7.1.min.js',
'public/javascripts/jquery.expander.min.js',
'public/javascripts/jquery.flot.min.js',
'public/javascripts/jquery.flot.stack.min.js',
#'public/javascripts/jquery.mobile-1.0rc2.min.js',
'public/javascripts/jquery.tablesorter.js',
'public/javascripts/jquery.tooltip.min.js',
'public/javascripts/jquery-ui-1.8.18.custom.min.js',
'public/javascripts/jrails.js',
'public/themes/bento/js/script.js',
'public/javascripts/application.js',
'public/javascripts/cm2/codemirror.js',
'public/javascripts/cm2/codemirror-ui-find.js',
'public/javascripts/cm2/codemirror-ui.js',
'public/javascripts/cm2/mode/changes.js',
'public/javascripts/cm2/mode/clike.js',
'public/javascripts/cm2/mode/clojure.js',
'public/javascripts/cm2/mode/coffeescript.js',
'public/javascripts/cm2/mode/css.js',
'public/javascripts/cm2/mode/diff.js',
#'public/javascripts/cm2/mode/ecl.js',
#'public/javascripts/cm2/mode/gfm.js',
'public/javascripts/cm2/mode/go.js',
'public/javascripts/cm2/mode/groovy.js',
'public/javascripts/cm2/mode/haskell.js',
'public/javascripts/cm2/mode/htmlembedded.js',
'public/javascripts/cm2/mode/htmlmixed.js',
'public/javascripts/cm2/mode/javascript.js',
'public/javascripts/cm2/mode/jinja2.js',
'public/javascripts/cm2/mode/less.js',
'public/javascripts/cm2/mode/lua.js',
'public/javascripts/cm2/mode/markdown.js',
'public/javascripts/cm2/mode/mysql.js',
#'public/javascripts/cm2/mode/ntriples.js',
'public/javascripts/cm2/mode/pascal.js',
'public/javascripts/cm2/mode/perl.js',
'public/javascripts/cm2/mode/php.js',
#'public/javascripts/cm2/mode/plsql.js',
'public/javascripts/cm2/mode/prjconf.js',
'public/javascripts/cm2/mode/properties.js',
'public/javascripts/cm2/mode/python.js',
'public/javascripts/cm2/mode/r.js',
'public/javascripts/cm2/mode/rst.js',
'public/javascripts/cm2/mode/ruby.js',
#'public/javascripts/cm2/mode/rust.js',
'public/javascripts/cm2/mode/scheme.js',
'public/javascripts/cm2/mode/smalltalk.js',
#'public/javascripts/cm2/mode/sparql.js',
'public/javascripts/cm2/mode/spec.js',
#'public/javascripts/cm2/mode/stex.js',
#'public/javascripts/cm2/mode/tiddlywiki.js',
#'public/javascripts/cm2/mode/velocity.js',
#'public/javascripts/cm2/mode/verilog.js',
'public/javascripts/cm2/mode/xml.js',
'public/javascripts/cm2/mode/xmlpure.js',
'public/javascripts/cm2/mode/yaml.js',
]

# Beware, order matters:
CSS_FILENAMES = [
'public/themes/bento/css/reset.css',
'public/themes/bento/css/960.css',
'public/themes/bento/css/base.css',
'public/themes/bento/css/base.fluid.fix.css',
'public/themes/bento/css/grid.css',
'public/themes/bento/css/print.css',
'public/themes/bento/css/style.css',
#'public/themes/bento/css/style.fluid.css',
#'public/themes/tumblr-bento/html/style.css',
'public/stylesheets/style.css',
'public/stylesheets/dialog.css',
'public/stylesheets/monitor.css',
'public/stylesheets/package.css',
'public/stylesheets/project.css',
#'public/stylesheets/jquery.mobile-1.0rc2.min.css',
'public/stylesheets/jquery.tooltip.css',
'public/stylesheets/cm2/suse.css',
#'public/stylesheets/style.mobile.css',
]

namespace :minimize do

desc 'Minimize JavaScript with UglifyJS'
task :js do
# UglifyJS only accepts one input file, thus put everything into one big blob:
tmpfile = Tempfile.new('ugly_js')
JAVASCRIPT_FILENAMES.each do |js_filename|
puts "Minify JS file '#{js_filename}'"
File.open(js_filename, 'r') do |js_file|
js_file.each { |line| tmpfile.write(line) }
end
end
tmpfile.close
system("uglifyjs -v #{tmpfile.path} > public/javascripts/obs.min.js")
tmpfile.unlink
end

desc 'Minimize CSS'
task :css do
#TODO
end

end
826 changes: 0 additions & 826 deletions src/webui/public/javascripts/layout-squashed.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/webui/public/javascripts/obs.min.js

Large diffs are not rendered by default.

0 comments on commit 03e6d9f

Please sign in to comment.