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 118 holder.articles.where(type: types, parent_id: if parent.nil? then nil else parent end)
119 119 end
120 120  
121   - def content(args={})
122   - block = self
123   -
  121 + def docs
124 122 order_string = "published_at"
125 123 order_string += " DESC" if order_by_recent
126 124  
127 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 128 .where(articles: {type: self.types})
131 129 .includes(:profile, :image, :tags)
132 130 if nodes.present?
133 131 nodes_conditions = 'articles.id IN(:nodes)'
134 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 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 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 140 end
143 141  
  142 + documents
  143 + end
  144 +
  145 + def content(args={})
  146 + block = self
  147 +
  148 + items = self.docs
  149 +
144 150 proc do
145 151 block.block_title(block.title, block.subtitle) +
146   - content_tag('ul', docs.map {|item|
  152 + content_tag('ul', items.map {|item|
147 153 if !item.folder? && item.class != RssFeed
148 154 content_sections = ''
149 155 read_more_section = ''
... ...