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 60 end
61 61  
62 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 67 end
75 68  
76 69 def expand_address(address)
... ... @@ -99,8 +92,6 @@ class LinkListBlock < Block
99 92 end
100 93 end
101 94  
102   - private
103   -
104 95 def sanitize_link(text)
105 96 sanitizer = HTML::WhiteListSanitizer.new
106 97 sanitizer.sanitize(text)
... ...
app/models/location_block.rb
... ... @@ -15,9 +15,8 @@ class LocationBlock < Block
15 15  
16 16 def content(args={})
17 17 block = self
18   - profile = self.owner
19 18 proc do
20   - render :file => 'blocks/location', :locals => {:block => block, :profile => profile}
  19 + render :file => 'blocks/location', :locals => {:block => block}
21 20 end
22 21 end
23 22  
... ...
app/models/my_network_block.rb
... ... @@ -17,10 +17,7 @@ class MyNetworkBlock < Block
17 17 def content(args={})
18 18 block = self
19 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 21 end
25 22 end
26 23  
... ...
app/models/products_block.rb
... ... @@ -20,19 +20,10 @@ class ProductsBlock < Block
20 20 end
21 21  
22 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 27 end
37 28  
38 29 def footer
... ...
app/models/profile_image_block.rb
... ... @@ -14,12 +14,8 @@ class ProfileImageBlock < Block
14 14  
15 15 def content(args={})
16 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 19 end
24 20 end
25 21  
... ...
app/models/profile_info_block.rb
... ... @@ -18,7 +18,7 @@ class ProfileInfoBlock < Block
18 18  
19 19 def content(args={})
20 20 block = self
21   - lambda do |_|
  21 + proc do
22 22 render :file => 'blocks/profile_info', :locals => { :block => block }
23 23 end
24 24 end
... ...
app/models/profile_search_block.rb
... ... @@ -5,9 +5,9 @@ class ProfileSearchBlock < Block
5 5 end
6 6  
7 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 11 end
12 12 end
13 13  
... ...
app/models/raw_html_block.rb
... ... @@ -13,7 +13,10 @@ class RawHTMLBlock < Block
13 13 attr_accessible :html
14 14  
15 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 20 end
18 21  
19 22 def has_macro?
... ...
app/models/recent_documents_block.rb
... ... @@ -23,11 +23,9 @@ class RecentDocumentsBlock < Block
23 23 settings_items :limit, :type => :integer, :default => 5
24 24  
25 25 def content(args={})
26   - docs = self.docs
27   - title = self.title
  26 + block = self
28 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 29 end
32 30 end
33 31  
... ...
app/models/sellers_search_block.rb
... ... @@ -23,9 +23,9 @@ class SellersSearchBlock < Block
23 23 end
24 24  
25 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 29 end
30 30 end
31 31 end
... ...
app/models/slideshow_block.rb
... ... @@ -35,18 +35,8 @@ class SlideshowBlock < Block
35 35  
36 36 def content(args={})
37 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 40 end
51 41 end
52 42  
... ...
app/views/blocks/link_list.html.erb 0 → 100644
... ... @@ -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 2 <%= block_title block.title %>
3 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 5 </div>
6 6 <% else %>
7 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 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 7 <li><%= link_to _('Control panel'), :controller => 'profile_editor', :profile => profile.identifier %></li>
8 8 <% end %>
9 9 </ul>
10 10  
11 11 <div class="my-network-actions">
12   - <%= render_profile_actions owner.class %>
  12 + <%= render_profile_actions block.owner.class %>
13 13 </div>
... ...
app/views/blocks/products.html.erb 0 → 100644
... ... @@ -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 12 </div>
13 13 </div>
14 14  
15   -<% if show_name %>
  15 +<% if block.show_name %>
16 16 <p><%= h block.owner.short_name %></p>
17 17 <% end %>
18 18  
... ...
app/views/blocks/profile_search.html.erb
1   -<%= block_title(title) %>
  1 +<%= block_title(block.title) %>
2 2  
3 3 <%= render :partial => 'shared/profile_search_form' %>
... ...
app/views/blocks/raw_html.html.erb 0 → 100644
... ... @@ -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 @@
  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 @@
  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 10 <%= block_title(block.title) %>
  11 +
2 12 <% if images %>
3 13 <% description = images.any? { |img| !img.abstract.blank? } %>
4 14 <div class='slideshow-border<%= (description ? ' with-descriptions' : '')%>'>
... ...
app/views/search/_sellers_form.html.erb
... ... @@ -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 %>