noumenon 0.2.0 → 0.2.1

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.
@@ -1,3 +1,10 @@
1
+ # 0.2.1
2
+
3
+ ## New Features
4
+
5
+ * The nav_menu helper, and ContentRepository#children now includes the root item by default, and sorts
6
+ on path name.
7
+
1
8
  # 0.2.0
2
9
 
3
10
  ## Backwards Compatiability Broken
@@ -60,27 +60,26 @@ class Noumenon::ContentRepository::FileSystem < Noumenon::ContentRepository
60
60
  #
61
61
  # @see Noumenon::Repository#children
62
62
  # @api public
63
- def children(root = "/", depth = 1)
63
+ def children(root = "/", depth = 1, include_root = true)
64
64
  root.gsub! /\/$/, ''
65
65
 
66
66
  pattern = File.join(repository_path(root), "*")
67
- items = Dir.glob(pattern).collect do |i|
67
+
68
+ items = Dir.glob(pattern).collect { |i|
68
69
  i.gsub(repository_path("/"), "/").
69
70
  gsub(".yml", "")
70
- end
71
-
72
- # We're not interested in indexes, since they're not children.
73
- items.delete(File.join(root, "index"))
71
+ }.reject { |i| i.gsub(root, "").split("/").size > depth + 1 }
72
+ items.delete(File.join(root, "index")) unless include_root
74
73
 
75
- items.reject { |i| i.gsub(root, "").split("/").size > depth + 1 }.collect do |item|
76
- path = item == "" ? "/" : item
74
+ items.collect { |item|
75
+ path = item == "" ? "/" : item.gsub("index", "")
77
76
 
78
77
  # Loading every item probably isn't scalable, but it'll do for now. We can add caching
79
78
  # at a later date if needed.
80
79
  page = get(path).merge({ path: path })
81
- page[:children] = children(page[:path], depth - 1) if depth - 1 > 0
80
+ page[:children] = children(page[:path], depth - 1, false) if depth - 1 > 0
82
81
  page
83
- end
82
+ }.sort { |a, b| a[:path] <=> b[:path] }
84
83
  end
85
84
 
86
85
  # Save a static asset to the repository.
@@ -58,20 +58,20 @@ module Noumenon::Template::CoreTags
58
58
  # @api public
59
59
  # @example
60
60
  # <header>
61
- # {{ nav_menu }}
61
+ # {% nav_menu %}
62
62
  # </header>
63
63
  #
64
64
  # <div id="sidebar">
65
65
  # <h1>About Our Stuff</h1>
66
66
  # <nav>
67
- # {{ nav_menu root=/about depth=1 }}
67
+ # {% nav_menu root=/about depth=1 include_root=false %}
68
68
  # </nav>
69
69
  # </div>
70
70
  class NavigationTag < Liquid::Tag
71
71
  def initialize(tag_name, syntax, tokens)
72
72
  super
73
73
 
74
- @options = { depth: 1, root: "/" }
74
+ @options = { depth: 1, root: "/", include_root: true }
75
75
 
76
76
  syntax.split(" ").each do |option|
77
77
  key, value = option.split("=")
@@ -80,6 +80,8 @@ module Noumenon::Template::CoreTags
80
80
  @options[:depth] = value.to_i
81
81
  when "root"
82
82
  @options[:root] = value
83
+ when "include_root"
84
+ @options[:include_root] = [ "true", "yes", "1" ].include?(value)
83
85
  end
84
86
  end
85
87
  end
@@ -98,7 +100,7 @@ module Noumenon::Template::CoreTags
98
100
  end
99
101
 
100
102
  def render(context)
101
- render_list Noumenon.content_repository.children(@options[:root], @options[:depth])
103
+ render_list Noumenon.content_repository.children(@options[:root], @options[:depth], @options[:include_root])
102
104
  end
103
105
  end
104
106
  Liquid::Template.register_tag('nav_menu', NavigationTag)
@@ -1,5 +1,5 @@
1
1
  module Noumenon
2
2
  # The current version of Noumenon.
3
3
  # @api public
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -131,7 +131,7 @@ describe Noumenon::ContentRepository::FileSystem do
131
131
  end
132
132
 
133
133
  it "does not list items below the top level" do
134
- subject.children("/").should have(2).items
134
+ subject.children("/").should have(3).items
135
135
  end
136
136
 
137
137
  describe "each item" do
@@ -142,13 +142,15 @@ describe Noumenon::ContentRepository::FileSystem do
142
142
  end
143
143
 
144
144
  it "has a path" do
145
- items[0][:path].should == "/about"
146
- items[1][:path].should == "/contact"
145
+ items[0][:path].should == "/"
146
+ items[1][:path].should == "/about"
147
+ items[2][:path].should == "/contact"
147
148
  end
148
149
 
149
150
  it "has a title" do
150
- items[0][:title].should == "About"
151
- items[1][:title].should == "Contact"
151
+ items[0][:title].should == "Home"
152
+ items[1][:title].should == "About"
153
+ items[2][:title].should == "Contact"
152
154
  end
153
155
  end
154
156
  end
@@ -158,7 +160,8 @@ describe Noumenon::ContentRepository::FileSystem do
158
160
 
159
161
  describe "an item with children" do
160
162
  it "has an array of children" do
161
- items[0][:children].should have(2).items
163
+ items[1][:children].should have(2).items
164
+ items[1][:children][0][:title].should == "Location"
162
165
  end
163
166
  end
164
167
  end
@@ -167,9 +170,10 @@ describe Noumenon::ContentRepository::FileSystem do
167
170
  let(:items) { subject.children("/about") }
168
171
 
169
172
  it "lists only items below that point" do
170
- items.should have(2).items
171
- items[0][:title].should == "Location"
172
- items[1][:title].should == "Team"
173
+ items.should have(3).items
174
+ items[0][:title].should == "About"
175
+ items[1][:title].should == "Location"
176
+ items[2][:title].should == "Team"
173
177
  end
174
178
  end
175
179
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: noumenon
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jon Wood