vitreous_share 0.0.21 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,10 @@ module Vitreous
11
11
 
12
12
  return nil
13
13
  end
14
+
15
+ def self.not_found( index )
16
+ Vitreous::Share::Element.new( index.not_found )
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -9,10 +9,11 @@ module Vitreous
9
9
  structure = @structure
10
10
 
11
11
  {
12
- 'title' => Vitreous::Share::IndexerUtils.to_title( structure['name'] ),
13
- 'link' => Vitreous::Share::IndexerUtils.to_link( structure['path'] ),
14
- 'type' => 'collection',
15
- 'elements' => tree( structure['elements'].select { |e| !(e['name'] =~ /^_root\./) }.sort { |x, y| x['name'] <=> y['name'] } )
12
+ 'not_found' => generate_not_found( structure ),
13
+ 'title' => Vitreous::Share::IndexerUtils.to_title( structure['name'] ),
14
+ 'link' => Vitreous::Share::IndexerUtils.to_link( structure['path'] ),
15
+ 'type' => 'collection',
16
+ 'elements' => tree( structure['elements'].select { |e| !(e['name'] =~ /^_/) }.sort { |x, y| x['name'] <=> y['name'] } )
16
17
  }.merge(
17
18
  Vitreous::Share::IndexerUtils.meta_properties(
18
19
  structure['elements'].select { |e| e['name'] =~ /^_root\./ }
@@ -31,6 +32,20 @@ module Vitreous
31
32
  end
32
33
  end
33
34
 
35
+ def generate_not_found( structure )
36
+ {
37
+ 'title' => 'Not found',
38
+ 'type' => 'item',
39
+ 'elements' => [],
40
+ 'txt' => 'Not found',
41
+ 'description' => 'Not found'
42
+ }.merge(
43
+ Vitreous::Share::IndexerUtils.meta_properties(
44
+ structure['elements'].select { |e| e['name'] =~ /^_not_found\./ }
45
+ )
46
+ )
47
+ end
48
+
34
49
  def json
35
50
  JSON.pretty_generate( generate )
36
51
  end
@@ -80,10 +80,6 @@ module Vitreous
80
80
 
81
81
  return result
82
82
  end
83
-
84
- def self.meta_wildcards( meta )
85
-
86
- end
87
83
  end
88
84
  end
89
85
  end
@@ -0,0 +1,33 @@
1
+ module Vitreous
2
+ module Share
3
+ module Render
4
+ def self.render( opts )
5
+ index = Vitreous::Share::Element.new( opts[:index] )
6
+ element = Vitreous::Share::IndexSearcher.search( index, opts[:resource] )
7
+ status = 200
8
+
9
+ if element.nil?
10
+ element = Vitreous::Share::IndexSearcher.not_found( index )
11
+ status = 404
12
+ end
13
+
14
+ Mustache.template_path = opts[:templates]
15
+
16
+ body =
17
+ Mustache.render(
18
+ File.read( "#{opts[:templates]}/layout.html" ),
19
+ {
20
+ :index => index,
21
+ :element => element,
22
+ :assets => opts[:assets]
23
+ }
24
+ )
25
+
26
+ OpenStruct.new(
27
+ :status => status,
28
+ :body => body
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  module Vitreous
2
2
  module Share
3
- VERSION = "0.0.21"
3
+ VERSION = "0.0.23"
4
4
  end
5
5
  end
@@ -4,6 +4,8 @@ require 'mustache'
4
4
  require 'rdiscount'
5
5
  require 'ostruct'
6
6
 
7
+ Mustache.template_extension = 'html'
8
+
7
9
  require "#{File.dirname(__FILE__)}/vitreous/vitreous"
8
10
  require "#{File.dirname(__FILE__)}/vitreous/share/indexer_utils"
9
11
  require "#{File.dirname(__FILE__)}/vitreous/share/version"
@@ -13,3 +15,4 @@ require "#{File.dirname(__FILE__)}/vitreous/share/dropbox_structure"
13
15
  require "#{File.dirname(__FILE__)}/vitreous/share/indexer"
14
16
  require "#{File.dirname(__FILE__)}/vitreous/share/index_searcher"
15
17
  require "#{File.dirname(__FILE__)}/vitreous/share/element"
18
+ require "#{File.dirname(__FILE__)}/vitreous/share/render"
File without changes
@@ -0,0 +1 @@
1
+ This is the not found item
@@ -1,4 +1,27 @@
1
1
  {
2
+ "not_found": {
3
+ "title": "Not found",
4
+ "type": "item",
5
+ "elements": [
6
+
7
+ ],
8
+ "txt": "This is the not found item",
9
+ "description": "This is the not found item",
10
+ "file": "wadus uri",
11
+ "files": [
12
+ "wadus uri"
13
+ ],
14
+ "jpg": "wadus uri",
15
+ "descriptions": [
16
+ "This is the not found item"
17
+ ],
18
+ "jpgs": [
19
+ "wadus uri"
20
+ ],
21
+ "txts": [
22
+ "This is the not found item"
23
+ ]
24
+ },
2
25
  "title": "fixtures",
3
26
  "link": "/",
4
27
  "type": "collection",
@@ -0,0 +1,13 @@
1
+ assets: /assets_path
2
+
3
+ collection: subfolder 1
4
+ item: bbb
5
+ item: aaa
6
+ collection: subfolder 2
7
+ item: file 1
8
+
9
+ collection title: subfolder 1
10
+ collection jpg: wadus uri
11
+ collection txt: file content
12
+ collection description: file content
13
+ collection file: wadus uri
@@ -0,0 +1,13 @@
1
+ assets: /assets_path
2
+
3
+ collection: subfolder 1
4
+ item: bbb
5
+ item: aaa
6
+ collection: subfolder 2
7
+ item: file 1
8
+
9
+ item title: file 1
10
+ item jpg:
11
+ item txt: file content
12
+ item description: file content
13
+ item file:
@@ -0,0 +1,13 @@
1
+ assets: /assets_path
2
+
3
+ collection: subfolder 1
4
+ item: bbb
5
+ item: aaa
6
+ collection: subfolder 2
7
+ item: file 1
8
+
9
+ item title: Not found
10
+ item jpg: wadus uri
11
+ item txt: This is the not found item
12
+ item description: This is the not found item
13
+ item file: wadus uri
@@ -0,0 +1,13 @@
1
+ assets: /assets_path
2
+
3
+ collection: subfolder 1
4
+ item: bbb
5
+ item: aaa
6
+ collection: subfolder 2
7
+ item: file 1
8
+
9
+ collection title: fixtures
10
+ collection jpg: wadus uri
11
+ collection txt: root content
12
+ collection description: root content
13
+ collection file: wadus uri
@@ -111,6 +111,26 @@
111
111
  ],
112
112
  "content": null
113
113
  },
114
+ {
115
+ "name": "_not_found.jpg",
116
+ "path": "/_not_found.jpg",
117
+ "uri": "wadus uri",
118
+ "type": "file",
119
+ "elements": [
120
+
121
+ ],
122
+ "content": null
123
+ },
124
+ {
125
+ "name": "_not_found.txt",
126
+ "path": "/_not_found.txt",
127
+ "uri": "wadus uri",
128
+ "type": "file",
129
+ "elements": [
130
+
131
+ ],
132
+ "content": "This is the not found item"
133
+ },
114
134
  {
115
135
  "name": "_root.jpg",
116
136
  "path": "/_root.jpg",
@@ -0,0 +1,5 @@
1
+ collection title: {{title}}
2
+ collection jpg: {{jpg}}
3
+ collection txt: {{txt}}
4
+ collection description: {{description}}
5
+ collection file: {{file}}
@@ -0,0 +1,5 @@
1
+ item title: {{title}}
2
+ item jpg: {{jpg}}
3
+ item txt: {{txt}}
4
+ item description: {{description}}
5
+ item file: {{file}}
@@ -0,0 +1,19 @@
1
+ assets: {{assets}}
2
+
3
+ {{#index}}
4
+ {{#collections}}
5
+ collection: {{title}}
6
+ {{#items}}
7
+ item: {{title}}
8
+ {{/items}}
9
+ {{/collections}}
10
+ {{/index}}
11
+
12
+ {{#element}}
13
+ {{#collection?}}
14
+ {{>collection}}
15
+ {{/collection?}}
16
+ {{#item?}}
17
+ {{>item}}
18
+ {{/item?}}
19
+ {{/element}}
@@ -51,7 +51,7 @@ class IndexerUtilsTest < Test::Unit::TestCase
51
51
  structure = JSON.load( File.read( "#{FIXTURES_PATH}/structure.json" ) )
52
52
 
53
53
  groups = Vitreous::Share::IndexerUtils.grouping( structure['elements'] )
54
- assert_equal( 4, groups.size )
54
+ assert_equal( 5, groups.size )
55
55
  end
56
56
 
57
57
  def test_meta_properties
@@ -0,0 +1,83 @@
1
+ require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
2
+
3
+ class IndexerTest < Test::Unit::TestCase
4
+ def test_render_collection
5
+ index = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
6
+ result =
7
+ Vitreous::Share::Render.render(
8
+ :resource => '/subfolder-1',
9
+ :index => index,
10
+ :assets => '/assets_path',
11
+ :templates => "#{FIXTURES_PATH}/template"
12
+ )
13
+
14
+ # # write fixture
15
+ # puts "This should be commented out!"
16
+ # File.open( "#{FIXTURES_PATH}/render_collection.txt", 'w' ) do |f|
17
+ # f.write result.body
18
+ # end
19
+
20
+ assert_equal( 200, result.status )
21
+ assert_equal( File.read( "#{FIXTURES_PATH}/render_collection.txt" ), result.body )
22
+ end
23
+
24
+ def test_render_item
25
+ index = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
26
+ result =
27
+ Vitreous::Share::Render.render(
28
+ :resource => '/subfolder-1/subsubfolder-1/file-1',
29
+ :index => index,
30
+ :assets => '/assets_path',
31
+ :templates => "#{FIXTURES_PATH}/template"
32
+ )
33
+
34
+ # # write fixture
35
+ # puts "This should be commented out!"
36
+ # File.open( "#{FIXTURES_PATH}/render_item.txt", 'w' ) do |f|
37
+ # f.write result.body
38
+ # end
39
+
40
+ assert_equal( 200, result.status )
41
+ assert_equal( File.read( "#{FIXTURES_PATH}/render_item.txt" ), result.body )
42
+ end
43
+
44
+ def test_render_root
45
+ index = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
46
+ result =
47
+ Vitreous::Share::Render.render(
48
+ :resource => '/',
49
+ :index => index,
50
+ :assets => '/assets_path',
51
+ :templates => "#{FIXTURES_PATH}/template"
52
+ )
53
+
54
+ # # write fixture
55
+ # puts "This should be commented out!"
56
+ # File.open( "#{FIXTURES_PATH}/render_root.txt", 'w' ) do |f|
57
+ # f.write result.body
58
+ # end
59
+
60
+ assert_equal( 200, result.status )
61
+ assert_equal( File.read( "#{FIXTURES_PATH}/render_root.txt" ), result.body )
62
+ end
63
+
64
+ def test_render_not_found
65
+ index = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
66
+ result =
67
+ Vitreous::Share::Render.render(
68
+ :resource => '/wadus/not/found',
69
+ :index => index,
70
+ :assets => '/assets_path',
71
+ :templates => "#{FIXTURES_PATH}/template"
72
+ )
73
+
74
+ # # write fixture
75
+ # puts "This should be commented out!"
76
+ # File.open( "#{FIXTURES_PATH}/render_not_found.txt", 'w' ) do |f|
77
+ # f.write result.body
78
+ # end
79
+
80
+ assert_equal( 404, result.status )
81
+ assert_equal( File.read( "#{FIXTURES_PATH}/render_not_found.txt" ), result.body )
82
+ end
83
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 21
9
- version: 0.0.21
8
+ - 23
9
+ version: 0.0.23
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-12 00:00:00 +02:00
17
+ date: 2011-08-13 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -148,6 +148,7 @@ files:
148
148
  - lib/vitreous/share/indexer.rb
149
149
  - lib/vitreous/share/indexer_utils.rb
150
150
  - lib/vitreous/share/local_structure.rb
151
+ - lib/vitreous/share/render.rb
151
152
  - lib/vitreous/share/version.rb
152
153
  - lib/vitreous/vitreous.rb
153
154
  - lib/vitreous_share.rb
@@ -162,6 +163,8 @@ files:
162
163
  - test/fixtures/folder_structure/01 subfolder 1/002 aaa.txt
163
164
  - test/fixtures/folder_structure/01 subfolder 1/subsubfolder 1/file 1.txt
164
165
  - test/fixtures/folder_structure/02 subfolder 2/file 1.txt
166
+ - test/fixtures/folder_structure/_not_found.jpg
167
+ - test/fixtures/folder_structure/_not_found.txt
165
168
  - test/fixtures/folder_structure/_root.jpg
166
169
  - test/fixtures/folder_structure/_root.txt
167
170
  - test/fixtures/folder_structure/file 1.jpg
@@ -169,11 +172,19 @@ files:
169
172
  - test/fixtures/folder_structure/file 1.thumb.txt
170
173
  - test/fixtures/folder_structure/file 1.txt
171
174
  - test/fixtures/index.json
175
+ - test/fixtures/render_collection.txt
176
+ - test/fixtures/render_item.txt
177
+ - test/fixtures/render_not_found.txt
178
+ - test/fixtures/render_root.txt
172
179
  - test/fixtures/structure.json
180
+ - test/fixtures/template/collection.html
181
+ - test/fixtures/template/item.html
182
+ - test/fixtures/template/layout.html
173
183
  - test/index_searcher_test.rb
174
184
  - test/indexer_test.rb
175
185
  - test/indexer_utils_test.rb
176
186
  - test/local_structure_test.rb
187
+ - test/render_test.rb
177
188
  - test/test_helper.rb
178
189
  - vitreous_share.gemspec
179
190
  has_rdoc: true
@@ -220,6 +231,8 @@ test_files:
220
231
  - test/fixtures/folder_structure/01 subfolder 1/002 aaa.txt
221
232
  - test/fixtures/folder_structure/01 subfolder 1/subsubfolder 1/file 1.txt
222
233
  - test/fixtures/folder_structure/02 subfolder 2/file 1.txt
234
+ - test/fixtures/folder_structure/_not_found.jpg
235
+ - test/fixtures/folder_structure/_not_found.txt
223
236
  - test/fixtures/folder_structure/_root.jpg
224
237
  - test/fixtures/folder_structure/_root.txt
225
238
  - test/fixtures/folder_structure/file 1.jpg
@@ -227,9 +240,17 @@ test_files:
227
240
  - test/fixtures/folder_structure/file 1.thumb.txt
228
241
  - test/fixtures/folder_structure/file 1.txt
229
242
  - test/fixtures/index.json
243
+ - test/fixtures/render_collection.txt
244
+ - test/fixtures/render_item.txt
245
+ - test/fixtures/render_not_found.txt
246
+ - test/fixtures/render_root.txt
230
247
  - test/fixtures/structure.json
248
+ - test/fixtures/template/collection.html
249
+ - test/fixtures/template/item.html
250
+ - test/fixtures/template/layout.html
231
251
  - test/index_searcher_test.rb
232
252
  - test/indexer_test.rb
233
253
  - test/indexer_utils_test.rb
234
254
  - test/local_structure_test.rb
255
+ - test/render_test.rb
235
256
  - test/test_helper.rb