gollum-descendant_tree 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 011a69d0b24bc3d9070a5730df90e4f497472d82
4
- data.tar.gz: 9ff25b636b2f48f602fa2217aaa30f28ae3be760
3
+ metadata.gz: e58211e3637a19ad2fd57668d7f109269c71d5bb
4
+ data.tar.gz: 83f25aa50e62b98f8face77e7aef54ae33d910c7
5
5
  SHA512:
6
- metadata.gz: a238b3f368852651c6f6556540973a1c46495c0b14d6fff1327ff775ea1e57c82b72bfdc4bb62674c92cc855a98edf6fd956a6bbcf020f6e8f5f7c9587ab33a8
7
- data.tar.gz: 663a8044f4de0356a6e0afa31241aa585ce8586cc07718179fe525b9801c8a208e6c9f313b409ae0bd4bae2ec55a526846182aabdfc8f07926ccdeaeff728750
6
+ metadata.gz: ef85eed1b68e6a236d58b5e5cbfb3cdbf94edb877f588b389ff700ecf6f1057003dc1c593535486b6fa8347bd74c3ba27e3bb1efbc512d86d8e4fecc7c976d74
7
+ data.tar.gz: 90f8ff0e540930f8f699c441e63c5355065527ba05a49c4b8dc59e75f88da68634ead0ba5359645cb764da9090153891e7d4bbe0eca2c2a2f4081e27e28a9c73
@@ -2,18 +2,19 @@ module Gollum
2
2
  module DescendantTree
3
3
  class TreeBuilder
4
4
 
5
- def initialize (wiki, name)
5
+ def initialize (wiki, name, dir)
6
6
  @wiki = wiki
7
7
  @name = name
8
+ @dir = dir
8
9
  @current_nest_index = 0
10
+ set_current_page_identifier
9
11
  end
10
12
 
11
13
  def tree
12
- current_page_name = get_current_page_name
13
14
  page_descendants = []
14
15
  @wiki.pages.each do |page|
15
16
  set_current_nest_index(page) if page.filename == @name
16
- if (page.url_path.include?(current_page_name))
17
+ if (is_descendant?(page))
17
18
  page_descendants << {
18
19
  title: page.title,
19
20
  url_path: page.url_path,
@@ -27,16 +28,21 @@ module Gollum
27
28
 
28
29
  private
29
30
 
31
+ def set_current_page_identifier
32
+ current_page_name = @name.split('.').first
33
+ @current_page_identifier = (@dir.length > 1) ? @dir + '/' + current_page_name : current_page_name
34
+ end
35
+
30
36
  def set_current_nest_index(page)
31
37
  @current_nest_index = get_path_array(page).length
32
38
  end
33
39
 
34
- def get_current_index(page)
35
- get_path_array(page).length - @current_nest_index
40
+ def is_descendant?(page)
41
+ return true if page.url_path.include?(@current_page_identifier)
36
42
  end
37
43
 
38
- def get_current_page_name
39
- @name.split('.').first
44
+ def get_current_index(page)
45
+ get_path_array(page).length - @current_nest_index
40
46
  end
41
47
 
42
48
  def get_path_array(page)
@@ -1,5 +1,5 @@
1
1
  module Gollum
2
2
  module DescendantTree
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
data/lib/gollum/markup.rb CHANGED
@@ -3,7 +3,7 @@ module Gollum
3
3
 
4
4
  def render_with_descendant_tree (no_follow = false, encoding = nil)
5
5
  data = render_without_descendant_tree(no_follow, encoding)
6
- tree_builder = Gollum::DescendantTree::TreeBuilder.new(@wiki, @name)
6
+ tree_builder = Gollum::DescendantTree::TreeBuilder.new(@wiki, @name, @dir)
7
7
  tree = tree_builder.tree
8
8
  tree_renderer = Gollum::DescendantTree::TreeRenderer.new
9
9
  #[[_TREE_]] is already rendered from Markup.render
@@ -5,7 +5,7 @@ describe Gollum::DescendantTree::TreeBuilder do
5
5
  it "returns the correct tree" do
6
6
  wiki = double
7
7
  wiki.stub(:pages).and_return(pages)
8
- tree_builder = Gollum::DescendantTree::TreeBuilder.new(wiki, 'current_page.md')
8
+ tree_builder = Gollum::DescendantTree::TreeBuilder.new(wiki, 'current_page.md', 'home')
9
9
  expect(tree_builder.tree).to eq(tree_with_correct_nesting)
10
10
  end
11
11
 
@@ -9,7 +9,8 @@ module Gollum
9
9
  ['home/current_page/child','child.md','Child'],
10
10
  ['home/current_page/child/grandchild','grandchild.md','Grandchild'],
11
11
  ['home/current_page/child/grandchild/greatgrandchild','greatgrandchild.md','GreatGrandchild'],
12
- ['home/current_page/child_sibling', 'childsibling.md', 'Child Sibling']
12
+ ['home/current_page/child_sibling', 'childsibling.md', 'Child Sibling'],
13
+ ['home/sibling/current_page', 'current_page.md', 'Sibling']
13
14
  ]
14
15
  pages = []
15
16
  pages_info.each do |page|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum-descendant_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Froehlich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-08 00:00:00.000000000 Z
11
+ date: 2013-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler