Commit bd5cf3a66186e2fa9df3bf544566da7257d5e516
1 parent
11dfb86b
Exists in
master
and in
29 other branches
Abstract core to use standard and replaceable helpers
Showing
22 changed files
with
58 additions
and
44 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -592,7 +592,7 @@ module ApplicationHelper |
592 | 592 | extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) |
593 | 593 | links = links_for_balloon(profile) |
594 | 594 | content_tag('div', content_tag(tag, |
595 | - (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) : "") + | |
595 | + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") + | |
596 | 596 | link_to( |
597 | 597 | content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + |
598 | 598 | content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + |
... | ... | @@ -604,6 +604,14 @@ module ApplicationHelper |
604 | 604 | :class => 'vcard'), :class => 'common-profile-list-block') |
605 | 605 | end |
606 | 606 | |
607 | + def popover_menu(title,menu_title,links,html_options={}) | |
608 | + html_options[:class] = "" unless html_options[:class] | |
609 | + html_options[:class] << " menu-submenu-trigger" | |
610 | + html_options[:onclick] = "toggleSubmenu(this, '#{menu_title}', #{CGI::escapeHTML(links.to_json)}); return false" | |
611 | + | |
612 | + link_to(content_tag(:span, title), '#', html_options) | |
613 | + end | |
614 | + | |
607 | 615 | def gravatar_default |
608 | 616 | (respond_to?(:theme_option) && theme_option.present? && theme_option['gravatar']) || NOOSFERO_CONF['gravatar'] || 'mm' |
609 | 617 | end |
... | ... | @@ -718,7 +726,7 @@ module ApplicationHelper |
718 | 726 | class NoosferoFormBuilder < ActionView::Helpers::FormBuilder |
719 | 727 | extend ActionView::Helpers::TagHelper |
720 | 728 | |
721 | - def self.output_field(text, field_html, field_id = nil) | |
729 | + def self.output_field(text, field_html, field_id = nil, options = {}) | |
722 | 730 | # try to guess an id if none given |
723 | 731 | if field_id.nil? |
724 | 732 | field_html =~ /id=['"]([^'"]*)['"]/ |
... | ... | @@ -1050,7 +1058,7 @@ module ApplicationHelper |
1050 | 1058 | end |
1051 | 1059 | |
1052 | 1060 | link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-articles'), {:controller => "search", :action => 'contents', :category_path => nil}, :id => 'submenu-contents') + |
1053 | - 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') | |
1061 | + popover_menu(_('Contents menu'),'',links,:class => 'up', :id => 'submenu-contents-trigger') | |
1054 | 1062 | end |
1055 | 1063 | alias :browse_contents_menu :search_contents_menu |
1056 | 1064 | |
... | ... | @@ -1066,7 +1074,7 @@ module ApplicationHelper |
1066 | 1074 | end |
1067 | 1075 | |
1068 | 1076 | link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "search", :action => 'people', :category_path => ''}, :id => 'submenu-people') + |
1069 | - 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') | |
1077 | + popover_menu(_('People menu'),'',links,:class => 'up', :id => 'submenu-people-trigger') | |
1070 | 1078 | end |
1071 | 1079 | alias :browse_people_menu :search_people_menu |
1072 | 1080 | |
... | ... | @@ -1082,7 +1090,7 @@ module ApplicationHelper |
1082 | 1090 | end |
1083 | 1091 | |
1084 | 1092 | link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "search", :action => 'communities'}, :id => 'submenu-communities') + |
1085 | - 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') | |
1093 | + popover_menu(_('Communities menu'),'',links,:class => 'up', :id => 'submenu-communities-trigger') | |
1086 | 1094 | end |
1087 | 1095 | alias :browse_communities_menu :search_communities_menu |
1088 | 1096 | ... | ... |
app/helpers/block_helper.rb
... | ... | @@ -19,7 +19,7 @@ module BlockHelper |
19 | 19 | content_tag('span', _('Title')) + |
20 | 20 | text_field_tag('block[images][][title]', image[:title], :class => 'highlight-title', :size => 45) |
21 | 21 | }</label></td> |
22 | - <td>#{link_to '', '#', :class=>'button icon-button icon-delete delete-highlight', :confirm=>_('Are you sure you want to remove this highlight')}</td> | |
22 | + <td>#{button_without_text(:delete, _('Remove'), '#', class: 'delete-highlight', :confirm=>_('Are you sure you want to remove this highlight'))}</td> | |
23 | 23 | </tr> |
24 | 24 | " |
25 | 25 | end | ... | ... |
app/helpers/categories_helper.rb
... | ... | @@ -25,10 +25,13 @@ module CategoriesHelper |
25 | 25 | ) |
26 | 26 | end |
27 | 27 | |
28 | - def update_categories_link(body, category_id=nil, html_options={}) | |
28 | + #TODO: remove this function and, in views, use existing basic buttons | |
29 | + def update_categories_link(type, body, category_id=nil, html_options={}) | |
30 | + html_class = 'select-subcategory-link' | |
31 | + html_class = " icon-#{type} btn btn-primary btn-xs" if type.present? | |
29 | 32 | link_to body, |
30 | 33 | { :action => "update_categories", :category_id => category_id, :id => @object }, |
31 | - {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => 'select-subcategory-link'}.merge(html_options) | |
34 | + {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => html_class}.merge(html_options) | |
32 | 35 | end |
33 | 36 | |
34 | 37 | end | ... | ... |
app/helpers/language_helper.rb
1 | 1 | module LanguageHelper |
2 | 2 | def language |
3 | - locale | |
3 | + locale.to_s | |
4 | 4 | end |
5 | 5 | |
6 | 6 | def tinymce_language |
... | ... | @@ -20,7 +20,7 @@ module LanguageHelper |
20 | 20 | separator = options[:separator] || ' — ' |
21 | 21 | |
22 | 22 | if options[:element] == 'dropdown' |
23 | - select_tag('lang', | |
23 | + select_tag('lang', | |
24 | 24 | options_for_select(locales.map{|code,name| [name, code]}, current), |
25 | 25 | :onchange => "document.location.href= #{url_for(params.merge(:lang => 'LANGUAGE'))}.replace(/LANGUAGE/, this.value) ;", |
26 | 26 | :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
... | ... | @@ -31,12 +31,12 @@ module LayoutHelper |
31 | 31 | plugins_javascripts = @plugins.map { |plugin| [plugin.js_files].flatten.map { |js| plugin.class.public_path(js) } }.flatten |
32 | 32 | |
33 | 33 | output = '' |
34 | - output += render :file => 'layouts/_javascript' | |
35 | - output += javascript_tag 'render_all_jquery_ui_widgets()' | |
34 | + output += render 'layouts/javascript' | |
36 | 35 | unless plugins_javascripts.empty? |
37 | 36 | output += javascript_include_tag plugins_javascripts, :cache => "cache/plugins-#{Digest::MD5.hexdigest plugins_javascripts.to_s}" |
38 | 37 | end |
39 | 38 | output += theme_javascript_ng.to_s |
39 | + output += javascript_tag 'render_all_jquery_ui_widgets()' | |
40 | 40 | |
41 | 41 | output |
42 | 42 | end |
... | ... | @@ -85,6 +85,7 @@ module LayoutHelper |
85 | 85 | end |
86 | 86 | end |
87 | 87 | |
88 | + | |
88 | 89 | def icon_theme_stylesheet_path |
89 | 90 | icon_themes = [] |
90 | 91 | theme_icon_themes = theme_option(:icon_theme) || [] | ... | ... |
app/views/account/login.html.erb
... | ... | @@ -7,7 +7,7 @@ |
7 | 7 | |
8 | 8 | <%= @message %> |
9 | 9 | |
10 | -<%= labelled_form_for :user, :url => login_url do |f| %> | |
10 | +<%= labelled_form_for :user, :url => login_url, :horizontal => true 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
... | ... | @@ -20,9 +20,7 @@ |
20 | 20 | <% button_bar do %> |
21 | 21 | <%= submit_button( 'login', _('Log in') )%> |
22 | 22 | <% unless @plugins.dispatch(:allow_user_registration).include?(false) %> |
23 | - <%= link_to content_tag( 'span', _('New user') ), | |
24 | - { :controller => 'account', :action => 'signup' }, | |
25 | - :class => 'button with-text icon-add' %> | |
23 | + <%= button(:add, _('New user'), { :controller => 'account', :action => 'signup' }) %> | |
26 | 24 | <% end %> |
27 | 25 | <% end %> |
28 | 26 | ... | ... |
app/views/blocks/login_block.html.erb
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | <li><%= link_to _('Homepage'), user.public_profile_url %></li> |
7 | 7 | </ul> |
8 | 8 | <div class="user-actions"> |
9 | - <%= link_to content_tag('span', _('Logout')), { :controller => 'account', :action => 'logout' }, :class => 'button with-text icon-menu-logout' %> | |
9 | + <%= button(:'menu-logout', _('Logout'), :controller => 'account', :action => 'logout') %> | |
10 | 10 | </div> |
11 | 11 | </div> |
12 | 12 | <% else %> | ... | ... |
app/views/blocks/profile_info_actions/_community.html.erb
... | ... | @@ -5,11 +5,11 @@ |
5 | 5 | <% if logged_in? %> |
6 | 6 | <% if profile.enable_contact? %> |
7 | 7 | <li> |
8 | - <%= link_to content_tag('span', _('Send an e-mail')), | |
9 | - { :profile => profile.identifier, | |
10 | - :controller => 'contact', | |
11 | - :action => 'new' }, | |
12 | - {:class => 'button with-text icon-menu-mail', :title => _('Send an e-mail to the administrators')} %> | |
8 | + <%= button(:'menu-mail', _('Send an e-mail'), | |
9 | + { :profile => profile.identifier, | |
10 | + :controller => 'contact', | |
11 | + :action => 'new' }, | |
12 | + { :title => _('Send an e-mail to the administrators')}) %> | |
13 | 13 | </li> |
14 | 14 | <% end %> |
15 | 15 | ... | ... |
app/views/blocks/profile_info_actions/_enterprise.html.erb
1 | 1 | <ul> |
2 | 2 | <%if logged_in? %> |
3 | 3 | <%if !user.favorite_enterprises.include?(profile) %> |
4 | - <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> | |
4 | + <li><%= button(:add, _('Add as favorite'), { :profile => user.identifier, :controller => 'favorite_enterprises', :action => 'add', :id => profile.id }, :title => _('Add enterprise as favorite')) %></li> | |
5 | 5 | <% end %> |
6 | 6 | <% end %> |
7 | 7 | <% if profile.enable_contact? %> |
8 | - <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> | |
8 | + <li><%= button(:'menu-mail', _('Send an e-mail'), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}, {:id => 'enterprise-contact-button'} ) %></li> | |
9 | 9 | <% end %> |
10 | 10 | |
11 | 11 | <li><%= report_abuse(profile, :button) %></li> | ... | ... |
app/views/blocks/profile_info_actions/_join_leave_community.html.erb
... | ... | @@ -22,8 +22,6 @@ |
22 | 22 | <% end %> |
23 | 23 | <% end %> |
24 | 24 | <% else %> |
25 | - <%= link_to content_tag('span', _('Join')), profile.join_not_logged_url, | |
26 | - :class => 'button with-text icon-add', | |
27 | - :title => _('Join this community') %> | |
25 | + <%= button(:add, _('Join'), profile.join_not_logged_url, :title => _('Join this community')) %> | |
28 | 26 | <% end %> |
29 | 27 | </div> | ... | ... |
app/views/blocks/profile_info_actions/_person.html.erb
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | <% end %> |
9 | 9 | |
10 | 10 | <% if user.is_a_friend?(profile) && profile.enable_contact? %> |
11 | - <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> | |
11 | + <li><%= button(:back, _('Send an e-mail'), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}) %></li> | |
12 | 12 | <% end %> |
13 | 13 | |
14 | 14 | <li><%= report_abuse(profile, :button) %></li> | ... | ... |
app/views/box_organizer/_highlights_block.html.erb
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | </tbody> |
16 | 16 | </table> |
17 | 17 | |
18 | -<%= link_to(_('New highlight'), '#', :class => 'button icon-add with-text new-highlight-button')%> | |
18 | +<%= button(:add, _('New highlight'), '#', class: 'new-highlight-button') %> | |
19 | 19 | |
20 | 20 | <%= 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]}) %> |
21 | 21 | ... | ... |
app/views/comment/_comment_actions.html.erb
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | <% if !links_submenu.empty? %> |
3 | 3 | <div class="comment-actions"> |
4 | 4 | <li class="vcard"> |
5 | - <%= 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) %> | |
5 | + <%= popover_menu(_('Contents menu'),'',links_submenu,:class => 'comment-trigger', :url => url) %> | |
6 | 6 | </li> |
7 | 7 | </div> |
8 | 8 | <% end %> | ... | ... |
app/views/favorite_enterprises/index.html.erb
... | ... | @@ -9,10 +9,7 @@ |
9 | 9 | enterprise.identifier, :class => 'profile-link' %> |
10 | 10 | <%# profile_image_link enterprise, :portrait, 'div' %> |
11 | 11 | <div class="controll"> |
12 | - <%= link_to content_tag('span',_('remove')), | |
13 | - { :action => 'remove', :id => enterprise.id }, | |
14 | - :class => 'button icon-delete', | |
15 | - :title => _('remove') %> | |
12 | + <%= button(:delete, _('remove'), { :action => 'remove', :id => enterprise.id },:title => _('remove')) %> | |
16 | 13 | </div><!-- end class="controll" --> |
17 | 14 | </li> |
18 | 15 | <% end %> | ... | ... |
app/views/search/_sellers_form.html.erb
app/views/shared/_change_image.html.erb
1 | 1 | <%= i.file_field( :uploaded_data, { :onchange => 'updateImg(this.value)' } ) %> |
2 | - <%= 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') %> | |
2 | + <%= 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
... | ... | @@ -4,12 +4,12 @@ |
4 | 4 | <%= hidden_field_tag "#{object_name}[#{object_name}_category_id]", @current_category.id unless multiple %> |
5 | 5 | <%= hidden_field_tag "#{object_name}[category_ids][]", @current_category.id if multiple %> |
6 | 6 | |
7 | - <%= update_categories_link("", nil, :id => "cancel-category-button", :class => "button icon-back") %> | |
7 | + <%= update_categories_link(:back, "", nil, :id => "cancel-category-button") %> | |
8 | 8 | <% |
9 | 9 | categories = [@current_category] |
10 | 10 | categories.push(@current_category) while @current_category = @current_category.parent |
11 | 11 | %> |
12 | - <%= categories.compact.reverse.map{|i| update_categories_link(i.name, i.id)}.join %> | |
12 | + <%= categories.compact.reverse.map{|i| update_categories_link(nil,i.name, i.id)}.join %> | |
13 | 13 | |
14 | 14 | <script> |
15 | 15 | function add_category() { | ... | ... |
app/views/shared/_select_subcategories.html.erb
... | ... | @@ -3,6 +3,6 @@ |
3 | 3 | <div class="category-helper-label"><%= _('Click to select a category') %></div> |
4 | 4 | |
5 | 5 | <% categories.select{|i| @object.accept_category?(i)}.each do |category| %> |
6 | - <%= update_categories_link(category.name, category.id) %> | |
6 | + <%= update_categories_link(nil,category.name, category.id) %> | |
7 | 7 | <% end %> |
8 | 8 | <% end %> | ... | ... |
app/views/shared/_show_thumbnail.html.erb
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 3 | <br/> |
4 | 4 | |
5 | - <%= link_to_function(_('Change image'), 'display_change_image()', :id => 'change-image-link', :class => 'button icon-photos with-text') %> | |
5 | + <%= button_to_function(:photos, _('Change image'), 'display_change_image()', :id => 'change-image-link' ) %> | |
6 | 6 | |
7 | 7 | <script> |
8 | 8 | function display_change_image() { | ... | ... |
app/views/tasks/index.html.erb
... | ... | @@ -23,7 +23,7 @@ |
23 | 23 | |
24 | 24 | <% if @tasks.empty? %> |
25 | 25 | <p> |
26 | - <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => 'document.location.href = "?filter_type="+this.value')%> | |
26 | + <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => "document.location.href = '?filter_type='+this.value")%> | |
27 | 27 | </p> |
28 | 28 | <em><%= _('No pending tasks for %s') % profile.name %></em> |
29 | 29 | <% else %> | ... | ... |
test/test_helper.rb
... | ... | @@ -140,9 +140,18 @@ class ActiveSupport::TestCase |
140 | 140 | end |
141 | 141 | |
142 | 142 | # For models that render views (blocks, articles, ...) |
143 | - def render(*args) | |
144 | - view_paths = @explicit_view_paths || ActionController::Base.view_paths | |
145 | - ActionView::Base.new(view_paths, {}).render(*args) | |
143 | + def self.action_view | |
144 | + @action_view ||= begin | |
145 | + view_paths = ActionController::Base.view_paths | |
146 | + action_view = ActionView::Base.new view_paths, {} | |
147 | + # for using Noosfero helpers inside render calls | |
148 | + action_view.extend ApplicationHelper | |
149 | + action_view | |
150 | + end | |
151 | + end | |
152 | + | |
153 | + def render *args | |
154 | + self.class.action_view.render(*args) | |
146 | 155 | end |
147 | 156 | |
148 | 157 | private | ... | ... |