noodall-core 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'mongo_mapper', '~> 0.8.4'
4
- gem 'bson_ext', '~> 1.0.9'
3
+ gem 'mongo_mapper', '~> 0.8.6'
5
4
  gem 'ramdiv-mongo_mapper_acts_as_tree', '~> 0.1.1'
6
5
  gem 'canable', '~> 0.1.1'
7
6
  gem 'ruby-stemmer'
@@ -14,5 +13,6 @@ group :development do
14
13
  gem "factory_girl", "~> 1.3.2"
15
14
  gem "faker", "~> 0.3.1"
16
15
  gem "rake"
16
+ gem 'bson_ext', '~> 1.1.0'
17
17
  end
18
18
 
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (3.0.0)
5
- bson (1.0.9)
6
- bson_ext (1.0.9)
4
+ activesupport (3.0.1)
5
+ bson (1.1.1)
6
+ bson_ext (1.1.1)
7
7
  canable (0.1.1)
8
8
  database_cleaner (0.5.2)
9
9
  diff-lcs (1.1.2)
@@ -11,7 +11,7 @@ GEM
11
11
  faker (0.3.1)
12
12
  gemcutter (0.6.1)
13
13
  git (1.2.5)
14
- i18n (0.4.1)
14
+ i18n (0.4.2)
15
15
  jeweler (1.4.0)
16
16
  gemcutter (>= 0.1.0)
17
17
  git (>= 1.2.5)
@@ -19,27 +19,27 @@ GEM
19
19
  jnunemaker-validatable (1.8.4)
20
20
  activesupport (>= 2.3.4)
21
21
  json_pure (1.4.6)
22
- mongo (1.0.9)
23
- bson (>= 1.0.5)
24
- mongo_mapper (0.8.4)
22
+ mongo (1.1.1)
23
+ bson (>= 1.1.1)
24
+ mongo_mapper (0.8.6)
25
25
  activesupport (>= 2.3.4)
26
26
  jnunemaker-validatable (~> 1.8.4)
27
- plucky (~> 0.3.5)
28
- plucky (0.3.5)
29
- mongo (~> 1.0.8)
27
+ plucky (~> 0.3.6)
28
+ plucky (0.3.6)
29
+ mongo (~> 1.1)
30
30
  rake (0.8.7)
31
- ramdiv-mongo_mapper_acts_as_tree (0.1.1)
31
+ ramdiv-mongo_mapper_acts_as_tree (0.1.2)
32
32
  mongo_mapper (>= 0.6.8)
33
- rspec (2.0.0.beta.22)
34
- rspec-core (= 2.0.0.beta.22)
35
- rspec-expectations (= 2.0.0.beta.22)
36
- rspec-mocks (= 2.0.0.beta.22)
37
- rspec-core (2.0.0.beta.22)
38
- rspec-expectations (2.0.0.beta.22)
33
+ rspec (2.0.1)
34
+ rspec-core (~> 2.0.1)
35
+ rspec-expectations (~> 2.0.1)
36
+ rspec-mocks (~> 2.0.1)
37
+ rspec-core (2.0.1)
38
+ rspec-expectations (2.0.1)
39
39
  diff-lcs (>= 1.1.2)
40
- rspec-mocks (2.0.0.beta.22)
41
- rspec-core (= 2.0.0.beta.22)
42
- rspec-expectations (= 2.0.0.beta.22)
40
+ rspec-mocks (2.0.1)
41
+ rspec-core (~> 2.0.1)
42
+ rspec-expectations (~> 2.0.1)
43
43
  ruby-stemmer (0.8.2)
44
44
  rubyforge (2.0.4)
45
45
  json_pure (>= 1.1.7)
@@ -48,14 +48,14 @@ PLATFORMS
48
48
  ruby
49
49
 
50
50
  DEPENDENCIES
51
- bson_ext (~> 1.0.9)
51
+ bson_ext (~> 1.1.0)
52
52
  canable (~> 0.1.1)
53
53
  database_cleaner (~> 0.5.2)
54
54
  factory_girl (~> 1.3.2)
55
55
  faker (~> 0.3.1)
56
56
  i18n
57
57
  jeweler (~> 1.4.0)
58
- mongo_mapper (~> 0.8.4)
58
+ mongo_mapper (~> 0.8.6)
59
59
  rake
60
60
  ramdiv-mongo_mapper_acts_as_tree (~> 0.1.1)
61
61
  rspec (~> 2.0.0.beta.22)
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  gem.homepage = "http://github.com/beef/noodall-core"
13
13
  gem.authors = ["Steve England"]
14
14
  gem.add_dependency('mongo_mapper', '~> 0.8.6')
15
- gem.add_dependency('ramdiv-mongo_mapper_acts_as_tree', '0.1.1')
15
+ gem.add_dependency('ramdiv-mongo_mapper_acts_as_tree', '~> 0.1.1')
16
16
  gem.add_dependency('canable', '0.1.1')
17
17
  gem.add_dependency('ruby-stemmer')
18
18
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/lib/noodall/node.rb CHANGED
@@ -3,15 +3,15 @@ module Noodall
3
3
  include MongoMapper::Document
4
4
  include MongoMapper::Acts::Tree
5
5
  include Canable::Ables
6
-
6
+
7
7
  plugin MultiParameterAttributes
8
8
  plugin Indexer
9
9
  plugin Search
10
10
  plugin Tagging
11
11
  plugin GlobalUpdateTime
12
-
12
+
13
13
  key :title, String, :required => true
14
- key :link_name, String
14
+ key :name, String
15
15
  key :description, String
16
16
  key :body, String
17
17
  key :position, Integer, :default => nil
@@ -22,83 +22,83 @@ module Noodall
22
22
  key :destroyable_groups, Array
23
23
  key :publishable_groups, Array
24
24
  key :permalink, Permalink, :required => true, :index => true
25
-
25
+
26
26
  timestamps!
27
27
  userstamps!
28
-
28
+
29
29
  alias_method :keywords, :tag_list
30
30
  alias_method :keywords=, :tag_list=
31
-
31
+
32
32
  attr_accessor :publish, :hide #for publishing
33
-
33
+
34
34
  acts_as_tree :order => "position"
35
-
35
+
36
36
  searchable_keys :title, :description, :keywords, :body
37
-
37
+
38
38
  validates_true_for :template, :message => "cannot be changed as sub content is not allowed in this template", :logic => lambda { children.reject{|c| self._type.constantize.template_classes.include?(c.class)}.empty? }
39
-
39
+
40
40
  def published_children
41
41
  self.children.select{|c| c.published? }
42
42
  end
43
-
43
+
44
44
  # Allow parent to be set to none using a string. Allows us to set the parent to nil easily via forms
45
45
  def parent=(var)
46
46
  self[parent_id_field] = nil
47
47
  var == "none" ? super(nil) : super
48
48
  end
49
-
49
+
50
50
  def template
51
51
  self.class.name.titleize
52
52
  end
53
-
53
+
54
54
  def template=(template_name)
55
55
  self._type = template_name.gsub(' ','') unless template_name.blank?
56
56
  end
57
-
57
+
58
58
  def published?
59
59
  !published_at.nil? and published_at <= current_time and (published_to.nil? or published_to >= current_time)
60
60
  end
61
-
61
+
62
62
  def pending?
63
63
  published_at.nil? or published_at >= current_time
64
64
  end
65
-
65
+
66
66
  def expired?
67
67
  !published_to.nil? and published_to <= current_time
68
68
  end
69
-
69
+
70
70
  def first?
71
71
  position == 0
72
72
  end
73
-
73
+
74
74
  def last?
75
75
  position == self.class.count(:_id => {"$ne" => self._id}, parent_id_field => self[parent_id_field])
76
76
  end
77
77
  def move_lower
78
78
  sibling = self.class.first(:position => {"$gt" => self.position}, parent_id_field => self[parent_id_field], :order => 'position ASC')
79
-
79
+
80
80
  tmp = sibling.position
81
81
  sibling.position = self.position
82
82
  self.position = tmp
83
-
83
+
84
84
  self.class.collection.update({:_id => self._id}, self.to_mongo)
85
85
  self.class.collection.update({:_id => sibling._id}, sibling.to_mongo)
86
-
86
+
87
87
  global_updated!
88
88
  end
89
89
  def move_higher
90
90
  sibling = self.class.first(:position => {"$lt" => self.position}, parent_id_field => self[parent_id_field], :order => 'position DESC')
91
-
91
+
92
92
  tmp = sibling.position
93
93
  sibling.position = self.position
94
94
  self.position = tmp
95
-
95
+
96
96
  self.class.collection.update({:_id => self._id}, self.to_mongo)
97
97
  self.class.collection.update({:_id => sibling._id}, sibling.to_mongo)
98
-
98
+
99
99
  global_updated!
100
100
  end
101
-
101
+
102
102
  def run_callbacks(kind, options = {}, &block)
103
103
  self.class.send("#{kind}_callback_chain").run(self, options, &block)
104
104
  self.embedded_associations.each do |association|
@@ -110,7 +110,7 @@ module Noodall
110
110
  self.send(key.name).run_callbacks(kind, options, &block) unless self.send(key.name).nil?
111
111
  end
112
112
  end
113
-
113
+
114
114
  def slots
115
115
  slots = []
116
116
  for slot_type in self.class.possible_slots.map(&:to_s)
@@ -120,95 +120,95 @@ module Noodall
120
120
  end
121
121
  slots.compact
122
122
  end
123
-
123
+
124
124
  ## CANS
125
125
  def all_groups
126
126
  updatable_groups | destroyable_groups | publishable_groups
127
127
  end
128
-
128
+
129
129
  %w( updatable destroyable publishable ).each do |permission|
130
130
  define_method("#{permission}_by?") do |user|
131
131
  user.admin? or send("#{permission}_groups").empty? or user.groups.any?{ |g| send("#{permission}_groups").include?(g) }
132
132
  end
133
-
133
+
134
134
  define_method("#{permission}_groups_list") do
135
135
  send("#{permission}_groups").join(', ')
136
136
  end
137
-
137
+
138
138
  define_method("#{permission}_groups_list=") do |groups_string|
139
139
  send("#{permission}_groups=", groups_string.split(',').map{|g| g.blank? ? nil : g.strip }.compact.uniq)
140
140
  end
141
141
  end
142
-
142
+
143
143
  def creatable_by?(user)
144
144
  parent.nil? or parent.updatable_by?(user)
145
145
  end
146
-
146
+
147
147
  # tree method that allow oprions to be passed
148
148
  def siblings(options = {})
149
149
  self.class.all(options.merge(:_id => {"$ne" => self._id}, parent_id_field => self[parent_id_field], :order => tree_order))
150
150
  end
151
-
151
+
152
152
  def self_and_siblings(options = {})
153
153
  self.class.all(options.merge(parent_id_field => self[parent_id_field], :order => tree_order))
154
154
  end
155
-
155
+
156
156
  def children(options = {})
157
157
  self.class.all(options.merge(parent_id_field => self._id, :order => tree_order))
158
158
  end
159
-
159
+
160
160
  private
161
161
 
162
162
  def current_time
163
163
  self.class.current_time
164
164
  end
165
-
165
+
166
166
  before_validation :set_permalink
167
167
  def set_permalink
168
168
  self.permalink = Permalink.new(*(ancestors << self).map{ |a| a.title.parameterize }) if permalink.blank? and not title.blank?
169
169
  end
170
-
170
+
171
171
  before_save :set_position
172
172
  def set_position
173
173
  write_attribute :position, siblings.size if position.nil?
174
174
  end
175
-
175
+
176
176
  before_save :clean_slots
177
-
177
+
178
178
  # This method removes any uneeded modules from the object
179
179
  # modules that would otherwise remain hidden
180
180
  # if the objects class was changed
181
181
  def clean_slots
182
-
182
+
183
183
  # TODO: spec this
184
-
184
+
185
185
  slot_types = self.class.possible_slots.map(&:to_s)
186
186
  # collect all of the slot attributes
187
187
  # (so we don't have to loop through the whole object each time)
188
188
  slots = self.attributes.select{|k,v| k =~ /^(#{slot_types.join('|')})_slot_\d+$/ }
189
-
189
+
190
190
  # for each type of slot
191
191
  for slot_type in slot_types
192
192
  # get the number of slots of this type in the (possibly new) class
193
193
  slot_count = self._type.constantize.send("#{slot_type}_slots_count").to_i
194
-
194
+
195
195
  # loop through all of the slot attributes for this type
196
196
  slots.select{|k,v| k =~ /^#{slot_type}_slot_\d+$/ }.each do |key, slot|
197
-
197
+
198
198
  index = key[/#{slot_type}_slot_(\d+)$/, 1].to_i
199
-
199
+
200
200
  logger.debug "Deleting #{key} #{self.send(key).inspect}" if index >= slot_count
201
201
  # set the slot to nil
202
202
  write_attribute(key.to_sym, nil) if index >= slot_count
203
203
  end
204
204
  end
205
205
  end
206
-
206
+
207
207
  before_save :set_path
208
208
  def set_path
209
209
  write_attribute :path, parent.path + [parent._id] unless parent.nil?
210
210
  end
211
-
211
+
212
212
  before_create :inherit_permisions
213
213
  def inherit_permisions
214
214
  unless parent.nil?
@@ -217,7 +217,7 @@ module Noodall
217
217
  self.publishable_groups = parent.publishable_groups
218
218
  end
219
219
  end
220
-
220
+
221
221
  after_save :order_siblings
222
222
  def order_siblings
223
223
  if position_changed?
@@ -230,7 +230,7 @@ module Noodall
230
230
  end
231
231
  end
232
232
  end
233
-
233
+
234
234
  before_save :set_published
235
235
  def set_published
236
236
  if publish
@@ -242,17 +242,22 @@ module Noodall
242
242
  write_attribute :published_to, 10.years.from_now
243
243
  end
244
244
  end
245
-
245
+
246
+ before_save :set_name
247
+ def set_name
248
+ self.name = self.title if self.name.blank?
249
+ end
250
+
246
251
  module ClassMethods
247
252
  @@slots = []
248
-
253
+
249
254
  # Set the names of the slots that will be avaiable to fill with components
250
255
  # For each name new methods will be created;
251
- #
256
+ #
252
257
  # <name>_slots(count)
253
258
  # This allow you to set the number of slots available in a template
254
259
  # <name>_slots_count(count)
255
- # Reads back the count you set
260
+ # Reads back the count you set
256
261
  def slots(*args)
257
262
  @@slots = args.map(&:to_sym).uniq
258
263
 
@@ -281,13 +286,13 @@ module Noodall
281
286
  def roots(options = {})
282
287
  self.all(options.merge(parent_id_field => nil, :order => tree_order))
283
288
  end
284
-
289
+
285
290
  def find_by_permalink(permalink)
286
291
  node = find_one(:permalink => permalink.to_s, :published_at => { :$lte => current_time })
287
292
  raise MongoMapper::DocumentNotFound if node.nil? or node.expired?
288
293
  node
289
294
  end
290
-
295
+
291
296
  def template_classes
292
297
  return @template_classes if @template_classes
293
298
  classes = []
@@ -297,11 +302,11 @@ module Noodall
297
302
  end
298
303
  @template_classes = classes
299
304
  end
300
-
305
+
301
306
  def template_names
302
307
  template_classes.collect{|c| c.name.titleize}.sort
303
308
  end
304
-
309
+
305
310
  def all_template_classes
306
311
  templates = []
307
312
  template_classes.each do |template|
@@ -310,15 +315,15 @@ module Noodall
310
315
  end
311
316
  templates.uniq.collect{ |c| c.name.titleize }.sort
312
317
  end
313
-
318
+
314
319
  def sub_templates(*arr)
315
320
  @template_classes = arr
316
321
  end
317
-
322
+
318
323
  def root_template!
319
324
  @root_template = true
320
325
  end
321
-
326
+
322
327
  def root_template?
323
328
  @root_template
324
329
  end
@@ -326,7 +331,7 @@ module Noodall
326
331
  def single_collection_inherited?
327
332
  false
328
333
  end
329
-
334
+
330
335
  # Returns a list of classes that can have this model as a child
331
336
  def parent_classes
332
337
  classes = []
@@ -336,15 +341,15 @@ module Noodall
336
341
  end
337
342
  classes
338
343
  end
339
-
340
- # If rails style time zones are unavaiable fallback to standard now
344
+
345
+ # If rails style time zones are unavaiable fallback to standard now
341
346
  def current_time
342
- Time.zone ? Time.zone.now : Time.now
347
+ Time.zone ? Time.zone.now : Time.now
343
348
  end
344
349
  end
345
350
  extend ClassMethods
346
-
347
-
351
+
352
+
348
353
  end
349
354
 
350
355
  end
data/noodall-core.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{noodall-core}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steve England"]
@@ -60,18 +60,18 @@ Gem::Specification.new do |s|
60
60
 
61
61
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
62
  s.add_runtime_dependency(%q<mongo_mapper>, ["~> 0.8.6"])
63
- s.add_runtime_dependency(%q<ramdiv-mongo_mapper_acts_as_tree>, ["= 0.1.1"])
63
+ s.add_runtime_dependency(%q<ramdiv-mongo_mapper_acts_as_tree>, ["~> 0.1.1"])
64
64
  s.add_runtime_dependency(%q<canable>, ["= 0.1.1"])
65
65
  s.add_runtime_dependency(%q<ruby-stemmer>, [">= 0"])
66
66
  else
67
67
  s.add_dependency(%q<mongo_mapper>, ["~> 0.8.6"])
68
- s.add_dependency(%q<ramdiv-mongo_mapper_acts_as_tree>, ["= 0.1.1"])
68
+ s.add_dependency(%q<ramdiv-mongo_mapper_acts_as_tree>, ["~> 0.1.1"])
69
69
  s.add_dependency(%q<canable>, ["= 0.1.1"])
70
70
  s.add_dependency(%q<ruby-stemmer>, [">= 0"])
71
71
  end
72
72
  else
73
73
  s.add_dependency(%q<mongo_mapper>, ["~> 0.8.6"])
74
- s.add_dependency(%q<ramdiv-mongo_mapper_acts_as_tree>, ["= 0.1.1"])
74
+ s.add_dependency(%q<ramdiv-mongo_mapper_acts_as_tree>, ["~> 0.1.1"])
75
75
  s.add_dependency(%q<canable>, ["= 0.1.1"])
76
76
  s.add_dependency(%q<ruby-stemmer>, [">= 0"])
77
77
  end
data/spec/node_spec.rb CHANGED
@@ -55,7 +55,7 @@ describe Noodall::Node do
55
55
 
56
56
  @child = Page.create!(:title => "Ickle Kid", :parent => @root)
57
57
 
58
- @grandchild = Page.create!(:title => "Very Ickle Kid", :parent => @child)
58
+ @grandchild = Page.create!(:title => "Very Ickle Kid", :parent => @child)
59
59
  end
60
60
 
61
61
  it "should create permlink based on tree" do
@@ -63,11 +63,11 @@ describe Noodall::Node do
63
63
  @grandchild.reload
64
64
  @grandchild.permalink.to_s.should == "root/ickle-kid/very-ickle-kid"
65
65
  end
66
-
66
+
67
67
  it "should be under the correct path once moved" do
68
68
  grand_child_2 = Page.create!(:title => "Ickle Kid", :parent => @child)
69
69
  root_2 = Page.create!(:title => "Root 2")
70
-
70
+
71
71
  grand_child_2.parent = root_2
72
72
  grand_child_2.save!
73
73
 
@@ -82,7 +82,7 @@ describe Noodall::Node do
82
82
  @child.save(:validate => false)
83
83
 
84
84
  grand_child_2.reload
85
-
85
+
86
86
  grand_child_2.path.should_not include(@root.id)
87
87
  grand_child_2.path.should include(root_2.id)
88
88
  end
@@ -327,4 +327,15 @@ describe Noodall::Node do
327
327
  Page.parent_classes.should_not include(ArticlesList)
328
328
  end
329
329
 
330
+ it "should fall back to title for link name if it is blank" do
331
+ page = Factory(:page, :title => "My Long Title that is long")
332
+
333
+ page.name.should == "My Long Title that is long"
334
+
335
+ page.name = "Shorty"
336
+ page.save
337
+
338
+ page.name.should == "Shorty"
339
+ end
340
+
330
341
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noodall-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steve England
@@ -41,7 +41,7 @@ dependencies:
41
41
  version_requirements: &id002 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - "="
44
+ - - ~>
45
45
  - !ruby/object:Gem::Version
46
46
  hash: 25
47
47
  segments: