noosfero | 2 new commits pushed to repository

Bráulio Bhavamitra gitlab at gitlab.com
Tue Feb 24 13:11:47 BRT 2015


Bráulio Bhavamitra pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/bd5cf3a66186e2fa9df3bf544566da7257d5e516">bd5cf3a6</a> by Braulio Bhavamitra
Abstract core to use standard and replaceable helpers

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/6856933513fd673b53d6124fb046d83795e8d93f">68569335</a> by Bráulio Bhavamitra
Merge branch 'use-more-helpers' into 'master'

Abstract core to use standard and replaceable helpers

See merge request !426

- - - - -


Changes:

=====================================
app/helpers/application_helper.rb
=====================================
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -592,7 +592,7 @@ module ApplicationHelper
     extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' )
     links = links_for_balloon(profile)
     content_tag('div', content_tag(tag,
-                                   (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{CGI::escapeHTML(links.to_json)}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") +
+                                   (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") +
     link_to(
       content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) +
       content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
@@ -604,6 +604,14 @@ module ApplicationHelper
       :class => 'vcard'), :class => 'common-profile-list-block')
   end
 
+  def popover_menu(title,menu_title,links,html_options={})
+    html_options[:class] = "" unless html_options[:class]
+    html_options[:class] << " menu-submenu-trigger"
+    html_options[:onclick] = "toggleSubmenu(this, '#{menu_title}', #{CGI::escapeHTML(links.to_json)}); return false"
+
+    link_to(content_tag(:span, title), '#', html_options)
+  end
+
   def gravatar_default
     (respond_to?(:theme_option) && theme_option.present? && theme_option['gravatar']) || NOOSFERO_CONF['gravatar'] || 'mm'
   end
@@ -718,7 +726,7 @@ module ApplicationHelper
   class NoosferoFormBuilder < ActionView::Helpers::FormBuilder
     extend ActionView::Helpers::TagHelper
 
-    def self.output_field(text, field_html, field_id = nil)
+    def self.output_field(text, field_html, field_id = nil, options = {})
       # try to guess an id if none given
       if field_id.nil?
         field_html =~ /id=['"]([^'"]*)['"]/
@@ -1050,7 +1058,7 @@ module ApplicationHelper
     end
 
     link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-articles'), {:controller => "search", :action => 'contents', :category_path => nil}, :id => 'submenu-contents') +
-    link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger')
+    popover_menu(_('Contents menu'),'',links,:class => 'up', :id => 'submenu-contents-trigger')
   end
   alias :browse_contents_menu :search_contents_menu
 
@@ -1066,7 +1074,7 @@ module ApplicationHelper
      end
 
     link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "search", :action => 'people', :category_path => ''}, :id => 'submenu-people') +
-    link_to(content_tag(:span, _('People menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger')
+    popover_menu(_('People menu'),'',links,:class => 'up', :id => 'submenu-people-trigger')
   end
   alias :browse_people_menu :search_people_menu
 
@@ -1082,7 +1090,7 @@ module ApplicationHelper
      end
 
     link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "search", :action => 'communities'}, :id => 'submenu-communities') +
-    link_to(content_tag(:span, _('Communities menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger')
+    popover_menu(_('Communities menu'),'',links,:class => 'up', :id => 'submenu-communities-trigger')
   end
   alias :browse_communities_menu :search_communities_menu
 

=====================================
app/helpers/block_helper.rb
=====================================
--- a/app/helpers/block_helper.rb
+++ b/app/helpers/block_helper.rb
@@ -19,7 +19,7 @@ module BlockHelper
         content_tag('span', _('Title')) +
         text_field_tag('block[images][][title]', image[:title], :class => 'highlight-title', :size => 45)
       }</label></td>
-      <td>#{link_to '', '#', :class=>'button icon-button icon-delete delete-highlight', :confirm=>_('Are you sure you want to remove this highlight')}</td>
+      <td>#{button_without_text(:delete, _('Remove'), '#', class: 'delete-highlight', :confirm=>_('Are you sure you want to remove this highlight'))}</td>
     </tr>
     "
   end

=====================================
app/helpers/categories_helper.rb
=====================================
--- a/app/helpers/categories_helper.rb
+++ b/app/helpers/categories_helper.rb
@@ -25,10 +25,13 @@ module CategoriesHelper
     )
   end
 
-  def update_categories_link(body, category_id=nil, html_options={})
+  #TODO: remove this function and, in views, use existing basic buttons
+  def update_categories_link(type, body, category_id=nil, html_options={})
+    html_class = 'select-subcategory-link'
+    html_class = " icon-#{type}  btn btn-primary btn-xs" if type.present?
     link_to body,
       { :action => "update_categories", :category_id => category_id, :id => @object },
-      {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => 'select-subcategory-link'}.merge(html_options)
+      {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => html_class}.merge(html_options)
   end
 
 end

=====================================
app/helpers/language_helper.rb
=====================================
--- a/app/helpers/language_helper.rb
+++ b/app/helpers/language_helper.rb
@@ -1,6 +1,6 @@
 module LanguageHelper
   def language
-    locale
+    locale.to_s
   end
 
   def tinymce_language
@@ -20,7 +20,7 @@ module LanguageHelper
     separator = options[:separator] || ' — '
 
     if options[:element] == 'dropdown'
-      select_tag('lang', 
+      select_tag('lang',
         options_for_select(locales.map{|code,name| [name, code]}, current),
         :onchange => "document.location.href= #{url_for(params.merge(:lang => 'LANGUAGE'))}.replace(/LANGUAGE/, this.value) ;",
         :help => _('The language you choose here is the language used for options, buttons, etc. It does not affect the language of the content created by other users.')

=====================================
app/helpers/layout_helper.rb
=====================================
--- a/app/helpers/layout_helper.rb
+++ b/app/helpers/layout_helper.rb
@@ -31,12 +31,12 @@ module LayoutHelper
     plugins_javascripts = @plugins.map { |plugin| [plugin.js_files].flatten.map { |js| plugin.class.public_path(js) } }.flatten
 
     output = ''
-    output += render :file =>  'layouts/_javascript'
-    output += javascript_tag 'render_all_jquery_ui_widgets()'
+    output += render 'layouts/javascript'
     unless plugins_javascripts.empty?
       output += javascript_include_tag plugins_javascripts, :cache => "cache/plugins-#{Digest::MD5.hexdigest plugins_javascripts.to_s}"
     end
     output += theme_javascript_ng.to_s
+    output += javascript_tag 'render_all_jquery_ui_widgets()'
 
     output
   end
@@ -85,6 +85,7 @@ module LayoutHelper
     end
   end
 
+
   def icon_theme_stylesheet_path
     icon_themes = []
     theme_icon_themes = theme_option(:icon_theme) || []

=====================================
app/views/account/login.html.erb
=====================================
--- a/app/views/account/login.html.erb
+++ b/app/views/account/login.html.erb
@@ -7,7 +7,7 @@
 
 <%= @message %>
 
-<%= labelled_form_for :user, :url => login_url do |f| %>
+<%= labelled_form_for :user, :url => login_url, :horizontal => true do |f| %>
 
      <%= f.text_field :login, :id => 'main_user_login', :onchange => 'this.value = convToValidLogin( this.value )', :value => params[:userlogin] %>
 

=====================================
app/views/account/login_block.html.erb
=====================================
--- a/app/views/account/login_block.html.erb
+++ b/app/views/account/login_block.html.erb
@@ -20,9 +20,7 @@
       <% button_bar do %>
         <%= submit_button( 'login', _('Log in') )%>
         <% unless @plugins.dispatch(:allow_user_registration).include?(false) %>
-          <%= link_to content_tag( 'span', _('New user') ),
-              { :controller => 'account', :action => 'signup' },
-              :class => 'button with-text icon-add' %>
+          <%= button(:add, _('New user'), { :controller => 'account', :action => 'signup' }) %>
         <% end %>
       <% end %>
 

=====================================
app/views/blocks/login_block.html.erb
=====================================
--- a/app/views/blocks/login_block.html.erb
+++ b/app/views/blocks/login_block.html.erb
@@ -6,7 +6,7 @@
       <li><%= link_to _('Homepage'), user.public_profile_url %></li>
     </ul>
     <div class="user-actions">
-      <%= link_to content_tag('span', _('Logout')), { :controller => 'account', :action => 'logout' }, :class => 'button with-text icon-menu-logout' %>
+      <%= button(:'menu-logout',  _('Logout'), :controller => 'account', :action => 'logout') %>
     </div>
   </div>
 <% else %>

=====================================
app/views/blocks/profile_info_actions/_community.html.erb
=====================================
--- a/app/views/blocks/profile_info_actions/_community.html.erb
+++ b/app/views/blocks/profile_info_actions/_community.html.erb
@@ -5,11 +5,11 @@
   <% if logged_in? %>
     <% if profile.enable_contact? %>
       <li>
-      <%= link_to content_tag('span', _('Send an e-mail')),
-        { :profile => profile.identifier,
-          :controller => 'contact',
-          :action => 'new' },
-        {:class => 'button with-text icon-menu-mail', :title => _('Send an e-mail to the administrators')} %>
+        <%= button(:'menu-mail', _('Send an e-mail'),
+                   { :profile => profile.identifier,
+                     :controller => 'contact',
+                     :action => 'new' },
+                   { :title => _('Send an e-mail to the administrators')}) %>
       </li>
     <% end %>
 

=====================================
app/views/blocks/profile_info_actions/_enterprise.html.erb
=====================================
--- a/app/views/blocks/profile_info_actions/_enterprise.html.erb
+++ b/app/views/blocks/profile_info_actions/_enterprise.html.erb
@@ -1,11 +1,11 @@
 <ul>
   <%if logged_in? %>
     <%if !user.favorite_enterprises.include?(profile) %>
-      <li><%= link_to content_tag('span', _('Add as favorite')), { :profile => user.identifier, :controller => 'favorite_enterprises', :action => 'add', :id => profile.id }, :class => 'button with-text icon-add', :title => _('Add enterprise as favorite') %></li>
+      <li><%= button(:add, _('Add as favorite'), { :profile => user.identifier, :controller => 'favorite_enterprises', :action => 'add', :id => profile.id }, :title => _('Add enterprise as favorite')) %></li>
     <% end %>
   <% end %>
   <% if profile.enable_contact? %>
-    <li> <%= link_to content_tag('span', _('Send an e-mail')), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}, {:id => 'enterprise-contact-button', :class => 'button with-text icon-menu-mail'} %> </li>
+      <li><%= button(:'menu-mail', _('Send an e-mail'), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}, {:id => 'enterprise-contact-button'} ) %></li>
   <% end %>
 
   <li><%= report_abuse(profile, :button) %></li>

=====================================
app/views/blocks/profile_info_actions/_join_leave_community.html.erb
=====================================
--- a/app/views/blocks/profile_info_actions/_join_leave_community.html.erb
+++ b/app/views/blocks/profile_info_actions/_join_leave_community.html.erb
@@ -22,8 +22,6 @@
       <% end %>
     <% end %>
   <% else %>
-    <%= link_to content_tag('span', _('Join')), profile.join_not_logged_url,
-      :class => 'button with-text icon-add',
-      :title => _('Join this community') %>
+      <%= button(:add, _('Join'), profile.join_not_logged_url, :title => _('Join this community')) %>
   <% end %>
 </div>

=====================================
app/views/blocks/profile_info_actions/_person.html.erb
=====================================
--- a/app/views/blocks/profile_info_actions/_person.html.erb
+++ b/app/views/blocks/profile_info_actions/_person.html.erb
@@ -8,7 +8,7 @@
     <% end %>
 
     <% if user.is_a_friend?(profile) && profile.enable_contact? %>
-      <li> <%= link_to content_tag('span', _('Send an e-mail')), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}, :class => 'button with-text icon-menu-mail' %> </li>
+      <li><%= button(:back, _('Send an e-mail'), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}) %></li>
     <% end %>
 
     <li><%= report_abuse(profile, :button) %></li>

=====================================
app/views/box_organizer/_highlights_block.html.erb
=====================================
--- a/app/views/box_organizer/_highlights_block.html.erb
+++ b/app/views/box_organizer/_highlights_block.html.erb
@@ -15,7 +15,7 @@
   </tbody>
 </table>
 
-<%= link_to(_('New highlight'), '#', :class => 'button icon-add with-text new-highlight-button')%>
+<%= button(:add, _('New highlight'), '#', class: 'new-highlight-button') %>
 
 <%= labelled_form_field _('Image transition:'), select('block', 'interval', [[_('No automatic transition'), 0]] + [1, 2, 3, 4, 5, 10, 20, 30, 60].map {|item| [n_('Every 1 second', 'Every %d seconds', item) % item, item]}) %>
 

=====================================
app/views/comment/_comment_actions.html.erb
=====================================
--- a/app/views/comment/_comment_actions.html.erb
+++ b/app/views/comment/_comment_actions.html.erb
@@ -2,7 +2,7 @@
   <% if !links_submenu.empty? %>
     <div class="comment-actions">
       <li class="vcard">
-        <%= link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links_submenu.to_json)}); return false", :class => 'menu-submenu-trigger comment-trigger', :url => url) %>
+        <%= popover_menu(_('Contents menu'),'',links_submenu,:class => 'comment-trigger', :url => url) %>
       </li>
     </div>
   <% end %>

=====================================
app/views/favorite_enterprises/index.html.erb
=====================================
--- a/app/views/favorite_enterprises/index.html.erb
+++ b/app/views/favorite_enterprises/index.html.erb
@@ -9,10 +9,7 @@
                         enterprise.identifier, :class => 'profile-link' %>
     <%# profile_image_link enterprise, :portrait, 'div' %>
     <div class="controll">
-      <%= link_to content_tag('span',_('remove')),
-          { :action => 'remove', :id => enterprise.id },
-            :class => 'button icon-delete',
-            :title => _('remove') %>
+      <%= button(:delete, _('remove'), { :action => 'remove', :id => enterprise.id },:title => _('remove')) %>
     </div><!-- end class="controll" -->
   </li>
 <% end %>

=====================================
app/views/search/_sellers_form.html.erb
=====================================
--- a/app/views/search/_sellers_form.html.erb
+++ b/app/views/search/_sellers_form.html.erb
@@ -18,7 +18,7 @@
   </div>
 
   <div class="button-bar">
-    <%= submit_tag _('Search'), :class => 'button with-text icon-search' %>
+    <%= submit_button :search, _('Search') %>
   </div>
 
 <% end %>

=====================================
app/views/shared/_change_image.html.erb
=====================================
--- a/app/views/shared/_change_image.html.erb
+++ b/app/views/shared/_change_image.html.erb
@@ -1,2 +1,2 @@
   <%= i.file_field( :uploaded_data, { :onchange => 'updateImg(this.value)' } ) %>
-  <%= link_to_function(_('Cancel'), "jQuery('#change-image-link').show(); jQuery('#change-image').html('')", :id => 'cancel-change-image-link', :class => 'button icon-cancel with-text', :style => 'display: none') %>
+  <%= button_to_function(:cancel,_('Cancel'),"jQuery('#change-image-link').show(); jQuery('#change-image').html('')", :id => 'cancel-change-image-link', :style => 'display: none')%>

=====================================
app/views/shared/_select_categories.html.erb
=====================================
--- a/app/views/shared/_select_categories.html.erb
+++ b/app/views/shared/_select_categories.html.erb
@@ -4,12 +4,12 @@
   <%= hidden_field_tag "#{object_name}[#{object_name}_category_id]", @current_category.id unless multiple %>
   <%= hidden_field_tag "#{object_name}[category_ids][]", @current_category.id if multiple %>
 
-  <%= update_categories_link("", nil, :id => "cancel-category-button", :class => "button icon-back") %>
+  <%= update_categories_link(:back, "", nil, :id => "cancel-category-button") %>
   <%
     categories = [@current_category]
     categories.push(@current_category) while @current_category = @current_category.parent
   %>
-  <%= categories.compact.reverse.map{|i| update_categories_link(i.name, i.id)}.join %>
+  <%= categories.compact.reverse.map{|i| update_categories_link(nil,i.name, i.id)}.join %>
 
   <script>
     function add_category() {

=====================================
app/views/shared/_select_subcategories.html.erb
=====================================
--- a/app/views/shared/_select_subcategories.html.erb
+++ b/app/views/shared/_select_subcategories.html.erb
@@ -3,6 +3,6 @@
   <div class="category-helper-label"><%= _('Click to select a category') %></div>
 
   <% categories.select{|i| @object.accept_category?(i)}.each do |category| %>
-    <%= update_categories_link(category.name, category.id) %>
+    <%= update_categories_link(nil,category.name, category.id) %>
   <% end %>
 <% end %>

=====================================
app/views/shared/_show_thumbnail.html.erb
=====================================
--- a/app/views/shared/_show_thumbnail.html.erb
+++ b/app/views/shared/_show_thumbnail.html.erb
@@ -2,7 +2,7 @@
 
   <br/>
 
-  <%= link_to_function(_('Change image'), 'display_change_image()', :id => 'change-image-link', :class => 'button icon-photos with-text') %>
+  <%= button_to_function(:photos, _('Change image'), 'display_change_image()', :id => 'change-image-link' ) %>
 
   <script>
     function display_change_image() {

=====================================
app/views/tasks/index.html.erb
=====================================
--- a/app/views/tasks/index.html.erb
+++ b/app/views/tasks/index.html.erb
@@ -23,7 +23,7 @@
 
 <% if @tasks.empty? %>
   <p>
-    <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter,  type_collection, :onchange => 'document.location.href = "?filter_type="+this.value')%>
+    <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter,  type_collection, :onchange => "document.location.href = '?filter_type='+this.value")%>
   </p>
   <em><%= _('No pending tasks for %s') % profile.name %></em>
 <% else %>

=====================================
test/test_helper.rb
=====================================
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -140,9 +140,18 @@ class ActiveSupport::TestCase
   end
 
   # For models that render views (blocks, articles, ...)
-  def render(*args)
-    view_paths = @explicit_view_paths || ActionController::Base.view_paths
-    ActionView::Base.new(view_paths, {}).render(*args)
+  def self.action_view
+    @action_view ||= begin
+      view_paths = ActionController::Base.view_paths
+      action_view = ActionView::Base.new view_paths, {}
+      # for using Noosfero helpers inside render calls
+      action_view.extend ApplicationHelper
+      action_view
+    end
+  end
+
+  def render *args
+    self.class.action_view.render(*args)
   end
 
   private

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150224/cba2fb6b/attachment-0001.html>


More information about the Noosfero-dev mailing list