Commit 95bab8a2affbaded5c00dc9e4f299f6be8eefdab

Authored by Rafael Reggiani Manzo
1 parent 0834f87c

Extract DisplayContentBlock doc list into method

This is the logic the actually belongs to the class. The remainder of
content method should get refactored in terms of views and helpers.
plugins/display_content/lib/display_content_block.rb
@@ -118,32 +118,38 @@ class DisplayContentBlock < Block @@ -118,32 +118,38 @@ class DisplayContentBlock < Block
118 holder.articles.where(type: types, parent_id: if parent.nil? then nil else parent end) 118 holder.articles.where(type: types, parent_id: if parent.nil? then nil else parent end)
119 end 119 end
120 120
121 - def content(args={})  
122 - block = self  
123 - 121 + def docs
124 order_string = "published_at" 122 order_string = "published_at"
125 order_string += " DESC" if order_by_recent 123 order_string += " DESC" if order_by_recent
126 124
127 limit_final = [limit_to_show, 0].max 125 limit_final = [limit_to_show, 0].max
128 126
129 - docs = owner.articles.order(order_string) 127 + documents = owner.articles.order(order_string)
130 .where(articles: {type: self.types}) 128 .where(articles: {type: self.types})
131 .includes(:profile, :image, :tags) 129 .includes(:profile, :image, :tags)
132 if nodes.present? 130 if nodes.present?
133 nodes_conditions = 'articles.id IN(:nodes)' 131 nodes_conditions = 'articles.id IN(:nodes)'
134 nodes_conditions << ' OR articles.parent_id IN(:nodes) ' if display_folder_children 132 nodes_conditions << ' OR articles.parent_id IN(:nodes) ' if display_folder_children
135 - docs = docs.where nodes_conditions, nodes: nodes 133 + documents = documents.where nodes_conditions, nodes: nodes
136 end 134 end
137 - docs = docs.limit limit_final if display_folder_children 135 + documents = documents.limit limit_final if display_folder_children
138 136
139 if content_with_translations 137 if content_with_translations
140 - docs = docs.native_translations  
141 - docs.replace docs.map{ |p| p.get_translation_to(FastGettext.locale) }.compact 138 + documents = documents.native_translations
  139 + documents.replace documents.map{ |p| p.get_translation_to(FastGettext.locale) }.compact
142 end 140 end
143 141
  142 + documents
  143 + end
  144 +
  145 + def content(args={})
  146 + block = self
  147 +
  148 + items = self.docs
  149 +
144 proc do 150 proc do
145 block.block_title(block.title, block.subtitle) + 151 block.block_title(block.title, block.subtitle) +
146 - content_tag('ul', docs.map {|item| 152 + content_tag('ul', items.map {|item|
147 if !item.folder? && item.class != RssFeed 153 if !item.folder? && item.class != RssFeed
148 content_sections = '' 154 content_sections = ''
149 read_more_section = '' 155 read_more_section = ''