From b6f11d12d09372caad557b2e4735b266ce714b40 Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Wed, 25 Nov 2015 17:15:48 -0200 Subject: [PATCH] moved HTML out of all core blocks --- app/models/blog_archives_block.rb | 1 - app/models/disabled_enterprise_message_block.rb | 2 +- app/models/product_categories_block.rb | 17 ++--------------- app/models/profile_list_block.rb | 19 +++---------------- app/models/tags_block.rb | 20 +++----------------- app/views/blocks/blog_archives.html.erb | 26 ++++++++++++++------------ app/views/blocks/product_categories.html.erb | 16 +++++++++++++--- app/views/blocks/profile_list.html.erb | 16 ++++++++++++++++ app/views/blocks/tags.html.erb | 25 +++++++++++++++++++++++++ 9 files changed, 77 insertions(+), 65 deletions(-) create mode 100644 app/views/blocks/profile_list.html.erb create mode 100644 app/views/blocks/tags.html.erb diff --git a/app/models/blog_archives_block.rb b/app/models/blog_archives_block.rb index 00713a8..e16c3ba 100644 --- a/app/models/blog_archives_block.rb +++ b/app/models/blog_archives_block.rb @@ -22,7 +22,6 @@ class BlogArchivesBlock < Block end def content(args={}) - return nil unless self.blog block = self proc do render :file => 'blocks/blog_archives', :locals => { :block => block } diff --git a/app/models/disabled_enterprise_message_block.rb b/app/models/disabled_enterprise_message_block.rb index f3f217d..5d06f89 100644 --- a/app/models/disabled_enterprise_message_block.rb +++ b/app/models/disabled_enterprise_message_block.rb @@ -14,7 +14,7 @@ class DisabledEnterpriseMessageBlock < Block def content(args={}) block = self - lambda do |_| + proc do render :file => 'blocks/disabled_enterprise_message', :locals => { :block => block } end end diff --git a/app/models/product_categories_block.rb b/app/models/product_categories_block.rb index 427fd2d..071412f 100644 --- a/app/models/product_categories_block.rb +++ b/app/models/product_categories_block.rb @@ -14,22 +14,9 @@ class ProductCategoriesBlock < Block end def content(args={}) - profile = owner + block = self proc do - if @categories.nil? or @categories.length == 0 - categories = ProductCategory.on_level(nil).order(:name) - if @categories and @categories.length == 0 - notice = _('There are no sub-categories for %s') % @category.name - end - else - categories = @categories - end - render :file => 'blocks/product_categories', - :locals => { - :profile => profile, - :categories => categories, - :notice => notice - } + render :file => 'blocks/product_categories', :locals => { :block => block } end end diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index fc8ea89..76ca8fa 100644 --- a/app/models/profile_list_block.rb +++ b/app/models/profile_list_block.rb @@ -41,22 +41,9 @@ result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at end def content(args={}) - profiles = self.profile_list - title = self.view_title - nl = "\n" - proc do |context| - count=0 - list = profiles.map {|item| - count+=1 - send(:profile_image_link, item, :minor ) - }.join("\n ") - if list.empty? - list = content_tag 'div', _('None'), :class => 'common-profile-list-block-none' - else - list = content_tag 'ul', nl +' '+ list + nl - end - block_title(title) + nl + - content_tag('div', nl + list + nl + tag('br', :style => 'clear:both')) + block = self + proc do + render :file => 'blocks/profile_list', :locals => { :block => block } end end diff --git a/app/models/tags_block.rb b/app/models/tags_block.rb index 9a94712..bd14289 100644 --- a/app/models/tags_block.rb +++ b/app/models/tags_block.rb @@ -29,24 +29,10 @@ class TagsBlock < Block end def content(args={}) - is_env = owner.class == Environment - tags = is_env ? owner.tag_counts : owner.article_tags - return '' if tags.empty? - - if limit - tags_tmp = tags.sort_by{ |k,v| -v }[0..(limit-1)] - tags = {} - tags_tmp.map{ |k,v| tags[k] = v } + block = self + proc do + render :file => 'blocks/tags', :locals => { :block => block } end - - url = is_env ? {:host=>owner.default_hostname, :controller=>'search', :action => 'tag'} : - owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged') - tagname_option = is_env ? :tag : :id - - block_title(title) + - "\n
\n".html_safe+ - tag_cloud( tags, tagname_option, url, :max_size => 16, :min_size => 9 ) + - "\n
\n".html_safe end def footer diff --git a/app/views/blocks/blog_archives.html.erb b/app/views/blocks/blog_archives.html.erb index 342e848..552490c 100644 --- a/app/views/blocks/blog_archives.html.erb +++ b/app/views/blocks/blog_archives.html.erb @@ -1,14 +1,16 @@ -<%= block_title(block.title) %> +<% if block.blog %> + <%= block_title(block.title) %> - + -<%= content_tag('div', link_to(_('Subscribe RSS Feed'), block.blog.feed.url), :class => 'subscribe-feed') %> + <%= content_tag('div', link_to(_('Subscribe RSS Feed'), block.blog.feed.url), :class => 'subscribe-feed') %> +<% end %> diff --git a/app/views/blocks/product_categories.html.erb b/app/views/blocks/product_categories.html.erb index bbffe02..3288ec0 100644 --- a/app/views/blocks/product_categories.html.erb +++ b/app/views/blocks/product_categories.html.erb @@ -1,9 +1,19 @@ -<%= link_to _('Catalog start'), profile.catalog_url, :class=>'catalog-home-link' %> +<% + if @categories.nil? or @categories.length == 0 + categories = ProductCategory.on_level(nil).order(:name) + else + categories = @categories + end +%> + +<%= link_to _('Catalog start'), block.owner.catalog_url, :class=>'catalog-home-link' %> -<% if notice %> -
<%= notice %>
+<% if @categories and @categories.length == 0 %> +
+ <%= _('There are no sub-categories for %s') % @category.name %> +
<% end %> diff --git a/app/views/blocks/profile_list.html.erb b/app/views/blocks/profile_list.html.erb new file mode 100644 index 0000000..6243b9a --- /dev/null +++ b/app/views/blocks/profile_list.html.erb @@ -0,0 +1,16 @@ +<%= block_title(block.view_title) %> + +<% + count=0 + list = block.profile_list.map {|item| count+=1 block.send(:profile_image_link, item, :minor)}.join("\n ") +%> + +
+ <% if list.empty? %> +
<%= _('None') %>
+ <% else %> + + <% end %> +
+ +
diff --git a/app/views/blocks/tags.html.erb b/app/views/blocks/tags.html.erb new file mode 100644 index 0000000..46eebfc --- /dev/null +++ b/app/views/blocks/tags.html.erb @@ -0,0 +1,25 @@ +<%= block_title(block.title) %> + +<% + is_env = block.owner.class == Environment + tags = is_env ? block.owner.tag_counts : block.owner.article_tags + if block.limit + tags_tmp = tags.sort_by{ |k,v| -v }[0..(block.limit-1)] + tags = {} + tags_tmp.map{ |k,v| tags[k] = v } + end +%> + +<% unless tags.empty? %> +
+ <% if is_env %> + <%= tag_cloud(tags, :tag, + {:host=>block.owner.default_hostname, :controller=>'search', :action => 'tag'}, + :max_size => 16, :min_size => 9) %> + <% else %> + <%= tag_cloud(tags, :id, + owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged'), + :max_size => 16, :min_size => 9) %> + <% end %> +
+<% end %> -- libgit2 0.21.2