vitreous_standalone 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .bundle
2
+ pkg
3
+
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.8.7@vitreous_standalone
data/Gemfile CHANGED
@@ -1,13 +1,3 @@
1
- source 'http://rubygems.org'
1
+ source "http://rubygems.org"
2
2
 
3
- gem 'sinatra'
4
- gem 'dropbox'
5
- gem 'dummy_dropbox'
6
- gem 'json'
7
- gem 'mustache'
8
-
9
- group 'test' do
10
- gem 'ruby-debug19'
11
- gem 'rack-test'
12
- gem 'mocha'
13
- end
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,57 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vitreous_standalone (0.0.3)
5
+ json
6
+ mustache
7
+ sinatra
8
+ vitreous_share
9
+
1
10
  GEM
2
11
  remote: http://rubygems.org/
3
12
  specs:
4
- archive-tar-minitar (0.5.2)
5
- columnize (0.3.2)
6
- dropbox (1.2.3)
13
+ dropbox (1.3.0)
7
14
  json (>= 1.2.0)
8
- mechanize (>= 1.0.0)
9
- multipart-post (>= 1.0)
15
+ multipart-post (>= 1.1.0)
10
16
  oauth (>= 0.3.6)
11
- dummy_dropbox (0.0.2)
12
- dropbox
13
- json (1.5.1)
14
- linecache19 (0.5.11)
15
- ruby_core_source (>= 0.1.4)
16
- mechanize (1.0.0)
17
- nokogiri (>= 1.2.1)
17
+ json (1.5.3)
18
18
  mocha (0.9.12)
19
- multipart-post (1.1.0)
20
- mustache (0.12.0)
21
- nokogiri (1.4.4)
22
- oauth (0.4.4)
23
- rack (1.2.1)
24
- rack-test (0.5.7)
25
- rack (>= 1.0)
26
- ruby-debug-base19 (0.11.24)
27
- columnize (>= 0.3.1)
28
- linecache19 (>= 0.5.11)
29
- ruby_core_source (>= 0.1.4)
30
- ruby-debug19 (0.11.6)
31
- columnize (>= 0.3.1)
32
- linecache19 (>= 0.5.11)
33
- ruby-debug-base19 (>= 0.11.19)
34
- ruby_core_source (0.1.4)
35
- archive-tar-minitar (>= 0.5.2)
36
- sinatra (1.1.2)
19
+ multipart-post (1.1.3)
20
+ mustache (0.99.4)
21
+ oauth (0.4.5)
22
+ rack (1.3.2)
23
+ rake (0.9.2)
24
+ sinatra (1.2.6)
37
25
  rack (~> 1.1)
38
- tilt (~> 1.2)
39
- tilt (1.2.2)
40
- webrat (0.7.3)
41
- nokogiri (>= 1.2.0)
42
- rack (>= 1.0)
43
- rack-test (>= 0.5.3)
26
+ tilt (>= 1.2.2, < 2.0)
27
+ tilt (1.3.2)
28
+ vitreous_share (0.0.1)
29
+ dropbox
30
+ json
31
+ mustache
44
32
 
45
33
  PLATFORMS
46
34
  ruby
47
35
 
48
36
  DEPENDENCIES
49
- dropbox
50
- dummy_dropbox
51
- json
37
+ bundler (>= 1.0.0.rc.6)
52
38
  mocha
53
- mustache
54
- rack-test
55
- ruby-debug19
56
- sinatra
57
- webrat
39
+ rake
40
+ vitreous_standalone!
data/Rakefile CHANGED
@@ -1,13 +1,15 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
4
-
5
- Echoe.new('vitreous_standalone', '0.0.1') do |p|
6
- p.description = "Vitreous standalone server"
7
- p.url = "http://github.com/fguillen/VitreousStandalone"
8
- p.author = "Fernando Guillen & Juan Jose Vidal"
9
- p.email = ["fguillen.mail@gmail.com", "juanjicho@gmail.com "]
10
- p.ignore_pattern = ['test/*']
11
- p.development_dependencies = ['mocha', 'rack-test']
12
- p.runtime_dependencies = ['sinatra', 'dropbox', 'dummy_dropbox', 'json', 'mustache']
1
+ # require 'bundler/gem_tasks'
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'bundler'
6
+
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ task :default => :test
10
+
11
+ Rake::TestTask.new do |t|
12
+ t.libs << '.'
13
+ t.test_files = FileList['test/*_test.rb']
14
+ t.verbose = true
13
15
  end
@@ -15,8 +15,6 @@ rescue LoadError
15
15
  require 'vitreous_standalone'
16
16
  end
17
17
 
18
- puts "XXX: ENV['VITREOUS_FOLDER']: #{ENV['VITREOUS_FOLDER']}"
19
-
20
18
  puts "Starting Vitreous standalone"
21
19
 
22
- VitreousStandalone.run!
20
+ Vitreous::Standalone::App.run!
@@ -0,0 +1,49 @@
1
+ VITREOUS_FOLDER = ENV['VITREOUS_FOLDER']
2
+ Mustache.template_path = "#{VITREOUS_FOLDER}/template"
3
+ Mustache.template_extension = 'html'
4
+
5
+ module Vitreous
6
+ module Share
7
+ class LocalStructure
8
+ def self.base_uri
9
+ "/local/file"
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ module Vitreous
16
+ module Standalone
17
+ class App < Sinatra::Base
18
+ # assets
19
+ get "/assets/*" do |asset|
20
+ send_file "#{VITREOUS_FOLDER}/template/assets/#{asset}"
21
+ end
22
+
23
+ # file
24
+ get "#{Vitreous::Share::LocalStructure.base_uri}/*" do |file|
25
+ send_file "#{VITREOUS_FOLDER}/website/#{file}"
26
+ end
27
+
28
+ # element
29
+ get '/*' do |resource|
30
+ structure = Vitreous::Share::LocalStructure.new( "/#{VITREOUS_FOLDER}/website" )
31
+ indexer = Vitreous::Share::Indexer.new( structure.generate )
32
+ index = Vitreous::Share::Element.new( indexer.generate[0] )
33
+ element = Vitreous::Share::IndexSearcher.search( index, "/#{resource}" )
34
+
35
+ raise Sinatra::NotFound if element.nil?
36
+
37
+ Mustache.render(
38
+ File.read( "#{VITREOUS_FOLDER}/template/layout.html" ),
39
+ {
40
+ :domain => 'mydomain.com',
41
+ :index => index,
42
+ :element => element,
43
+ :assets_path => "/assets"
44
+ }
45
+ )
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module Vitreous
2
+ module Standalone
3
+ VERSION = "0.0.5"
4
+ end
5
+ end
@@ -2,9 +2,6 @@ require 'rubygems'
2
2
  require 'sinatra/base'
3
3
  require 'mustache'
4
4
  require 'yaml'
5
- require 'dropbox'
6
- require 'dummy_dropbox'
7
- require File.expand_path "#{File.dirname(__FILE__)}/vitreous_standalone/element.rb"
8
- require File.expand_path "#{File.dirname(__FILE__)}/vitreous_standalone/indexer.rb"
9
- require File.expand_path "#{File.dirname(__FILE__)}/vitreous_standalone/element_mustache.rb"
10
- require File.expand_path "#{File.dirname(__FILE__)}/vitreous_standalone/app.rb"
5
+ require 'vitreous_share'
6
+ require File.expand_path "#{File.dirname(__FILE__)}/vitreous/standalone/app.rb"
7
+ require File.expand_path "#{File.dirname(__FILE__)}/vitreous/standalone/version.rb"
@@ -2,5 +2,5 @@ collection: folder
2
2
  item: file
3
3
 
4
4
  element title: file
5
- element jpg: /website/folder/file.jpg
5
+ element jpg: /local/file/folder/file.jpg
6
6
  element txt: This is my text
@@ -7,16 +7,15 @@ require 'mocha'
7
7
 
8
8
  FIXTURES_PATH = "#{File.dirname(__FILE__)}/fixtures"
9
9
 
10
- class ThimblSingingTest < Test::Unit::TestCase
10
+ class VitreousStandaloneTest < Test::Unit::TestCase
11
11
  include Rack::Test::Methods
12
12
 
13
13
  def app
14
- VitreousStandalone.new
14
+ Vitreous::Standalone::App.new
15
15
  end
16
16
 
17
17
  def test_show_root
18
18
  get '/'
19
- # puts last_response.body
20
19
  assert_equal File.read( "#{FIXTURES_PATH}/responses/show.txt" ), last_response.body
21
20
  end
22
21
 
@@ -42,7 +41,7 @@ class ThimblSingingTest < Test::Unit::TestCase
42
41
  end
43
42
 
44
43
  def test_file
45
- get '/website/folder/file.jpg'
44
+ get "#{Vitreous::Share::LocalStructure.base_uri}/folder/file.jpg"
46
45
  assert_equal 'image/jpeg', last_response.content_type
47
46
  assert_equal 750, last_response.content_length
48
47
  end
@@ -1,54 +1,30 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "vitreous/standalone/version"
2
4
 
3
5
  Gem::Specification.new do |s|
4
- s.name = %q{vitreous_standalone}
5
- s.version = "0.0.1"
6
+ s.name = "vitreous_standalone"
7
+ s.version = Vitreous::Standalone::VERSION
8
+ s.authors = ["Fernando Guillen"]
9
+ s.email = ["fguillen.mail@gmail.com"]
10
+ s.homepage = "https://github.com/fguillen/VitreousStandalone"
11
+ s.summary = "Standalone version for the VitreousCloud"
12
+ s.description = "Standalone version for the VitreousCloud"
6
13
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Fernando Guillen & Juan Jose Vidal"]
9
- s.date = %q{2011-02-23}
10
- s.default_executable = %q{vitreous_standalone}
11
- s.description = %q{Vitreous standalone server}
12
- s.email = ["fguillen.mail@gmail.com", "juanjicho@gmail.com "]
13
- s.executables = ["vitreous_standalone"]
14
- s.extra_rdoc_files = ["README.md", "bin/vitreous_standalone", "lib/vitreous_standalone.rb", "lib/vitreous_standalone/app.rb", "lib/vitreous_standalone/element.rb", "lib/vitreous_standalone/element_mustache.rb", "lib/vitreous_standalone/indexer.rb"]
15
- s.files = ["Gemfile", "Gemfile.lock", "README.md", "Rakefile", "bin/vitreous_standalone", "lib/vitreous_standalone.rb", "lib/vitreous_standalone/app.rb", "lib/vitreous_standalone/element.rb", "lib/vitreous_standalone/element_mustache.rb", "lib/vitreous_standalone/indexer.rb", "test/fixtures/responses/collection.txt", "test/fixtures/responses/element.txt", "test/fixtures/responses/show.txt", "test/fixtures/vitreous_folder/template/assets/nyc.png", "test/fixtures/vitreous_folder/template/assets/style.css", "test/fixtures/vitreous_folder/template/layout.html", "test/fixtures/vitreous_folder/website/folder/file.jpg", "test/fixtures/vitreous_folder/website/folder/file.txt", "Manifest", "vitreous_standalone.gemspec", "test/vitreous_standalone_test.rb"]
16
- s.homepage = %q{http://github.com/fguillen/VitreousStandalone}
17
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Vitreous_standalone", "--main", "README.md"]
18
- s.require_paths = ["lib"]
19
- s.rubyforge_project = %q{vitreous_standalone}
20
- s.rubygems_version = %q{1.3.7}
21
- s.summary = %q{Vitreous standalone server}
22
- s.test_files = ["test/vitreous_standalone_test.rb"]
23
-
24
- if s.respond_to? :specification_version then
25
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
- s.specification_version = 3
14
+ s.rubyforge_project = "VitreousStandalone"
15
+
16
+ s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
17
+ s.add_development_dependency "mocha"
18
+ s.add_development_dependency "rake"
19
+ s.add_development_dependency "rack-test"
20
+
21
+ s.add_dependency "sinatra"
22
+ s.add_dependency "json"
23
+ s.add_dependency "mustache"
24
+ s.add_dependency "vitreous_share"
27
25
 
28
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
- s.add_runtime_dependency(%q<sinatra>, [">= 0"])
30
- s.add_runtime_dependency(%q<dropbox>, [">= 0"])
31
- s.add_runtime_dependency(%q<dummy_dropbox>, [">= 0"])
32
- s.add_runtime_dependency(%q<json>, [">= 0"])
33
- s.add_runtime_dependency(%q<mustache>, [">= 0"])
34
- s.add_development_dependency(%q<mocha>, [">= 0"])
35
- s.add_development_dependency(%q<rack-test>, [">= 0"])
36
- else
37
- s.add_dependency(%q<sinatra>, [">= 0"])
38
- s.add_dependency(%q<dropbox>, [">= 0"])
39
- s.add_dependency(%q<dummy_dropbox>, [">= 0"])
40
- s.add_dependency(%q<json>, [">= 0"])
41
- s.add_dependency(%q<mustache>, [">= 0"])
42
- s.add_dependency(%q<mocha>, [">= 0"])
43
- s.add_dependency(%q<rack-test>, [">= 0"])
44
- end
45
- else
46
- s.add_dependency(%q<sinatra>, [">= 0"])
47
- s.add_dependency(%q<dropbox>, [">= 0"])
48
- s.add_dependency(%q<dummy_dropbox>, [">= 0"])
49
- s.add_dependency(%q<json>, [">= 0"])
50
- s.add_dependency(%q<mustache>, [">= 0"])
51
- s.add_dependency(%q<mocha>, [">= 0"])
52
- s.add_dependency(%q<rack-test>, [">= 0"])
53
- end
26
+ s.files = `git ls-files`.split("\n")
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
29
+ s.require_paths = ["lib"]
54
30
  end
metadata CHANGED
@@ -1,140 +1,159 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitreous_standalone
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 21
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 1
9
- version: 0.0.1
9
+ - 5
10
+ version: 0.0.5
10
11
  platform: ruby
11
12
  authors:
12
- - Fernando Guillen & Juan Jose Vidal
13
+ - Fernando Guillen
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-02-23 00:00:00 +01:00
18
+ date: 2011-07-27 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- name: sinatra
22
+ name: bundler
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 15424057
28
30
  segments:
31
+ - 1
29
32
  - 0
30
- version: "0"
31
- type: :runtime
33
+ - 0
34
+ - rc
35
+ - 6
36
+ version: 1.0.0.rc.6
37
+ type: :development
32
38
  version_requirements: *id001
33
39
  - !ruby/object:Gem::Dependency
34
- name: dropbox
40
+ name: mocha
35
41
  prerelease: false
36
42
  requirement: &id002 !ruby/object:Gem::Requirement
37
43
  none: false
38
44
  requirements:
39
45
  - - ">="
40
46
  - !ruby/object:Gem::Version
47
+ hash: 3
41
48
  segments:
42
49
  - 0
43
50
  version: "0"
44
- type: :runtime
51
+ type: :development
45
52
  version_requirements: *id002
46
53
  - !ruby/object:Gem::Dependency
47
- name: dummy_dropbox
54
+ name: rake
48
55
  prerelease: false
49
56
  requirement: &id003 !ruby/object:Gem::Requirement
50
57
  none: false
51
58
  requirements:
52
59
  - - ">="
53
60
  - !ruby/object:Gem::Version
61
+ hash: 3
54
62
  segments:
55
63
  - 0
56
64
  version: "0"
57
- type: :runtime
65
+ type: :development
58
66
  version_requirements: *id003
59
67
  - !ruby/object:Gem::Dependency
60
- name: json
68
+ name: rack-test
61
69
  prerelease: false
62
70
  requirement: &id004 !ruby/object:Gem::Requirement
63
71
  none: false
64
72
  requirements:
65
73
  - - ">="
66
74
  - !ruby/object:Gem::Version
75
+ hash: 3
67
76
  segments:
68
77
  - 0
69
78
  version: "0"
70
- type: :runtime
79
+ type: :development
71
80
  version_requirements: *id004
72
81
  - !ruby/object:Gem::Dependency
73
- name: mustache
82
+ name: sinatra
74
83
  prerelease: false
75
84
  requirement: &id005 !ruby/object:Gem::Requirement
76
85
  none: false
77
86
  requirements:
78
87
  - - ">="
79
88
  - !ruby/object:Gem::Version
89
+ hash: 3
80
90
  segments:
81
91
  - 0
82
92
  version: "0"
83
93
  type: :runtime
84
94
  version_requirements: *id005
85
95
  - !ruby/object:Gem::Dependency
86
- name: mocha
96
+ name: json
87
97
  prerelease: false
88
98
  requirement: &id006 !ruby/object:Gem::Requirement
89
99
  none: false
90
100
  requirements:
91
101
  - - ">="
92
102
  - !ruby/object:Gem::Version
103
+ hash: 3
93
104
  segments:
94
105
  - 0
95
106
  version: "0"
96
- type: :development
107
+ type: :runtime
97
108
  version_requirements: *id006
98
109
  - !ruby/object:Gem::Dependency
99
- name: rack-test
110
+ name: mustache
100
111
  prerelease: false
101
112
  requirement: &id007 !ruby/object:Gem::Requirement
102
113
  none: false
103
114
  requirements:
104
115
  - - ">="
105
116
  - !ruby/object:Gem::Version
117
+ hash: 3
106
118
  segments:
107
119
  - 0
108
120
  version: "0"
109
- type: :development
121
+ type: :runtime
110
122
  version_requirements: *id007
111
- description: Vitreous standalone server
123
+ - !ruby/object:Gem::Dependency
124
+ name: vitreous_share
125
+ prerelease: false
126
+ requirement: &id008 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ type: :runtime
136
+ version_requirements: *id008
137
+ description: Standalone version for the VitreousCloud
112
138
  email:
113
139
  - fguillen.mail@gmail.com
114
- - "juanjicho@gmail.com "
115
140
  executables:
116
141
  - vitreous_standalone
117
142
  extensions: []
118
143
 
119
- extra_rdoc_files:
120
- - README.md
121
- - bin/vitreous_standalone
122
- - lib/vitreous_standalone.rb
123
- - lib/vitreous_standalone/app.rb
124
- - lib/vitreous_standalone/element.rb
125
- - lib/vitreous_standalone/element_mustache.rb
126
- - lib/vitreous_standalone/indexer.rb
144
+ extra_rdoc_files: []
145
+
127
146
  files:
147
+ - .gitignore
148
+ - .rvmrc
128
149
  - Gemfile
129
150
  - Gemfile.lock
130
151
  - README.md
131
152
  - Rakefile
132
153
  - bin/vitreous_standalone
154
+ - lib/vitreous/standalone/app.rb
155
+ - lib/vitreous/standalone/version.rb
133
156
  - lib/vitreous_standalone.rb
134
- - lib/vitreous_standalone/app.rb
135
- - lib/vitreous_standalone/element.rb
136
- - lib/vitreous_standalone/element_mustache.rb
137
- - lib/vitreous_standalone/indexer.rb
138
157
  - test/fixtures/responses/collection.txt
139
158
  - test/fixtures/responses/element.txt
140
159
  - test/fixtures/responses/show.txt
@@ -143,21 +162,15 @@ files:
143
162
  - test/fixtures/vitreous_folder/template/layout.html
144
163
  - test/fixtures/vitreous_folder/website/folder/file.jpg
145
164
  - test/fixtures/vitreous_folder/website/folder/file.txt
146
- - Manifest
147
- - vitreous_standalone.gemspec
148
165
  - test/vitreous_standalone_test.rb
166
+ - vitreous_standalone.gemspec
149
167
  has_rdoc: true
150
- homepage: http://github.com/fguillen/VitreousStandalone
168
+ homepage: https://github.com/fguillen/VitreousStandalone
151
169
  licenses: []
152
170
 
153
171
  post_install_message:
154
- rdoc_options:
155
- - --line-numbers
156
- - --inline-source
157
- - --title
158
- - Vitreous_standalone
159
- - --main
160
- - README.md
172
+ rdoc_options: []
173
+
161
174
  require_paths:
162
175
  - lib
163
176
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -165,6 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
178
  requirements:
166
179
  - - ">="
167
180
  - !ruby/object:Gem::Version
181
+ hash: 3
168
182
  segments:
169
183
  - 0
170
184
  version: "0"
@@ -173,16 +187,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
187
  requirements:
174
188
  - - ">="
175
189
  - !ruby/object:Gem::Version
190
+ hash: 3
176
191
  segments:
177
- - 1
178
- - 2
179
- version: "1.2"
192
+ - 0
193
+ version: "0"
180
194
  requirements: []
181
195
 
182
- rubyforge_project: vitreous_standalone
196
+ rubyforge_project: VitreousStandalone
183
197
  rubygems_version: 1.3.7
184
198
  signing_key:
185
199
  specification_version: 3
186
- summary: Vitreous standalone server
200
+ summary: Standalone version for the VitreousCloud
187
201
  test_files:
202
+ - test/fixtures/responses/collection.txt
203
+ - test/fixtures/responses/element.txt
204
+ - test/fixtures/responses/show.txt
205
+ - test/fixtures/vitreous_folder/template/assets/nyc.png
206
+ - test/fixtures/vitreous_folder/template/assets/style.css
207
+ - test/fixtures/vitreous_folder/template/layout.html
208
+ - test/fixtures/vitreous_folder/website/folder/file.jpg
209
+ - test/fixtures/vitreous_folder/website/folder/file.txt
188
210
  - test/vitreous_standalone_test.rb
data/Manifest DELETED
@@ -1,19 +0,0 @@
1
- Gemfile
2
- Gemfile.lock
3
- README.md
4
- Rakefile
5
- bin/vitreous_standalone
6
- lib/vitreous_standalone.rb
7
- lib/vitreous_standalone/app.rb
8
- lib/vitreous_standalone/element.rb
9
- lib/vitreous_standalone/element_mustache.rb
10
- lib/vitreous_standalone/indexer.rb
11
- test/fixtures/responses/collection.txt
12
- test/fixtures/responses/element.txt
13
- test/fixtures/responses/show.txt
14
- test/fixtures/vitreous_folder/template/assets/nyc.png
15
- test/fixtures/vitreous_folder/template/assets/style.css
16
- test/fixtures/vitreous_folder/template/layout.html
17
- test/fixtures/vitreous_folder/website/folder/file.jpg
18
- test/fixtures/vitreous_folder/website/folder/file.txt
19
- Manifest
@@ -1,46 +0,0 @@
1
- VITREOUS_FOLDER = ENV['VITREOUS_FOLDER']
2
- Mustache.template_path = "#{VITREOUS_FOLDER}/template"
3
- Mustache.template_extension = 'html'
4
-
5
- class Vitreous::Dropbox::Indexer
6
- def dropbox_public_path
7
- ""
8
- end
9
- end
10
-
11
- class VitreousStandalone < Sinatra::Base
12
- # assets
13
- get "/assets/*" do |asset|
14
- send_file "#{VITREOUS_FOLDER}/template/assets/#{asset}"
15
- end
16
-
17
- # file
18
- get "/website/*" do |file|
19
- send_file "#{VITREOUS_FOLDER}/website/#{file}"
20
- end
21
-
22
- # resource
23
- get '/*' do |resource|
24
- DummyDropbox.root_path = VITREOUS_FOLDER
25
- dropbox_session = ::Dropbox::Session.new('key', 'secret')
26
- indexer = Vitreous::Dropbox::Indexer.new( dropbox_session, '/website' )
27
- index = Element.from_json indexer.create_index
28
-
29
- resource = "/#{resource}"
30
- element = resource == '/' ? index : index.search( resource )
31
-
32
- raise Sinatra::NotFound if element.nil?
33
-
34
-
35
-
36
- Mustache.render(
37
- File.read( "#{VITREOUS_FOLDER}/template/layout.html" ),
38
- {
39
- :domain => 'mydomain.com',
40
- :index => ElementMustache.new( index ),
41
- :element => ElementMustache.new( element ),
42
- :assets_path => "/assets"
43
- }
44
- )
45
- end
46
- end
@@ -1,45 +0,0 @@
1
- class Element < Mustache
2
- attr_accessor :elements
3
- attr_accessor :title
4
- attr_accessor :slug
5
- attr_accessor :link
6
- attr_accessor :type
7
- attr_accessor :meta
8
-
9
- def initialize( opts = {} )
10
- @title = opts[:title]
11
- @slug = opts[:slug]
12
- @link = opts[:link]
13
- @type = opts[:type]
14
- @meta = opts[:meta] || {}
15
- @elements = []
16
- end
17
-
18
- def search( link )
19
- return self if link == self.link
20
-
21
- self.elements.each do |element|
22
- found = element.search( link )
23
- return found if found
24
- end
25
-
26
- return nil
27
- end
28
-
29
- def self.from_json( hash )
30
- element =
31
- Element.new(
32
- :title => hash['title'],
33
- :slug => hash['slug'],
34
- :link => hash['link'],
35
- :type => hash['type'],
36
- :meta => hash['meta']
37
- )
38
-
39
- hash['elements'].each do |element_hash|
40
- element.elements << Element.from_json( element_hash )
41
- end
42
-
43
- return element
44
- end
45
- end
@@ -1,73 +0,0 @@
1
- class ElementMustache < Mustache
2
- def initialize( element )
3
- @element = element
4
- end
5
-
6
- def respond_to?( method_name )
7
- if(
8
- @element.meta.has_key?( method_name ) ||
9
- @element.meta.has_key?( method_name.to_s ) ||
10
- super.respond_to?( method_name ) ||
11
- (method_name.to_s =~ /\?$/ && method_name.to_s != 'has_key?')
12
- )
13
- return true
14
- end
15
-
16
- super
17
- end
18
-
19
- def method_missing( method_name, *args, &block )
20
-
21
- # jumping {{#meta}}
22
- if @element.meta.has_key? method_name
23
- return @element.meta[method_name]
24
- end
25
-
26
- if @element.meta.has_key? method_name.to_s
27
- return @element.meta[method_name.to_s]
28
- end
29
-
30
- # asking if has a key
31
- if method_name.to_s =~ /\?$/ && method_name.to_s != 'has_key?'
32
- return ( @element.meta.has_key?( method_name.to_s.gsub(/\?$/,'').to_sym ) || @element.meta.has_key?( method_name.to_s.gsub(/\?$/,'') ) )
33
- end
34
-
35
- super
36
- end
37
-
38
- def title
39
- @element.title
40
- end
41
-
42
- def link
43
- @element.link
44
- end
45
-
46
- def slug
47
- @element.slug
48
- end
49
-
50
- def meta
51
- @element.meta
52
- end
53
-
54
- def collection?
55
- @element.type == 'collection'
56
- end
57
-
58
- def item?
59
- @element.type == 'item'
60
- end
61
-
62
- def elements
63
- @element.elements.map { |e| ElementMustache.new( e ) }
64
- end
65
-
66
- def collections
67
- @element.elements.select { |e| e.type == 'collection' }.map { |e| ElementMustache.new( e ) }
68
- end
69
-
70
- def items
71
- @element.elements.select { |e| e.type == 'item' }.map { |e| ElementMustache.new( e ) }
72
- end
73
- end
@@ -1,87 +0,0 @@
1
- module Vitreous
2
- module Dropbox
3
- class Indexer
4
- TXT_EXTENSIONS = /^(txt|md|html|meta)$/
5
-
6
- attr_accessor :session
7
-
8
- def initialize( session, root_path = nil )
9
- @session = session
10
- @root_path = root_path
11
- end
12
-
13
- def create_index
14
- dropbox_root = @session.entry( @root_path )
15
- dropbox_root_elements = dropbox_root.list.to_a
16
- return self.create_element( dropbox_root.path, dropbox_root_elements )
17
- end
18
-
19
- def create_element( dropbox_element_path, dropbox_elements )
20
- dropbox_element = @session.entry( dropbox_element_path )
21
-
22
- # Basic data
23
- element = Element.new
24
- element.type = dropbox_element.metadata.directory? ? 'collection' : 'item'
25
- element.title = Vitreous::Dropbox::Indexer.path_to_title( dropbox_element.path )
26
- element.slug = Vitreous::Dropbox::Indexer.path_to_slug( dropbox_element.path )
27
- element.link = Vitreous::Dropbox::Indexer.path_to_link( dropbox_element.path, @root_path )
28
-
29
- # Files metadata
30
- file_name = File.basename( dropbox_element.path, File.extname( dropbox_element.path ) )
31
-
32
- dropbox_files_same_name = dropbox_elements.select do |e|
33
- file_name == File.basename( e.path, File.extname( e.path ) ) &&
34
- !e.directory?
35
- end
36
-
37
- dropbox_files_same_name.each do |e|
38
- ext_name = File.extname( e.path ).gsub( '.', '' )
39
- if( ext_name =~ TXT_EXTENSIONS )
40
- element.meta[ext_name] = @session.download( e.path )
41
- else
42
- element.meta[ext_name] = "#{self.dropbox_public_path}#{e.path.gsub( /^\/Public\//, '' )}"
43
- end
44
- end
45
-
46
- # In case directory then recursion
47
- if( element.type == 'collection' )
48
- dropbox_elements = dropbox_element.list.to_a
49
- Vitreous::Dropbox::Indexer.clean_directory_metadata( file_name, dropbox_elements )
50
-
51
- dropbox_elements.each do |e|
52
- # jump files with same name of elements already digested
53
- next if element.elements.map(&:link).include?( Vitreous::Dropbox::Indexer.path_to_link( e.path, @root_path ) )
54
- element.elements << self.create_element( e.path, dropbox_elements )
55
- end
56
- end
57
-
58
- return element
59
- end
60
-
61
- def self.path_to_title( path )
62
- return File.basename( path, File.extname( path ) ).gsub( /^0\d*\s/, '' )
63
- end
64
-
65
- def self.path_to_slug( path )
66
- return Vitreous::Dropbox::Indexer.path_to_title(path).downcase.gsub(/[^a-z0-9 -_]/,"").gsub('_', '-').gsub(/[ ]+/,"-")
67
- end
68
-
69
- def self.path_to_link( path, root_path )
70
- path = path.gsub( root_path, '' )
71
- link = path.split('/').map { |e| Vitreous::Dropbox::Indexer.path_to_slug( e ) }.join('/')
72
- return link
73
- end
74
-
75
- # clean file elements that are metadata of a directory
76
- def self.clean_directory_metadata( file_name, dropbox_elements )
77
- dropbox_elements.delete_if do |e1|
78
- !e1.directory? && dropbox_elements.any? { |e2| e2.directory? && file_name == File.basename( e2.path ) }
79
- end
80
- end
81
-
82
- def dropbox_public_path
83
- "http://dl.dropbox.com/u/#{@session.account.uid}"
84
- end
85
- end
86
- end
87
- end