bone_tree 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +190 -0
  4. data/Guardfile +14 -0
  5. data/README +1 -0
  6. data/Rakefile +21 -0
  7. data/app/assets/images/bonetree.png +0 -0
  8. data/app/assets/images/crushed_bone.png +0 -0
  9. data/app/assets/index.html +439 -0
  10. data/app/assets/javascripts/bone_tree.js +1292 -0
  11. data/app/assets/stylesheets/bone_tree.css +186 -0
  12. data/app/assets/stylesheets/bone_tree_repo.css +73 -0
  13. data/bone_tree-0.0.1.gem +0 -0
  14. data/bone_tree.gemspec +20 -0
  15. data/config.rb +26 -0
  16. data/config.ru +4 -0
  17. data/docs/index.html +222 -0
  18. data/docs/resources/base.css +70 -0
  19. data/docs/resources/index.css +20 -0
  20. data/docs/resources/module.css +24 -0
  21. data/docs/source/javascripts/bone_tree/_namespace.js.html +45 -0
  22. data/docs/source/javascripts/bone_tree/models/_directory.js.html +126 -0
  23. data/docs/source/javascripts/bone_tree/models/_file.js.html +112 -0
  24. data/docs/source/javascripts/bone_tree/models/_nodes.js.html +174 -0
  25. data/docs/source/javascripts/bone_tree/models/_settings.js.html +75 -0
  26. data/docs/source/javascripts/bone_tree/views/_directory.js.html +94 -0
  27. data/docs/source/javascripts/bone_tree/views/_file.js.html +82 -0
  28. data/docs/source/javascripts/bone_tree/views/_menu.js.html +110 -0
  29. data/docs/source/javascripts/bone_tree/views/_tree.js.html +432 -0
  30. data/lib/version.rb +4 -0
  31. data/source/images/bonetree.png +0 -0
  32. data/source/images/crushed_bone.png +0 -0
  33. data/source/index.html.haml +438 -0
  34. data/source/javascripts/_backbone.js +1293 -0
  35. data/source/javascripts/_jquery.min.js +5 -0
  36. data/source/javascripts/_underscore.js +999 -0
  37. data/source/javascripts/bone_tree/_namespace.js.coffee +7 -0
  38. data/source/javascripts/bone_tree/models/_directory.js.coffee +63 -0
  39. data/source/javascripts/bone_tree/models/_file.js.coffee +55 -0
  40. data/source/javascripts/bone_tree/models/_nodes.js.coffee +117 -0
  41. data/source/javascripts/bone_tree/models/_settings.js.coffee +25 -0
  42. data/source/javascripts/bone_tree/views/_directory.js.coffee +73 -0
  43. data/source/javascripts/bone_tree/views/_file.js.coffee +49 -0
  44. data/source/javascripts/bone_tree/views/_menu.js.coffee +97 -0
  45. data/source/javascripts/bone_tree/views/_tree.js.coffee +498 -0
  46. data/source/javascripts/bone_tree.js.coffee +1 -0
  47. data/source/layout.haml +13 -0
  48. data/source/stylesheets/bone_tree.css.sass +107 -0
  49. data/source/stylesheets/bone_tree_repo.css.sass +65 -0
  50. data/spec/javascripts/directory_view_spec.coffee +91 -0
  51. data/spec/javascripts/file_view_spec.coffee +70 -0
  52. data/spec/javascripts/helpers/spec_helper.coffee +7 -0
  53. data/spec/javascripts/menu_view_spec.coffee +42 -0
  54. data/spec/javascripts/nodes_spec.coffee +37 -0
  55. data/spec/javascripts/support/jasmine.yml +8 -0
  56. data/spec/javascripts/support/jasmine_config.rb +23 -0
  57. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  58. data/spec/javascripts/tree_view_spec.coffee +39 -0
  59. metadata +123 -0
@@ -0,0 +1,91 @@
1
+ #= require bone_tree/_namespace
2
+ #= require bone_tree/views/_directory
3
+
4
+ describe 'BoneTree.Views.Directory', ->
5
+ beforeEach ->
6
+ setFixtures("<div id='test'></div>")
7
+
8
+ treeView = new Backbone.View
9
+ treeView.findView = (model) ->
10
+ @view.model = model
11
+
12
+ return @view
13
+
14
+ treeView.settings = @settings
15
+
16
+ @settings = new Backbone.Model
17
+ treeView: treeView
18
+
19
+ @model = new Backbone.Model
20
+ name: "TestDir"
21
+ open: false
22
+
23
+ @model.collection = new Backbone.Collection
24
+ @model.collection.comparator = (item) =>
25
+ return item.get('name')
26
+
27
+ @view = new BoneTree.Views.Directory
28
+ model: @model
29
+ settings: @settings
30
+
31
+ $('#test').append @view.render().$el
32
+
33
+ afterEach ->
34
+ @view.remove()
35
+ $('#test').empty()
36
+
37
+ describe 'rendering', ->
38
+ it 'should render the correct element', ->
39
+ expect($('#test ul.directory')).toExist()
40
+ expect($('#test ul.directory').length).toEqual(1)
41
+
42
+ it 'should render the directory name as the DOM text', ->
43
+ expect($('#test ul.directory').text()).toEqual(@model.get('name'))
44
+
45
+ it 'should change the directory name in the DOM when the model name is updated', ->
46
+ renameSpy = sinon.spy()
47
+
48
+ @settings.get('treeView').bind 'rename', renameSpy
49
+
50
+ @model.set
51
+ name: "NewDir"
52
+
53
+ expect(renameSpy).toHaveBeenCalledOnce()
54
+ expect(renameSpy).toHaveBeenCalledWith(@model, @model.get('name'))
55
+
56
+ it 'should toggle the open class based on the model state', ->
57
+ #TODO this should be the case. Change it so that appendView doesn't automatically open the dir
58
+ # expect($('#test ul.directory')).not.toHaveClass('open')
59
+
60
+ @model.set
61
+ open: false
62
+
63
+ expect($('#test ul.directory')).not.toHaveClass('open')
64
+
65
+ @model.set
66
+ open: true
67
+
68
+ expect($('#test ul.directory')).toHaveClass('open')
69
+
70
+ #TODO mock findView properly so you can test this
71
+ #it 'should render new directories to the DOM', ->
72
+ # newDir = new Backbone.Model
73
+ # name: 'newDir'
74
+ # open: false
75
+
76
+ # @model.collection.add newDir
77
+
78
+ # expect($('#test ul.directory ul.directory').length).toEqual(1)
79
+
80
+ #TODO tests around hiding children directories
81
+
82
+ it 'should trigger a rename event on the tree when the directory name is changed', ->
83
+ spy = sinon.spy()
84
+
85
+ @settings.get('treeView').bind 'rename', spy
86
+
87
+ @model.set
88
+ name: 'dir2'
89
+
90
+ expect(spy).toHaveBeenCalledOnce()
91
+ expect(spy).toHaveBeenCalledWith(@model, @model.get('name'))
@@ -0,0 +1,70 @@
1
+ #= require bone_tree/_namespace
2
+ #= require bone_tree/views/_file
3
+
4
+ describe "BoneTree.Views.File", ->
5
+ beforeEach ->
6
+ setFixtures("<div id='test'></div>")
7
+
8
+ @settings = new Backbone.Model
9
+ treeView: new Backbone.View
10
+ showExtensions: true
11
+
12
+ @model = new Backbone.Model
13
+ name: "Testing"
14
+ extension: "exe"
15
+
16
+ @model.nameWithExtension = =>
17
+ @model.get('name') + "." + @model.get('extension')
18
+
19
+ @view = new BoneTree.Views.File
20
+ model: @model
21
+ settings: @settings
22
+
23
+ $('#test').append @view.render().el
24
+
25
+ afterEach ->
26
+ $('#test').empty()
27
+ @view.remove()
28
+
29
+ describe 'rendering', ->
30
+ it 'should render the correct element', ->
31
+ expect($('#test li.file')).toExist()
32
+ expect($('#test li.file').length).toEqual(1)
33
+
34
+ it 'should have the extension as a class name', ->
35
+ expect($('#test li.file')).toHaveClass('exe')
36
+
37
+ it 'should have the filename as the text of the node', ->
38
+ expect($('#test li.file').text()).toEqual('Testing.exe')
39
+
40
+ it 'should exclude the extension if that option is set', ->
41
+ @settings.set
42
+ showExtensions: false
43
+
44
+ @view.render()
45
+
46
+ expect($('#test li.file').text()).toEqual('Testing')
47
+
48
+ describe 'events', ->
49
+ it 'should trigger a change event on the file tree when the name has changed', ->
50
+ spy = sinon.spy()
51
+
52
+ @settings.get('treeView').bind 'rename', spy
53
+
54
+ @model.set
55
+ name: 'new name'
56
+
57
+ expect(spy).toHaveBeenCalledOnce()
58
+ expect(spy).toHaveBeenCalledWith(@model, @model.nameWithExtension())
59
+
60
+ it 'should trigger a change event on the file tree when the extension has changed', ->
61
+ spy = sinon.spy()
62
+
63
+ @settings.get('treeView').bind 'rename', spy
64
+
65
+ @model.set
66
+ extension: 'js'
67
+
68
+ expect(spy).toHaveBeenCalledOnce()
69
+ expect(spy).toHaveBeenCalledWith(@model, @model.nameWithExtension())
70
+
@@ -0,0 +1,7 @@
1
+ #= require _jquery.min
2
+ #= require _underscore
3
+ #= require _backbone
4
+ #= require sinon
5
+ #= require jasmine-jquery
6
+ #= require jasmine-sinon
7
+
@@ -0,0 +1,42 @@
1
+ #= require bone_tree/_namespace
2
+ #= require bone_tree/views/_menu
3
+
4
+ describe "BoneTree.Views.Menu", ->
5
+ beforeEach ->
6
+ setFixtures("<div id='test'></div>")
7
+
8
+ @model = new Backbone.Model
9
+
10
+ @settings = new Backbone.Model
11
+ confirmDeletes: false
12
+
13
+ @menu = new BoneTree.Views.Menu
14
+ model: @model
15
+ settings: @settings
16
+
17
+ $('#test').append @menu.render().el
18
+
19
+ afterEach ->
20
+ @menu.remove()
21
+ $('#test').empty()
22
+
23
+ describe "rendering", ->
24
+ it "should render the correct DOM elements", ->
25
+ expect($('#test .filetree_context_menu')).toExist()
26
+ expect($('#test .filetree_context_menu').length).toEqual(1)
27
+
28
+ expect($('#test .filetree_context_menu li').length).toEqual(2)
29
+ expect($('#test .filetree_context_menu li.rename')).toExist()
30
+ expect($('#test .filetree_context_menu li.delete')).toExist()
31
+
32
+ describe "interactions", ->
33
+ it "should delete", ->
34
+ spy = sinon.spy()
35
+
36
+ @model.bind 'destroy', spy
37
+
38
+ $('#test .delete').click()
39
+
40
+ expect(spy).toHaveBeenCalled()
41
+ expect($('#test .filetree_context_menu')).toBeHidden()
42
+
@@ -0,0 +1,37 @@
1
+ #= require bone_tree/_namespace
2
+ #= require bone_tree/models/_nodes
3
+
4
+ describe 'BoneTree.Models.Node', ->
5
+ beforeEach ->
6
+ {Models} = BoneTree
7
+
8
+ @file = new Models.Node
9
+ nodeType: 'file'
10
+ name: 'config'
11
+ extension: 'json'
12
+
13
+ @directory = new Models.Node
14
+ nodeType: 'directory'
15
+ name: 'src'
16
+
17
+ it 'should return the correct constantized type', ->
18
+ expect(@file.constantize()).toEqual('File')
19
+ expect(@directory.constantize()).toEqual('Directory')
20
+
21
+ it 'should return the full name with extension when appropriate', ->
22
+ expect(@file.nameWithExtension()).toEqual('config.json')
23
+ expect(@directory.nameWithExtension()).toEqual('src')
24
+
25
+ it 'should return just the fileName when no extension is present', ->
26
+ @file = new BoneTree.Models.Node
27
+ nodeType: 'file'
28
+ name: 'something'
29
+
30
+ expect(@file.nameWithExtension()).toEqual('something')
31
+
32
+ @anotherFile = new BoneTree.Models.Node
33
+ nodeType: 'file'
34
+ name: 'main'
35
+ extension: ''
36
+
37
+ expect(@anotherFile.nameWithExtension()).toEqual('main')
@@ -0,0 +1,8 @@
1
+ src_files:
2
+ - "**/*"
3
+ helpers:
4
+ - helpers/**/*
5
+ spec_files:
6
+ - "**/*_spec.*"
7
+ src_dir: source/javascripts
8
+ spec_dir: spec/javascripts
@@ -0,0 +1,23 @@
1
+ module Jasmine
2
+ class Config
3
+
4
+ # Add your overrides or custom config code here
5
+
6
+ end
7
+ end
8
+
9
+
10
+ # Note - this is necessary for rspec2, which has removed the backtrace
11
+ module Jasmine
12
+ class SpecBuilder
13
+ def declare_spec(parent, spec)
14
+ me = self
15
+ example_name = spec["name"]
16
+ @spec_ids << spec["id"]
17
+ backtrace = @example_locations[parent.description + " " + example_name]
18
+ parent.it example_name, {} do
19
+ me.report_spec(spec["id"])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ $:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
2
+
3
+ require 'rubygems'
4
+ require 'jasmine'
5
+ jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
6
+ require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
7
+ if Jasmine::Dependencies.rspec2?
8
+ require 'rspec'
9
+ else
10
+ require 'spec'
11
+ end
12
+
13
+ jasmine_config = Jasmine::Config.new
14
+ spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
15
+
16
+ should_stop = false
17
+
18
+ if Jasmine::Dependencies.rspec2?
19
+ RSpec.configuration.after(:suite) do
20
+ spec_builder.stop if should_stop
21
+ end
22
+ else
23
+ Spec::Runner.configure do |config|
24
+ config.after(:suite) do
25
+ spec_builder.stop if should_stop
26
+ end
27
+ end
28
+ end
29
+
30
+ spec_builder.start
31
+ should_stop = true
32
+ spec_builder.declare_suites
@@ -0,0 +1,39 @@
1
+ #= require bone_tree/_namespace
2
+ #= require bone_tree/views/_tree
3
+
4
+ describe "BoneTree.Views.Tree", ->
5
+ beforeEach ->
6
+ setFixtures("<div id='test'></div>")
7
+
8
+ @tree = new BoneTree.Views.Tree
9
+
10
+ $('#test').append @tree.render().el
11
+
12
+ afterEach ->
13
+ @tree.remove()
14
+ $('#test').empty()
15
+
16
+ describe "rendering", ->
17
+ it "should render the correct DOM elements", ->
18
+ expect($('#test .tree')).toExist()
19
+ expect($('#test .tree').length).toEqual(1)
20
+
21
+ describe "configuration", ->
22
+ it "should pass options through to the settings object", ->
23
+ @tree = new BoneTree.Views.Tree
24
+ confirmDeletes: true
25
+
26
+ expect(@tree.settings.get('confirmDeletes')).toBeTruthy()
27
+
28
+ @tree = new BoneTree.Views.Tree
29
+ showExtensions: true
30
+
31
+ expect(@tree.settings.get('showExtensions')).toBeTruthy()
32
+
33
+ describe 'API', ->
34
+ it 'should be able to find files by their path', ->
35
+ @tree = new BoneTree.Views.Tree
36
+
37
+ srcMain = @tree.file('src/main.coffee', {added: true})
38
+
39
+ expect(@tree.file('src/main.coffee')).toEqual(srcMain)
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bone_tree
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
+ platform: ruby
12
+ authors:
13
+ - Matt Diebolt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-30 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: This is a filetree, written with Backbone. It is meant to be tree that will update your file nodes live and sort them when the node state is changed.
22
+ email:
23
+ - mdiebolt@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - Gemfile.lock
34
+ - Guardfile
35
+ - README
36
+ - Rakefile
37
+ - app/assets/images/bonetree.png
38
+ - app/assets/images/crushed_bone.png
39
+ - app/assets/index.html
40
+ - app/assets/javascripts/bone_tree.js
41
+ - app/assets/stylesheets/bone_tree.css
42
+ - app/assets/stylesheets/bone_tree_repo.css
43
+ - bone_tree-0.0.1.gem
44
+ - bone_tree.gemspec
45
+ - config.rb
46
+ - config.ru
47
+ - docs/index.html
48
+ - docs/resources/base.css
49
+ - docs/resources/index.css
50
+ - docs/resources/module.css
51
+ - docs/source/javascripts/bone_tree/_namespace.js.html
52
+ - docs/source/javascripts/bone_tree/models/_directory.js.html
53
+ - docs/source/javascripts/bone_tree/models/_file.js.html
54
+ - docs/source/javascripts/bone_tree/models/_nodes.js.html
55
+ - docs/source/javascripts/bone_tree/models/_settings.js.html
56
+ - docs/source/javascripts/bone_tree/views/_directory.js.html
57
+ - docs/source/javascripts/bone_tree/views/_file.js.html
58
+ - docs/source/javascripts/bone_tree/views/_menu.js.html
59
+ - docs/source/javascripts/bone_tree/views/_tree.js.html
60
+ - lib/version.rb
61
+ - source/images/bonetree.png
62
+ - source/images/crushed_bone.png
63
+ - source/index.html.haml
64
+ - source/javascripts/_backbone.js
65
+ - source/javascripts/_jquery.min.js
66
+ - source/javascripts/_underscore.js
67
+ - source/javascripts/bone_tree.js.coffee
68
+ - source/javascripts/bone_tree/_namespace.js.coffee
69
+ - source/javascripts/bone_tree/models/_directory.js.coffee
70
+ - source/javascripts/bone_tree/models/_file.js.coffee
71
+ - source/javascripts/bone_tree/models/_nodes.js.coffee
72
+ - source/javascripts/bone_tree/models/_settings.js.coffee
73
+ - source/javascripts/bone_tree/views/_directory.js.coffee
74
+ - source/javascripts/bone_tree/views/_file.js.coffee
75
+ - source/javascripts/bone_tree/views/_menu.js.coffee
76
+ - source/javascripts/bone_tree/views/_tree.js.coffee
77
+ - source/layout.haml
78
+ - source/stylesheets/bone_tree.css.sass
79
+ - source/stylesheets/bone_tree_repo.css.sass
80
+ - spec/javascripts/directory_view_spec.coffee
81
+ - spec/javascripts/file_view_spec.coffee
82
+ - spec/javascripts/helpers/spec_helper.coffee
83
+ - spec/javascripts/menu_view_spec.coffee
84
+ - spec/javascripts/nodes_spec.coffee
85
+ - spec/javascripts/support/jasmine.yml
86
+ - spec/javascripts/support/jasmine_config.rb
87
+ - spec/javascripts/support/jasmine_runner.rb
88
+ - spec/javascripts/tree_view_spec.coffee
89
+ homepage: http://mdiebolt.github.com/bone_tree
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project: bone_tree
118
+ rubygems_version: 1.8.24
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: A backbone filetree widget
122
+ test_files: []
123
+