content_driven 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/changelog.md +6 -0
- data/lib/content_driven.rb +1 -0
- data/lib/content_driven/article.rb +6 -0
- data/lib/content_driven/blog.rb +0 -1
- data/lib/content_driven/dsl.rb +2 -2
- data/lib/content_driven/hooks.rb +21 -0
- data/lib/content_driven/page.rb +13 -10
- data/lib/content_driven/version.rb +1 -1
- data/spec/dsl_spec.rb +3 -3
- data/spec/page_spec.rb +8 -8
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca15caf0ab486baf01025ee59176a8af87105d63
|
4
|
+
data.tar.gz: cc7802c13a37324c11e058111ade263041bef7cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13b3ac06b258383c7f6f6d2a83acd4072e973d36a4b2b321655f7bd9bff852cb6b432df160464e065493c6b6a67fe11f288e413e2fb6d3bceb916fc68d68e3c0
|
7
|
+
data.tar.gz: d8c69dae0a02923f509b7c62a545e833af838f0dcecd541d93394167a956c14da04469af29722cc555069d3f9c0d0b8fa42789d0e518237cd125fa19f6eac937
|
data/changelog.md
ADDED
data/lib/content_driven.rb
CHANGED
data/lib/content_driven/blog.rb
CHANGED
data/lib/content_driven/dsl.rb
CHANGED
@@ -10,8 +10,8 @@ module ContentDriven
|
|
10
10
|
|
11
11
|
# Allows us to call methods like site.blogs and blog.blog_posts
|
12
12
|
define_method("get_#{class_name.pluralise}") do
|
13
|
-
|
14
|
-
!
|
13
|
+
self.dup.delete_if do |child|
|
14
|
+
!self[child].is_a? subclass
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
module ContentDriven
|
3
|
+
module Hooks
|
4
|
+
|
5
|
+
attr :after_hooks
|
6
|
+
def after_hooks
|
7
|
+
@after_hooks ||= []
|
8
|
+
end
|
9
|
+
|
10
|
+
def call_after_hooks
|
11
|
+
after_hooks.each do |hook|
|
12
|
+
self.instance_eval &hook
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def after &block
|
17
|
+
after_hooks << block
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/content_driven/page.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative "support"
|
2
2
|
require_relative "dsl"
|
3
3
|
require_relative "page_list"
|
4
|
+
require_relative "hooks"
|
4
5
|
require_relative "routes"
|
5
6
|
require 'active_support/core_ext/string'
|
6
7
|
|
@@ -8,11 +9,12 @@ module ContentDriven
|
|
8
9
|
|
9
10
|
# ContentDriven defines a tree of content. Page is the base class.
|
10
11
|
# A Page has a parent and zero or more children
|
11
|
-
class Page
|
12
|
-
attr_accessor :parent, :
|
12
|
+
class Page < Hash
|
13
|
+
attr_accessor :parent, :url, :title, :date
|
13
14
|
|
14
15
|
extend ContentDriven::DSL
|
15
16
|
include ContentDriven::Routes
|
17
|
+
extend ContentDriven::Hooks
|
16
18
|
|
17
19
|
# Extend the DSL when Page is subclasses
|
18
20
|
def self.inherited(subclass)
|
@@ -20,21 +22,21 @@ module ContentDriven
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def initialize &block
|
23
|
-
self.children = PageList.new
|
24
25
|
if block_given?
|
25
26
|
self.instance_eval &block
|
26
27
|
end
|
28
|
+
self.class.call_after_hooks
|
27
29
|
end
|
28
30
|
|
29
31
|
# Add a child page. You will seldom need to call this directly.
|
30
32
|
# Instead use add_blog or add_article
|
31
33
|
def add_child key, page = nil
|
32
34
|
if key.is_a? Page
|
33
|
-
page, key = key, (
|
35
|
+
page, key = key, (self.keys.length + 1).to_sym
|
34
36
|
end
|
35
37
|
page.parent = self
|
36
38
|
page.url = key
|
37
|
-
|
39
|
+
self[key] = page
|
38
40
|
end
|
39
41
|
|
40
42
|
# Is this a root page, i.e. it has no parent?
|
@@ -44,12 +46,13 @@ module ContentDriven
|
|
44
46
|
|
45
47
|
# Returns the URL fragment as a symbol, or :root if it is the root page
|
46
48
|
def to_sym
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
root? ? :root : self.url.to_sym
|
50
|
+
end
|
51
|
+
|
52
|
+
def children
|
53
|
+
self
|
52
54
|
end
|
53
55
|
|
56
|
+
|
54
57
|
end
|
55
58
|
end
|
data/spec/dsl_spec.rb
CHANGED
@@ -16,8 +16,8 @@ describe ContentDriven::Page do
|
|
16
16
|
expect(ContentDriven::Page.instance_methods.include? :add_pony).to be_true
|
17
17
|
page = ContentDriven::Page.new
|
18
18
|
page.add_pony :wow_a_pony
|
19
|
-
expect(page.
|
20
|
-
expect(page
|
19
|
+
expect(page.length).to eq(1)
|
20
|
+
expect(page[:wow_a_pony].class).to be(ContentDriven::Pony)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "will gain a method of the form get_x when subclassed" do
|
@@ -42,7 +42,7 @@ describe ContentDriven::Page do
|
|
42
42
|
add_dog :fifth
|
43
43
|
end
|
44
44
|
puts "Cats"
|
45
|
-
expect(page.
|
45
|
+
expect(page.length).to be(5)
|
46
46
|
expect(page.get_dogs.length).to be(2)
|
47
47
|
expect(page.get_cats.length).to be(3)
|
48
48
|
end
|
data/spec/page_spec.rb
CHANGED
@@ -11,8 +11,8 @@ describe ContentDriven::Page do
|
|
11
11
|
|
12
12
|
it "can be initialized with a block" do
|
13
13
|
page = ContentDriven::Page.new {add_blog :test}
|
14
|
-
expect(page.
|
15
|
-
expect(page
|
14
|
+
expect(page.length).to be(1)
|
15
|
+
expect(page[:test].class).to be(ContentDriven::Blog)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "can be initialized with a nested block" do
|
@@ -21,10 +21,10 @@ describe ContentDriven::Page do
|
|
21
21
|
add_blog :test_2
|
22
22
|
end
|
23
23
|
end
|
24
|
-
expect(page.
|
25
|
-
expect(page
|
26
|
-
expect(page
|
27
|
-
expect(page
|
24
|
+
expect(page.length).to be(1)
|
25
|
+
expect(page[:test].class).to be(ContentDriven::Blog)
|
26
|
+
expect(page[:test].children.length).to be(1)
|
27
|
+
expect(page[:test].children[:test_2].class).to be(ContentDriven::Blog)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "has a title" do
|
@@ -35,8 +35,8 @@ describe ContentDriven::Page do
|
|
35
35
|
it "can add a child page with a key" do
|
36
36
|
child = ContentDriven::Page.new
|
37
37
|
@page.add_child :child, child
|
38
|
-
expect(@page.
|
39
|
-
expect(@page
|
38
|
+
expect(@page.length).to be(1)
|
39
|
+
expect(@page[:child]).to be(child)
|
40
40
|
expect(child.parent).to be(@page)
|
41
41
|
end
|
42
42
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: content_driven
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -79,11 +79,14 @@ files:
|
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
|
+
- changelog.md
|
82
83
|
- content_driven.gemspec
|
83
84
|
- lib/content_driven.rb
|
85
|
+
- lib/content_driven/article.rb
|
84
86
|
- lib/content_driven/blog.rb
|
85
87
|
- lib/content_driven/blog_post.rb
|
86
88
|
- lib/content_driven/dsl.rb
|
89
|
+
- lib/content_driven/hooks.rb
|
87
90
|
- lib/content_driven/page.rb
|
88
91
|
- lib/content_driven/page_list.rb
|
89
92
|
- lib/content_driven/routes.rb
|
@@ -116,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
119
|
version: '0'
|
117
120
|
requirements: []
|
118
121
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.0.
|
122
|
+
rubygems_version: 2.0.2
|
120
123
|
signing_key:
|
121
124
|
specification_version: 4
|
122
125
|
summary: Emphasised great Information Architecture, Metadata and SEO. Define your
|