ancestry-treeview 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32fc67a1525de8362af589df7bd1b6bdcfcbd58f
4
+ data.tar.gz: a77601fffdaf5207a50ce98cb02a09bee67b7dea
5
+ SHA512:
6
+ metadata.gz: 08e989cd2f5ca15594123ba634e47a4ddbd5602a02cf52cb8d770def7c7cf62fd8741a18eedf184f8ac5c69cbf9da6f2273ed80494a60a87fcb8eb182939124c
7
+ data.tar.gz: 4b4ee0283bdadeec4d0efcc447804dace10fb53ca0d3d9a73efdf1bf7cf5621ea12e553d4a9eef525c4adfaa0a60a51d68573e46f32368eb523bac9df5f355d9
@@ -0,0 +1,12 @@
1
+ /*.gem
2
+ ~*
3
+ #*
4
+ *~
5
+ .bundle
6
+ Gemfile.lock
7
+ .rbenv-version
8
+ .ruby-version
9
+ doc/*
10
+ tmp/*
11
+ .yardoc
12
+ pkg
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ # - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ gemfile:
7
+ - Gemfile
@@ -0,0 +1,4 @@
1
+ # 0.0.1 (2013/06/23)
2
+
3
+ First Version
4
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+ source 'https://rubygems.org'
3
+
4
+ gemspec
5
+ gem 'ancestry-treeview', path: '.'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Naotoshi SEO
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.
@@ -0,0 +1,59 @@
1
+ # ancestry-treeview [![Build Status](https://secure.travis-ci.org/sonots/ancestry-treeview.png?branch=master)](http://travis-ci.org/sonots/ancestry-treeview) [![Dependency Status](https://gemnasium.com/sonots/ancestry-treeview.png)](https://gemnasium.com/sonots/ancestry-treeview)
2
+
3
+ testing ruby: 1.9.2, 1.9.3, 2.0.0; ancestry: 2.0.0
4
+
5
+ ## About OnePuch
6
+
7
+ ancestry-treeview is an extension of ancestry gem to show a tree view which looks like http://jsfiddle.net/Fh47n/.
8
+
9
+ ## Install
10
+
11
+ gem install ancestry-treeview
12
+
13
+ ## Dependencies
14
+
15
+ jquery, and rails are required.
16
+
17
+ ## Basic Usage
18
+
19
+ Add the following in your app/assets/stylesheets/application.css.scss
20
+
21
+ @import "ancestry-treeview";
22
+
23
+ Then, call
24
+
25
+ model.tree
26
+
27
+ in your view where `model` is your `ancestry` model.
28
+
29
+ ## Custom Link
30
+
31
+ As default, html links in the tree view are as
32
+
33
+ <a href="#">id</a>
34
+
35
+ You can change the htmll links by giving a block to `#tree` method as
36
+
37
+ model.tree {|node| link_to("text", your_controller_path(node)) }
38
+
39
+ ## Contraint Depth
40
+
41
+ As default, all childrens of specified node is shown as a tree. Use `to_depth` option to contraint the depth
42
+
43
+ mode.tree(to_depth: 1)
44
+
45
+ ## Acknowledgements
46
+
47
+ I appreciate Vitaliy Bychik for giving such a nice css style at http://stackoverflow.com/questions/11167628/trees-in-twitter-bootstrap .
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new [Pull Request](../../pull/new/master)
56
+
57
+ ## Copyright
58
+
59
+ Copyright (c) 2013 Naotoshi SEO. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+ task :default => :spec
10
+
11
+ desc 'Open an irb session preloaded with the gem library'
12
+ task :console do
13
+ sh 'irb -rubygems -I lib -r ancestry-treeview.rb'
14
+ end
15
+ task :c => :console
@@ -0,0 +1,27 @@
1
+ #! /usr/bin/env gem build
2
+ # encoding: utf-8
3
+ require File.expand_path('../lib/ancestry/treeview//version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'ancestry-treeview'
7
+ gem.version = Ancestry::Treeview::VERSION
8
+ gem.authors = ["Naotoshi Seo"]
9
+ gem.email = ["sonots@gmail.com"]
10
+ gem.homepage = "https://github.com/sonots/ancestry-treeview"
11
+ gem.summary = "An extension of ancestry gem to show a tree view"
12
+ gem.description = gem.summary
13
+
14
+ gem.files = `git ls-files`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_runtime_dependency "ancestry", [">= 2.0.0"]
20
+
21
+ # for testing
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "rspec"
24
+
25
+ # for debug
26
+ gem.add_development_dependency "pry"
27
+ end
@@ -0,0 +1,4 @@
1
+ require 'ancestry/treeview/version'
2
+ require 'ancestry/treeview/engine'
3
+ require 'ancestry/treeview/instance_methods'
4
+
@@ -0,0 +1,6 @@
1
+ module Ancestry
2
+ module Treeview
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,31 @@
1
+ module Ancestry
2
+ module InstanceMethods
3
+ def tree(params = {})
4
+ return '' unless self
5
+ subtree = (params[:to_depth].present? ? self.subtree(to_depth: params[:to_depth]) : self.subtree).order('path ASC')
6
+ html = '<div class="ancestry-treeview">'
7
+ open_ul = 0
8
+ prev_depth = self.depth - 1
9
+ subtree.each do |node|
10
+ curr_depth = node.depth
11
+ diff = curr_depth - prev_depth
12
+ if curr_depth > prev_depth
13
+ html += '<ul><li style="list-style:none">' * (diff - 1).abs
14
+ html += node.is_childless? ? '<ul><li class="leaf">' : '<ul><li>'
15
+ open_ul += diff
16
+ elsif curr_depth == prev_depth
17
+ html += node.is_childless? ? '</li><li class="leaf">' : '</li><li>'
18
+ elsif curr_depth < prev_depth
19
+ html += '</li></ul>' * diff.abs
20
+ html += node.is_childless? ? '</li><li class="leaf">' : '</li><li>'
21
+ open_ul -= diff
22
+ end
23
+ prev_depth = curr_depth
24
+ html += block_given? ? yield(node) : "<a href=#>#{node.id}</a>"
25
+ end
26
+ html += '</li></ul>' * open_ul.abs
27
+ html += '</div>'
28
+ html
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Ancestry
2
+ module Treeview
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ require "bundler/setup"
3
+ require "pry"
4
+
5
+ ROOT = File.dirname(__FILE__)
6
+ Dir[File.expand_path("support/**/*.rb", ROOT)].each {|f| require f }
7
+
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ end
@@ -0,0 +1,72 @@
1
+ /*
2
+ * @reference
3
+ * http://jsfiddle.net/Fh47n/
4
+ * http://stackoverflow.com/questions/11167628.ancestry-treeviews-in-twitter-bootstrap
5
+ * */
6
+ .ancestry-treeview li {
7
+ margin: 0;
8
+ list-style-type: none;
9
+ position: relative;
10
+ padding: 5px 5px 0px 5px;
11
+ }
12
+
13
+ .ancestry-treeview li::before {
14
+ content: '';
15
+ position: absolute;
16
+ top: 0;
17
+ width: 1px;
18
+ height: 100%;
19
+ right: auto;
20
+ left: -10px;
21
+ border-left: 1px solid #ccc;
22
+ bottom: 50px;
23
+ }
24
+ .ancestry-treeview li::after {
25
+ content: '';
26
+ position: absolute;
27
+ top: 15px;
28
+ width: 15px;
29
+ height: 20px;
30
+ right: auto;
31
+ left: -10px;
32
+ border-top: 1px solid #ccc;
33
+ }
34
+ .ancestry-treeview li a {
35
+ display: inline-block;
36
+ border: 1px solid #ccc;
37
+ padding: 0px 10px;
38
+ text-decoration: none;
39
+ color: #666;
40
+ font-family: arial, verdana, tahoma;
41
+ font-size: 11px;
42
+ border-radius: 5px;
43
+ -webkit-border-radius: 5px;
44
+ -moz-border-radius: 5px;
45
+ }
46
+
47
+ .ancestry-treeview li.leaf a {
48
+ background: #c8e4f8; color: #000; border: 1px solid #94a0b4;
49
+ }
50
+
51
+ /*Remove connectors before root*/
52
+ .ancestry-treeview > ul > li::before, .ancestry-treeview > ul > li::after {
53
+ border: 0;
54
+ }
55
+ /*Remove connectors after last child*/
56
+ .ancestry-treeview li:last-child::before {
57
+ height: 15px;
58
+ }
59
+
60
+ /*Time for some hover effects*/
61
+ /*We will apply the hover effect the the lineage of the element also*/
62
+ .ancestry-treeview li a:hover, .ancestry-treeview li a:hover+ul li a {
63
+ background: #c8f8e4; color: #000; border: 1px solid #94a0b4;
64
+ }
65
+ /*Connector styles on hover*/
66
+ .ancestry-treeview li a:hover+ul li::after,
67
+ .ancestry-treeview li a:hover+ul li::before,
68
+ .ancestry-treeview li a:hover+ul::before,
69
+ .ancestry-treeview li a:hover+ul ul::before {
70
+ border-color: #94a0b4;
71
+ }
72
+
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ancestry-treeview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ancestry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: An extension of ancestry gem to show a tree view
70
+ email:
71
+ - sonots@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - ancestry-treeview.gemspec
85
+ - lib/ancestry-treeview.rb
86
+ - lib/ancestry/treeview/engine.rb
87
+ - lib/ancestry/treeview/instance_methods.rb
88
+ - lib/ancestry/treeview/version.rb
89
+ - spec/spec_helper.rb
90
+ - vendor/assets/stylesheets/ancestry-treeview.css
91
+ homepage: https://github.com/sonots/ancestry-treeview
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.0
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: An extension of ancestry gem to show a tree view
114
+ test_files:
115
+ - spec/spec_helper.rb