Commit 2b143a6d243acca2d67234efb084f607833bf09e

Authored by Joenio Costa
Committed by Rafael Reggiani Manzo
1 parent bc4a8cfe

moving out HTML from several blocks

app/models/link_list_block.rb
@@ -60,17 +60,10 @@ class LinkListBlock < Block @@ -60,17 +60,10 @@ class LinkListBlock < Block
60 end 60 end
61 61
62 def content(args={}) 62 def content(args={})
63 - block_title(title) +  
64 - content_tag('ul',  
65 - links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_html(i))}.join  
66 - )  
67 - end  
68 -  
69 - def link_html(link)  
70 - klass = 'icon-' + link[:icon] if link[:icon]  
71 - sanitize_link(  
72 - link_to(link[:name], expand_address(link[:address]), :target => link[:target], :class => klass, :title => link[:title])  
73 - ) 63 + block = self
  64 + proc do
  65 + render :file => 'blocks/link_list', :locals => { :block => block }
  66 + end
74 end 67 end
75 68
76 def expand_address(address) 69 def expand_address(address)
@@ -99,8 +92,6 @@ class LinkListBlock < Block @@ -99,8 +92,6 @@ class LinkListBlock < Block
99 end 92 end
100 end 93 end
101 94
102 - private  
103 -  
104 def sanitize_link(text) 95 def sanitize_link(text)
105 sanitizer = HTML::WhiteListSanitizer.new 96 sanitizer = HTML::WhiteListSanitizer.new
106 sanitizer.sanitize(text) 97 sanitizer.sanitize(text)
app/models/location_block.rb
@@ -15,9 +15,8 @@ class LocationBlock < Block @@ -15,9 +15,8 @@ class LocationBlock < Block
15 15
16 def content(args={}) 16 def content(args={})
17 block = self 17 block = self
18 - profile = self.owner  
19 proc do 18 proc do
20 - render :file => 'blocks/location', :locals => {:block => block, :profile => profile} 19 + render :file => 'blocks/location', :locals => {:block => block}
21 end 20 end
22 end 21 end
23 22
app/models/my_network_block.rb
@@ -17,10 +17,7 @@ class MyNetworkBlock < Block @@ -17,10 +17,7 @@ class MyNetworkBlock < Block
17 def content(args={}) 17 def content(args={})
18 block = self 18 block = self
19 proc do 19 proc do
20 - render :file => 'blocks/my_network', :locals => {  
21 - :title => block.title,  
22 - :owner => block.owner  
23 - } 20 + render :file => 'blocks/my_network', :locals => { :block => block }
24 end 21 end
25 end 22 end
26 23
app/models/products_block.rb
@@ -20,19 +20,10 @@ class ProductsBlock < Block @@ -20,19 +20,10 @@ class ProductsBlock < Block
20 end 20 end
21 21
22 def content(args={}) 22 def content(args={})
23 - block_title(title) +  
24 - content_tag(  
25 - 'ul',  
26 - products.map {|product|  
27 - content_tag('li',  
28 - link_to( product.name,  
29 - product.url,  
30 - :style => 'background-image:url(%s)' % product.default_image('minor')  
31 - ),  
32 - :class => 'product'  
33 - )  
34 - }.join  
35 - ) 23 + block = self
  24 + proc do
  25 + render :file => 'blocks/products', :locals => { :block => block }
  26 + end
36 end 27 end
37 28
38 def footer 29 def footer
app/models/profile_image_block.rb
@@ -14,12 +14,8 @@ class ProfileImageBlock < Block @@ -14,12 +14,8 @@ class ProfileImageBlock < Block
14 14
15 def content(args={}) 15 def content(args={})
16 block = self 16 block = self
17 - s = show_name  
18 - lambda do |object|  
19 - render(  
20 - :file => 'blocks/profile_image',  
21 - :locals => { :block => block, :show_name => s }  
22 - ) 17 + proc do
  18 + render :file => 'blocks/profile_image', :locals => { :block => block }
23 end 19 end
24 end 20 end
25 21
app/models/profile_info_block.rb
@@ -18,7 +18,7 @@ class ProfileInfoBlock < Block @@ -18,7 +18,7 @@ class ProfileInfoBlock < Block
18 18
19 def content(args={}) 19 def content(args={})
20 block = self 20 block = self
21 - lambda do |_| 21 + proc do
22 render :file => 'blocks/profile_info', :locals => { :block => block } 22 render :file => 'blocks/profile_info', :locals => { :block => block }
23 end 23 end
24 end 24 end
app/models/profile_search_block.rb
@@ -5,9 +5,9 @@ class ProfileSearchBlock < Block @@ -5,9 +5,9 @@ class ProfileSearchBlock < Block
5 end 5 end
6 6
7 def content(args={}) 7 def content(args={})
8 - title = self.title  
9 - lambda do |_|  
10 - render :file => 'blocks/profile_search', :locals => { :title => title } 8 + block = self
  9 + proc do
  10 + render :file => 'blocks/profile_search', :locals => { :block => block }
11 end 11 end
12 end 12 end
13 13
app/models/raw_html_block.rb
@@ -13,7 +13,10 @@ class RawHTMLBlock < Block @@ -13,7 +13,10 @@ class RawHTMLBlock < Block
13 attr_accessible :html 13 attr_accessible :html
14 14
15 def content(args={}) 15 def content(args={})
16 - (title.blank? ? '' : block_title(title)).html_safe + html.to_s.html_safe 16 + block = self
  17 + proc do
  18 + render :file => 'blocks/raw_html', :locals => { :block => block }
  19 + end
17 end 20 end
18 21
19 def has_macro? 22 def has_macro?
app/models/recent_documents_block.rb
@@ -23,11 +23,9 @@ class RecentDocumentsBlock < Block @@ -23,11 +23,9 @@ class RecentDocumentsBlock < Block
23 settings_items :limit, :type => :integer, :default => 5 23 settings_items :limit, :type => :integer, :default => 5
24 24
25 def content(args={}) 25 def content(args={})
26 - docs = self.docs  
27 - title = self.title 26 + block = self
28 proc do 27 proc do
29 - block_title(title) +  
30 - content_tag('ul', docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) 28 + render :file => 'blocks/recent_documents', :locals => { :block => block }
31 end 29 end
32 end 30 end
33 31
app/models/sellers_search_block.rb
@@ -23,9 +23,9 @@ class SellersSearchBlock < Block @@ -23,9 +23,9 @@ class SellersSearchBlock < Block
23 end 23 end
24 24
25 def content(args={}) 25 def content(args={})
26 - title = self.title  
27 - lambda do |object|  
28 - render :file => 'search/_sellers_form', :locals => { :title => title } 26 + block = self
  27 + proc do
  28 + render :file => 'blocks/sellers_search', :locals => { :block => block }
29 end 29 end
30 end 30 end
31 end 31 end
app/models/slideshow_block.rb
@@ -35,18 +35,8 @@ class SlideshowBlock < Block @@ -35,18 +35,8 @@ class SlideshowBlock < Block
35 35
36 def content(args={}) 36 def content(args={})
37 block = self 37 block = self
38 - if gallery  
39 - images = block_images  
40 - if shuffle  
41 - images = images.shuffle  
42 - end  
43 - proc do  
44 - render :file => 'blocks/slideshow', :locals => { :block => block, :images => images }  
45 - end  
46 - else  
47 - proc do  
48 - render :file => 'blocks/slideshow', :locals => { :block => block, :images => nil }  
49 - end 38 + proc do
  39 + render :file => 'blocks/slideshow', :locals => { :block => block }
50 end 40 end
51 end 41 end
52 42
app/views/blocks/link_list.html.erb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +<%= block_title(block.title) %>
  2 +
  3 +<ul>
  4 + <% block.links.select{|i| !i[:name].blank? and !i[:address].blank?}.each do |link| %>
  5 + <li>
  6 + <%= block.sanitize_link(link_to(link[:name], block.expand_address(link[:address]),
  7 + :target => link[:target],
  8 + :class => (link[:icon] ? "icon-#{link[:icon]}" : ''),
  9 + :title => link[:title])) %>
  10 + </li>
  11 + <% end %>
  12 +</ul>
app/views/blocks/location.html.erb
1 -<% if profile.lat %> 1 +<% if block.owner.lat %>
2 <%= block_title block.title %> 2 <%= block_title block.title %>
3 <div class='the-localization-map'> 3 <div class='the-localization-map'>
4 - <img src="https://maps.google.com/maps/api/staticmap?center=<%=profile.lat%>,<%=profile.lng%>&zoom=<%=block.zoom%>&size=190x250&maptype=<%=block.map_type%>&markers=<%=profile.lat%>,<%=profile.lng%>&sensor=false"/> 4 + <img src="https://maps.google.com/maps/api/staticmap?center=<%=block.owner.lat%>,<%=block.owner.lng%>&zoom=<%=block.zoom%>&size=190x250&maptype=<%=block.map_type%>&markers=<%=block.owner.lat%>,<%=block.owner.lng%>&sensor=false"/>
5 </div> 5 </div>
6 <% else %> 6 <% else %>
7 <i><%= _('This profile has no geographical position registered.') %></i> 7 <i><%= _('This profile has no geographical position registered.') %></i>
app/views/blocks/my_network.html.erb
1 -<%= block_title(title) %> 1 +<%= block_title(block.title) %>
2 2
3 <ul> 3 <ul>
4 - <li><%= link_to(_('Homepage'), owner.url, :class => 'url') %></li>  
5 - <li><%= link_to(_('View profile'), owner.public_profile_url) %></li>  
6 - <% if !user.nil? and owner.organization? and user.has_permission?('edit_profile', profile) %> 4 + <li><%= link_to(_('Homepage'), block.owner.url, :class => 'url') %></li>
  5 + <li><%= link_to(_('View profile'), block.owner.public_profile_url) %></li>
  6 + <% if !user.nil? and block.owner.organization? and user.has_permission?('edit_profile', profile) %>
7 <li><%= link_to _('Control panel'), :controller => 'profile_editor', :profile => profile.identifier %></li> 7 <li><%= link_to _('Control panel'), :controller => 'profile_editor', :profile => profile.identifier %></li>
8 <% end %> 8 <% end %>
9 </ul> 9 </ul>
10 10
11 <div class="my-network-actions"> 11 <div class="my-network-actions">
12 - <%= render_profile_actions owner.class %> 12 + <%= render_profile_actions block.owner.class %>
13 </div> 13 </div>
app/views/blocks/products.html.erb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +<%= block_title(block.title) %>
  2 +
  3 +<ul>
  4 + <% block.products.each do |product| %>
  5 + <li class='product'>
  6 + <%= link_to(product.name, product.url, :style => 'background-image:url(%s)' % product.default_image('minor')) %>
  7 + </li>
  8 + <% end %>
  9 +</ul>
app/views/blocks/profile_image.html.erb
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 </div> 12 </div>
13 </div> 13 </div>
14 14
15 -<% if show_name %> 15 +<% if block.show_name %>
16 <p><%= h block.owner.short_name %></p> 16 <p><%= h block.owner.short_name %></p>
17 <% end %> 17 <% end %>
18 18
app/views/blocks/profile_search.html.erb
1 -<%= block_title(title) %> 1 +<%= block_title(block.title) %>
2 2
3 <%= render :partial => 'shared/profile_search_form' %> 3 <%= render :partial => 'shared/profile_search_form' %>
app/views/blocks/raw_html.html.erb 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +<%=h block_title(block.title) %>
  2 +
  3 +<%=h block.html %>
app/views/blocks/recent_documents.html.erb 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +<%= block_title(block.title) %>
  2 +
  3 +<ul>
  4 + <% block.docs.map do |item| %>
  5 + <%= content_tag('li', link_to(h(item.title), item.url)) %>
  6 + <% end %>
  7 +</ul>
app/views/blocks/sellers_search.html.erb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +<h3><%= block.title %></h3>
  2 +
  3 +<%= form_tag({:controller => 'search', :action => 'assets'}, {:method => 'get'}) do %>
  4 +
  5 + <div class="search-in-opt"><%= _('Search in:') %>
  6 + <dir>
  7 + <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', true %><br />
  8 + <%= labelled_radio_button _('Products'), 'asset', 'products', false %>
  9 + </dir>
  10 + </div>
  11 +
  12 + <div class="formfield search-from-opt">
  13 + <%= select_city(true) %>
  14 + </div>
  15 +
  16 + <div class="formfield search-distance-opt">
  17 + <%= labelled_select(_('Distance:'), 'radius', :first, :last, nil, [15, 30, 50, 100, 150, 200, 300, 400, 500, 1000].map{|n|[n, n.to_s + 'km']}) %>
  18 + </div>
  19 +
  20 + <div class="button-bar">
  21 + <%= submit_button :search, _('Search') %>
  22 + </div>
  23 +
  24 +<% end %>
app/views/blocks/slideshow.html.erb
  1 +<%
  2 + if block.gallery
  3 + images = block.block_images
  4 + if block.shuffle
  5 + images = images.shuffle
  6 + end
  7 + end
  8 +%>
  9 +
1 <%= block_title(block.title) %> 10 <%= block_title(block.title) %>
  11 +
2 <% if images %> 12 <% if images %>
3 <% description = images.any? { |img| !img.abstract.blank? } %> 13 <% description = images.any? { |img| !img.abstract.blank? } %>
4 <div class='slideshow-border<%= (description ? ' with-descriptions' : '')%>'> 14 <div class='slideshow-border<%= (description ? ' with-descriptions' : '')%>'>
app/views/search/_sellers_form.html.erb
@@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
1 -<h3><%= title %></h3>  
2 -  
3 -<%= form_tag({:controller => 'search', :action => 'assets'}, {:method => 'get'}) do %>  
4 -  
5 - <div class="search-in-opt"><%= _('Search in:') %>  
6 - <dir>  
7 - <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', true %><br />  
8 - <%= labelled_radio_button _('Products'), 'asset', 'products', false %>  
9 - </dir>  
10 - </div>  
11 -  
12 - <div class="formfield search-from-opt">  
13 - <%= select_city(true) %>  
14 - </div>  
15 -  
16 - <div class="formfield search-distance-opt">  
17 - <%= labelled_select(_('Distance:'), 'radius', :first, :last, nil, [15, 30, 50, 100, 150, 200, 300, 400, 500, 1000].map{|n|[n, n.to_s + 'km']}) %>  
18 - </div>  
19 -  
20 - <div class="button-bar">  
21 - <%= submit_button :search, _('Search') %>  
22 - </div>  
23 -  
24 -<% end %>