noumenon 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
67
|
+
|
68
|
+
items = Dir.glob(pattern).collect { |i|
|
68
69
|
i.gsub(repository_path("/"), "/").
|
69
70
|
gsub(".yml", "")
|
70
|
-
|
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.
|
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
|
-
|
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
|
-
# {
|
61
|
+
# {% nav_menu %}
|
62
62
|
# </header>
|
63
63
|
#
|
64
64
|
# <div id="sidebar">
|
65
65
|
# <h1>About Our Stuff</h1>
|
66
66
|
# <nav>
|
67
|
-
# {
|
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)
|
data/lib/noumenon/version.rb
CHANGED
@@ -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(
|
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 == "/
|
146
|
-
items[1][:path].should == "/
|
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 == "
|
151
|
-
items[1][:title].should == "
|
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[
|
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(
|
171
|
-
items[0][:title].should == "
|
172
|
-
items[1][:title].should == "
|
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
|