content_blocks 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gem "RedCloth"
5
5
  gem "aasm"
6
6
 
7
7
  group :development do
8
+ gem "rails", "~> 3.0.3"
8
9
  gem "rspec-rails", "~> 2.1.0"
9
10
  gem "rspec", "~> 2.1.0"
10
11
  gem "bundler", "~> 1.0.0"
data/Gemfile.lock CHANGED
@@ -3,6 +3,20 @@ GEM
3
3
  specs:
4
4
  RedCloth (4.2.3)
5
5
  aasm (2.2.0)
6
+ abstract (1.0.0)
7
+ actionmailer (3.0.3)
8
+ actionpack (= 3.0.3)
9
+ mail (~> 2.2.9)
10
+ actionpack (3.0.3)
11
+ activemodel (= 3.0.3)
12
+ activesupport (= 3.0.3)
13
+ builder (~> 2.1.2)
14
+ erubis (~> 2.6.6)
15
+ i18n (~> 0.4)
16
+ rack (~> 1.2.1)
17
+ rack-mount (~> 0.6.13)
18
+ rack-test (~> 0.5.6)
19
+ tzinfo (~> 0.3.23)
6
20
  activemodel (3.0.3)
7
21
  activesupport (= 3.0.3)
8
22
  builder (~> 2.1.2)
@@ -12,16 +26,46 @@ GEM
12
26
  activesupport (= 3.0.3)
13
27
  arel (~> 2.0.2)
14
28
  tzinfo (~> 0.3.23)
29
+ activeresource (3.0.3)
30
+ activemodel (= 3.0.3)
31
+ activesupport (= 3.0.3)
15
32
  activesupport (3.0.3)
16
33
  arel (2.0.6)
17
34
  builder (2.1.2)
18
35
  diff-lcs (1.1.2)
36
+ erubis (2.6.6)
37
+ abstract (>= 1.0.0)
19
38
  git (1.2.5)
20
39
  i18n (0.5.0)
21
40
  jeweler (1.5.1)
22
41
  bundler (~> 1.0.0)
23
42
  git (>= 1.2.5)
24
43
  rake
44
+ mail (2.2.12)
45
+ activesupport (>= 2.3.6)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.16)
50
+ polyglot (0.3.1)
51
+ rack (1.2.1)
52
+ rack-mount (0.6.13)
53
+ rack (>= 1.0.0)
54
+ rack-test (0.5.6)
55
+ rack (>= 1.0)
56
+ rails (3.0.3)
57
+ actionmailer (= 3.0.3)
58
+ actionpack (= 3.0.3)
59
+ activerecord (= 3.0.3)
60
+ activeresource (= 3.0.3)
61
+ activesupport (= 3.0.3)
62
+ bundler (~> 1.0)
63
+ railties (= 3.0.3)
64
+ railties (3.0.3)
65
+ actionpack (= 3.0.3)
66
+ activesupport (= 3.0.3)
67
+ rake (>= 0.8.7)
68
+ thor (~> 0.14.4)
25
69
  rake (0.8.7)
26
70
  rcov (0.9.9)
27
71
  rspec (2.1.0)
@@ -35,6 +79,9 @@ GEM
35
79
  rspec-rails (2.1.0)
36
80
  rspec (~> 2.1.0)
37
81
  sqlite3-ruby (1.3.2)
82
+ thor (0.14.6)
83
+ treetop (1.4.9)
84
+ polyglot (>= 0.3.1)
38
85
  tzinfo (0.3.23)
39
86
 
40
87
  PLATFORMS
@@ -46,6 +93,7 @@ DEPENDENCIES
46
93
  activerecord (~> 3.0.3)
47
94
  bundler (~> 1.0.0)
48
95
  jeweler (~> 1.5.1)
96
+ rails (~> 3.0.3)
49
97
  rcov
50
98
  rspec (~> 2.1.0)
51
99
  rspec-rails (~> 2.1.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{content_blocks}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pawe\305\202 Pacana"]
12
- s.date = %q{2010-12-20}
12
+ s.date = %q{2010-12-23}
13
13
  s.description = %q{Content blocks are commonly used models representing editable page partials.}
14
14
  s.email = %q{pawel.pacana@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,7 +27,8 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "content_blocks.gemspec",
29
29
  "lib/content_blocks.rb",
30
- "lib/content_blocks/snippet.rb",
30
+ "lib/content_blocks/models/snippet.rb",
31
+ "lib/content_blocks/railtie.rb",
31
32
  "lib/generators/content_blocks/snippet_generator.rb",
32
33
  "lib/generators/content_blocks/templates/migration.rb",
33
34
  "spec/schema/schema.rb",
@@ -53,6 +54,7 @@ Gem::Specification.new do |s|
53
54
  s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.3"])
54
55
  s.add_runtime_dependency(%q<RedCloth>, [">= 0"])
55
56
  s.add_runtime_dependency(%q<aasm>, [">= 0"])
57
+ s.add_development_dependency(%q<rails>, ["~> 3.0.3"])
56
58
  s.add_development_dependency(%q<rspec-rails>, ["~> 2.1.0"])
57
59
  s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
58
60
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -69,6 +71,7 @@ Gem::Specification.new do |s|
69
71
  s.add_dependency(%q<activerecord>, ["~> 3.0.3"])
70
72
  s.add_dependency(%q<RedCloth>, [">= 0"])
71
73
  s.add_dependency(%q<aasm>, [">= 0"])
74
+ s.add_dependency(%q<rails>, ["~> 3.0.3"])
72
75
  s.add_dependency(%q<rspec-rails>, ["~> 2.1.0"])
73
76
  s.add_dependency(%q<rspec>, ["~> 2.1.0"])
74
77
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -86,6 +89,7 @@ Gem::Specification.new do |s|
86
89
  s.add_dependency(%q<activerecord>, ["~> 3.0.3"])
87
90
  s.add_dependency(%q<RedCloth>, [">= 0"])
88
91
  s.add_dependency(%q<aasm>, [">= 0"])
92
+ s.add_dependency(%q<rails>, ["~> 3.0.3"])
89
93
  s.add_dependency(%q<rspec-rails>, ["~> 2.1.0"])
90
94
  s.add_dependency(%q<rspec>, ["~> 2.1.0"])
91
95
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -0,0 +1,49 @@
1
+ require 'active_record'
2
+ require 'aasm'
3
+ require 'RedCloth'
4
+
5
+ module ContentBlocks
6
+ module Models
7
+ class Snippet < ActiveRecord::Base
8
+ include AASM
9
+
10
+ set_table_name 'content_blocks_snippets'
11
+
12
+ LABEL_FORMAT = /^[a-zA-Z\d_]+$/
13
+
14
+ aasm_initial_state :draft
15
+ aasm_column :status
16
+
17
+ aasm_state :draft
18
+ aasm_state :published
19
+
20
+ aasm_event :preview do
21
+ transitions :from => :published, :to => :draft
22
+ end
23
+
24
+ aasm_event :publish do
25
+ transitions :from => :draft, :to => :published
26
+ end
27
+
28
+ scope :published, where(:status => 'published')
29
+ scope :draft, where(:status => 'draft')
30
+
31
+ validates :label,
32
+ :presence => true,
33
+ :format => { :with => LABEL_FORMAT },
34
+ :uniqueness => { :scope => :status, :if => :published? }
35
+
36
+ def self.[](label)
37
+ find_or_create_by_label(label)
38
+ end
39
+
40
+ def content
41
+ textilize(raw_content)
42
+ end
43
+
44
+ def raw_content
45
+ self[:content] if published?
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,11 @@
1
+ require 'content_blocks'
2
+ require 'rails'
3
+
4
+ module ContentBlocks
5
+ class Railtie < Rails::Railtie
6
+ initializer 'append models path' do
7
+ models_path = File.join(File.dirname(__FILE__), 'models')
8
+ Rails.application.paths.app.models.push File.expand_path(models_path)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,7 @@
1
+ require 'content_blocks/railtie'
2
+
1
3
  module ContentBlocks
2
- autoload :Snippet, "content_blocks/snippet"
4
+ module Models
5
+ autoload :Snippet, "content_blocks/models/snippet"
6
+ end
3
7
  end
data/spec/snippet_spec.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe ContentBlocks::Snippet do
3
+ describe ContentBlocks::Models::Snippet do
4
4
  before do
5
5
  @valid_attributes = {
6
6
  :label => "sidebar",
7
7
  :content => "h1. Sidebar links"
8
8
  }
9
- @snippet = ContentBlocks::Snippet.new(@valid_attributes)
9
+ @snippet = ContentBlocks::Models::Snippet.new(@valid_attributes)
10
10
  end
11
11
 
12
12
  it "should be initially draft" do
@@ -16,7 +16,7 @@ describe ContentBlocks::Snippet do
16
16
 
17
17
  it "should be unique when published" do
18
18
  @snippet.save!
19
- cloned = ContentBlocks::Snippet.create!(@valid_attributes)
19
+ cloned = ContentBlocks::Models::Snippet.create!(@valid_attributes)
20
20
  @snippet.publish!
21
21
  @snippet.should be_valid
22
22
  @snippet.published?.should be_true
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_blocks
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Pawe\xC5\x82 Pacana"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-20 00:00:00 +01:00
18
+ date: 2010-12-23 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -65,8 +65,24 @@ dependencies:
65
65
  - !ruby/object:Gem::Dependency
66
66
  type: :development
67
67
  prerelease: false
68
- name: rspec-rails
68
+ name: rails
69
69
  version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 1
75
+ segments:
76
+ - 3
77
+ - 0
78
+ - 3
79
+ version: 3.0.3
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ type: :development
83
+ prerelease: false
84
+ name: rspec-rails
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
70
86
  none: false
71
87
  requirements:
72
88
  - - ~>
@@ -77,12 +93,12 @@ dependencies:
77
93
  - 1
78
94
  - 0
79
95
  version: 2.1.0
80
- requirement: *id004
96
+ requirement: *id005
81
97
  - !ruby/object:Gem::Dependency
82
98
  type: :development
83
99
  prerelease: false
84
100
  name: rspec
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
86
102
  none: false
87
103
  requirements:
88
104
  - - ~>
@@ -93,12 +109,12 @@ dependencies:
93
109
  - 1
94
110
  - 0
95
111
  version: 2.1.0
96
- requirement: *id005
112
+ requirement: *id006
97
113
  - !ruby/object:Gem::Dependency
98
114
  type: :development
99
115
  prerelease: false
100
116
  name: bundler
101
- version_requirements: &id006 !ruby/object:Gem::Requirement
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
102
118
  none: false
103
119
  requirements:
104
120
  - - ~>
@@ -109,12 +125,12 @@ dependencies:
109
125
  - 0
110
126
  - 0
111
127
  version: 1.0.0
112
- requirement: *id006
128
+ requirement: *id007
113
129
  - !ruby/object:Gem::Dependency
114
130
  type: :development
115
131
  prerelease: false
116
132
  name: jeweler
117
- version_requirements: &id007 !ruby/object:Gem::Requirement
133
+ version_requirements: &id008 !ruby/object:Gem::Requirement
118
134
  none: false
119
135
  requirements:
120
136
  - - ~>
@@ -125,12 +141,12 @@ dependencies:
125
141
  - 5
126
142
  - 1
127
143
  version: 1.5.1
128
- requirement: *id007
144
+ requirement: *id008
129
145
  - !ruby/object:Gem::Dependency
130
146
  type: :development
131
147
  prerelease: false
132
148
  name: rcov
133
- version_requirements: &id008 !ruby/object:Gem::Requirement
149
+ version_requirements: &id009 !ruby/object:Gem::Requirement
134
150
  none: false
135
151
  requirements:
136
152
  - - ">="
@@ -139,12 +155,12 @@ dependencies:
139
155
  segments:
140
156
  - 0
141
157
  version: "0"
142
- requirement: *id008
158
+ requirement: *id009
143
159
  - !ruby/object:Gem::Dependency
144
160
  type: :development
145
161
  prerelease: false
146
162
  name: sqlite3-ruby
147
- version_requirements: &id009 !ruby/object:Gem::Requirement
163
+ version_requirements: &id010 !ruby/object:Gem::Requirement
148
164
  none: false
149
165
  requirements:
150
166
  - - ">="
@@ -153,12 +169,12 @@ dependencies:
153
169
  segments:
154
170
  - 0
155
171
  version: "0"
156
- requirement: *id009
172
+ requirement: *id010
157
173
  - !ruby/object:Gem::Dependency
158
174
  type: :runtime
159
175
  prerelease: false
160
176
  name: aasm
161
- version_requirements: &id010 !ruby/object:Gem::Requirement
177
+ version_requirements: &id011 !ruby/object:Gem::Requirement
162
178
  none: false
163
179
  requirements:
164
180
  - - ~>
@@ -169,12 +185,12 @@ dependencies:
169
185
  - 2
170
186
  - 0
171
187
  version: 2.2.0
172
- requirement: *id010
188
+ requirement: *id011
173
189
  - !ruby/object:Gem::Dependency
174
190
  type: :runtime
175
191
  prerelease: false
176
192
  name: RedCloth
177
- version_requirements: &id011 !ruby/object:Gem::Requirement
193
+ version_requirements: &id012 !ruby/object:Gem::Requirement
178
194
  none: false
179
195
  requirements:
180
196
  - - ~>
@@ -185,12 +201,12 @@ dependencies:
185
201
  - 2
186
202
  - 3
187
203
  version: 4.2.3
188
- requirement: *id011
204
+ requirement: *id012
189
205
  - !ruby/object:Gem::Dependency
190
206
  type: :runtime
191
207
  prerelease: false
192
208
  name: activerecord
193
- version_requirements: &id012 !ruby/object:Gem::Requirement
209
+ version_requirements: &id013 !ruby/object:Gem::Requirement
194
210
  none: false
195
211
  requirements:
196
212
  - - ">="
@@ -200,12 +216,12 @@ dependencies:
200
216
  - 3
201
217
  - 0
202
218
  version: "3.0"
203
- requirement: *id012
219
+ requirement: *id013
204
220
  - !ruby/object:Gem::Dependency
205
221
  type: :development
206
222
  prerelease: false
207
223
  name: rspec
208
- version_requirements: &id013 !ruby/object:Gem::Requirement
224
+ version_requirements: &id014 !ruby/object:Gem::Requirement
209
225
  none: false
210
226
  requirements:
211
227
  - - ">="
@@ -216,12 +232,12 @@ dependencies:
216
232
  - 1
217
233
  - 0
218
234
  version: 2.1.0
219
- requirement: *id013
235
+ requirement: *id014
220
236
  - !ruby/object:Gem::Dependency
221
237
  type: :development
222
238
  prerelease: false
223
239
  name: rspec-rails
224
- version_requirements: &id014 !ruby/object:Gem::Requirement
240
+ version_requirements: &id015 !ruby/object:Gem::Requirement
225
241
  none: false
226
242
  requirements:
227
243
  - - ">="
@@ -232,12 +248,12 @@ dependencies:
232
248
  - 1
233
249
  - 0
234
250
  version: 2.1.0
235
- requirement: *id014
251
+ requirement: *id015
236
252
  - !ruby/object:Gem::Dependency
237
253
  type: :development
238
254
  prerelease: false
239
255
  name: sqlite3-ruby
240
- version_requirements: &id015 !ruby/object:Gem::Requirement
256
+ version_requirements: &id016 !ruby/object:Gem::Requirement
241
257
  none: false
242
258
  requirements:
243
259
  - - ">="
@@ -246,7 +262,7 @@ dependencies:
246
262
  segments:
247
263
  - 0
248
264
  version: "0"
249
- requirement: *id015
265
+ requirement: *id016
250
266
  description: Content blocks are commonly used models representing editable page partials.
251
267
  email: pawel.pacana@gmail.com
252
268
  executables: []
@@ -267,7 +283,8 @@ files:
267
283
  - VERSION
268
284
  - content_blocks.gemspec
269
285
  - lib/content_blocks.rb
270
- - lib/content_blocks/snippet.rb
286
+ - lib/content_blocks/models/snippet.rb
287
+ - lib/content_blocks/railtie.rb
271
288
  - lib/generators/content_blocks/snippet_generator.rb
272
289
  - lib/generators/content_blocks/templates/migration.rb
273
290
  - spec/schema/schema.rb
@@ -1,47 +0,0 @@
1
- require 'active_record'
2
- require 'aasm'
3
- require 'RedCloth'
4
-
5
- module ContentBlocks
6
- class Snippet < ActiveRecord::Base
7
- include AASM
8
-
9
- set_table_name 'content_blocks_snippets'
10
-
11
- LABEL_FORMAT = /^[a-zA-Z\d_]+$/
12
-
13
- aasm_initial_state :draft
14
- aasm_column :status
15
-
16
- aasm_state :draft
17
- aasm_state :published
18
-
19
- aasm_event :preview do
20
- transitions :from => :published, :to => :draft
21
- end
22
-
23
- aasm_event :publish do
24
- transitions :from => :draft, :to => :published
25
- end
26
-
27
- scope :published, where(:status => 'published')
28
- scope :draft, where(:status => 'draft')
29
-
30
- validates :label,
31
- :presence => true,
32
- :format => { :with => LABEL_FORMAT },
33
- :uniqueness => { :scope => :status, :if => :published? }
34
-
35
- def self.[](label)
36
- find_or_create_by_label(label)
37
- end
38
-
39
- def content
40
- textilize(raw_content)
41
- end
42
-
43
- def raw_content
44
- self[:content] if published?
45
- end
46
- end
47
- end