Commit 555171514783ca260cd963f911be31d44a694d9c

Authored by Antonio Terceiro
1 parent 19a038f4

Random fixes to get the initial page loading

plus login and signup screens being displayed. They don't work yet,
though.
MIGRATION_ISSUES
... ... @@ -22,7 +22,7 @@
22 22  
23 23 * check FIXME's in Gemfile
24 24  
25   -* rewrite config/routes.rb
  25 +* Finish rewriting config/routes.rb (look for __END__)
26 26  
27 27 * rewrite conditional routing. See FIXME in lib/route_if.rb and re-implement using the Rails 3 mechanism - http://guides.rubyonrails.org/routing.html#advanced-constraints
28 28  
... ... @@ -30,4 +30,12 @@
30 30  
31 31 * xss_terminate sucks. We should replace it with the builtin mechanism in Rails 3
32 32  
33   -* instance_eval on Ruby 1.9 yields self, so lambdas that are passed to instance_eval and do not accept exactly 1 argument will blow up. See http://www.ruby-forum.com/topic/213313 ... search for instance_eval and fix where necessary.
  33 +* instance_eval on Ruby 1.9 yields self, so lambdas that are passed to instance_eval and do not accept exactly 1 argument will blow up. See http://www.ruby-forum.com/topic/213313 ... search for instance_eval and fix where necessary. In special, most of the blocks still need fixing.
  34 +
  35 +* all instances of <% *_form_for ... %> must be changed to <%= instead of <%
  36 +
  37 +* all ActiveRecord models have to declare explicitly which attributes must be allowed for mass assignment with attr_accessible.
  38 +
  39 +* check if we need to update config/locales/*
  40 +
  41 +* check observe_field and labelled_form_for in app/helpers/application_helper.rb
... ...
app/helpers/application_helper.rb
... ... @@ -826,8 +826,8 @@ module ApplicationHelper
826 826 end
827 827  
828 828 def labelled_form_for(name, object = nil, options = {}, &proc)
829   - object ||= instance_variable_get("@#{name}")
830   - form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc)
  829 + # FIXME remove the =object= argument and adapt the calling code
  830 + form_for(name, { :builder => NoosferoFormBuilder }.merge(options), &proc)
831 831 end
832 832  
833 833 def optional_field(profile, name, field_html = nil, only_required = false, &block)
... ... @@ -1409,4 +1409,28 @@ module ApplicationHelper
1409 1409 options[:class] = "comment-footer comment-footer-link comment-footer-hide"
1410 1410 expirable_content_reference content, action, text, url, options
1411 1411 end
  1412 +
  1413 + def error_messages_for(*args)
  1414 + options = args.pop if args.last.is_a?(Hash)
  1415 + errors = []
  1416 + args.each do |name|
  1417 + object = instance_variable_get("@#{name}")
  1418 + object.errors.full_messages.each do |msg|
  1419 + errors << msg
  1420 + end
  1421 + end
  1422 + return '' if errors.empty?
  1423 +
  1424 + content_tag(:div, :class => 'errorExplanation', :id => 'errorExplanation') do
  1425 + content_tag(:h2, _('Errors while saving')) +
  1426 + content_tag(:ul) do
  1427 + errors.map { |err| content_tag(:li, err) }
  1428 + end
  1429 + end
  1430 + end
  1431 +
  1432 + # FIXME
  1433 + def observe_field(*args)
  1434 + ''
  1435 + end
1412 1436 end
... ...
app/helpers/countries_helper.rb
... ... @@ -267,7 +267,7 @@ module CountriesHelper
267 267 end
268 268  
269 269 def countries
270   - self.class.countries.map {|item| [gettext(item[0]), item[1] ]}.sort_by { |entry| entry.first.transliterate }
  270 + CountriesHelper.countries.map {|item| [gettext(item[0]), item[1] ]}.sort_by { |entry| entry.first.transliterate }
271 271 end
272 272  
273 273 def lookup(code)
... ...
app/models/article.rb
... ... @@ -219,13 +219,6 @@ class Article &lt; ActiveRecord::Base
219 219 limit(limit).
220 220 order(['articles.published_at desc', 'articles.id desc'])
221 221  
222   - if !( scoped_methods && scoped_methods.last &&
223   - scoped_methods.last[:find] &&
224   - scoped_methods.last[:find][:joins] &&
225   - scoped_methods.last[:find][:joins].index('profiles') )
226   - result = result.includes(:profile)
227   - end
228   -
229 222 pagination ? result.paginate({:page => 1, :per_page => limit}) : result
230 223 end
231 224  
... ...
app/models/communities_block.rb
... ... @@ -16,11 +16,11 @@ class CommunitiesBlock &lt; ProfileListBlock
16 16 owner = self.owner
17 17 case owner
18 18 when Profile
19   - lambda do
  19 + lambda do |context|
20 20 link_to s_('communities|View all'), :profile => owner.identifier, :controller => 'profile', :action => 'communities'
21 21 end
22 22 when Environment
23   - lambda do
  23 + lambda do |context|
24 24 link_to s_('communities|View all'), :controller => 'search', :action => 'communities'
25 25 end
26 26 else
... ...
app/models/domain.rb
  1 +require 'noosfero/multi_tenancy'
  2 +
1 3 class Domain < ActiveRecord::Base
2 4  
3 5 attr_accessible :name
... ...
app/models/login_block.rb
... ... @@ -9,7 +9,7 @@ class LoginBlock &lt; Block
9 9 end
10 10  
11 11 def content(args={})
12   - lambda do
  12 + lambda do |context|
13 13 render :file => 'blocks/login_block'
14 14 end
15 15 end
... ...
app/models/people_block.rb
... ... @@ -17,7 +17,7 @@ class PeopleBlock &lt; ProfileListBlock
17 17 end
18 18  
19 19 def footer
20   - lambda do
  20 + lambda do |context|
21 21 link_to _('View all'), :controller => 'search', :action => 'people'
22 22 end
23 23 end
... ...
app/models/profile_list_block.rb
... ... @@ -44,7 +44,7 @@ class ProfileListBlock &lt; Block
44 44 profiles = self.profile_list
45 45 title = self.view_title
46 46 nl = "\n"
47   - lambda do
  47 + lambda do |context|
48 48 count=0
49 49 list = profiles.map {|item|
50 50 count+=1
... ...
app/views/account/_signup_form.html.erb
... ... @@ -2,7 +2,7 @@
2 2  
3 3 <%= error_messages_for :user, :person, :header_message => _('The account could not be created') %>
4 4  
5   -<% labelled_form_for :user, @user, :html => { :multipart => true, :id => 'signup-form' } do |f| %>
  5 +<%= labelled_form_for :user, @user, :html => { :multipart => true, :id => 'signup-form' } do |f| %>
6 6  
7 7 <%= hidden_field_tag :invitation_code, @invitation_code %>
8 8  
... ...
app/views/account/login.html.erb
... ... @@ -7,7 +7,7 @@
7 7  
8 8 <%= @message %>
9 9  
10   -<% labelled_form_for :user, @user, :url => login_url do |f| %>
  10 +<%= labelled_form_for :user, @user, :url => login_url do |f| %>
11 11  
12 12 <%= f.text_field :login, :id => 'main_user_login', :onchange => 'this.value = convToValidLogin( this.value )', :value => params[:userlogin] %>
13 13  
... ...
app/views/account/login_block.html.erb
... ... @@ -9,7 +9,7 @@
9 9 @user ||= User.new
10 10 %>
11 11  
12   - <% labelled_form_for :user, @user, :url => login_url do |f| %>
  12 + <%= labelled_form_for :user, @user, :url => login_url do |f| %>
13 13  
14 14 <%= f.text_field :login, :onchange => 'this.value = convToValidLogin( this.value )' %>
15 15  
... ...
app/views/layouts/_javascript.html.erb
... ... @@ -3,7 +3,7 @@
3 3 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery-validation/jquery.validate',
4 4 'jquery.cookie', 'jquery.ba-bbq.min.js', 'reflection', 'jquery.tokeninput',
5 5 'add-and-join', 'report-abuse', 'catalog', 'manage-products',
6   -'jquery-ui-timepicker-addon', :cache => 'cache-general' %>
  6 +'jquery-ui-timepicker-addon', 'application.js', :cache => 'cache-general' %>
7 7  
8 8 <% language = FastGettext.locale %>
9 9 <% %w{messages methods}.each do |type| %>
... ...
app/views/layouts/application-ng.html.erb
... ... @@ -9,14 +9,14 @@
9 9 <link rel="shortcut icon" href="<%= image_path(theme_favicon) %>" type="image/x-icon" />
10 10 <%= noosfero_javascript %>
11 11 <%= stylesheet_link_tag *noosfero_stylesheets, :cache => 'cache' %>
12   - <%= stylesheet_link_tag template_stylesheet_path %>
13   - <%= stylesheet_link_tag icon_theme_stylesheet_path %>
14   - <%= stylesheet_link_tag jquery_ui_theme_stylesheet_path %>
  12 + <%= stylesheet_link_tag *template_stylesheet_path %>
  13 + <%= stylesheet_link_tag *icon_theme_stylesheet_path %>
  14 + <%= stylesheet_link_tag *jquery_ui_theme_stylesheet_path %>
15 15 <%
16 16 plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') }
17 17 %>
18   - <%= stylesheet_link_tag(plugins_stylesheets, :cache => 'cache/plugins-' + Digest::MD5.hexdigest(plugins_stylesheets.to_s)) unless plugins_stylesheets.empty? %>
19   - <%= stylesheet_link_tag theme_stylesheet_path %>
  18 + <%= stylesheet_link_tag(*plugins_stylesheets, :cache => 'cache/plugins-' + Digest::MD5.hexdigest(plugins_stylesheets.to_s)) unless plugins_stylesheets.empty? %>
  19 + <%= stylesheet_link_tag *theme_stylesheet_path %>
20 20  
21 21 <%# Add custom tags/styles/etc via content_for %>
22 22 <%= yield :head %>
... ... @@ -24,7 +24,7 @@
24 24 <%
25 25 plugins_javascripts = @plugins.map { |plugin| plugin.js_files.map { |js| plugin.class.public_path(js) } }.flatten
26 26 %>
27   - <%= javascript_include_tag(plugins_javascripts, :cache => 'cache/plugins-' + Digest::MD5.hexdigest(plugins_javascripts.to_s)) unless plugins_javascripts.empty? %>
  27 + <%= javascript_include_tag(*plugins_javascripts, :cache => 'cache/plugins-' + Digest::MD5.hexdigest(plugins_javascripts.to_s)) unless plugins_javascripts.empty? %>
28 28 <%=
29 29 @plugins.dispatch(:head_ending).collect do |content|
30 30 content.respond_to?(:call) ? content.call : content
... ...
config/application.rb
... ... @@ -74,7 +74,7 @@ module Noosfero
74 74 config.active_record.whitelist_attributes = true
75 75  
76 76 # Enable the asset pipeline
77   - config.assets.enabled = true
  77 + config.assets.enabled = false
78 78  
79 79 # Version of your assets, change this if you want to expire all your assets
80 80 config.assets.version = '1.0'
... ...
config/routes.rb
1 1 require 'noosfero'
  2 +require 'environment_domain_constraint'
2 3  
3 4 Noosfero::Application.routes.draw do
4 5 # The priority is based upon order of creation: first created -> highest priority.
5   -
6 6 # Sample of regular route:
7 7 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
8 8 # Keep in mind you can assign values other than :controller and :action
... ... @@ -16,47 +16,45 @@ Noosfero::Application.routes.draw do
16 16 ######################################################
17 17  
18 18 match 'test/:controller(/:action(/:id))' , :controller => /.*test.*/
19   -
  19 +
20 20 # -- just remember to delete public/index.html.
21 21 # You can have the root of your site routed by hooking up ''
22   - root :to => 'home#index'
  22 + root :to => 'home#index', :constraints => EnvironmentDomainConstraint.new
23 23  
24   - # FIXME adapt the rest of the routes below
25   -end
26   -__END__
27   - map.connect '', :controller => "home", :conditions => { :if => lambda { |env| !Domain.hosting_profile_at(env[:host]) } }
28   - map.home 'site/:action', :controller => 'home'
  24 + match 'site(/:action)', :controller => 'home'
29 25  
30   - map.connect 'images/*stuff', :controller => 'not_found', :action => 'nothing'
31   - map.connect 'stylesheets/*stuff', :controller => 'not_found', :action => 'nothing'
32   - map.connect 'designs/*stuff', :controller => 'not_found', :action => 'nothing'
33   - map.connect 'articles/*stuff', :controller => 'not_found', :action => 'nothing'
34   - map.connect 'javascripts/*stuff', :controller => 'not_found', :action => 'nothing'
35   - map.connect 'thumbnails/*stuff', :controller => 'not_found', :action => 'nothing'
36   - map.connect 'user_themes/*stuff', :controller => 'not_found', :action => 'nothing'
  26 + match 'images/*stuff' => 'not_found#nothing'
  27 + match 'stylesheets/*stuff' => 'not_found#nothing'
  28 + match 'designs/*stuff' => 'not_found#nothing'
  29 + match 'articles/*stuff' => 'not_found#nothing'
  30 + match 'javascripts/*stuff' => 'not_found#nothing'
  31 + match 'thumbnails/*stuff' => 'not_found#nothing'
  32 + match 'user_themes/*stuff' => 'not_found#nothing'
37 33  
38 34 # online documentation
39   - map.doc 'doc', :controller => 'doc', :action => 'index'
40   - map.doc_section 'doc/:section', :controller => 'doc', :action => 'section'
41   - map.doc_topic 'doc/:section/:topic', :controller => 'doc', :action => 'topic'
42   -
  35 + match 'doc' => 'doc#index', :as => :doc
  36 + match 'doc/:section' => 'doc#section', :as => :doc_section
  37 + match 'doc/:section/:topic' => 'doc#topic', :as => :doc_topic
  38 +
43 39 # user account controller
44   - map.connect 'account/new_password/:code', :controller => 'account', :action => 'new_password'
45   - map.connect 'account/:action', :controller => 'account'
  40 + match 'account/new_password/:code' => 'account#new_password', :controller => 'account', :action => 'new_password'
  41 + match 'account/:action', :controller => 'account'
46 42  
47 43 # enterprise registration
48   - map.connect 'enterprise_registration/:action', :controller => 'enterprise_registration'
  44 + match 'enterprise_registration/:action', :controller => 'enterprise_registration'
49 45  
50 46 # tags
51   - map.tag 'tag', :controller => 'search', :action => 'tags'
52   - map.tag 'tag/:tag', :controller => 'search', :action => 'tag', :tag => /.*/
53   -
  47 + match 'tag', :controller => 'search', :action => 'tags'
  48 + match 'tag/:tag', :controller => 'search', :action => 'tag', :tag => /.*/
  49 +
54 50 # categories index
55   - map.category 'cat/*category_path', :controller => 'search', :action => 'category_index'
56   - map.assets 'assets/:asset/*category_path', :controller => 'search', :action => 'assets'
  51 + match 'cat/*category_path' => 'search#category_index', :as => :category
  52 + match 'assets/:asset(/*category_path)' => 'search#assets', :as => :assets
57 53 # search
58   - map.connect 'search/:action/*category_path', :controller => 'search'
59   -
  54 + match 'search/:action(/*category_path)', :controller => 'search'
  55 +
  56 +end # FIXME remove this line and the following and finish rewriting the routes
  57 +__END__
60 58 # events
61 59 map.events 'profile/:profile/events_by_day', :controller => 'events', :action => 'events_by_day', :profile => /#{Noosfero.identifier_format}/
62 60 map.events 'profile/:profile/events/:year/:month/:day', :controller => 'events', :action => 'events', :year => /\d*/, :month => /\d*/, :day => /\d*/, :profile => /#{Noosfero.identifier_format}/
... ...
lib/environment_domain_constraint.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class EnvironmentDomainConstraint
  2 + def matches?(request)
  3 + !Domain.hosting_profile_at(request.host)
  4 + end
  5 +end
... ...