Commit ce6338053dd6cd2060eef580b6a6204f5b63cb2c

Authored by Braulio Bhavamitra
1 parent f8bfab0f

event: fix lead

app/models/event.rb
... ... @@ -145,11 +145,9 @@ class Event < Article
145 145 ((self.end_date || self.start_date) - self.start_date).to_i
146 146 end
147 147  
  148 + alias_method :article_lead, :lead
148 149 def lead
149   - content_tag('div',
150   - show_period(start_date, end_date),
151   - :class => 'event-dates'
152   - ) + super
  150 + self.class.action_view.render 'content_viewer/event_lead', event: self
153 151 end
154 152  
155 153 def event?
... ...
app/views/content_viewer/_event_lead.html.erb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +
  2 +<div class="event-dates">
  3 + <%= show_period event.start_date, event.end_date %>
  4 +</div>
  5 +
  6 +<%= event.article_lead %>
  7 +
... ...
lib/noosfero/core_ext/active_record.rb
... ... @@ -6,6 +6,22 @@ class ActiveRecord::Base
6 6 ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
7 7 end
8 8  
  9 + # an ActionView instance for rendering views on models
  10 + def self.action_view
  11 + @action_view ||= begin
  12 + view_paths = ActionController::Base.view_paths
  13 + action_view = ActionView::Base.new view_paths
  14 + # for using Noosfero helpers inside render calls
  15 + action_view.extend ApplicationHelper
  16 + action_view
  17 + end
  18 + end
  19 +
  20 + # default value needed for the above ActionView
  21 + def to_partial_path
  22 + self.class.name.underscore
  23 + end
  24 +
9 25 alias :meta_cache_key :cache_key
10 26 def cache_key
11 27 key = [Noosfero::VERSION, meta_cache_key]
... ...