gollum-descendant_tree 0.0.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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "titleize", "~> 1.3.0"
4
+
5
+ # Specify your gem's dependencies in gollum-descendant_tree.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aaron Froehlich
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Gollum::DescendantTree
2
+
3
+ DescendantTree adds a helper function, similar to Gollum's Table of Contents (TOC), which adds an unordered list of links to all descendants of the current page.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gollum-descendant_tree'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gollum-descendant_tree
18
+
19
+ ## Usage
20
+
21
+ Simply add `[[_TREE_]]` to any page of your wiki to add an unordered list of descendants to the page. If you're using custom css, you can target `ul.tree` for styling the list.
22
+
23
+ ## Automated Tests
24
+
25
+ $ bundle exec rspec spec
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gollum/descendant_tree/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gollum-descendant_tree"
8
+ spec.version = Gollum::DescendantTree::VERSION
9
+ spec.authors = ["Aaron Froehlich"]
10
+ spec.email = ["aaron@singlebrook.com"]
11
+ spec.description = %q{Provides a tag that can be used in gollum to output descedants of the current page}
12
+ spec.summary = %q{Descendant Tree is similar to Gollum's _TOC_ tag, except that it outputs an unordered list of all descendants of the current page, as determined by the page paths.}
13
+ spec.homepage = "https://github.com/singlebrook/gollum-descendant_tree"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'rspec', '~> 2.13'
24
+ spec.add_dependency "gollum", "~> 2.4.0"
25
+ spec.add_dependency "titleize", "~> 1.3"
26
+ end
@@ -0,0 +1,4 @@
1
+ require "gollum/descendant_tree/version"
2
+ require "gollum/markup"
3
+ require "gollum/descendant_tree/tree_builder"
4
+ require "gollum/descendant_tree/tree_renderer"
@@ -0,0 +1,53 @@
1
+ module Gollum
2
+ module DescendantTree
3
+ class TreeBuilder
4
+
5
+ def initialize (wiki, name)
6
+ @wiki = wiki
7
+ @name = name
8
+ @current_nest_index = 0
9
+ end
10
+
11
+ def tree
12
+ current_page_name = get_current_page_name
13
+ page_descendants = []
14
+ previous_page = ''
15
+ @wiki.pages.each do |page|
16
+ if (page.url_path.include?(current_page_name))
17
+ page_descendants << {
18
+ title: page.title,
19
+ url_path: page.url_path,
20
+ nest_index: get_current_index(page, previous_page)
21
+ }
22
+ previous_page = page
23
+ end
24
+
25
+ end
26
+ page_descendants
27
+ end
28
+
29
+ private
30
+
31
+ def get_current_index(current, previous)
32
+ return 0 if previous == ''
33
+ current_path_array = get_path_array(current)
34
+ previous_path_array = get_path_array(previous)
35
+ i = -1
36
+ previous_path_array.reverse_each do |node|
37
+ next if current_path_array.include?(node)
38
+ i += 1
39
+ end
40
+ @current_nest_index -= i
41
+ end
42
+
43
+ def get_current_page_name
44
+ @name.split('.').first
45
+ end
46
+
47
+ def get_path_array(page)
48
+ return page.url_path.split('/')
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,38 @@
1
+ require 'titleize'
2
+
3
+ module Gollum
4
+ module DescendantTree
5
+ class TreeRenderer
6
+
7
+ def initialize
8
+ @previous_nest_index = 0
9
+ end
10
+
11
+ def render(tree)
12
+ output = "<ul class='tree'>\n"
13
+ tree.each do |page|
14
+ output += nest_for(page) if page[:nest_index] != 0
15
+ output += "<li><a href='/#{page[:url_path]}'>#{page[:title].titleize}</a>"
16
+ end
17
+ output += "</ul></li>\n"
18
+ output += "</ul>\n"
19
+ output
20
+ end
21
+
22
+ private
23
+
24
+ def nest_for(page)
25
+ output = ''
26
+ if page[:nest_index] == @previous_nest_index
27
+ output += "</li>\n"
28
+ elsif page[:nest_index] > @previous_nest_index
29
+ output += "<ul>\n"
30
+ else
31
+ output += "</li></ul>\n" * (@previous_nest_index - page[:nest_index])
32
+ end
33
+ @previous_nest_index = page[:nest_index]
34
+ output
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module Gollum
2
+ module DescendantTree
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ module Gollum
2
+ class Markup
3
+
4
+ def render_with_descendant_tree (no_follow = false, encoding = nil)
5
+ data = render_without_descendant_tree(no_follow, encoding)
6
+ tree_builder = Gollum::DescendantTree::TreeBuilder.new(@wiki, @name)
7
+ tree = tree_builder.tree
8
+ tree_renderer = Gollum::DescendantTree::TreeRenderer.new
9
+ #[[_TREE_]] is already rendered from Markup.render
10
+ data.gsub(rendered_tree_link, tree_renderer.render(tree))
11
+ end
12
+ alias_method :render_without_descendant_tree, :render
13
+ alias_method :render, :render_with_descendant_tree
14
+
15
+ def rendered_tree_link
16
+ '<a class="internal absent" href="/_TREE_">_TREE_</a>'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gollum::Markup do
4
+ subject { Gollum::Markup }
5
+ #it { should alias_from(:render).to(:render_with_descendant_tree) }
6
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gollum::DescendantTree::TreeBuilder do
4
+
5
+ it "returns the correct tree" do
6
+ wiki = double
7
+ wiki.stub(:pages).and_return(pages)
8
+ tree_builder = Gollum::DescendantTree::TreeBuilder.new(wiki, 'current_page.md')
9
+ expect(tree_builder.tree).to eq(tree_with_correct_nesting)
10
+ end
11
+
12
+ def pages
13
+ build_mock_pages
14
+ end
15
+
16
+ def tree_with_correct_nesting
17
+ [{:title=>"Current Page", :url_path=>"current_page", :nest_index=>0},
18
+ {:title=>"Child", :url_path=>"current_page/child", :nest_index=>1},
19
+ {:title=>"Grandchild", :url_path=>"current_page/child/grandchild", :nest_index=>2},
20
+ {:title=>"GreatGrandchild",:url_path=>"current_page/child/grandchild/greatgrandchild", :nest_index=>3},
21
+ {:title=>"Child Sibling", :url_path=>"current_page/child_sibling", :nest_index=>1}]
22
+ end
23
+
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gollum::DescendantTree::TreeRenderer do
4
+
5
+ it "correctly renders a tree with indexes" do
6
+ wiki = double
7
+ wiki.stub(:pages).and_return(pages)
8
+ tree_renderer = Gollum::DescendantTree::TreeRenderer.new
9
+ expect(tree_renderer.render(tree_with_nesting)).to eq(correct_output)
10
+ end
11
+
12
+ def pages
13
+ build_mock_pages
14
+ end
15
+
16
+ def correct_output
17
+ "<ul class='tree'>\n<li><a href='/current_page'>Current Page</a><ul>\n<li><a href='/current_page/child'>Child</a><ul>\n<li><a href='/current_page/child/grandchild'>Grandchild</a><ul>\n<li><a href='/current_page/child/grandchild/greatgrandchild'>GreatGrandchild</a></li></ul>\n</li></ul>\n<li><a href='/current_page/child_sibling'>Child Sibling</a></ul></li>\n</ul>\n"
18
+ end
19
+
20
+ def tree_with_nesting
21
+ [{:title=>"Current Page", :url_path=>"current_page", :nest_index=>0},
22
+ {:title=>"Child", :url_path=>"current_page/child", :nest_index=>1},
23
+ {:title=>"Grandchild", :url_path=>"current_page/child/grandchild", :nest_index=>2},
24
+ {:title=>"GreatGrandchild",:url_path=>"current_page/child/grandchild/greatgrandchild", :nest_index=>3},
25
+ {:title=>"Child Sibling", :url_path=>"current_page/child_sibling", :nest_index=>1}]
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'gollum/app'
3
+ require 'gollum-descendant_tree'
4
+ require 'support/test_helpers'
5
+
6
+
7
+ RSpec.configure do |config|
8
+ config.include Gollum::DescendantTree::TestHelpers::PageMockFactory
9
+ end
@@ -0,0 +1,30 @@
1
+ module Gollum
2
+ module DescendantTree
3
+ module TestHelpers
4
+ module PageMockFactory
5
+ def build_mock_pages
6
+ pages_info = [
7
+ ['current_page', 'current_page.md', 'Current Page'],
8
+ ['current_page/child','child.md','Child'],
9
+ ['current_page/child/grandchild','grandchild.md','Grandchild'],
10
+ ['current_page/child/grandchild/greatgrandchild','greatgrandchild.md','GreatGrandchild'],
11
+ ['current_page/child_sibling', 'childsibling.md', 'Child Sibling']
12
+ ]
13
+ pages = []
14
+ pages_info.each do |page|
15
+ pages << create_page(page)
16
+ end
17
+ pages
18
+ end
19
+
20
+ def create_page(page_config)
21
+ page = double
22
+ page.stub(:url_path).and_return(page_config[0])
23
+ page.stub(:filename).and_return(page_config[1])
24
+ page.stub(:title).and_return(page_config[2])
25
+ page
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gollum-descendant_tree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Froehlich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70271551146020 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70271551146020
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70271551144980 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70271551144980
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70271551141900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.13'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70271551141900
47
+ - !ruby/object:Gem::Dependency
48
+ name: gollum
49
+ requirement: &70271551140480 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.4.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70271551140480
58
+ - !ruby/object:Gem::Dependency
59
+ name: titleize
60
+ requirement: &70271551139500 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '1.3'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70271551139500
69
+ description: Provides a tag that can be used in gollum to output descedants of the
70
+ current page
71
+ email:
72
+ - aaron@singlebrook.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - gollum-descendant_tree.gemspec
84
+ - lib/gollum-descendant_tree.rb
85
+ - lib/gollum/descendant_tree/tree_builder.rb
86
+ - lib/gollum/descendant_tree/tree_renderer.rb
87
+ - lib/gollum/descendant_tree/version.rb
88
+ - lib/gollum/markup.rb
89
+ - spec/gollum/descendant_tree/markup_spec.rb
90
+ - spec/gollum/descendant_tree/tree_builder_spec.rb
91
+ - spec/gollum/descendant_tree/tree_renderer_spec.rb
92
+ - spec/spec_helper.rb
93
+ - spec/support/test_helpers.rb
94
+ homepage: https://github.com/singlebrook/gollum-descendant_tree
95
+ licenses:
96
+ - MIT
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.15
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Descendant Tree is similar to Gollum's _TOC_ tag, except that it outputs
119
+ an unordered list of all descendants of the current page, as determined by the page
120
+ paths.
121
+ test_files:
122
+ - spec/gollum/descendant_tree/markup_spec.rb
123
+ - spec/gollum/descendant_tree/tree_builder_spec.rb
124
+ - spec/gollum/descendant_tree/tree_renderer_spec.rb
125
+ - spec/spec_helper.rb
126
+ - spec/support/test_helpers.rb