noodall-core 0.3.12 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/noodall/node.rb +4 -0
- data/lib/noodall/site.rb +55 -0
- data/noodall-core.gemspec +5 -2
- data/spec/factories/node.rb +1 -0
- data/spec/site_map_spec.rb +47 -0
- metadata +8 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/noodall/node.rb
CHANGED
data/lib/noodall/site.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Noodall
|
2
|
+
class Site
|
3
|
+
class << self
|
4
|
+
|
5
|
+
attr_accessor :map, :permalinks
|
6
|
+
|
7
|
+
def build!
|
8
|
+
map.each do |permalink, attributes|
|
9
|
+
build_node(permalink, attributes)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def contains?(permalink)
|
14
|
+
self.permalinks ||= []
|
15
|
+
return true if map.keys.include?(permalink)
|
16
|
+
map.values.each do |attrubutes|
|
17
|
+
extract_permalinks(attrubutes)
|
18
|
+
end
|
19
|
+
return permalinks.include?(permalink)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def extract_permalinks(attributes)
|
25
|
+
children = attributes['children']
|
26
|
+
if children
|
27
|
+
self.permalinks = permalinks | children.keys
|
28
|
+
children.values.each do |attributes|
|
29
|
+
extract_permalinks(attributes)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_node(permalink, attr)
|
35
|
+
attributes = attr.dup
|
36
|
+
klass_name = attributes.delete('type')
|
37
|
+
children = attributes.delete('children')
|
38
|
+
|
39
|
+
node = Noodall::Node.first(:permalink => permalink) || create_node(klass_name, attributes.merge(:permalink => permalink))
|
40
|
+
children.each do |permalink, attributes|
|
41
|
+
build_node(permalink, attributes.merge(:parent => node))
|
42
|
+
end if children
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_node(klass_name, attributes)
|
46
|
+
if defined?(Factory) && Factory.factories[klass_name.underscore.to_sym]
|
47
|
+
Factory(klass_name.underscore, attributes)
|
48
|
+
else
|
49
|
+
klass_name.constantize.create!(attributes)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/noodall-core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{noodall-core}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
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"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-20}
|
13
13
|
s.description = %q{Core data objects for Noodall}
|
14
14
|
s.email = %q{steve@wearebeef.co.uk}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,12 +32,14 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/noodall/node.rb",
|
33
33
|
"lib/noodall/permalink.rb",
|
34
34
|
"lib/noodall/search.rb",
|
35
|
+
"lib/noodall/site.rb",
|
35
36
|
"lib/noodall/tagging.rb",
|
36
37
|
"noodall-core.gemspec",
|
37
38
|
"spec/component_spec.rb",
|
38
39
|
"spec/factories/component.rb",
|
39
40
|
"spec/factories/node.rb",
|
40
41
|
"spec/node_spec.rb",
|
42
|
+
"spec/site_map_spec.rb",
|
41
43
|
"spec/spec_helper.rb"
|
42
44
|
]
|
43
45
|
s.homepage = %q{http://github.com/beef/noodall-core}
|
@@ -47,6 +49,7 @@ Gem::Specification.new do |s|
|
|
47
49
|
s.summary = %q{Core data objects for Noodall}
|
48
50
|
s.test_files = [
|
49
51
|
"spec/node_spec.rb",
|
52
|
+
"spec/site_map_spec.rb",
|
50
53
|
"spec/component_spec.rb",
|
51
54
|
"spec/spec_helper.rb",
|
52
55
|
"spec/factories/node.rb",
|
data/spec/factories/node.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'noodall/site'
|
3
|
+
|
4
|
+
describe Noodall::Site do
|
5
|
+
|
6
|
+
before do
|
7
|
+
class LandingPage < Noodall::Node; end
|
8
|
+
class Home < Noodall::Node; end
|
9
|
+
Noodall::Site.map = {
|
10
|
+
'home' => {
|
11
|
+
'title' => 'Welcome',
|
12
|
+
'type' => 'Home'
|
13
|
+
},
|
14
|
+
'section' => {
|
15
|
+
'title' => 'Welcome to section',
|
16
|
+
'type' => 'LandingPage',
|
17
|
+
'children' => {
|
18
|
+
'section/page' => {
|
19
|
+
'title' => 'About this section',
|
20
|
+
'type' => 'Page',
|
21
|
+
},
|
22
|
+
'section/page2' => {
|
23
|
+
'title' => 'More info',
|
24
|
+
'type' => 'Page',
|
25
|
+
}
|
26
|
+
}
|
27
|
+
},
|
28
|
+
'about' => {
|
29
|
+
'title' => 'About us',
|
30
|
+
'type' => 'Page',
|
31
|
+
}
|
32
|
+
}
|
33
|
+
Noodall::Site.build!
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should be populated from a permalink attributues hash' do
|
37
|
+
Noodall::Node.count.should == 5
|
38
|
+
Noodall::Node.roots.count.should == 3
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should know if it contains a permalink' do
|
42
|
+
Noodall::Site.contains?('section/page').should == true
|
43
|
+
Noodall::Site.contains?('about').should == true
|
44
|
+
Noodall::Site.contains?('wout').should == false
|
45
|
+
Home.first.in_site_map?.should == true
|
46
|
+
end
|
47
|
+
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:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Steve England
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-20 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -121,12 +121,14 @@ files:
|
|
121
121
|
- lib/noodall/node.rb
|
122
122
|
- lib/noodall/permalink.rb
|
123
123
|
- lib/noodall/search.rb
|
124
|
+
- lib/noodall/site.rb
|
124
125
|
- lib/noodall/tagging.rb
|
125
126
|
- noodall-core.gemspec
|
126
127
|
- spec/component_spec.rb
|
127
128
|
- spec/factories/component.rb
|
128
129
|
- spec/factories/node.rb
|
129
130
|
- spec/node_spec.rb
|
131
|
+
- spec/site_map_spec.rb
|
130
132
|
- spec/spec_helper.rb
|
131
133
|
has_rdoc: true
|
132
134
|
homepage: http://github.com/beef/noodall-core
|
@@ -164,6 +166,7 @@ specification_version: 3
|
|
164
166
|
summary: Core data objects for Noodall
|
165
167
|
test_files:
|
166
168
|
- spec/node_spec.rb
|
169
|
+
- spec/site_map_spec.rb
|
167
170
|
- spec/component_spec.rb
|
168
171
|
- spec/spec_helper.rb
|
169
172
|
- spec/factories/node.rb
|