Commit 41803288364ec560da9d01b0b3727d0570f5996a

Authored by Braulio Bhavamitra
1 parent 074c6c08

Enable asset pipeline

Gemfile
... ... @@ -20,6 +20,11 @@ gem 'locale', '~> 2.0.5'
20 20 gem 'whenever', :require => false
21 21 gem 'eita-jrails', '>= 0.9.5', :require => 'jrails'
22 22  
  23 +group :assets do
  24 + gem 'uglifier', '>= 1.0.3'
  25 + gem 'sass-rails'
  26 +end
  27 +
23 28 group :production do
24 29 gem 'dalli', '~> 2.7.0'
25 30 end
... ...
app/assets/designs/icons 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../../../public/designs/icons
0 2 \ No newline at end of file
... ...
app/assets/designs/themes 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../../../public/designs/themes
0 2 \ No newline at end of file
... ...
app/assets/images 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../../public/images
0 2 \ No newline at end of file
... ...
app/assets/javascripts 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../../public/javascripts
0 2 \ No newline at end of file
... ...
app/assets/plugins 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../../public/plugins
0 2 \ No newline at end of file
... ...
app/assets/stylesheets 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../../public/stylesheets
0 2 \ No newline at end of file
... ...
app/helpers/application_helper.rb
... ... @@ -919,18 +919,6 @@ module ApplicationHelper
919 919 end
920 920 end
921 921  
922   - def icon_theme_stylesheet_path
923   - icon_themes = []
924   - theme_icon_themes = theme_option(:icon_theme) || []
925   - for icon_theme in theme_icon_themes do
926   - theme_path = "/designs/icons/#{icon_theme}/style.css"
927   - if File.exists?(Rails.root.join('public', theme_path[1..-1]))
928   - icon_themes << theme_path
929   - end
930   - end
931   - icon_themes
932   - end
933   -
934 922 def page_title
935 923 CGI.escapeHTML(
936 924 (@page ? @page.title + ' - ' : '') +
... ...
app/helpers/layout_helper.rb
... ... @@ -28,12 +28,12 @@ module LayoutHelper
28 28 end
29 29  
30 30 def noosfero_javascript
31   - plugins_javascripts = @plugins.map { |plugin| [plugin.js_files].flatten.map { |js| plugin.class.public_path(js) } }.flatten
  31 + plugins_javascripts = @plugins.map { |plugin| [plugin.js_files].flatten.map { |js| plugin.class.public_path(js, true) } }.flatten
32 32  
33 33 output = ''
34 34 output += render 'layouts/javascript'
35 35 unless plugins_javascripts.empty?
36   - output += javascript_include_tag plugins_javascripts, :cache => "cache/plugins-#{Digest::MD5.hexdigest plugins_javascripts.to_s}"
  36 + output += javascript_include_tag *plugins_javascripts
37 37 end
38 38 output += theme_javascript_ng.to_s
39 39 output += javascript_tag 'render_all_jquery_ui_widgets()'
... ... @@ -42,16 +42,6 @@ module LayoutHelper
42 42 end
43 43  
44 44 def noosfero_stylesheets
45   - standard_stylesheets = [
46   - 'application',
47   - 'search',
48   - 'colorbox',
49   - 'selectordie',
50   - 'inputosaurus',
51   - 'chat',
52   - 'selectordie-theme',
53   - pngfix_stylesheet_path,
54   - ] + tokeninput_stylesheets
55 45 plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin|
56 46 plugin.class.public_path('style.css')
57 47 }
... ... @@ -59,13 +49,13 @@ module LayoutHelper
59 49 global_css_at_fs = Rails.root.join 'public' + global_css_pub
60 50  
61 51 output = []
62   - output << stylesheet_link_tag(standard_stylesheets, :cache => 'cache/application')
  52 + output << stylesheet_link_tag('application')
63 53 output << stylesheet_link_tag(template_stylesheet_path)
64   - output << stylesheet_link_tag(icon_theme_stylesheet_path)
  54 + output << stylesheet_link_tag(*icon_theme_stylesheet_path)
65 55 output << stylesheet_link_tag(jquery_ui_theme_stylesheet_path)
66 56 unless plugins_stylesheets.empty?
67 57 cacheid = "cache/plugins-#{Digest::MD5.hexdigest plugins_stylesheets.to_s}"
68   - output << stylesheet_link_tag(plugins_stylesheets, :cache => cacheid)
  58 + output << stylesheet_link_tag(*plugins_stylesheets, cache: cacheid)
69 59 end
70 60 if File.exists? global_css_at_fs
71 61 output << stylesheet_link_tag(global_css_pub)
... ... @@ -74,14 +64,6 @@ module LayoutHelper
74 64 output.join "\n"
75 65 end
76 66  
77   - def pngfix_stylesheet_path
78   - 'iepngfix/iepngfix.css' #TODO: deprecate it
79   - end
80   -
81   - def tokeninput_stylesheets
82   - ['token-input', 'token-input-facebook', 'token-input-mac', 'token-input-facet']
83   - end
84   -
85 67 def noosfero_layout_features
86 68 render :file => 'shared/noosfero_layout_features'
87 69 end
... ... @@ -99,7 +81,7 @@ module LayoutHelper
99 81 icon_themes = []
100 82 theme_icon_themes = theme_option(:icon_theme) || []
101 83 for icon_theme in theme_icon_themes do
102   - theme_path = "/designs/icons/#{icon_theme}/style.css"
  84 + theme_path = "designs/icons/#{icon_theme}/style.css"
103 85 if File.exists?(Rails.root.join('public', theme_path))
104 86 icon_themes << theme_path
105 87 end
... ... @@ -112,7 +94,7 @@ module LayoutHelper
112 94 end
113 95  
114 96 def theme_stylesheet_path
115   - theme_path + '/style.css'
  97 + "/assets#{theme_path}/style.css"
116 98 end
117 99  
118 100 def layout_template
... ...
app/helpers/macros_helper.rb
... ... @@ -42,7 +42,9 @@ module MacrosHelper
42 42 [macro.configuration[:js_files]].flatten.map { |js| plugins_javascripts << macro.plugin.public_path(js) }
43 43 end
44 44 end
45   - javascript_include_tag(plugins_javascripts, :cache => 'cache/plugins-' + Digest::MD5.hexdigest(plugins_javascripts.to_s)) unless plugins_javascripts.empty?
  45 + unless plugins_javascripts.empty?
  46 + javascript_include_tag *plugins_javascripts
  47 + end
46 48 end
47 49  
48 50 def macro_css_files
... ...
app/views/layouts/_javascript.html.erb
1   -<%= javascript_include_tag 'jquery-2.1.1.min', 'jquery-migrate-1.2.1', 'jrails', 'rails.js',
2   - 'jquery.cycle.all.min.js', 'jquery.colorbox-min.js',
3   - 'jquery-ui-1.10.4/js/jquery-ui-1.10.4.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery-validation/jquery.validate',
4   - 'jquery.cookie', 'jquery.ba-bbq.min.js', 'reflection', 'jquery.tokeninput', 'jquery.typewatch', 'jquery.textchange',
5   - 'jquery-timepicker-addon/dist/jquery-ui-timepicker-addon', 'inputosaurus.js', 'select-or-die/_src/selectordie',
6   - # noosfero libraries
7   - 'application.js', 'modal.js',
8   - 'add-and-join', 'report-abuse', 'catalog', 'manage-products', 'autogrow',
9   - :cache => 'cache/application' %>
  1 +<%= javascript_include_tag 'application.js' %>
10 2  
11 3 <% language = FastGettext.locale %>
12 4 <% %w{messages methods}.each do |type| %>
... ...
app/views/layouts/application.html.erb
... ... @@ -21,7 +21,7 @@
21 21 import_controller_stylesheets(:themed_source => true)
22 22 %>
23 23 <%= stylesheet_link_tag template_stylesheet_path %>
24   - <%= stylesheet_link_tag icon_theme_stylesheet_path %>
  24 + <%= stylesheet_link_tag *icon_theme_stylesheet_path %>
25 25 <%= stylesheet_link_tag jquery_ui_theme_stylesheet_path %>
26 26  
27 27 <%# Add custom tags/styles/etc via content_for %>
... ...
app/views/layouts/chat.html.erb 0 → 100644
... ... @@ -0,0 +1,64 @@
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= html_language %>" lang="<%= html_language %>">
  3 + <head>
  4 + <title><%= h page_title %></title>
  5 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6 + <meta name="description" content="<%= @environment.name %>" />
  7 + <link rel="shortcut icon" href="<%= image_path(theme_favicon) %>" type="image/x-icon" />
  8 + <%= noosfero_javascript %>
  9 + <%= javascript_include_tag 'jquery.scrollabletab', 'strophejs-1.0.1/strophe', 'jquery.emoticon', '../designs/icons/pidgin/emoticons.js', 'ba-linkify', 'jquery.ba-hashchange', 'jquery.sound', 'chat' %>
  10 + <%= noosfero_stylesheets %>
  11 + <%= stylesheet_link_tag *icon_theme_stylesheet_path %>
  12 + <%= stylesheet_link_tag theme_stylesheet_path %>
  13 + <%= stylesheet_link_tag jquery_ui_theme_stylesheet_path %>
  14 + <script type='text/javascript'>
  15 + var $presence_status_label = {
  16 + chat: '<%= _('Online') %>',
  17 + dnd: '<%= _('Busy') %>',
  18 + '': '<%= _('Offline') %>'
  19 + };
  20 + var $own_name = '<%= user.name %>';
  21 + var $starting_chat_notice = '<%= _("starting chat with %{name}") %>';
  22 + var $muc_domain = '<%= "conference.#{environment.default_hostname}" %>';
  23 + var $user_unavailable_error = '<%= _("<strong>ooops!</strong> The message could not be sent because the user is not online") %>';
  24 + var $update_presence_status_every = <%= User.expires_chat_status_every.minutes %>;
  25 + var $balloon_template = '<div data-who="%{who}" class="message %{who}"><img class="avatar" src="%{avatar_url}"/><% comment_balloon do %><h5 class="%{who}-name">%{name}</h5><span class="time">%{time}</span><p>%{message}</p><% end %></div>';
  26 + </script>
  27 + </head>
  28 + <body id='chat'>
  29 + <div id='title-bar'>
  30 + <h1 class='title'><%= _("%s - Friends online (<span id='friends-online'>%d</span>)") % [h(page_title), 0] %></h1>
  31 + </div>
  32 + <div id='buddy-list'>
  33 + <div id='environment-logo'>
  34 + <%= image_tag "#{theme_path}/images/thin-logo.png", :title => environment.name, :alt => environment.name %>
  35 + </div>
  36 + <div class='toolbar'>
  37 + <div id='user-status'><%= user_status_menu('icon-menu-offline', _('Offline')) %></div>
  38 + <div class='dialog-error' style='display: none'></div>
  39 + </div>
  40 + <ul class='buddy-list'>
  41 + <!-- <li class='offline'><a id='%{jid_id}' class='icon-menu-offline-11' href='#'>%{name}</a></li> -->
  42 + </ul>
  43 + </div>
  44 + <div id='chat-window' class='tabs-bottom'>
  45 + <div id='tabs'>
  46 + <ul>
  47 + <!-- <li class="tab"><a href="#{href}">#{label}</a></li> -->
  48 + </ul>
  49 + </div>
  50 + <!--
  51 + <div id='#conversation-%{jid_id}' class='conversation'>
  52 + <div class='history'>
  53 + <div class='message %{who}'><img class='avatar' src='%{avatar_url}' /><h5 class='%{who}-info'>%{name}</h5><span class='time'>%{time}</span><p>%{message}</p></div>
  54 + </div>
  55 + <div class='input-div'>
  56 + <div class='icon-chat'></div>
  57 + <textarea type='textarea' data-to='%{jid}'></textarea>
  58 + </div>
  59 + </div>
  60 + -->
  61 + </div>
  62 + <%= yield %>
  63 + </body>
  64 +</html>
... ...
app/views/layouts/slideshow.html.erb
... ... @@ -11,7 +11,7 @@
11 11 %></title>
12 12  
13 13 <%= stylesheet_import "slideshow" %>
14   - <%= javascript_include_tag 'jquery-2.1.1.min', 'sliderjs', 'pikachoose', :cache => 'cache/slideshow' %>
  14 + <%= javascript_include_tag 'jquery-2.1.1.min', 'sliderjs', 'pikachoose' %>
15 15 <script type="text/javascript">
16 16 $(document).ready(function (){
17 17 $("#slideshow").PikaChoose({
... ...
config/application.rb
... ... @@ -88,11 +88,25 @@ module Noosfero
88 88 config.active_record.whitelist_attributes = true
89 89  
90 90 # Enable the asset pipeline
91   - config.assets.enabled = false
  91 + config.assets.enabled = true
  92 +
  93 + # don't let rails prepend app/assets to config.assets.paths
  94 + # as we are doing it
  95 + config.paths['app/assets'] = ''
  96 +
  97 + config.assets.paths =
  98 + Dir.glob("app/assets/plugins/*/{,stylesheets,javascripts}") +
  99 + Dir.glob("app/assets/{,stylesheets,javascripts}") +
  100 + # no precedence over core
  101 + Dir.glob("app/assets/designs/{icons,themes,user_themes}/*")
92 102  
93 103 # Version of your assets, change this if you want to expire all your assets
94 104 config.assets.version = '1.0'
95 105  
  106 + config.sass.preferred_syntax = :scss
  107 + config.sass.cache = true
  108 + config.sass.line_comments = false
  109 +
96 110 def noosfero_session_secret
97 111 require 'fileutils'
98 112 target_dir = File.join(File.dirname(__FILE__), '../tmp')
... ...
config/environments/production.rb
... ... @@ -14,12 +14,19 @@ Noosfero::Application.configure do
14 14 # Compress JavaScripts and CSS
15 15 config.assets.compress = true
16 16  
17   - # Don't fallback to assets pipeline if a precompiled asset is missed
18   - config.assets.compile = false
19   -
20 17 # Generate digests for assets URLs
21 18 config.assets.digest = true
22 19  
  20 + # pre-compile every asset
  21 + config.assets.precompile = Dir.glob("app/assets/**/*").map do |file|
  22 + next unless File.exists?(file) and File.file?(file)
  23 + File.basename file
  24 + end.compact
  25 +
  26 + # fallback to assets pipeline if a precompiled asset is missed
  27 + config.assets.digest = true
  28 + config.assets.cache_store = :assets_live_compile_store
  29 +
23 30 # Defaults to nil and saved in location specified by config.assets.prefix
24 31 # config.assets.manifest = YOUR_PATH
25 32  
... ...
config/routes.rb
... ... @@ -52,7 +52,6 @@ Noosfero::Application.routes.draw do
52 52  
53 53 # categories index
54 54 match 'cat/*category_path' => 'search#category_index', :as => :category
55   - match 'assets/:asset(/*category_path)' => 'search#assets', :as => :assets
56 55 # search
57 56 match 'search(/:action(/*category_path))', :controller => 'search'
58 57  
... ...
gitignore.example
... ... @@ -22,8 +22,12 @@ public/user_themes
22 22 public/designs/themes/default
23 23 public/designs/themes/*
24 24 public/designs/icons/default
  25 +
  26 +public/assets
  27 +.sass-cache
25 28 public/javascripts/cache*
26 29 public/stylesheets/cache*
  30 +
27 31 public/plugins
28 32 db/development.db
29 33 db/production.db
... ...
lib/noosfero/plugin.rb
... ... @@ -150,8 +150,8 @@ class Noosfero::Plugin
150 150 self.name.underscore.gsub('_plugin','')
151 151 end
152 152  
153   - def public_path(file = '')
154   - File.join('/plugins', public_name, file)
  153 + def public_path file = '', relative=false
  154 + File.join "#{if relative then '' else '/' end}plugins", public_name, file
155 155 end
156 156  
157 157 def root_path
... ...
public/javascripts/application.js
1 1 // Place your application-specific JavaScript functions and classes here
2 2 // This file is automatically included by javascript_include_tag :defaults
  3 +/*
  4 +* third party libraries
  5 +*= require jquery-2.1.1.min.js
  6 +*= require jquery-migrate-1.2.1.js
  7 +*= require jquery.cycle.all.min.js
  8 +*= require jquery.colorbox-min.js
  9 +*= require jquery-ui-1.10.4/js/jquery-ui-1.10.4.min.js
  10 +*= require jquery.scrollTo.js
  11 +*= require jquery.form.js
  12 +*= require jquery-validation/jquery.validate.js
  13 +*= require jquery.cookie.js
  14 +*= require jquery.ba-bbq.min.js
  15 +*= require jquery.tokeninput.js
  16 +*= require jquery-timepicker-addon/dist/jquery-ui-timepicker-addon.js
  17 +*= require inputosaurus.js
  18 +*= require reflection.js
  19 +*= require rails.js
  20 +*= require jrails.js
  21 +* noosfero libraries
  22 +*= require_self
  23 +*= require modal.js
  24 +* views speficics
  25 +*= require add-and-join.js
  26 +*= require report-abuse.js
  27 +*= require manage-products.js
  28 +*= require catalog.js
  29 +*= require autogrow.js
  30 +*/
3 31  
4 32 // scope for noosfero stuff
5 33 noosfero = {
... ...
public/stylesheets/application.css
  1 +/*
  2 + * thidparty libraries
  3 + *= require colorbox
  4 + *= require selectordie
  5 + *= require selectordie-theme
  6 + *= require inputosaurus
  7 + *= require token-input
  8 + *= require token-input-facebook
  9 + *= require token-input-mac
  10 + *= require token-input-facet
  11 + * noosfero libraries
  12 + *= require_self
  13 + *= require iepngfix/iepngfix
  14 + * views specifics
  15 + *= require chat
  16 + *= require search
  17 + */
  18 +
1 19 /* browser fixes */
2 20  
3 21 img:-moz-broken {
... ... @@ -6920,8 +6938,8 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img {
6920 6938 }
6921 6939  
6922 6940 .fetching-overlay {
6923   - position: absolute;
6924   - top: 0px;
  6941 + position: absolute;
  6942 + top: 0px;
6925 6943 left: 0px;
6926 6944 right: 0px;
6927 6945 bottom: 0px;
... ...
test/unit/application_helper_test.rb
... ... @@ -463,13 +463,13 @@ class ApplicationHelperTest &lt; ActionView::TestCase
463 463  
464 464 should 'base theme uses default icon theme' do
465 465 stubs(:current_theme).returns('base')
466   - assert_equal "/designs/icons/default/style.css", icon_theme_stylesheet_path.first
  466 + assert_equal "designs/icons/default/style.css", icon_theme_stylesheet_path.first
467 467 end
468 468  
469 469 should 'base theme uses config to specify more then an icon theme' do
470 470 stubs(:current_theme).returns('base')
471   - assert_includes icon_theme_stylesheet_path, "/designs/icons/default/style.css"
472   - assert_includes icon_theme_stylesheet_path, "/designs/icons/pidgin/style.css"
  471 + assert_includes icon_theme_stylesheet_path, "designs/icons/default/style.css"
  472 + assert_includes icon_theme_stylesheet_path, "designs/icons/pidgin/style.css"
473 473 end
474 474  
475 475 should 'not display active field if only required' do
... ...