public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
update default theme with archive stuff

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2207 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Sep 17 23:44:55 -0700 2006
commit  e80c19e18e8177e7f480f226284f8a8c538e9b0a
tree    898f530f179b6153c3aa87ded2be574e8402b01e
parent  940954d66b52f281bce9ec928ddc91369dd48a90
...
1
2
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
0
@@ -1,5 +1,9 @@
0
 * SVN *
0
 
0
+* Add {{ section | link_to_month: '2006-9' }} for linking to archive pages.
0
+
0
+* Add {{ '2006-1' | parse_date }} for general date parsing
0
+
0
 * Fixed issues previewing article drafts
0
 
0
 # Added new liquid vars {{ site.latest_articles }} and {{ site.latest_comments }},
...
79
80
81
82
 
83
84
85
...
79
80
81
 
82
83
84
85
0
@@ -79,7 +79,7 @@ class MephistoController < ApplicationController
0
         month = Time.now.utc.month
0
       end
0
       @articles = @section.articles.find_all_in_month(year, month, :include => :user)
0
- render_liquid_template_for(:archive, 'articles' => @articles, 'archive_date' => Time.utc(year, month))
0
+ render_liquid_template_for(:archive, 'section' => @section, 'articles' => @articles, 'archive_date' => Time.utc(year, month))
0
     end
0
 
0
     def dispatch_search
...
40
41
42
43
 
44
45
46
...
40
41
42
 
43
44
45
46
0
@@ -40,7 +40,7 @@ class SectionDrop < BaseDrop
0
   end
0
   
0
   def earliest_month
0
- @earliest_month ||= @source.articles.find(:first, :order => 'published_at').published_at.beginning_of_month.to_date rescue :false
0
+ @earliest_month ||= @source.articles.find_by_date(:limit => 1, :order => 'published_at').first.published_at.beginning_of_month.to_date rescue :false
0
   end
0
   
0
   def months
...
30
31
32
 
 
 
 
 
 
33
34
35
36
 
37
38
 
39
40
41
...
30
31
32
33
34
35
36
37
38
39
40
41
 
42
43
 
44
45
46
47
0
@@ -30,12 +30,18 @@ module CoreFilters
0
     text.blank? ? '' : RedCloth.new(text).to_html
0
   end
0
 
0
+ def parse_date(date)
0
+ date ||= Time.now.utc
0
+ date = "#{date}-1" if date.to_s =~ /^\d{4}-\d{1,2}$/ unless [Time, Date].include?(date.class)
0
+ date = date.to_time
0
+ end
0
+
0
   def format_date(date, format, ordinalized = false)
0
     return '' if date.nil?
0
     if ordinalized
0
- date ? date.to_time.to_ordinalized_s(format.to_sym) : nil
0
+ date ? parse_date(date).to_ordinalized_s(format.to_sym) : nil
0
     else
0
- date ? date.to_time.to_s(format.to_sym) : nil unless ordinalized
0
+ date ? parse_date(date).to_s(format.to_sym) : nil unless ordinalized
0
     end
0
   end
0
   
...
58
59
60
 
 
 
 
61
62
63
64
 
 
65
66
 
 
 
 
 
67
68
69
...
58
59
60
61
62
63
64
65
 
 
 
66
67
68
 
69
70
71
72
73
74
75
76
0
@@ -58,12 +58,19 @@ module UrlFilters
0
     content_tag :a, tag, :href => tag_url(tag)
0
   end
0
 
0
+ def link_to_month(section, date = nil, format = 'my')
0
+ content_tag :a, format_date(date, format), :href => monthly_url(section, date)
0
+ end
0
+
0
   def monthly_url(section, date = nil)
0
- date ||= Time.now.utc.beginning_of_month
0
- date = Date.new(*date.split('-')) unless date.is_a?(Date)
0
- File.join(section.url, section['archive_path'], date.year.to_s, date.month.to_s)
0
+ date = parse_date(date)
0
+ archive_url(section, date.year.to_s, date.month.to_s)
0
   end
0
-
0
+
0
+ def archive_url(section, *pieces)
0
+ File.join(section.url, section['archive_path'], *pieces)
0
+ end
0
+
0
   def tag_url(*tags)
0
     tags = [tags] ; tags.flatten!
0
     absolute_url @context['site'].source.tag_url(*tags)
...
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
15
16
...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
0
@@ -12,4 +12,16 @@ context "Core Filters" do
0
     assign_to 'blah', 'foo'
0
     assert_equal 'blah', @context['foo']
0
   end
0
+
0
+ specify "should parse date into time" do
0
+ assert_equal Time.local(2006, 1, 1), parse_date(Date.new(2006, 1))
0
+ end
0
+
0
+ specify "should parse time into time" do
0
+ assert_equal Time.utc(2006, 1, 1), parse_date(Time.utc(2006, 1))
0
+ end
0
+
0
+ specify "should parse string into time" do
0
+ assert_equal Time.utc(2006, 1, 1), parse_date('2006-1')
0
+ end
0
 end
0
\ No newline at end of file
...
1
2
3
4
 
5
6
7
8
9
10
11
12
 
 
 
 
13
14
15
 
16
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
...
1
2
3
 
4
5
6
7
8
 
 
 
 
9
10
11
12
13
14
 
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
0
@@ -1,22 +1,36 @@
0
 require File.dirname(__FILE__) + '/../test_helper'
0
 context "Url Filters" do
0
   fixtures :sites, :sections, :contents
0
- include UrlFilters
0
+ include CoreFilters, UrlFilters
0
 
0
   def setup
0
     @context = {'site' => sites(:first).to_liquid, 'section' => sections(:about).to_liquid}
0
   end
0
-
0
- specify "should generate tag url" do
0
- assert_equal "/tags/foo", tag_url('foo')
0
- assert_equal "/tags/foo/bar", tag_url(%w(foo bar))
0
+
0
+ specify "should generate archive url" do
0
+ assert_equal "/archives", archive_url(sections(:home).to_liquid)
0
+ assert_equal "/archives/foo/bar", archive_url(sections(:home).to_liquid, 'foo', 'bar')
0
   end
0
   
0
- specify "should generate monthly url" do
0
+ specify "should generate monthly url from date" do
0
     assert_equal "/archives/2006/1", monthly_url(sections(:home).to_liquid, Date.new(2006, 1))
0
     assert_equal "/about/archives/2006/1", monthly_url(sections(:about).to_liquid, Date.new(2006, 1))
0
   end
0
 
0
+ specify "should generate monthly url from time" do
0
+ assert_equal "/archives/2006/1", monthly_url(sections(:home).to_liquid, Time.utc(2006, 1))
0
+ assert_equal "/about/archives/2006/1", monthly_url(sections(:about).to_liquid, Time.utc(2006, 1))
0
+ end
0
+
0
+ specify "should generate monthly url from string" do
0
+ assert_equal "/archives/2006/1", monthly_url(sections(:home).to_liquid, '2006-1')
0
+ assert_equal "/about/archives/2006/1", monthly_url(sections(:about).to_liquid, '2006-1-4')
0
+ end
0
+
0
+ specify "should generate monthly link" do
0
+ assert_equal "<a href=\"/archives/2006/1\">January 2006</a>", link_to_month(sections(:home).to_liquid, '2006-1')
0
+ end
0
+
0
   specify "should generate paged url" do
0
     assert_equal "/about", page_url(contents(:welcome).to_liquid(:page => true))
0
     assert_equal "/about/welcome-to-mephisto", page_url(contents(:welcome).to_liquid)
...
16
17
18
19
 
 
 
20
21
22
...
35
36
37
38
 
39
40
41
...
16
17
18
 
19
20
21
22
23
24
...
37
38
39
 
40
41
42
43
0
@@ -16,7 +16,9 @@
0
         </form>
0
       </div>
0
       <h2><a href="/">{{ site.title }}</a></h2>
0
- <p class="description">{{ site.subtitle }}</p>
0
+ <p class="description">
0
+{% if section.path != '' %}{{ section.name }}{% else %}{{ site.subtitle }}{% endif %}
0
+ </p>
0
     </div>
0
   </div>
0
 {{ content_for_layout }}
0
@@ -35,7 +37,7 @@
0
         <div class="block">
0
           <h2>Recently</h2>
0
           <ul class="dates">
0
-{% for article in articles %}
0
+{% for article in site.latest_articles %}
0
             <li><a href="{{ article.url }}"><span class="date">{{ article.published_at | strftime: '%m.%y' }}</span> {{ article.title }}</a></li>
0
 {% endfor %}
0
          </ul>
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
3
4
5
6
...
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
 
36
0
@@ -1,5 +1,35 @@
0
-<p>archive</p>
0
+ <div id="primary" class="single-post">
0
+ <div class="inside">
0
+ <div class="primary">
0
+ <h1>Archives for {{section.name}} on {{archive_date | format_date: 'my'}}</h1>
0
+ <ul class="dates">
0
+ {% for article in articles %}
0
+ <li>
0
+ <span class="date">{{article.published_at | date: '%d.%m.%y' }}</span>
0
+ {{ article | link_to_article }} posted in
0
+ {% for section in article.sections %}
0
+ {{section | link_to_section }}{% unless forloop.last %}, {% endunless %}
0
+ {% endfor %}
0
+ </li>
0
+ {% endfor %}
0
+ </ul>
0
+ </div>
0
+
0
+
0
+ <div class="secondary">
0
+ <h2>About the archives</h2>
0
+ <div class="featured">
0
+ <p>Welcome to the archives here at {{site.title}}. Have a look around.</p>
0
+<ul>
0
+{% for month in section.months %}
0
+ <li>{{ section | link_to_month: month }}</li>
0
+{% endfor %}
0
+</ul>
0
+ </div>
0
+ </div>
0
+
0
+ <div class="clear"></div>
0
+ </div>
0
+</div>
0
+
0
 
0
-{% for article in articles %}
0
- <p>{{ article | link_to_article }}</p>
0
-{% endfor %}
0
\ No newline at end of file
...
17
18
19
 
 
 
 
20
21
22
...
17
18
19
20
21
22
23
24
25
26
0
@@ -17,6 +17,10 @@
0
 {% endfor %}
0
     
0
       <div class="clear"></div>
0
+
0
+{{ articles | first | assign_to: 'latest_article' }}
0
+<p>View archives for {{ section | link_to_month: latest_article.published_at }}.</p>
0
+
0
     </div>
0
   </div>
0
 
...
1
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
16
17
 
 
18
19
20
21
22
23
24
25
26
 
 
 
 
 
27
28
29
30
...
 
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
6
7
8
9
10
11
12
13
14
15
 
16
17
18
 
 
 
 
 
 
 
19
20
21
22
23
24
25
 
 
26
0
@@ -1,30 +1,26 @@
0
- <div id="primary" class="single-post">
0
+ <div id="primary" class="twocol-stories">
0
     <div class="inside">
0
- <div class="primary">
0
- <h1>Archives for {{section.name}}</h1>
0
- <ul class="dates">
0
- {% for article in articles %}
0
- <li>
0
- <span class="date">{{article.published_at | date: '%d.%m.%y' }}</span>
0
- {{ article | link_to_article }} posted in
0
- {% for section in article.sections %}
0
- {{section | link_to_section }}
0
- {% endfor %}
0
- </li>
0
- {% endfor %}
0
- </ul>
0
+{% for article in articles %}
0
+ {% if forloop.index < 3 %}
0
+ <div class="story{% if forloop.first %} first{% endif %}">
0
+ <h3>{{ article | link_to_article }}</h3>
0
+ {{ article.excerpt }}
0
+ {{ article.body }}
0
+ <div class="details">
0
+ Posted on {{ article.published_at | format_date: 'stub', true }} |
0
+ {{ article | link_to_comments }} |
0
+ Filed Under: {% for section in article.sections %}<a href="{{section.url}}" title="{{section.name}}">{{ section.name }}</a>{% endfor %} |
0
+ <span class="read-on"><a href="{{article.url}}">read on</a></span>
0
+ </div>
0
       </div>
0
-
0
+ {% endif %}
0
+{% endfor %}
0
     
0
- <div class="secondary">
0
- <h2>About the archives</h2>
0
- <div class="featured">
0
- <p>Welcome to the archives here at {{site.title}}. Have a look around.</p>
0
- </div>
0
- </div>
0
-
0
       <div class="clear"></div>
0
+
0
+{{ articles | first | assign_to: 'latest_article' }}
0
+<p>View archives for {{ section | link_to_month: latest_article.published_at }}.</p>
0
+
0
+ </div>
0
   </div>
0
-</div>
0
-
0
 

Comments

    No one has commented yet.