vitreous_share 0.0.27 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,15 @@ module Vitreous
14
14
  end
15
15
  end
16
16
 
17
+
18
+ def not_found?
19
+ @hash['type'] == 'not_found'
20
+ end
21
+
22
+ def home?
23
+ @hash['type'] == 'home'
24
+ end
25
+
17
26
  def collection?
18
27
  @hash['type'] == 'collection'
19
28
  end
@@ -18,7 +18,8 @@ module Vitreous
18
18
  {
19
19
  'title' => Vitreous::Share::IndexerUtils.to_title( structure['name'] ),
20
20
  'link' => '/',
21
- 'type' => 'collection',
21
+ 'slug' => '',
22
+ 'type' => 'home',
22
23
  'elements' => tree( structure['elements'].select { |e| !(e['name'] =~ /^_/) }.sort { |x, y| x['name'] <=> y['name'] } )
23
24
  }.merge(
24
25
  Vitreous::Share::IndexerUtils.meta_properties(
@@ -30,7 +31,8 @@ module Vitreous
30
31
  def generate_not_found( structure )
31
32
  {
32
33
  'title' => 'Not found',
33
- 'type' => 'item',
34
+ 'type' => 'not_found',
35
+ 'slug' => 'not_found',
34
36
  'elements' => [],
35
37
  }.merge(
36
38
  Vitreous::Share::IndexerUtils.meta_properties(
@@ -44,6 +46,7 @@ module Vitreous
44
46
  {
45
47
  'title' => Vitreous::Share::IndexerUtils.to_title( e[0]['name'] ),
46
48
  'link' => Vitreous::Share::IndexerUtils.to_link( e[0]['path'] ),
49
+ 'slug' => Vitreous::Share::IndexerUtils.to_slug( e[0]['path'] ),
47
50
  'type' => e.any? { |e2| e2['type'] == 'directory' } ? 'collection' : 'item',
48
51
  'elements' => tree( e[0]['elements'].sort { |x, y| x['name'] <=> y['name'] } )
49
52
  }.merge( Vitreous::Share::IndexerUtils.meta_properties( e ) )
@@ -21,6 +21,12 @@ module Vitreous
21
21
  end.join('/')
22
22
  end
23
23
 
24
+ def self.full_path_to_slug( path )
25
+ return '' if path.empty?
26
+
27
+ to_slug( remove_extensions( path.split('/').last ) )
28
+ end
29
+
24
30
  def self.to_slug( string )
25
31
  to_title( string ).
26
32
  downcase.
@@ -1,5 +1,5 @@
1
1
  module Vitreous
2
2
  module Share
3
- VERSION = "0.0.27"
3
+ VERSION = "0.0.31"
4
4
  end
5
5
  end
@@ -7,8 +7,10 @@ class ElementTest < Test::Unit::TestCase
7
7
 
8
8
  assert_equal( 'fixtures', home.title )
9
9
  assert_equal( '/', home.link )
10
- assert_equal( true, home.collection? )
10
+ assert_equal( true, home.home? )
11
11
  assert_equal( false, home.item? )
12
+ assert_equal( false, home.collection? )
13
+ assert_equal( false, home.not_found? )
12
14
  assert_equal( 3, home.elements.size )
13
15
  assert_equal( 1, home.items.size )
14
16
  assert_equal( 2, home.collections.size )
@@ -1 +1 @@
1
- root content
1
+ home content
@@ -2,16 +2,19 @@
2
2
  "home": {
3
3
  "title": "fixtures",
4
4
  "link": "/",
5
- "type": "collection",
5
+ "slug": "",
6
+ "type": "home",
6
7
  "elements": [
7
8
  {
8
9
  "title": "subfolder 1",
9
10
  "link": "/subfolder-1",
11
+ "slug": "subfolder-1",
10
12
  "type": "collection",
11
13
  "elements": [
12
14
  {
13
15
  "title": "bbb",
14
16
  "link": "/subfolder-1/bbb",
17
+ "slug": "bbb",
15
18
  "type": "item",
16
19
  "elements": [
17
20
 
@@ -36,6 +39,7 @@
36
39
  {
37
40
  "title": "aaa",
38
41
  "link": "/subfolder-1/aaa",
42
+ "slug": "aaa",
39
43
  "type": "item",
40
44
  "elements": [
41
45
 
@@ -60,11 +64,13 @@
60
64
  {
61
65
  "title": "subsubfolder 1",
62
66
  "link": "/subfolder-1/subsubfolder-1",
67
+ "slug": "subsubfolder-1",
63
68
  "type": "collection",
64
69
  "elements": [
65
70
  {
66
71
  "title": "file 1",
67
72
  "link": "/subfolder-1/subsubfolder-1/file-1",
73
+ "slug": "file-1",
68
74
  "type": "item",
69
75
  "elements": [
70
76
 
@@ -101,11 +107,13 @@
101
107
  {
102
108
  "title": "subfolder 2",
103
109
  "link": "/subfolder-2",
110
+ "slug": "subfolder-2",
104
111
  "type": "collection",
105
112
  "elements": [
106
113
  {
107
114
  "title": "file 1",
108
115
  "link": "/subfolder-2/file-1",
116
+ "slug": "file-1",
109
117
  "type": "item",
110
118
  "elements": [
111
119
 
@@ -124,6 +132,7 @@
124
132
  {
125
133
  "title": "file 1",
126
134
  "link": "/file-1",
135
+ "slug": "file-1",
127
136
  "type": "item",
128
137
  "elements": [
129
138
 
@@ -160,21 +169,22 @@
160
169
  "wadus uri"
161
170
  ],
162
171
  "jpg": "wadus uri",
163
- "description": "root content",
172
+ "description": "home content",
164
173
  "descriptions": [
165
- "root content"
174
+ "home content"
166
175
  ],
167
- "txt": "root content",
176
+ "txt": "home content",
168
177
  "jpgs": [
169
178
  "wadus uri"
170
179
  ],
171
180
  "txts": [
172
- "root content"
181
+ "home content"
173
182
  ]
174
183
  },
175
184
  "not_found": {
176
185
  "title": "Not found",
177
- "type": "item",
186
+ "type": "not_found",
187
+ "slug": "not_found",
178
188
  "elements": [
179
189
 
180
190
  ],
@@ -11,3 +11,5 @@ assets: /assets_path
11
11
  collection txt: file content
12
12
  collection description: file content
13
13
  collection file: wadus uri
14
+ collection link: /subfolder-1
15
+ collection slug: subfolder-1
@@ -0,0 +1,15 @@
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
+ home title: fixtures
10
+ home jpg: wadus uri
11
+ home txt: home content
12
+ home description: home content
13
+ home file: wadus uri
14
+ home link: /
15
+ home slug:
@@ -11,3 +11,5 @@ assets: /assets_path
11
11
  item txt: file content
12
12
  item description: file content
13
13
  item file:
14
+ item link: /subfolder-1/subsubfolder-1/file-1
15
+ item slug: file-1
@@ -6,8 +6,10 @@ assets: /assets_path
6
6
  collection: subfolder 2
7
7
  item: file 1
8
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
9
+ not_found title: Not found
10
+ not_found jpg: wadus uri
11
+ not_found txt: This is the not found item
12
+ not_found description: This is the not found item
13
+ not_found file: wadus uri
14
+ not_found link:
15
+ not_found slug: not_found
@@ -129,7 +129,7 @@
129
129
  "elements": [
130
130
 
131
131
  ],
132
- "content": "root content"
132
+ "content": "home content"
133
133
  },
134
134
  {
135
135
  "name": "_not_found.jpg",
@@ -3,3 +3,5 @@ collection jpg: {{jpg}}
3
3
  collection txt: {{txt}}
4
4
  collection description: {{description}}
5
5
  collection file: {{file}}
6
+ collection link: {{link}}
7
+ collection slug: {{slug}}
@@ -0,0 +1,7 @@
1
+ home title: {{title}}
2
+ home jpg: {{jpg}}
3
+ home txt: {{txt}}
4
+ home description: {{description}}
5
+ home file: {{file}}
6
+ home link: {{link}}
7
+ home slug: {{slug}}
@@ -3,3 +3,5 @@ item jpg: {{jpg}}
3
3
  item txt: {{txt}}
4
4
  item description: {{description}}
5
5
  item file: {{file}}
6
+ item link: {{link}}
7
+ item slug: {{slug}}
@@ -10,10 +10,16 @@ assets: {{assets}}
10
10
  {{/home}}
11
11
 
12
12
  {{#element}}
13
+ {{#home?}}
14
+ {{>home}}
15
+ {{/home?}}
13
16
  {{#collection?}}
14
17
  {{>collection}}
15
18
  {{/collection?}}
16
19
  {{#item?}}
17
20
  {{>item}}
18
21
  {{/item?}}
22
+ {{#not_found?}}
23
+ {{>not_found}}
24
+ {{/not_found?}}
19
25
  {{/element}}
@@ -0,0 +1,7 @@
1
+ not_found title: {{title}}
2
+ not_found jpg: {{jpg}}
3
+ not_found txt: {{txt}}
4
+ not_found description: {{description}}
5
+ not_found file: {{file}}
6
+ not_found link: {{link}}
7
+ not_found slug: {{slug}}
@@ -11,6 +11,23 @@ class IndexerUtilsTest < Test::Unit::TestCase
11
11
  )
12
12
  end
13
13
 
14
+ def test_full_path_to_slug
15
+ assert_equal(
16
+ 'pepe-y-jun',
17
+ Vitreous::Share::IndexerUtils.to_slug( '/folder 1/folder 2/001 pepe y juán.txt' )
18
+ )
19
+
20
+ assert_equal(
21
+ '',
22
+ Vitreous::Share::IndexerUtils.to_slug( '/' )
23
+ )
24
+
25
+ assert_equal(
26
+ '',
27
+ Vitreous::Share::IndexerUtils.to_slug( '' )
28
+ )
29
+ end
30
+
14
31
  def test_to_slug
15
32
  assert_equal(
16
33
  'pepe-y-jun',
@@ -41,7 +41,7 @@ class IndexerTest < Test::Unit::TestCase
41
41
  assert_equal( File.read( "#{FIXTURES_PATH}/render_item.txt" ), result.body )
42
42
  end
43
43
 
44
- def test_render_root
44
+ def test_render_home
45
45
  index = JSON.load( File.read( "#{FIXTURES_PATH}/index.json" ) )
46
46
  result =
47
47
  Vitreous::Share::Render.render(
@@ -53,12 +53,12 @@ class IndexerTest < Test::Unit::TestCase
53
53
 
54
54
  # # write fixture
55
55
  # puts "This should be commented out!"
56
- # File.open( "#{FIXTURES_PATH}/render_root.txt", 'w' ) do |f|
56
+ # File.open( "#{FIXTURES_PATH}/render_home.txt", 'w' ) do |f|
57
57
  # f.write result.body
58
58
  # end
59
59
 
60
60
  assert_equal( 200, result.status )
61
- assert_equal( File.read( "#{FIXTURES_PATH}/render_root.txt" ), result.body )
61
+ assert_equal( File.read( "#{FIXTURES_PATH}/render_home.txt" ), result.body )
62
62
  end
63
63
 
64
64
  def test_render_not_found
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 27
9
- version: 0.0.27
8
+ - 31
9
+ version: 0.0.31
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-16 00:00:00 +02:00
17
+ date: 2011-08-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -173,13 +173,15 @@ files:
173
173
  - test/fixtures/folder_structure/file 1.txt
174
174
  - test/fixtures/index.json
175
175
  - test/fixtures/render_collection.txt
176
+ - test/fixtures/render_home.txt
176
177
  - test/fixtures/render_item.txt
177
178
  - test/fixtures/render_not_found.txt
178
- - test/fixtures/render_root.txt
179
179
  - test/fixtures/structure.json
180
180
  - test/fixtures/template/collection.html
181
+ - test/fixtures/template/home.html
181
182
  - test/fixtures/template/item.html
182
183
  - test/fixtures/template/layout.html
184
+ - test/fixtures/template/not_found.html
183
185
  - test/index_searcher_test.rb
184
186
  - test/indexer_test.rb
185
187
  - test/indexer_utils_test.rb
@@ -241,13 +243,15 @@ test_files:
241
243
  - test/fixtures/folder_structure/file 1.txt
242
244
  - test/fixtures/index.json
243
245
  - test/fixtures/render_collection.txt
246
+ - test/fixtures/render_home.txt
244
247
  - test/fixtures/render_item.txt
245
248
  - test/fixtures/render_not_found.txt
246
- - test/fixtures/render_root.txt
247
249
  - test/fixtures/structure.json
248
250
  - test/fixtures/template/collection.html
251
+ - test/fixtures/template/home.html
249
252
  - test/fixtures/template/item.html
250
253
  - test/fixtures/template/layout.html
254
+ - test/fixtures/template/not_found.html
251
255
  - test/index_searcher_test.rb
252
256
  - test/indexer_test.rb
253
257
  - test/indexer_utils_test.rb
@@ -1,13 +0,0 @@
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