content_driven 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3403e03f4fc413624e8ce2e5f2d73bd279bc83c
4
- data.tar.gz: 6b0d0ab09da151ba396bae5eb3700c5b025ddd0f
3
+ metadata.gz: ca15caf0ab486baf01025ee59176a8af87105d63
4
+ data.tar.gz: cc7802c13a37324c11e058111ade263041bef7cc
5
5
  SHA512:
6
- metadata.gz: a3d3a1724d30c2bd7ee8f5ef159894ee2eff2b374d815345b1a40794101b9b19ec9989ca0673ae85473a493330147e72bf396486ebffa878000af29e65c109cf
7
- data.tar.gz: a33a5eb1b9435cfa87c0d719df4eca2d49a99acdfd7c129c8264793f5393c1a8076825af847a4d8d343e2733cc74d19e2d90b3f1197097c7084912256c311b29
6
+ metadata.gz: 13b3ac06b258383c7f6f6d2a83acd4072e973d36a4b2b321655f7bd9bff852cb6b432df160464e065493c6b6a67fe11f288e413e2fb6d3bceb916fc68d68e3c0
7
+ data.tar.gz: d8c69dae0a02923f509b7c62a545e833af838f0dcecd541d93394167a956c14da04469af29722cc555069d3f9c0d0b8fa42789d0e518237cd125fa19f6eac937
data/changelog.md ADDED
@@ -0,0 +1,6 @@
1
+ Content Driven Changelog
2
+
3
+ Version 0.2.0
4
+
5
+ * Added Article content type
6
+ * Removed children. Page now inherits directly from Hash.
@@ -1,3 +1,4 @@
1
+ require_relative "content_driven/article"
1
2
  require_relative "content_driven/blog"
2
3
  require_relative "content_driven/blog_post"
3
4
  require_relative "content_driven/tag"
@@ -0,0 +1,6 @@
1
+ require_relative 'page'
2
+
3
+ module ContentDriven
4
+ class Article < Page
5
+ end
6
+ end
@@ -1,7 +1,6 @@
1
1
  require_relative 'page'
2
2
 
3
3
  module ContentDriven
4
-
5
4
  class Blog < Page
6
5
  # TODO: Convenience shorthand methods
7
6
  # alias_method :add_post, :add_blog_post
@@ -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
- children.dup.delete_if do |child|
14
- !children[child].is_a? subclass
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
@@ -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, :children, :url, :title, :date
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, (children.keys.length + 1).to_sym
35
+ page, key = key, (self.keys.length + 1).to_sym
34
36
  end
35
37
  page.parent = self
36
38
  page.url = key
37
- children[key] = page
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
- if root?
48
- return :root
49
- else
50
- return self.url.to_sym
51
- end
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
@@ -1,3 +1,3 @@
1
1
  module ContentDriven
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  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.children.length).to eq(1)
20
- expect(page.children[:wow_a_pony].class).to be(ContentDriven::Pony)
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.children.length).to be(5)
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.children.length).to be(1)
15
- expect(page.children[:test].class).to be(ContentDriven::Blog)
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.children.length).to be(1)
25
- expect(page.children[:test].class).to be(ContentDriven::Blog)
26
- expect(page.children[:test].children.length).to be(1)
27
- expect(page.children[:test].children[:test_2].class).to be(ContentDriven::Blog)
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.children.length).to be(1)
39
- expect(@page.children[:child]).to be(child)
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.1.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-10-22 00:00:00.000000000 Z
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.3
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