vitreous_share 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/README.md +7 -0
- data/Rakefile +13 -0
- data/lib/vitreous/share/common_structure.rb +9 -0
- data/lib/vitreous/share/dropbox_structure.rb +38 -0
- data/lib/vitreous/share/element.rb +38 -0
- data/lib/vitreous/share/index_searcher.rb +16 -0
- data/lib/vitreous/share/indexer.rb +24 -0
- data/lib/vitreous/share/indexer_utils.rb +69 -0
- data/lib/vitreous/share/local_structure.rb +35 -0
- data/lib/vitreous/share/version.rb +5 -0
- data/lib/vitreous/vitreous.rb +3 -0
- data/lib/vitreous_share.rb +13 -0
- data/test/dropbox_structure_real_test.rb +26 -0
- data/test/dropbox_structure_test.rb +37 -0
- data/test/element_test.rb +18 -0
- data/test/fixtures/folder_structure/file 1.jpg +0 -0
- data/test/fixtures/folder_structure/file 1.thumb.txt +1 -0
- data/test/fixtures/folder_structure/file 1.txt +1 -0
- data/test/fixtures/folder_structure/subfolder 1/file 1.jpg +0 -0
- data/test/fixtures/folder_structure/subfolder 1/file 1.txt +1 -0
- data/test/fixtures/folder_structure/subfolder 1/file 2.jpg +0 -0
- data/test/fixtures/folder_structure/subfolder 1/file 2.txt +1 -0
- data/test/fixtures/folder_structure/subfolder 1/subsubfolder 1/file 1.txt +1 -0
- data/test/fixtures/folder_structure/subfolder 1.jpg +0 -0
- data/test/fixtures/folder_structure/subfolder 1.txt +1 -0
- data/test/fixtures/folder_structure/subfolder 2/file 1.txt +1 -0
- data/test/fixtures/index.json +110 -0
- data/test/fixtures/structure.json +146 -0
- data/test/index_searcher_test.rb +28 -0
- data/test/indexer_test.rb +30 -0
- data/test/indexer_utils_test.rb +85 -0
- data/test/local_structure_test.rb +23 -0
- data/test/test_helper.rb +7 -0
- data/vitreous_share.gemspec +29 -0
- metadata +225 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.8.7@vitreous_share
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Vitreous
|
2
|
+
module Share
|
3
|
+
class DropboxStructure < CommonStructure
|
4
|
+
def initialize( path, session )
|
5
|
+
@path = path
|
6
|
+
@session = session
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate( path = @path )
|
10
|
+
{
|
11
|
+
'name' => File.basename( path ),
|
12
|
+
'path' => '/',
|
13
|
+
'uri' => uri( path ),
|
14
|
+
'type' => 'directory',
|
15
|
+
'elements' => tree( path ),
|
16
|
+
'content' => nil
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def tree( path )
|
21
|
+
@session.entry( path ).list.to_a.map do |e|
|
22
|
+
{
|
23
|
+
'name' => File.basename( e.path ),
|
24
|
+
'path' => e.path.gsub( @path, '' ),
|
25
|
+
'uri' => uri( e.path ),
|
26
|
+
'type' => e.directory? ? 'directory' : 'file',
|
27
|
+
'elements' => e.directory? ? tree( e.path ) : [],
|
28
|
+
'content' => CommonStructure.txt?( e.path ) ? @session.download( e.path ) : nil
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def uri( path )
|
34
|
+
"http://dl.dropbox.com/u/#{@session.account.uid}/#{path.gsub( /^\/Public\//, '' ).gsub( /^\//, '' )}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Vitreous
|
2
|
+
module Share
|
3
|
+
class Element < Mustache
|
4
|
+
def initialize( hash )
|
5
|
+
@hash = hash
|
6
|
+
meta_methods
|
7
|
+
end
|
8
|
+
|
9
|
+
def meta_methods
|
10
|
+
@hash.each do |k,v|
|
11
|
+
(class << self; self; end).class_eval do
|
12
|
+
define_method( k.to_sym ) { v } if !method_defined?( k.to_sym )
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def collection?
|
18
|
+
@hash['type'] == 'collection'
|
19
|
+
end
|
20
|
+
|
21
|
+
def item?
|
22
|
+
@hash['type'] == 'item'
|
23
|
+
end
|
24
|
+
|
25
|
+
def elements
|
26
|
+
@hash['elements'].map { |e| Element.new( e ) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def collections
|
30
|
+
@hash['elements'].select { |e| e['type'] == 'collection' }.map { |e| Element.new( e ) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def items
|
34
|
+
@hash['elements'].select { |e| e['type'] == 'item' }.map { |e| Element.new( e ) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Vitreous
|
2
|
+
module Share
|
3
|
+
class IndexSearcher
|
4
|
+
def self.search( node, link )
|
5
|
+
return node if node['link'] == link
|
6
|
+
|
7
|
+
node['elements'].each do |e|
|
8
|
+
found = Vitreous::Share::IndexSearcher.search( e, link )
|
9
|
+
return found if found
|
10
|
+
end
|
11
|
+
|
12
|
+
return nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Vitreous
|
2
|
+
module Share
|
3
|
+
class Indexer
|
4
|
+
def initialize( structure )
|
5
|
+
@structure = structure
|
6
|
+
end
|
7
|
+
|
8
|
+
def generate( structure = [@structure] )
|
9
|
+
Vitreous::Share::IndexerUtils.grouping( structure ).values.map do |e|
|
10
|
+
{
|
11
|
+
'title' => Vitreous::Share::IndexerUtils.file_name_to_title( e[0]['name'] ),
|
12
|
+
'link' => Vitreous::Share::IndexerUtils.to_link( e[0]['path'] ),
|
13
|
+
'type' => e.any? { |e2| e2['type'] == 'directory' } ? 'collection' : 'item',
|
14
|
+
'elements' => generate( e[0]['elements'] )
|
15
|
+
}.merge( Vitreous::Share::IndexerUtils.meta( e ) )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def json
|
20
|
+
JSON.pretty_generate( generate[0] )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Vitreous
|
2
|
+
module Share
|
3
|
+
module IndexerUtils
|
4
|
+
def self.file_name_to_title( file_name )
|
5
|
+
remove_extensions( file_name ).gsub( /^\d*(_|\s)/, '' )
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.remove_extensions( file_name )
|
9
|
+
File.basename( file_name ).gsub( /\..*$/, '' )
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.to_link( path )
|
13
|
+
return path if path == '/'
|
14
|
+
|
15
|
+
path.split('/').map do |e|
|
16
|
+
to_slug( remove_extensions( e ) )
|
17
|
+
end.join('/')
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.to_slug( string )
|
21
|
+
string.
|
22
|
+
downcase.
|
23
|
+
gsub(/[^a-z0-9 -_]/,"").
|
24
|
+
gsub('_', '-').
|
25
|
+
gsub(/[ ]+/,"-")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.grouping( elements )
|
29
|
+
elements.group_by do |e|
|
30
|
+
to_slug( remove_extensions( e['name'] ) )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.meta( elements )
|
35
|
+
result = {}
|
36
|
+
|
37
|
+
elements.select { |e| e['type'] == 'file' }.each do |e|
|
38
|
+
ext_name = File.basename( e['path'] ).split( '.' )[-1]
|
39
|
+
meta_ext_name = File.basename( e['path'] ).split( '.' )[1..-1].reverse.join( '_' )
|
40
|
+
|
41
|
+
if( ext_name =~ Vitreous::TXT_EXTENSIONS )
|
42
|
+
result[meta_ext_name] = e['content']
|
43
|
+
else
|
44
|
+
result[meta_ext_name] = e['uri']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# create arrays of metas
|
49
|
+
result.merge!( meta_arrays( result ) )
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.meta_arrays( meta )
|
53
|
+
result = {}
|
54
|
+
|
55
|
+
meta.each do |k,v|
|
56
|
+
key = "#{k.split('_')[0]}s"
|
57
|
+
result[key] = [] unless result[key]
|
58
|
+
result[key] << v
|
59
|
+
end
|
60
|
+
|
61
|
+
result.each do |k,v|
|
62
|
+
result[k].sort!
|
63
|
+
end
|
64
|
+
|
65
|
+
return result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Vitreous
|
2
|
+
module Share
|
3
|
+
class LocalStructure < CommonStructure
|
4
|
+
|
5
|
+
def initialize( path )
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate( path = @path )
|
10
|
+
{
|
11
|
+
'name' => File.basename( path ),
|
12
|
+
'path' => path == @path ? '/' : path.gsub( @path, '' ),
|
13
|
+
'uri' => uri( path ),
|
14
|
+
'type' => File.directory?( path ) ? 'directory' : 'file',
|
15
|
+
'elements' => File.directory?( path ) ? tree( path ) : [],
|
16
|
+
'content' => CommonStructure.txt?( path ) ? File.read( path ) : nil
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def tree( path )
|
21
|
+
Dir.glob( File.join( path, '*' ) ).sort.map do |e|
|
22
|
+
generate( e )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def uri( path )
|
27
|
+
"#{Vitreous::Share::LocalStructure.base_uri}#{path.gsub( @path, '' )}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.base_uri
|
31
|
+
""
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'dropbox'
|
3
|
+
require 'mustache'
|
4
|
+
|
5
|
+
require "#{File.dirname(__FILE__)}/vitreous/vitreous"
|
6
|
+
require "#{File.dirname(__FILE__)}/vitreous/share/indexer_utils"
|
7
|
+
require "#{File.dirname(__FILE__)}/vitreous/share/version"
|
8
|
+
require "#{File.dirname(__FILE__)}/vitreous/share/common_structure"
|
9
|
+
require "#{File.dirname(__FILE__)}/vitreous/share/local_structure"
|
10
|
+
require "#{File.dirname(__FILE__)}/vitreous/share/dropbox_structure"
|
11
|
+
require "#{File.dirname(__FILE__)}/vitreous/share/indexer"
|
12
|
+
require "#{File.dirname(__FILE__)}/vitreous/share/index_searcher"
|
13
|
+
require "#{File.dirname(__FILE__)}/vitreous/share/element"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
|
2
|
+
#
|
3
|
+
# class DropboxStructureTest < Test::Unit::TestCase
|
4
|
+
# def setup
|
5
|
+
# @session =
|
6
|
+
# ::Dropbox::Session.deserialize(
|
7
|
+
# File.read( "#{File.dirname(__FILE__)}/../tmp/session_authorized.serialized" )
|
8
|
+
# )
|
9
|
+
#
|
10
|
+
# @session.mode = :dropbox
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# def test_generate
|
14
|
+
# structure =
|
15
|
+
# Vitreous::Share::DropboxStructure.new(
|
16
|
+
# "/Public/XXX5/website",
|
17
|
+
# @session
|
18
|
+
# )
|
19
|
+
#
|
20
|
+
# # create fixture
|
21
|
+
# puts "!!This should be commented!!"
|
22
|
+
# File.open( "#{FIXTURES_PATH}/dropbox_structure_real.json", 'w' ) do |f|
|
23
|
+
# f.write JSON.pretty_generate structure.generate
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
|
2
|
+
require 'dummy_dropbox'
|
3
|
+
|
4
|
+
class DropboxStructureTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
DummyDropbox.root_path = FIXTURES_PATH
|
7
|
+
@session = ::Dropbox::Session.new( 'key', 'secret' )
|
8
|
+
|
9
|
+
# @session =
|
10
|
+
# ::Dropbox::Session.deserialize(
|
11
|
+
# File.read( "#{File.dirname(__FILE__)}/tmp/session_authorized.serialized" )
|
12
|
+
# )
|
13
|
+
|
14
|
+
@session.mode = :dropbox
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_generate
|
18
|
+
Vitreous::Share::DropboxStructure.any_instance.stubs( :uri ).returns( 'wadus uri' )
|
19
|
+
|
20
|
+
structure =
|
21
|
+
Vitreous::Share::DropboxStructure.new(
|
22
|
+
"/folder_structure",
|
23
|
+
@session
|
24
|
+
)
|
25
|
+
|
26
|
+
# # create fixture
|
27
|
+
# puts "!!This should be commented!!"
|
28
|
+
# File.open( "#{FIXTURES_PATH}/structure.json", 'w' ) do |f|
|
29
|
+
# f.write JSON.pretty_generate structure.generate
|
30
|
+
# end
|
31
|
+
|
32
|
+
assert_equal(
|
33
|
+
JSON.load( File.read( "#{FIXTURES_PATH}/structure.json" ) ),
|
34
|
+
structure.generate
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
|
2
|
+
|
3
|
+
class ElementTest < Test::Unit::TestCase
|
4
|
+
def test_initialize
|
5
|
+
index = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
|
6
|
+
element = Vitreous::Share::Element.new( index )
|
7
|
+
|
8
|
+
assert_equal( 'folder_structure', element.title )
|
9
|
+
assert_equal( '/', element.link )
|
10
|
+
assert_equal( true, element.collection? )
|
11
|
+
assert_equal( false, element.item? )
|
12
|
+
assert_equal( 3, element.elements.size )
|
13
|
+
assert_equal( 1, element.items.size )
|
14
|
+
assert_equal( 2, element.collections.size )
|
15
|
+
|
16
|
+
assert_equal( '/file-1', element.elements.first.link )
|
17
|
+
end
|
18
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
file content
|
@@ -0,0 +1 @@
|
|
1
|
+
file content
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
file content
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
file content
|
@@ -0,0 +1 @@
|
|
1
|
+
file content
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
file content
|
@@ -0,0 +1 @@
|
|
1
|
+
file content
|
@@ -0,0 +1,110 @@
|
|
1
|
+
{
|
2
|
+
"title": "folder_structure",
|
3
|
+
"elements": [
|
4
|
+
{
|
5
|
+
"jpg": "wadus uri",
|
6
|
+
"title": "file 1",
|
7
|
+
"txt": "file content",
|
8
|
+
"txts": [
|
9
|
+
"file content",
|
10
|
+
"file content"
|
11
|
+
],
|
12
|
+
"elements": [
|
13
|
+
|
14
|
+
],
|
15
|
+
"type": "item",
|
16
|
+
"link": "/file-1",
|
17
|
+
"txt_thumb": "file content",
|
18
|
+
"jpgs": [
|
19
|
+
"wadus uri"
|
20
|
+
]
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"jpg": "wadus uri",
|
24
|
+
"title": "subfolder 1",
|
25
|
+
"txt": "file content",
|
26
|
+
"txts": [
|
27
|
+
"file content"
|
28
|
+
],
|
29
|
+
"elements": [
|
30
|
+
{
|
31
|
+
"jpg": "wadus uri",
|
32
|
+
"title": "file 1",
|
33
|
+
"txt": "file content",
|
34
|
+
"txts": [
|
35
|
+
"file content"
|
36
|
+
],
|
37
|
+
"elements": [
|
38
|
+
|
39
|
+
],
|
40
|
+
"type": "item",
|
41
|
+
"link": "/subfolder-1/file-1",
|
42
|
+
"jpgs": [
|
43
|
+
"wadus uri"
|
44
|
+
]
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"jpg": "wadus uri",
|
48
|
+
"title": "file 2",
|
49
|
+
"txt": "file content",
|
50
|
+
"txts": [
|
51
|
+
"file content"
|
52
|
+
],
|
53
|
+
"elements": [
|
54
|
+
|
55
|
+
],
|
56
|
+
"type": "item",
|
57
|
+
"link": "/subfolder-1/file-2",
|
58
|
+
"jpgs": [
|
59
|
+
"wadus uri"
|
60
|
+
]
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"title": "subsubfolder 1",
|
64
|
+
"elements": [
|
65
|
+
{
|
66
|
+
"title": "file 1",
|
67
|
+
"txt": "file content",
|
68
|
+
"txts": [
|
69
|
+
"file content"
|
70
|
+
],
|
71
|
+
"elements": [
|
72
|
+
|
73
|
+
],
|
74
|
+
"type": "item",
|
75
|
+
"link": "/subfolder-1/subsubfolder-1/file-1"
|
76
|
+
}
|
77
|
+
],
|
78
|
+
"type": "collection",
|
79
|
+
"link": "/subfolder-1/subsubfolder-1"
|
80
|
+
}
|
81
|
+
],
|
82
|
+
"type": "collection",
|
83
|
+
"link": "/subfolder-1",
|
84
|
+
"jpgs": [
|
85
|
+
"wadus uri"
|
86
|
+
]
|
87
|
+
},
|
88
|
+
{
|
89
|
+
"title": "subfolder 2",
|
90
|
+
"elements": [
|
91
|
+
{
|
92
|
+
"title": "file 1",
|
93
|
+
"txt": "file content",
|
94
|
+
"txts": [
|
95
|
+
"file content"
|
96
|
+
],
|
97
|
+
"elements": [
|
98
|
+
|
99
|
+
],
|
100
|
+
"type": "item",
|
101
|
+
"link": "/subfolder-2/file-1"
|
102
|
+
}
|
103
|
+
],
|
104
|
+
"type": "collection",
|
105
|
+
"link": "/subfolder-2"
|
106
|
+
}
|
107
|
+
],
|
108
|
+
"type": "collection",
|
109
|
+
"link": "/"
|
110
|
+
}
|
@@ -0,0 +1,146 @@
|
|
1
|
+
{
|
2
|
+
"name": "folder_structure",
|
3
|
+
"uri": "wadus uri",
|
4
|
+
"elements": [
|
5
|
+
{
|
6
|
+
"name": "file 1.jpg",
|
7
|
+
"uri": "wadus uri",
|
8
|
+
"elements": [
|
9
|
+
|
10
|
+
],
|
11
|
+
"type": "file",
|
12
|
+
"content": null,
|
13
|
+
"path": "/file 1.jpg"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"name": "file 1.thumb.txt",
|
17
|
+
"uri": "wadus uri",
|
18
|
+
"elements": [
|
19
|
+
|
20
|
+
],
|
21
|
+
"type": "file",
|
22
|
+
"content": "file content",
|
23
|
+
"path": "/file 1.thumb.txt"
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"name": "file 1.txt",
|
27
|
+
"uri": "wadus uri",
|
28
|
+
"elements": [
|
29
|
+
|
30
|
+
],
|
31
|
+
"type": "file",
|
32
|
+
"content": "file content",
|
33
|
+
"path": "/file 1.txt"
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"name": "subfolder 1",
|
37
|
+
"uri": "wadus uri",
|
38
|
+
"elements": [
|
39
|
+
{
|
40
|
+
"name": "file 1.jpg",
|
41
|
+
"uri": "wadus uri",
|
42
|
+
"elements": [
|
43
|
+
|
44
|
+
],
|
45
|
+
"type": "file",
|
46
|
+
"content": null,
|
47
|
+
"path": "/subfolder 1/file 1.jpg"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"name": "file 1.txt",
|
51
|
+
"uri": "wadus uri",
|
52
|
+
"elements": [
|
53
|
+
|
54
|
+
],
|
55
|
+
"type": "file",
|
56
|
+
"content": "file content",
|
57
|
+
"path": "/subfolder 1/file 1.txt"
|
58
|
+
},
|
59
|
+
{
|
60
|
+
"name": "file 2.jpg",
|
61
|
+
"uri": "wadus uri",
|
62
|
+
"elements": [
|
63
|
+
|
64
|
+
],
|
65
|
+
"type": "file",
|
66
|
+
"content": null,
|
67
|
+
"path": "/subfolder 1/file 2.jpg"
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"name": "file 2.txt",
|
71
|
+
"uri": "wadus uri",
|
72
|
+
"elements": [
|
73
|
+
|
74
|
+
],
|
75
|
+
"type": "file",
|
76
|
+
"content": "file content",
|
77
|
+
"path": "/subfolder 1/file 2.txt"
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"name": "subsubfolder 1",
|
81
|
+
"uri": "wadus uri",
|
82
|
+
"elements": [
|
83
|
+
{
|
84
|
+
"name": "file 1.txt",
|
85
|
+
"uri": "wadus uri",
|
86
|
+
"elements": [
|
87
|
+
|
88
|
+
],
|
89
|
+
"type": "file",
|
90
|
+
"content": "file content",
|
91
|
+
"path": "/subfolder 1/subsubfolder 1/file 1.txt"
|
92
|
+
}
|
93
|
+
],
|
94
|
+
"type": "directory",
|
95
|
+
"content": null,
|
96
|
+
"path": "/subfolder 1/subsubfolder 1"
|
97
|
+
}
|
98
|
+
],
|
99
|
+
"type": "directory",
|
100
|
+
"content": null,
|
101
|
+
"path": "/subfolder 1"
|
102
|
+
},
|
103
|
+
{
|
104
|
+
"name": "subfolder 1.jpg",
|
105
|
+
"uri": "wadus uri",
|
106
|
+
"elements": [
|
107
|
+
|
108
|
+
],
|
109
|
+
"type": "file",
|
110
|
+
"content": null,
|
111
|
+
"path": "/subfolder 1.jpg"
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"name": "subfolder 1.txt",
|
115
|
+
"uri": "wadus uri",
|
116
|
+
"elements": [
|
117
|
+
|
118
|
+
],
|
119
|
+
"type": "file",
|
120
|
+
"content": "file content",
|
121
|
+
"path": "/subfolder 1.txt"
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"name": "subfolder 2",
|
125
|
+
"uri": "wadus uri",
|
126
|
+
"elements": [
|
127
|
+
{
|
128
|
+
"name": "file 1.txt",
|
129
|
+
"uri": "wadus uri",
|
130
|
+
"elements": [
|
131
|
+
|
132
|
+
],
|
133
|
+
"type": "file",
|
134
|
+
"content": "file content",
|
135
|
+
"path": "/subfolder 2/file 1.txt"
|
136
|
+
}
|
137
|
+
],
|
138
|
+
"type": "directory",
|
139
|
+
"content": null,
|
140
|
+
"path": "/subfolder 2"
|
141
|
+
}
|
142
|
+
],
|
143
|
+
"type": "directory",
|
144
|
+
"content": null,
|
145
|
+
"path": "/"
|
146
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
|
2
|
+
|
3
|
+
class IndexSearcherTest < Test::Unit::TestCase
|
4
|
+
def test_search
|
5
|
+
root = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
|
6
|
+
|
7
|
+
element_found =
|
8
|
+
Vitreous::Share::IndexSearcher.search(
|
9
|
+
root,
|
10
|
+
'/subfolder-1/subsubfolder-1/file-1'
|
11
|
+
)
|
12
|
+
|
13
|
+
assert_equal( 'file 1', element_found['title'] )
|
14
|
+
assert_equal( '/subfolder-1/subsubfolder-1/file-1', element_found['link'] )
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_search_not_found
|
18
|
+
root = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
|
19
|
+
|
20
|
+
element_found =
|
21
|
+
Vitreous::Share::IndexSearcher.search(
|
22
|
+
root,
|
23
|
+
'/not/exists'
|
24
|
+
)
|
25
|
+
|
26
|
+
assert_nil( element_found )
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
|
2
|
+
|
3
|
+
class IndexerTest < Test::Unit::TestCase
|
4
|
+
def test_generate
|
5
|
+
indexer =
|
6
|
+
Vitreous::Share::Indexer.new(
|
7
|
+
JSON.load( File.read( "#{FIXTURES_PATH}/structure.json" ) )
|
8
|
+
)
|
9
|
+
|
10
|
+
assert( indexer.generate.is_a? Array )
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_json
|
14
|
+
indexer =
|
15
|
+
Vitreous::Share::Indexer.new(
|
16
|
+
JSON.load( File.read( "#{FIXTURES_PATH}/structure.json" ) )
|
17
|
+
)
|
18
|
+
|
19
|
+
# # create fixture
|
20
|
+
# puts "!!This should be commented!!"
|
21
|
+
# File.open( "#{FIXTURES_PATH}/index.json", 'w' ) do |f|
|
22
|
+
# f.write indexer.json
|
23
|
+
# end
|
24
|
+
|
25
|
+
assert_equal(
|
26
|
+
JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) ),
|
27
|
+
JSON.load( indexer.json )
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
|
2
|
+
|
3
|
+
class IndexerUtilsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_to_slug
|
6
|
+
assert_equal(
|
7
|
+
'pepe-y-jun',
|
8
|
+
Vitreous::Share::IndexerUtils.to_slug( 'pepe y juán' )
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_remove_extensions
|
13
|
+
assert_equal(
|
14
|
+
'pepe y juán',
|
15
|
+
Vitreous::Share::IndexerUtils.remove_extensions( 'pepe y juán.thumb.jpg' )
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_to_link
|
20
|
+
assert_equal(
|
21
|
+
'/path-1/path-2/my-file',
|
22
|
+
Vitreous::Share::IndexerUtils.to_link( '/Path 1/Path 2/My File.thumb.jpg' )
|
23
|
+
)
|
24
|
+
|
25
|
+
assert_equal(
|
26
|
+
'/',
|
27
|
+
Vitreous::Share::IndexerUtils.to_link( '/' )
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_grouping
|
32
|
+
structure = JSON.load( File.read( "#{FIXTURES_PATH}/structure.json" ) )
|
33
|
+
|
34
|
+
groups = Vitreous::Share::IndexerUtils.grouping( structure['elements'] )
|
35
|
+
assert_equal( 3, groups.size )
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_meta
|
39
|
+
structure = [
|
40
|
+
{
|
41
|
+
"type" => "file",
|
42
|
+
"content" => nil,
|
43
|
+
"path" => "/folder 1.jpg",
|
44
|
+
"uri" => "http://dropbox.com/user/folder 1.jpg",
|
45
|
+
"name" => "folder 1.jpg"
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"type" => "file",
|
49
|
+
"content" => "file content",
|
50
|
+
"path" => "/folder 1.txt",
|
51
|
+
"uri" => "http://dropbox.com/user/folder 1.txt",
|
52
|
+
"name" => "folder 1.txt"
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"type" => "directory",
|
56
|
+
"content" => nil,
|
57
|
+
"path" => "/folder 1",
|
58
|
+
"uri" => "http://dropbox.com/user/folder 1",
|
59
|
+
"name" => "folder 1"
|
60
|
+
}
|
61
|
+
]
|
62
|
+
|
63
|
+
meta = Vitreous::Share::IndexerUtils.meta( structure )
|
64
|
+
|
65
|
+
assert_equal( "http://dropbox.com/user/folder 1.jpg", meta['jpg'] )
|
66
|
+
assert_equal( "file content", meta['txt'] )
|
67
|
+
assert_equal( ["file content"], meta['txts'] )
|
68
|
+
assert_equal( ["http://dropbox.com/user/folder 1.jpg"], meta['jpgs'] )
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_meta_arrays
|
72
|
+
meta = {
|
73
|
+
'jpg' => 'jpg',
|
74
|
+
'jpg_0' => 'jpg 0',
|
75
|
+
'jpg_1' => 'jpg 1',
|
76
|
+
'txt' => 'txt',
|
77
|
+
'txt_0' => 'txt 0'
|
78
|
+
}
|
79
|
+
|
80
|
+
meta_arrays = Vitreous::Share::IndexerUtils.meta_arrays( meta )
|
81
|
+
|
82
|
+
assert_equal( ["txt", "txt 0"], meta_arrays['txts'] )
|
83
|
+
assert_equal( ["jpg", "jpg 0", "jpg 1"], meta_arrays['jpgs'] )
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
|
2
|
+
|
3
|
+
class LocalStructureTest < Test::Unit::TestCase
|
4
|
+
def test_generate
|
5
|
+
Vitreous::Share::LocalStructure.any_instance.stubs( :uri ).returns( 'wadus uri' )
|
6
|
+
|
7
|
+
structure =
|
8
|
+
Vitreous::Share::LocalStructure.new(
|
9
|
+
"#{FIXTURES_PATH}/folder_structure"
|
10
|
+
)
|
11
|
+
|
12
|
+
# # create fixture
|
13
|
+
# puts "!!This should be commented!!"
|
14
|
+
# File.open( "#{FIXTURES_PATH}/structure.json", 'w' ) do |f|
|
15
|
+
# f.write( JSON.pretty_generate( structure.generate ) )
|
16
|
+
# end
|
17
|
+
|
18
|
+
assert_equal(
|
19
|
+
JSON.load( File.read( "#{FIXTURES_PATH}/structure.json" ) ),
|
20
|
+
structure.generate
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "vitreous/share/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "vitreous_share"
|
7
|
+
s.version = Vitreous::Share::VERSION
|
8
|
+
s.authors = ["Fernando Guillen"]
|
9
|
+
s.email = ["fguillen.mail@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "Shared components for Vitreous"
|
12
|
+
s.description = "Shared components for Vitreous"
|
13
|
+
|
14
|
+
s.rubyforge_project = "vitreous_share"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "json"
|
22
|
+
s.add_dependency "dropbox"
|
23
|
+
s.add_dependency "mustache"
|
24
|
+
|
25
|
+
s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
|
26
|
+
s.add_development_dependency "mocha"
|
27
|
+
s.add_development_dependency "dummy_dropbox"
|
28
|
+
s.add_development_dependency "rake"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vitreous_share
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Fernando Guillen
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-27 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: dropbox
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: mustache
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: bundler
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 15424057
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 0
|
75
|
+
- 0
|
76
|
+
- rc
|
77
|
+
- 6
|
78
|
+
version: 1.0.0.rc.6
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: mocha
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
type: :development
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: dummy_dropbox
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
type: :development
|
108
|
+
version_requirements: *id006
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: rake
|
111
|
+
prerelease: false
|
112
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
type: :development
|
122
|
+
version_requirements: *id007
|
123
|
+
description: Shared components for Vitreous
|
124
|
+
email:
|
125
|
+
- fguillen.mail@gmail.com
|
126
|
+
executables: []
|
127
|
+
|
128
|
+
extensions: []
|
129
|
+
|
130
|
+
extra_rdoc_files: []
|
131
|
+
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- .rvmrc
|
135
|
+
- Gemfile
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- lib/vitreous/share/common_structure.rb
|
139
|
+
- lib/vitreous/share/dropbox_structure.rb
|
140
|
+
- lib/vitreous/share/element.rb
|
141
|
+
- lib/vitreous/share/index_searcher.rb
|
142
|
+
- lib/vitreous/share/indexer.rb
|
143
|
+
- lib/vitreous/share/indexer_utils.rb
|
144
|
+
- lib/vitreous/share/local_structure.rb
|
145
|
+
- lib/vitreous/share/version.rb
|
146
|
+
- lib/vitreous/vitreous.rb
|
147
|
+
- lib/vitreous_share.rb
|
148
|
+
- test/dropbox_structure_real_test.rb
|
149
|
+
- test/dropbox_structure_test.rb
|
150
|
+
- test/element_test.rb
|
151
|
+
- test/fixtures/folder_structure/file 1.jpg
|
152
|
+
- test/fixtures/folder_structure/file 1.thumb.txt
|
153
|
+
- test/fixtures/folder_structure/file 1.txt
|
154
|
+
- test/fixtures/folder_structure/subfolder 1.jpg
|
155
|
+
- test/fixtures/folder_structure/subfolder 1.txt
|
156
|
+
- test/fixtures/folder_structure/subfolder 1/file 1.jpg
|
157
|
+
- test/fixtures/folder_structure/subfolder 1/file 1.txt
|
158
|
+
- test/fixtures/folder_structure/subfolder 1/file 2.jpg
|
159
|
+
- test/fixtures/folder_structure/subfolder 1/file 2.txt
|
160
|
+
- test/fixtures/folder_structure/subfolder 1/subsubfolder 1/file 1.txt
|
161
|
+
- test/fixtures/folder_structure/subfolder 2/file 1.txt
|
162
|
+
- test/fixtures/index.json
|
163
|
+
- test/fixtures/structure.json
|
164
|
+
- test/index_searcher_test.rb
|
165
|
+
- test/indexer_test.rb
|
166
|
+
- test/indexer_utils_test.rb
|
167
|
+
- test/local_structure_test.rb
|
168
|
+
- test/test_helper.rb
|
169
|
+
- vitreous_share.gemspec
|
170
|
+
has_rdoc: true
|
171
|
+
homepage: ""
|
172
|
+
licenses: []
|
173
|
+
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
none: false
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
hash: 3
|
185
|
+
segments:
|
186
|
+
- 0
|
187
|
+
version: "0"
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
none: false
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
hash: 3
|
194
|
+
segments:
|
195
|
+
- 0
|
196
|
+
version: "0"
|
197
|
+
requirements: []
|
198
|
+
|
199
|
+
rubyforge_project: vitreous_share
|
200
|
+
rubygems_version: 1.3.7
|
201
|
+
signing_key:
|
202
|
+
specification_version: 3
|
203
|
+
summary: Shared components for Vitreous
|
204
|
+
test_files:
|
205
|
+
- test/dropbox_structure_real_test.rb
|
206
|
+
- test/dropbox_structure_test.rb
|
207
|
+
- test/element_test.rb
|
208
|
+
- test/fixtures/folder_structure/file 1.jpg
|
209
|
+
- test/fixtures/folder_structure/file 1.thumb.txt
|
210
|
+
- test/fixtures/folder_structure/file 1.txt
|
211
|
+
- test/fixtures/folder_structure/subfolder 1.jpg
|
212
|
+
- test/fixtures/folder_structure/subfolder 1.txt
|
213
|
+
- test/fixtures/folder_structure/subfolder 1/file 1.jpg
|
214
|
+
- test/fixtures/folder_structure/subfolder 1/file 1.txt
|
215
|
+
- test/fixtures/folder_structure/subfolder 1/file 2.jpg
|
216
|
+
- test/fixtures/folder_structure/subfolder 1/file 2.txt
|
217
|
+
- test/fixtures/folder_structure/subfolder 1/subsubfolder 1/file 1.txt
|
218
|
+
- test/fixtures/folder_structure/subfolder 2/file 1.txt
|
219
|
+
- test/fixtures/index.json
|
220
|
+
- test/fixtures/structure.json
|
221
|
+
- test/index_searcher_test.rb
|
222
|
+
- test/indexer_test.rb
|
223
|
+
- test/indexer_utils_test.rb
|
224
|
+
- test/local_structure_test.rb
|
225
|
+
- test/test_helper.rb
|