typo 3.99.4 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -78,9 +78,9 @@ class Admin::ContentController < Admin::BaseController
78
78
  def new_or_edit
79
79
  get_or_build_article
80
80
  params[:article] ||= {}
81
- params[:article].reverse_merge!('allow_comments' => this_blog.default_allow_comments,
82
- 'allow_pings' => this_blog.default_allow_pings,
83
- 'published' => true)
81
+ # params[:article].reverse_merge!('allow_comments' => this_blog.default_allow_comments,
82
+ # 'allow_pings' => this_blog.default_allow_pings,
83
+ # 'published' => true)
84
84
  @article.attributes = (params[:article])
85
85
  setup_categories
86
86
  @selected = @article.categories.collect { |c| c.id }
@@ -129,7 +129,11 @@ class Admin::ContentController < Admin::BaseController
129
129
  def get_or_build_article
130
130
  @article = case params[:action]
131
131
  when 'new'
132
- this_blog.articles.build
132
+ art = this_blog.articles.build
133
+ art.allow_comments = this_blog.default_allow_comments
134
+ art.allow_pings = this_blog.default_allow_pings
135
+ art.published = true
136
+ art
133
137
  when 'edit'
134
138
  this_blog.articles.find(params[:id])
135
139
  else
@@ -1,6 +1,5 @@
1
1
  require 'observer'
2
2
  require 'set'
3
- require 'Akismet'
4
3
 
5
4
  class Content < ActiveRecord::Base
6
5
  include Observable
@@ -9,6 +8,9 @@ class Content < ActiveRecord::Base
9
8
  belongs_to :blog
10
9
  validates_presence_of :blog_id
11
10
 
11
+ composed_of :state, :class_name => 'ContentState::Factory',
12
+ :mapping => %w{ state memento }
13
+
12
14
  has_and_belongs_to_many :notify_users, :class_name => 'User',
13
15
  :join_table => 'notifications', :foreign_key => 'notify_content_id',
14
16
  :association_foreign_key => 'notify_user_id', :uniq => true
@@ -25,10 +27,12 @@ class Content < ActiveRecord::Base
25
27
 
26
28
  def initialize(*args)
27
29
  super(*args)
30
+ set_default_blog
31
+ end
28
32
 
29
- #
33
+ def set_default_blog
30
34
  if self.blog_id == nil or self.blog_id == 0
31
- self.blog_id = Blog.default
35
+ self.blog = Blog.default
32
36
  end
33
37
  end
34
38
 
@@ -107,14 +111,6 @@ class Content < ActiveRecord::Base
107
111
  end
108
112
  end
109
113
 
110
- def state
111
- @state ||= ContentState::Factory.derived_from(self)
112
- end
113
-
114
- def state=(new_state)
115
- @state = new_state
116
- end
117
-
118
114
  def state_before_save
119
115
  self.state.before_save(self)
120
116
  end
@@ -10,6 +10,10 @@ module ContentState
10
10
  protected :new
11
11
  end
12
12
 
13
+ def memento
14
+ self.class.to_s
15
+ end
16
+
13
17
  def before_save(content)
14
18
  serialize_on(content)
15
19
  true
@@ -1,16 +1,13 @@
1
1
  module ContentState
2
2
  class Factory
3
- def self.derived_from(content)
4
- state = [New, Draft, PublicationPending,
5
- JustPublished, Published].detect(self) do |k|
6
- k.derivable_from(content)
7
- end.instance
8
-
9
- unless state
10
- raise "No derivable state for #{content.inspect}"
11
- else
12
- return state
3
+ def self.new(state_name)
4
+ return ContentState::New.instance unless state_name
5
+ state_name = state_name.to_s.underscore
6
+ unless state_name.rindex('/')
7
+ state_name = 'content_state/' + state_name
13
8
  end
9
+ require state_name
10
+ state_name.camelize.constantize.instance
14
11
  end
15
12
  end
16
13
  end
@@ -0,0 +1,24 @@
1
+ class AddContentStateField < ActiveRecord::Migration
2
+ class Content < ActiveRecord::Base
3
+ include BareMigration
4
+ end
5
+
6
+ def self.up
7
+ modify_tables_and_update(:add_column, Content,
8
+ :state, :text) do |content|
9
+ unless $schema_generator
10
+ if content.published?
11
+ content.state = 'Published'
12
+ elsif content.published_at
13
+ content.state = 'PublicationPending'
14
+ else
15
+ content.state = 'Draft'
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def self.down
22
+ remove_column :contents, :state
23
+ end
24
+ end
data/db/schema.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # migrations feature of ActiveRecord to incrementally modify your database, and
3
3
  # then regenerate this schema definition.
4
4
 
5
- ActiveRecord::Schema.define(:version => 46) do
5
+ ActiveRecord::Schema.define(:version => 47) do
6
6
 
7
7
  create_table "articles_categories", :id => false, :force => true do |t|
8
8
  t.column "article_id", :integer
@@ -65,6 +65,7 @@ ActiveRecord::Schema.define(:version => 46) do
65
65
  t.column "allow_comments", :boolean
66
66
  t.column "blog_id", :integer
67
67
  t.column "published_at", :datetime
68
+ t.column "state", :text
68
69
  end
69
70
 
70
71
  add_index "contents", ["article_id"], :name => "contents_article_id_index"
@@ -1,7 +1,7 @@
1
1
  require 'rake/gempackagetask'
2
2
  require 'rake/contrib/rubyforgepublisher'
3
3
 
4
- PKG_VERSION = "3.99.4"
4
+ PKG_VERSION = "4.0.0"
5
5
  PKG_NAME = "typo"
6
6
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
7
7
  RUBY_FORGE_PROJECT = 'typo'
data/lib/typo_version.rb CHANGED
@@ -1 +1 @@
1
- TYPO_VERSION = '3.99.4'
1
+ TYPO_VERSION = '4.0.0'
@@ -0,0 +1 @@
1
+ Tagging 3.99.4
@@ -19,6 +19,7 @@ article1:
19
19
  guid: a87c4220-18d4-11da-aadd-0002a5d5c51b
20
20
  type: Article
21
21
  published: true
22
+ state: ContentState::Published
22
23
 
23
24
  article2:
24
25
  type: Article
@@ -39,6 +40,7 @@ article2:
39
40
  author: Bob
40
41
  guid: bbbbb
41
42
  published: true
43
+ state: ContentState::Published
42
44
 
43
45
 
44
46
  article3:
@@ -60,6 +62,7 @@ article3:
60
62
  author: Tobi
61
63
  guid: ccccc
62
64
  published: true
65
+ state: ContentState::Published
63
66
 
64
67
  article4:
65
68
  type: Article
@@ -69,6 +72,7 @@ article4:
69
72
  body: I'm not "public":http://www.example.com/public!
70
73
  body_html: I'm not <a href="http://www.example.com/public">public</a>!
71
74
  published: false
75
+ state: ContentState::Draft
72
76
  created_at: 2004-06-01 20:00:01
73
77
  updated_at: 2004-06-01 20:00:01
74
78
  published_at: 2004-06-01 20:00:01
@@ -92,6 +96,7 @@ spam_comment:
92
96
  updated_at: 2005-01-01 02:00:00
93
97
  published_at: 2005-01-01 02:00:00
94
98
  guid: 12313123123123123
99
+ state: ContentState::Published
95
100
 
96
101
  comment2:
97
102
  type: Comment
@@ -108,12 +113,14 @@ comment2:
108
113
  updated_at: 2005-01-01 02:00:01
109
114
  published_at: 2005-01-01 02:00:01
110
115
  guid: 453456456456456
116
+ state: ContentState::Published
111
117
 
112
118
  comment3:
113
119
  type: Comment
114
120
  blog_id: 1
115
121
  id: 12
116
122
  published: false
123
+ state: ContentState::Draft
117
124
  article_id: 1
118
125
  author: Foo Bar
119
126
  body: Zzzzzz
@@ -128,6 +135,7 @@ trackback1:
128
135
  id: 7
129
136
  article_id: 2
130
137
  published: false
138
+ state: ContentState::Draft
131
139
  blog_name: Trackback Blog
132
140
  title: Trackback Entry
133
141
  url: http://www.example.com
@@ -142,6 +150,7 @@ trackback2:
142
150
  blog_id: 1
143
151
  id: 8
144
152
  article_id: 1
153
+ state: ContentState::Published
145
154
  published: true
146
155
  blog_name: Trackback Blog
147
156
  title: Trackback Entry
@@ -158,6 +167,7 @@ trackback3:
158
167
  id: 13
159
168
  article_id: 1
160
169
  published: true
170
+ state: ContentState::Published
161
171
  blog_name: Trackback Blog 2
162
172
  title: Trackback Entry 2
163
173
  url: http://www.example.com
@@ -179,6 +189,7 @@ first_page:
179
189
  updated_at: 2005-05-05 01:00:00
180
190
  user_id: 1
181
191
  published: true
192
+ state: ContentState::Published
182
193
 
183
194
  another_page:
184
195
  type: Page
@@ -192,6 +203,7 @@ another_page:
192
203
  published_at: 2005-05-05 01:00:00
193
204
  user_id: 1
194
205
  published: true
206
+ state: ContentState::Published
195
207
 
196
208
  markdown_page:
197
209
  type: Page
@@ -206,6 +218,7 @@ markdown_page:
206
218
  published_at: 2005-05-05 01:00:00
207
219
  user_id: 1
208
220
  published: true
221
+ state: ContentState::Published
209
222
 
210
223
  inactive_article:
211
224
  type: Article
@@ -226,6 +239,7 @@ inactive_article:
226
239
  author: Tobi
227
240
  guid: i1n2a3c4t5i6v7e
228
241
  published: true
242
+ state: ContentState::Published
229
243
 
230
244
  old_comment:
231
245
  type: Comment
@@ -241,6 +255,7 @@ old_comment:
241
255
  updated_at: 2004-05-02 20:00:02
242
256
  published_at: 2004-05-02 20:00:02
243
257
  published: true
258
+ state: ContentState::Published
244
259
 
245
260
  second_blog_article:
246
261
  type: Article
@@ -261,6 +276,7 @@ second_blog_article:
261
276
  author: Tobi
262
277
  guid: 2b1l0o6g4ar7
263
278
  published: true
279
+ state: ContentState::Published
264
280
 
265
281
  search_target:
266
282
  type: Article
@@ -281,6 +297,7 @@ search_target:
281
297
  author: Tobi
282
298
  guid: 2b1l0o6g4ar7
283
299
  published: true
300
+ state: ContentState::Published
284
301
 
285
302
  xmltest:
286
303
  type: Article
@@ -300,3 +317,4 @@ xmltest:
300
317
  author: Tobi
301
318
  guid: urn:uuid:0d676c66-4135-4a8b-9d65-b6a3248d3032
302
319
  published: true
320
+ state: ContentState::Published
@@ -2,32 +2,27 @@ require File.dirname(__FILE__) + '/../../test_helper'
2
2
  require 'content_state/factory'
3
3
 
4
4
  class ContentState::FactoryTest < Test::Unit::TestCase
5
- def test_correctly_derives_new_state
6
- assert_instance_of(ContentState::New,
7
- ContentState::Factory.derived_from(MockContent.new(true)))
5
+ def test_correctly_builds_new_state
6
+ [:new, 'new', 'content_state/new', 'New',
7
+ 'ContentState::New', nil].each do |memento|
8
+ assert_instance_of(ContentState::New,
9
+ ContentState::Factory.new(memento))
10
+ end
8
11
  end
9
12
 
10
- def test_correctly_derives_draft_state
13
+ def test_correctly_builds_draft_state
11
14
  assert_instance_of(ContentState::Draft,
12
- ContentState::Factory.derived_from(MockContent.new(false, nil, nil)))
15
+ ContentState::Factory.new('draft'))
13
16
  end
14
17
 
15
- def test_correctly_derives_publication_pending_state
16
- assert_instance_of(ContentState::PublicationPending,
17
- ContentState::Factory.derived_from(MockContent.new(false, nil, 1.day.from_now)))
18
- assert_instance_of(ContentState::PublicationPending,
19
- ContentState::Factory.derived_from(MockContent.new(true, true,
20
- 1.hour.from_now)))
21
-
18
+ def test_correctly_builds_publication_pending_state
22
19
  assert_instance_of(ContentState::PublicationPending,
23
- ContentState::Factory.derived_from(MockContent.new(true, false,
24
- 1.hour.from_now)))
20
+ ContentState::Factory.new('publication_pending'))
25
21
  end
26
22
 
27
- def test_correct_derives_published_state
23
+ def test_correct_builds_published_state
28
24
  assert_instance_of(ContentState::Published,
29
- ContentState::Factory.derived_from(MockContent.new(false, true,
30
- 1.hour.ago)))
25
+ ContentState::Factory.new('published'))
31
26
  end
32
27
 
33
28
  def test_cant_make_state_directly
File without changes
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: typo
5
5
  version: !ruby/object:Gem::Version
6
- version: 3.99.4
7
- date: 2006-07-21 00:00:00 -07:00
6
+ version: 4.0.0
7
+ date: 2006-07-22 00:00:00 -07:00
8
8
  summary: Modern weblog engine.
9
9
  require_paths:
10
10
  - .
@@ -28,7 +28,6 @@ cert_chain:
28
28
  authors:
29
29
  - Tobias Luetke
30
30
  files:
31
- - .DS_Store
32
31
  - app
33
32
  - bin
34
33
  - cache
@@ -45,6 +44,7 @@ files:
45
44
  - Rakefile
46
45
  - README
47
46
  - script
47
+ - svk-commitP6cVv.tmp
48
48
  - test
49
49
  - themes
50
50
  - tmp
@@ -490,6 +490,7 @@ files:
490
490
  - db/migrate/044_add_published_at_to_content.rb
491
491
  - db/migrate/045_fix_contents_published_default.rb
492
492
  - db/migrate/046_fixup_forthcoming_publications.rb
493
+ - db/migrate/047_add_content_state_field.rb
493
494
  - db/scripts/fix_permalinks.rb
494
495
  - db/updates/update.168.to.200.mysql.sql
495
496
  - db/updates/update.168.to.200.psql.sql
@@ -785,7 +786,7 @@ files:
785
786
  - vendor/sparklines
786
787
  - vendor/syntax
787
788
  - vendor/uuidtools
788
- - vendor/akismet/Akismet.rb
789
+ - vendor/akismet/akismet.rb
789
790
  - vendor/bluecloth/bin
790
791
  - vendor/bluecloth/CHANGES
791
792
  - vendor/bluecloth/install.rb
data/.DS_Store DELETED
Binary file