radiant-featured_pages-extension 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -111,6 +111,7 @@ module FeaturedPagesTags
111
111
  * format - used only with the date parameters to specify the format of the date you are using
112
112
  * window - '+3 days' no default, allows you to add(+n) or subtract(-n) days, weeks, months, years
113
113
  * offset - '-1 month' no default, allows you to offset the actual date from the date given
114
+ * latest - 'true' or 'false'. Defaults to 'false'. Expands only if the page is the latest feature
114
115
 
115
116
  Selecting a date of 'future' or 'past' will expand the window to any time in the future or past
116
117
  beyond the offset.
@@ -120,8 +121,9 @@ module FeaturedPagesTags
120
121
  }
121
122
  tag 'if_featured' do |tag|
122
123
  date = tag.attr["date"] || nil
124
+ latest = tag.attr['latest'] || false
123
125
 
124
- if date
126
+ if date || latest == 'true'
125
127
  offset_pair = change_pairs(tag.attr['offset'])
126
128
  window_pair = change_pairs(tag.attr['window'])
127
129
 
@@ -134,16 +136,17 @@ module FeaturedPagesTags
134
136
  Rails.env.test? ? Time.zone.now - 1.second : Time.zone.now
135
137
  end
136
138
 
137
- date_with_offset = focus_date.in_time_zone + offset_pair.first.send(offset_pair.last)
138
- date_with_window = date_with_offset + window_pair.first.send(window_pair.last)
139
+ date_with_offset = (focus_date.in_time_zone + offset_pair.first.send(offset_pair.last)).beginning_of_day
140
+ date_with_window = (date_with_offset + window_pair.first.send(window_pair.last)).end_of_day
139
141
  range_dates = [date_with_offset, date_with_window].sort
140
142
 
141
143
  in_future_window = (date == 'future' && tag.locals.page.featured_date > date_with_offset)
142
144
  in_past_window = (date == 'past' && tag.locals.page.featured_date < date_with_offset)
143
145
  in_range_window = (tag.locals.page.featured_date >= range_dates.first.beginning_of_day && tag.locals.page.featured_date <= range_dates.last.end_of_day)
144
146
 
145
- if in_future_window || in_past_window || in_range_window
146
- tag.expand
147
+ if (latest && Page.featured_before(range_dates.last).first == tag.locals.page) ||
148
+ in_future_window || in_past_window || in_range_window
149
+ tag.expand
147
150
  end
148
151
  else
149
152
  tag.expand if tag.locals.page.featured_date.present?
@@ -159,8 +162,9 @@ module FeaturedPagesTags
159
162
  }
160
163
  tag 'unless_featured' do |tag|
161
164
  date = tag.attr["date"] || nil
165
+ latest = tag.attr['latest'] || false
162
166
 
163
- if date
167
+ if date || latest
164
168
  offset_pair = change_pairs(tag.attr['offset'])
165
169
  window_pair = change_pairs(tag.attr['window'])
166
170
 
@@ -181,14 +185,15 @@ module FeaturedPagesTags
181
185
  in_past_window = (date == 'past' && tag.locals.page.featured_date < date_with_offset)
182
186
  in_range_window = (tag.locals.page.featured_date >= range_dates.first.beginning_of_day && tag.locals.page.featured_date <= range_dates.last.end_of_day)
183
187
 
184
- unless (in_future_window || in_past_window || in_range_window)
185
- tag.expand
188
+ unless (latest && Page.featured_before(range_dates.last).first == tag.locals.page) ||
189
+ (in_future_window || in_past_window || in_range_window)
190
+ tag.expand
186
191
  end
187
192
  else
188
193
  tag.expand unless tag.locals.page.featured_date.present?
189
194
  end
190
195
  end
191
-
196
+
192
197
  private
193
198
 
194
199
  def change_pairs(text='')
@@ -3,6 +3,10 @@ module RadiantFeaturedPagesExtension
3
3
  def self.included(base)
4
4
  base.class_eval {
5
5
  named_scope :featured, {:conditions => ["featured_date is NOT NULL"]}
6
+ named_scope :featured_before, lambda{|date|
7
+ {:conditions => ['featured_date is NOT NULL and featured_date < ?',date],
8
+ :order => 'featured_date DESC, id ASC'}
9
+ }
6
10
  }
7
11
  end
8
12
  end
@@ -1,3 +1,3 @@
1
1
  module RadiantFeaturedPagesExtension
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -126,6 +126,13 @@ describe Page do
126
126
  'plus_2_weeks plus_1_day page minus_1_week '
127
127
  )
128
128
  }
129
+ it 'should expand if the current page is the latest in the given range' do
130
+ page.should render(
131
+ '<r:featured_pages:each><r:if_featured latest="true"><r:title /> </r:if_featured></r:featured_pages:each>'
132
+ ).as(
133
+ 'page '
134
+ )
135
+ end
129
136
  end
130
137
  end
131
138
 
@@ -170,6 +177,13 @@ describe Page do
170
177
  'plus_2_years plus_2_months '
171
178
  )
172
179
  }
180
+ it 'should not expand if the current page is the latest in the given range' do
181
+ page.should render(
182
+ '<r:featured_pages:each><r:unless_featured latest="true"><r:title /> </r:unless_featured></r:featured_pages:each>'
183
+ ).as(
184
+ 'plus_2_years plus_2_months plus_2_weeks plus_1_day minus_1_week '
185
+ )
186
+ end
173
187
  end
174
188
  end
175
189
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-featured_pages-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 1
10
- version: 2.0.1
9
+ - 2
10
+ version: 2.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jim Gay
@@ -60,7 +60,7 @@ has_rdoc: true
60
60
  homepage: http://github.com/saturnflyer/radiant-featured_pages-extension
61
61
  licenses: []
62
62
 
63
- post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-featured_pages-extension', :version => '2.0.1'\n "
63
+ post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-featured_pages-extension', :version => '2.0.2'\n "
64
64
  rdoc_options: []
65
65
 
66
66
  require_paths: