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 !
Changed {{ article.body }} and added {{ article.content }}

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1926 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Mon Aug 28 22:46:01 -0700 2006
commit  9d9d46d2739184b257fd5b06e0c7ed6798421603
tree    0739982819b9de2464b4d6d62b15324f2b4182ea
parent  92522f79ccbb3464c2aebce926970a3a38938658
...
1
2
 
 
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
10
11
0
@@ -1,5 +1,11 @@
0
 * SVN *
0
 
0
+* [CHANGED] Changed {{ article.body }} and added {{ article.content }}
0
+
0
+ * {{ article.body }} is now always the article's body, regardless of what template is currently being rendered.
0
+ * {{ article.content }} tries to be a little smart. On sections with multiple articles, it shows the excerpt, or the body if the excerpt is missing.
0
+ Single article templates show the body.
0
+
0
 * [NEW] Added {{ article.excerpt }} liquid tag for accessing an articles excerpt.
0
 
0
 * Change - Article#body_for_mode only returns the body, not excerpt + body. This means you'll have to do this in your templates
...
91
92
93
94
 
95
96
97
...
165
166
167
168
169
170
171
172
173
174
...
91
92
93
 
94
95
96
97
...
165
166
167
 
 
 
 
168
169
170
0
@@ -91,7 +91,7 @@ class Article < Content
0
   end
0
 
0
   def full_permalink
0
- ['', published_at.year, published_at.month, published_at.day, permalink] * '/'
0
+ published? && ['', published_at.year, published_at.month, published_at.day, permalink] * '/'
0
   end
0
 
0
   def has_section?(section)
0
@@ -165,10 +165,6 @@ class Article < Content
0
       @new_sections = nil
0
     end
0
     
0
- def body_for_mode(mode = :list)
0
- (mode == :single ? [body_html, excerpt_html] : [excerpt_html, body_html]).detect { |attr| !attr.blank? }.to_s.strip
0
- end
0
-
0
     def pass_filter_to_comments
0
       return unless @old_filter
0
       self.record_timestamps = false
...
1
2
3
4
5
6
7
...
1
2
 
3
4
5
6
0
@@ -1,6 +1,5 @@
0
 class Content < ActiveRecord::Base
0
   filtered_column :body, :excerpt
0
- validates_presence_of :body
0
   belongs_to :user, :with_deleted => true
0
   belongs_to :site
0
 end
0
\ No newline at end of file
...
6
7
8
 
9
10
11
12
13
14
15
 
16
17
18
 
 
19
20
21
...
42
43
44
 
 
 
 
 
 
 
 
 
 
 
45
46
47
48
...
6
7
8
9
10
11
12
13
14
15
 
16
17
 
 
18
19
20
21
22
...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
0
@@ -6,16 +6,17 @@ module Mephisto
0
       def article() @source end
0
 
0
       def initialize(source, options = {})
0
+ @options = options
0
         @source = source
0
         @article_liquid = {
0
           'id' => @source.id,
0
           'title' => @source.title,
0
           'permalink' => @source.permalink,
0
           'url' => @source.full_permalink,
0
- 'body' => @source.send(:body_for_mode, options[:mode] || :list),
0
+ 'body' => @source.body_html,
0
           'excerpt' => @source.excerpt_html,
0
- 'published_at' => @source.site.timezone.utc_to_local(@source.published_at),
0
- 'updated_at' => @source.site.timezone.utc_to_local(@source.updated_at),
0
+ 'published_at' => (@source.site.timezone.utc_to_local(@source.published_at) rescue nil),
0
+ 'updated_at' => (@source.site.timezone.utc_to_local(@source.updated_at) rescue nil),
0
           'comments_count' => @source.comments_count,
0
           'author' => @source.user.to_liquid,
0
           'accept_comments' => @source.accept_comments?,
0
@@ -42,6 +43,17 @@ module Mephisto
0
       def page_sections
0
         sections.select { |s| s.section.paged? }
0
       end
0
+
0
+ def content
0
+ @content ||= body_for_mode(@options[:mode] || :list)
0
+ end
0
+
0
+ protected
0
+ def body_for_mode(mode)
0
+ contents = [before_method(:excerpt), before_method(:body)]
0
+ contents.reverse! if mode == :single
0
+ contents.detect { |content| !content.blank? }.to_s.strip
0
+ end
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
4
5
6
7
 
8
9
...
4
5
6
 
7
8
9
0
@@ -4,5 +4,5 @@
0
   <h2>{{ article.title }}</h2>
0
   <p><span>{{ article.published_at | format_date: 'standard' }}</span></p>
0
   <p>{{ article | link_to_article }}</p>
0
- <p>{{ article.body }}</p>
0
+ <p>{{ article.content }}</p>
0
 {% endfor %}
0
\ No newline at end of file
...
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
0
@@ -27,4 +27,32 @@ class ArticleDropTest < Test::Unit::TestCase
0
   def test_should_list_only_paged_sections
0
     assert_equal [sections(:about)], @article.page_sections.collect(&:section)
0
   end
0
+
0
+ def test_empty_body
0
+ assert contents(:welcome).update_attributes(:body => nil, :excerpt => nil), contents(:welcome).errors.full_messages.to_sentence
0
+ a = contents(:welcome).to_liquid
0
+ assert_equal '', a.send(:body_for_mode, :single)
0
+ assert_equal '', a.send(:body_for_mode, :list)
0
+ end
0
+
0
+ def test_body_with_excerpt
0
+ assert contents(:welcome).update_attributes(:body => 'body', :excerpt => 'excerpt'), contents(:welcome).errors.full_messages.to_sentence
0
+ a = contents(:welcome).to_liquid
0
+ assert_equal "<p>body</p>", a.send(:body_for_mode, :single)
0
+ assert_equal '<p>excerpt</p>', a.send(:body_for_mode, :list)
0
+ end
0
+
0
+ def test_only_body
0
+ assert contents(:welcome).update_attributes(:body => 'body', :excerpt => nil), contents(:welcome).errors.full_messages.to_sentence
0
+ a = contents(:welcome).to_liquid
0
+ assert_equal "<p>body</p>", a.send(:body_for_mode, :single)
0
+ assert_equal '<p>body</p>', a.send(:body_for_mode, :list)
0
+ end
0
+
0
+ def test_only_body_with_empty_excerpt
0
+ assert contents(:welcome).update_attributes(:body => 'body', :excerpt => ''), contents(:welcome).errors.full_messages.to_sentence
0
+ a = contents(:welcome).to_liquid
0
+ assert_equal "<p>body</p>", a.send(:body_for_mode, :single)
0
+ assert_equal '<p>body</p>', a.send(:body_for_mode, :list)
0
+ end
0
 end
...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
103
104
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
107
108
0
@@ -103,30 +103,6 @@ class ArticleTest < Test::Unit::TestCase
0
     assert a.accept_comments?
0
   end
0
 
0
- def test_empty_body
0
- a = create_article
0
- assert_equal '', a.send(:body_for_mode, :single)
0
- assert_equal '', a.send(:body_for_mode, :list)
0
- end
0
-
0
- def test_body_with_excerpt
0
- a = create_article :excerpt => 'excerpt', :body => 'body'
0
- assert_equal "<p>body</p>", a.send(:body_for_mode, :single)
0
- assert_equal '<p>excerpt</p>', a.send(:body_for_mode, :list)
0
- end
0
-
0
- def test_only_body
0
- a = create_article :body => 'body'
0
- assert_equal "<p>body</p>", a.send(:body_for_mode, :single)
0
- assert_equal '<p>body</p>', a.send(:body_for_mode, :list)
0
- end
0
-
0
- def test_only_body_with_empty_excerpt
0
- a = create_article :body => 'body', :excerpt => ''
0
- assert_equal "<p>body</p>", a.send(:body_for_mode, :single)
0
- assert_equal '<p>body</p>', a.send(:body_for_mode, :list)
0
- end
0
-
0
   def test_should_set_published_to_utc
0
     a = create_article :body => 'body', :published_at => Time.now
0
     assert a.published_at.utc?
...
1
2
 
 
3
...
 
1
2
3
4
0
@@ -1 +1,2 @@
0
-error
0
\ No newline at end of file
0
+<h2>You broke it!</h2>
0
+<p>Just kidding! It seems the page you requested doesn't exist.</p>
0
\ No newline at end of file

Comments

    No one has commented yet.