vitreous_share 0.0.25 → 0.0.27

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.
@@ -10,11 +10,7 @@ module Vitreous
10
10
  end
11
11
 
12
12
  return nil
13
- end
14
-
15
- def self.not_found( index )
16
- Vitreous::Share::Element.new( index.not_found )
17
- end
13
+ end
18
14
  end
19
15
  end
20
16
  end
@@ -9,29 +9,24 @@ module Vitreous
9
9
  structure = @structure
10
10
 
11
11
  {
12
- 'not_found' => generate_not_found( structure ),
12
+ 'home' => generate_home( structure ),
13
+ 'not_found' => generate_not_found( structure )
14
+ }
15
+ end
16
+
17
+ def generate_home( structure )
18
+ {
13
19
  'title' => Vitreous::Share::IndexerUtils.to_title( structure['name'] ),
14
- 'link' => Vitreous::Share::IndexerUtils.to_link( structure['path'] ),
20
+ 'link' => '/',
15
21
  'type' => 'collection',
16
22
  'elements' => tree( structure['elements'].select { |e| !(e['name'] =~ /^_/) }.sort { |x, y| x['name'] <=> y['name'] } )
17
23
  }.merge(
18
24
  Vitreous::Share::IndexerUtils.meta_properties(
19
- structure['elements'].select { |e| e['name'] =~ /^_root\./ }
25
+ structure['elements'].select { |e| e['name'] =~ /^_home\./ }
20
26
  )
21
27
  )
22
28
  end
23
29
 
24
- def tree( structure )
25
- Vitreous::Share::IndexerUtils.grouping( structure ).values.map do |e|
26
- {
27
- 'title' => Vitreous::Share::IndexerUtils.to_title( e[0]['name'] ),
28
- 'link' => Vitreous::Share::IndexerUtils.to_link( e[0]['path'] ),
29
- 'type' => e.any? { |e2| e2['type'] == 'directory' } ? 'collection' : 'item',
30
- 'elements' => tree( e[0]['elements'].sort { |x, y| x['name'] <=> y['name'] } )
31
- }.merge( Vitreous::Share::IndexerUtils.meta_properties( e ) )
32
- end
33
- end
34
-
35
30
  def generate_not_found( structure )
36
31
  {
37
32
  'title' => 'Not found',
@@ -44,6 +39,17 @@ module Vitreous
44
39
  )
45
40
  end
46
41
 
42
+ def tree( structure )
43
+ Vitreous::Share::IndexerUtils.grouping( structure ).values.map do |e|
44
+ {
45
+ 'title' => Vitreous::Share::IndexerUtils.to_title( e[0]['name'] ),
46
+ 'link' => Vitreous::Share::IndexerUtils.to_link( e[0]['path'] ),
47
+ 'type' => e.any? { |e2| e2['type'] == 'directory' } ? 'collection' : 'item',
48
+ 'elements' => tree( e[0]['elements'].sort { |x, y| x['name'] <=> y['name'] } )
49
+ }.merge( Vitreous::Share::IndexerUtils.meta_properties( e ) )
50
+ end
51
+ end
52
+
47
53
  def json
48
54
  JSON.pretty_generate( generate )
49
55
  end
@@ -44,6 +44,7 @@ module Vitreous
44
44
 
45
45
  if( ext_name == 'meta' )
46
46
  result[multi_ext_name] = YAML.load( e['content'] )
47
+
47
48
  elsif( ext_name =~ Vitreous::TXT_EXTENSIONS )
48
49
  # wildcard
49
50
  result['description'] ||= e['content']
@@ -51,6 +52,7 @@ module Vitreous
51
52
  result['descriptions'] << e['content']
52
53
 
53
54
  result[multi_ext_name] = e['content']
55
+
54
56
  else
55
57
  # wildcard
56
58
  result['file'] ||= e['uri']
@@ -2,12 +2,12 @@ module Vitreous
2
2
  module Share
3
3
  module Render
4
4
  def self.render( opts )
5
- index = Vitreous::Share::Element.new( opts[:index] )
6
- element = Vitreous::Share::IndexSearcher.search( index, opts[:resource] )
5
+ home = Vitreous::Share::Element.new( opts[:index]['home'] )
6
+ element = Vitreous::Share::IndexSearcher.search( home, opts[:resource] )
7
7
  status = 200
8
8
 
9
9
  if element.nil?
10
- element = Vitreous::Share::IndexSearcher.not_found( index )
10
+ element = Vitreous::Share::Element.new( opts[:index]['not_found'] )
11
11
  status = 404
12
12
  end
13
13
 
@@ -17,7 +17,7 @@ module Vitreous
17
17
  Mustache.render(
18
18
  File.read( "#{opts[:templates]}/layout.html" ),
19
19
  {
20
- :index => index,
20
+ :home => home,
21
21
  :element => element,
22
22
  :assets => opts[:assets]
23
23
  }
@@ -1,5 +1,5 @@
1
1
  module Vitreous
2
2
  module Share
3
- VERSION = "0.0.25"
3
+ VERSION = "0.0.27"
4
4
  end
5
5
  end
data/test/element_test.rb CHANGED
@@ -3,17 +3,17 @@ require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
3
3
  class ElementTest < Test::Unit::TestCase
4
4
  def test_initialize
5
5
  index = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
6
- element = Vitreous::Share::Element.new( index )
6
+ home = Vitreous::Share::Element.new( index['home'] )
7
7
 
8
- assert_equal( 'fixtures', 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 )
8
+ assert_equal( 'fixtures', home.title )
9
+ assert_equal( '/', home.link )
10
+ assert_equal( true, home.collection? )
11
+ assert_equal( false, home.item? )
12
+ assert_equal( 3, home.elements.size )
13
+ assert_equal( 1, home.items.size )
14
+ assert_equal( 2, home.collections.size )
15
15
 
16
- assert_equal( '/subfolder-1', element.elements.first.link )
16
+ assert_equal( '/subfolder-1', home.elements.first.link )
17
17
  end
18
18
 
19
19
  def test_render
@@ -1,196 +1,198 @@
1
1
  {
2
+ "home": {
3
+ "title": "fixtures",
4
+ "link": "/",
5
+ "type": "collection",
6
+ "elements": [
7
+ {
8
+ "title": "subfolder 1",
9
+ "link": "/subfolder-1",
10
+ "type": "collection",
11
+ "elements": [
12
+ {
13
+ "title": "bbb",
14
+ "link": "/subfolder-1/bbb",
15
+ "type": "item",
16
+ "elements": [
17
+
18
+ ],
19
+ "file": "wadus uri",
20
+ "files": [
21
+ "wadus uri"
22
+ ],
23
+ "jpg": "wadus uri",
24
+ "description": "file content",
25
+ "descriptions": [
26
+ "file content"
27
+ ],
28
+ "txt": "file content",
29
+ "jpgs": [
30
+ "wadus uri"
31
+ ],
32
+ "txts": [
33
+ "file content"
34
+ ]
35
+ },
36
+ {
37
+ "title": "aaa",
38
+ "link": "/subfolder-1/aaa",
39
+ "type": "item",
40
+ "elements": [
41
+
42
+ ],
43
+ "file": "wadus uri",
44
+ "files": [
45
+ "wadus uri"
46
+ ],
47
+ "jpg": "wadus uri",
48
+ "description": "file content",
49
+ "descriptions": [
50
+ "file content"
51
+ ],
52
+ "txt": "file content",
53
+ "jpgs": [
54
+ "wadus uri"
55
+ ],
56
+ "txts": [
57
+ "file content"
58
+ ]
59
+ },
60
+ {
61
+ "title": "subsubfolder 1",
62
+ "link": "/subfolder-1/subsubfolder-1",
63
+ "type": "collection",
64
+ "elements": [
65
+ {
66
+ "title": "file 1",
67
+ "link": "/subfolder-1/subsubfolder-1/file-1",
68
+ "type": "item",
69
+ "elements": [
70
+
71
+ ],
72
+ "description": "file content",
73
+ "descriptions": [
74
+ "file content"
75
+ ],
76
+ "txt": "file content",
77
+ "txts": [
78
+ "file content"
79
+ ]
80
+ }
81
+ ]
82
+ }
83
+ ],
84
+ "file": "wadus uri",
85
+ "files": [
86
+ "wadus uri"
87
+ ],
88
+ "jpg": "wadus uri",
89
+ "description": "file content",
90
+ "descriptions": [
91
+ "file content"
92
+ ],
93
+ "txt": "file content",
94
+ "jpgs": [
95
+ "wadus uri"
96
+ ],
97
+ "txts": [
98
+ "file content"
99
+ ]
100
+ },
101
+ {
102
+ "title": "subfolder 2",
103
+ "link": "/subfolder-2",
104
+ "type": "collection",
105
+ "elements": [
106
+ {
107
+ "title": "file 1",
108
+ "link": "/subfolder-2/file-1",
109
+ "type": "item",
110
+ "elements": [
111
+
112
+ ],
113
+ "description": "file content",
114
+ "descriptions": [
115
+ "file content"
116
+ ],
117
+ "txt": "file content",
118
+ "txts": [
119
+ "file content"
120
+ ]
121
+ }
122
+ ]
123
+ },
124
+ {
125
+ "title": "file 1",
126
+ "link": "/file-1",
127
+ "type": "item",
128
+ "elements": [
129
+
130
+ ],
131
+ "file": "wadus uri",
132
+ "files": [
133
+ "wadus uri"
134
+ ],
135
+ "jpg": "wadus uri",
136
+ "meta": {
137
+ "title": "This is my new title",
138
+ "collection": "collection1",
139
+ "price": 10,
140
+ "summary": "This is a summary\ntwo lines long\n"
141
+ },
142
+ "description": "file content",
143
+ "descriptions": [
144
+ "file content",
145
+ "file content"
146
+ ],
147
+ "txt_thumb": "file content",
148
+ "txt": "file content",
149
+ "jpgs": [
150
+ "wadus uri"
151
+ ],
152
+ "txts": [
153
+ "file content",
154
+ "file content"
155
+ ]
156
+ }
157
+ ],
158
+ "file": "wadus uri",
159
+ "files": [
160
+ "wadus uri"
161
+ ],
162
+ "jpg": "wadus uri",
163
+ "description": "root content",
164
+ "descriptions": [
165
+ "root content"
166
+ ],
167
+ "txt": "root content",
168
+ "jpgs": [
169
+ "wadus uri"
170
+ ],
171
+ "txts": [
172
+ "root content"
173
+ ]
174
+ },
2
175
  "not_found": {
3
176
  "title": "Not found",
4
177
  "type": "item",
5
178
  "elements": [
6
179
 
7
180
  ],
8
- "txt": "This is the not found item",
9
- "description": "This is the not found item",
10
181
  "file": "wadus uri",
11
182
  "files": [
12
183
  "wadus uri"
13
184
  ],
14
185
  "jpg": "wadus uri",
186
+ "description": "This is the not found item",
15
187
  "descriptions": [
16
188
  "This is the not found item"
17
189
  ],
190
+ "txt": "This is the not found item",
18
191
  "jpgs": [
19
192
  "wadus uri"
20
193
  ],
21
194
  "txts": [
22
195
  "This is the not found item"
23
196
  ]
24
- },
25
- "title": "fixtures",
26
- "link": "/",
27
- "type": "collection",
28
- "elements": [
29
- {
30
- "title": "subfolder 1",
31
- "link": "/subfolder-1",
32
- "type": "collection",
33
- "elements": [
34
- {
35
- "title": "bbb",
36
- "link": "/subfolder-1/bbb",
37
- "type": "item",
38
- "elements": [
39
-
40
- ],
41
- "file": "wadus uri",
42
- "files": [
43
- "wadus uri"
44
- ],
45
- "jpg": "wadus uri",
46
- "description": "file content",
47
- "descriptions": [
48
- "file content"
49
- ],
50
- "txt": "file content",
51
- "jpgs": [
52
- "wadus uri"
53
- ],
54
- "txts": [
55
- "file content"
56
- ]
57
- },
58
- {
59
- "title": "aaa",
60
- "link": "/subfolder-1/aaa",
61
- "type": "item",
62
- "elements": [
63
-
64
- ],
65
- "file": "wadus uri",
66
- "files": [
67
- "wadus uri"
68
- ],
69
- "jpg": "wadus uri",
70
- "description": "file content",
71
- "descriptions": [
72
- "file content"
73
- ],
74
- "txt": "file content",
75
- "jpgs": [
76
- "wadus uri"
77
- ],
78
- "txts": [
79
- "file content"
80
- ]
81
- },
82
- {
83
- "title": "subsubfolder 1",
84
- "link": "/subfolder-1/subsubfolder-1",
85
- "type": "collection",
86
- "elements": [
87
- {
88
- "title": "file 1",
89
- "link": "/subfolder-1/subsubfolder-1/file-1",
90
- "type": "item",
91
- "elements": [
92
-
93
- ],
94
- "description": "file content",
95
- "descriptions": [
96
- "file content"
97
- ],
98
- "txt": "file content",
99
- "txts": [
100
- "file content"
101
- ]
102
- }
103
- ]
104
- }
105
- ],
106
- "file": "wadus uri",
107
- "files": [
108
- "wadus uri"
109
- ],
110
- "jpg": "wadus uri",
111
- "description": "file content",
112
- "descriptions": [
113
- "file content"
114
- ],
115
- "txt": "file content",
116
- "jpgs": [
117
- "wadus uri"
118
- ],
119
- "txts": [
120
- "file content"
121
- ]
122
- },
123
- {
124
- "title": "subfolder 2",
125
- "link": "/subfolder-2",
126
- "type": "collection",
127
- "elements": [
128
- {
129
- "title": "file 1",
130
- "link": "/subfolder-2/file-1",
131
- "type": "item",
132
- "elements": [
133
-
134
- ],
135
- "description": "file content",
136
- "descriptions": [
137
- "file content"
138
- ],
139
- "txt": "file content",
140
- "txts": [
141
- "file content"
142
- ]
143
- }
144
- ]
145
- },
146
- {
147
- "title": "file 1",
148
- "link": "/file-1",
149
- "type": "item",
150
- "elements": [
151
-
152
- ],
153
- "file": "wadus uri",
154
- "files": [
155
- "wadus uri"
156
- ],
157
- "jpg": "wadus uri",
158
- "meta": {
159
- "title": "This is my new title",
160
- "collection": "collection1",
161
- "price": 10,
162
- "summary": "This is a summary\ntwo lines long\n"
163
- },
164
- "description": "file content",
165
- "descriptions": [
166
- "file content",
167
- "file content"
168
- ],
169
- "txt_thumb": "file content",
170
- "txt": "file content",
171
- "jpgs": [
172
- "wadus uri"
173
- ],
174
- "txts": [
175
- "file content",
176
- "file content"
177
- ]
178
- }
179
- ],
180
- "file": "wadus uri",
181
- "files": [
182
- "wadus uri"
183
- ],
184
- "jpg": "wadus uri",
185
- "description": "root content",
186
- "descriptions": [
187
- "root content"
188
- ],
189
- "txt": "root content",
190
- "jpgs": [
191
- "wadus uri"
192
- ],
193
- "txts": [
194
- "root content"
195
- ]
197
+ }
196
198
  }
@@ -112,8 +112,8 @@
112
112
  "content": null
113
113
  },
114
114
  {
115
- "name": "_not_found.jpg",
116
- "path": "/_not_found.jpg",
115
+ "name": "_home.jpg",
116
+ "path": "/_home.jpg",
117
117
  "uri": "wadus uri",
118
118
  "type": "file",
119
119
  "elements": [
@@ -122,18 +122,18 @@
122
122
  "content": null
123
123
  },
124
124
  {
125
- "name": "_not_found.txt",
126
- "path": "/_not_found.txt",
125
+ "name": "_home.txt",
126
+ "path": "/_home.txt",
127
127
  "uri": "wadus uri",
128
128
  "type": "file",
129
129
  "elements": [
130
130
 
131
131
  ],
132
- "content": "This is the not found item"
132
+ "content": "root content"
133
133
  },
134
134
  {
135
- "name": "_root.jpg",
136
- "path": "/_root.jpg",
135
+ "name": "_not_found.jpg",
136
+ "path": "/_not_found.jpg",
137
137
  "uri": "wadus uri",
138
138
  "type": "file",
139
139
  "elements": [
@@ -142,14 +142,14 @@
142
142
  "content": null
143
143
  },
144
144
  {
145
- "name": "_root.txt",
146
- "path": "/_root.txt",
145
+ "name": "_not_found.txt",
146
+ "path": "/_not_found.txt",
147
147
  "uri": "wadus uri",
148
148
  "type": "file",
149
149
  "elements": [
150
150
 
151
151
  ],
152
- "content": "root content"
152
+ "content": "This is the not found item"
153
153
  },
154
154
  {
155
155
  "name": "file 1.jpg",
@@ -1,13 +1,13 @@
1
1
  assets: {{assets}}
2
2
 
3
- {{#index}}
3
+ {{#home}}
4
4
  {{#collections}}
5
5
  collection: {{title}}
6
6
  {{#items}}
7
7
  item: {{title}}
8
8
  {{/items}}
9
9
  {{/collections}}
10
- {{/index}}
10
+ {{/home}}
11
11
 
12
12
  {{#element}}
13
13
  {{#collection?}}
@@ -2,27 +2,15 @@ require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
2
2
 
3
3
  class IndexSearcherTest < Test::Unit::TestCase
4
4
  def test_search
5
- root = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
5
+ index = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
6
6
 
7
7
  element_found =
8
8
  Vitreous::Share::IndexSearcher.search(
9
- root,
9
+ index['home'],
10
10
  '/subfolder-1/subsubfolder-1/file-1'
11
11
  )
12
12
 
13
13
  assert_equal( 'file 1', element_found['title'] )
14
14
  assert_equal( '/subfolder-1/subsubfolder-1/file-1', element_found['link'] )
15
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
16
  end
data/test/indexer_test.rb CHANGED
@@ -10,8 +10,8 @@ class IndexerTest < Test::Unit::TestCase
10
10
  index = indexer.generate
11
11
 
12
12
  assert( index.is_a? Hash )
13
- assert_equal( 'fixtures', index['title'] )
14
- assert_equal( '/', index['link'] )
13
+ assert_equal( 'fixtures', index['home']['title'] )
14
+ assert_equal( '/', index['home']['link'] )
15
15
  end
16
16
 
17
17
  def test_json
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 25
9
- version: 0.0.25
8
+ - 27
9
+ version: 0.0.27
10
10
  platform: ruby
11
11
  authors:
12
12
  - Fernando Guillen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-08-13 00:00:00 +02:00
17
+ date: 2011-08-16 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -163,10 +163,10 @@ files:
163
163
  - test/fixtures/folder_structure/01 subfolder 1/002 aaa.txt
164
164
  - test/fixtures/folder_structure/01 subfolder 1/subsubfolder 1/file 1.txt
165
165
  - test/fixtures/folder_structure/02 subfolder 2/file 1.txt
166
+ - test/fixtures/folder_structure/_home.jpg
167
+ - test/fixtures/folder_structure/_home.txt
166
168
  - test/fixtures/folder_structure/_not_found.jpg
167
169
  - test/fixtures/folder_structure/_not_found.txt
168
- - test/fixtures/folder_structure/_root.jpg
169
- - test/fixtures/folder_structure/_root.txt
170
170
  - test/fixtures/folder_structure/file 1.jpg
171
171
  - test/fixtures/folder_structure/file 1.meta
172
172
  - test/fixtures/folder_structure/file 1.thumb.txt
@@ -231,10 +231,10 @@ test_files:
231
231
  - test/fixtures/folder_structure/01 subfolder 1/002 aaa.txt
232
232
  - test/fixtures/folder_structure/01 subfolder 1/subsubfolder 1/file 1.txt
233
233
  - test/fixtures/folder_structure/02 subfolder 2/file 1.txt
234
+ - test/fixtures/folder_structure/_home.jpg
235
+ - test/fixtures/folder_structure/_home.txt
234
236
  - test/fixtures/folder_structure/_not_found.jpg
235
237
  - test/fixtures/folder_structure/_not_found.txt
236
- - test/fixtures/folder_structure/_root.jpg
237
- - test/fixtures/folder_structure/_root.txt
238
238
  - test/fixtures/folder_structure/file 1.jpg
239
239
  - test/fixtures/folder_structure/file 1.meta
240
240
  - test/fixtures/folder_structure/file 1.thumb.txt