dircat 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/scat +2 -2
- data/lib/dircat/cat_on_sqlite/migration/03_create_items.rb +1 -1
- data/lib/dircat/cat_on_sqlite/model/image.rb +32 -0
- data/lib/dircat/cat_on_sqlite/model/item.rb +26 -0
- data/lib/dircat/cat_on_sqlite/model/tag.rb +65 -0
- data/lib/dircat/cat_on_sqlite/model/tagging.rb +13 -0
- data/lib/dircat/cat_on_sqlite_cli/cmd_server.rb +2 -2
- data/lib/dircat/server/web_server.rb +4 -0
- data/lib/dircat/version.rb +1 -1
- data/spec/fixtures/tmp/prova.sqlite3 +0 -0
- data/spec/fixtures/tmp/prova.yml +8 -0
- data/spec/fixtures/tmp/test_ar.sqlite3 +0 -0
- metadata +6 -12
- data/lib/simple_cataloger_dm/cli.rb +0 -32
- data/lib/simple_cataloger_dm/core.rb +0 -43
- data/lib/simple_cataloger_dm/models/category.rb +0 -21
- data/lib/simple_cataloger_dm/models/image.rb +0 -30
- data/lib/simple_cataloger_dm/models/item.rb +0 -24
- data/lib/simple_cataloger_dm/models/tag.rb +0 -62
- data/lib/simple_cataloger_dm/models/tagging.rb +0 -11
- data/lib/simple_cataloger_dm/server/helpers.rb +0 -60
- data/lib/simple_cataloger_dm/server/my_static.rb +0 -40
- data/lib/simple_cataloger_dm/server/web_server.rb +0 -171
data/bin/scat
CHANGED
@@ -4,6 +4,6 @@ require 'rubygems'
|
|
4
4
|
cwd = File.expand_path(File.join(File.dirname(__FILE__), %w{.. lib}))
|
5
5
|
$:.unshift(cwd) unless $:.include?(cwd)
|
6
6
|
|
7
|
-
require '
|
8
|
-
# TODO: we need exit
|
7
|
+
require 'dircat_on_sqlite_cli'
|
8
|
+
# TODO: we need exit before run?
|
9
9
|
CliCat.run!
|
@@ -22,3 +22,35 @@ module SimpleCataloger
|
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
25
|
+
|
26
|
+
|
27
|
+
## -*- coding: utf-8 -*-
|
28
|
+
#module SimpleCataloger
|
29
|
+
#
|
30
|
+
# class Image
|
31
|
+
# include DataMapper::Resource
|
32
|
+
#
|
33
|
+
# property :id, Serial
|
34
|
+
# property :path, String
|
35
|
+
# property :path_from_catalog_root, String
|
36
|
+
#
|
37
|
+
# belongs_to :item, :required => false
|
38
|
+
# belongs_to :tag, :required => false
|
39
|
+
#
|
40
|
+
# def to_json(*a)
|
41
|
+
# {:item => if item then
|
42
|
+
# item.name
|
43
|
+
# else
|
44
|
+
# nil
|
45
|
+
# end,
|
46
|
+
# :tag => if tag then
|
47
|
+
# tag.name
|
48
|
+
# else
|
49
|
+
# nil
|
50
|
+
# end,
|
51
|
+
# :src => path_from_catalog_root}.to_json(*a)
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
#end
|
@@ -17,3 +17,29 @@ module SimpleCataloger
|
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
20
|
+
|
21
|
+
|
22
|
+
## -*- coding: utf-8 -*-
|
23
|
+
#module SimpleCataloger
|
24
|
+
#
|
25
|
+
# class Item
|
26
|
+
# include DataMapper::Resource
|
27
|
+
# property :id, Serial
|
28
|
+
# property :name, String
|
29
|
+
#
|
30
|
+
# property :added_at, Date
|
31
|
+
# property :path, String
|
32
|
+
# property :path_from_catalog_root, String
|
33
|
+
# property :rating, Integer
|
34
|
+
# property :flagged_at, Date
|
35
|
+
#
|
36
|
+
# has n, :taggings
|
37
|
+
# has n, :tags, :through => :taggings
|
38
|
+
# has n, :images
|
39
|
+
#
|
40
|
+
# def to_s
|
41
|
+
# @name
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
#end
|
@@ -56,3 +56,68 @@ module SimpleCataloger
|
|
56
56
|
end # class Tag
|
57
57
|
|
58
58
|
end # module SimpleCatalog
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
## -*- coding: utf-8 -*-
|
63
|
+
#module SimpleCataloger
|
64
|
+
#
|
65
|
+
# class Tag
|
66
|
+
# include DataMapper::Resource
|
67
|
+
#
|
68
|
+
# property :id, Serial
|
69
|
+
# property :name, String
|
70
|
+
#
|
71
|
+
# belongs_to :category, 'Category', :child_key => [:category_id]
|
72
|
+
# has n, :taggings
|
73
|
+
# has n, :items, :through => :taggings, :order => [:name]
|
74
|
+
# has n, :images
|
75
|
+
#
|
76
|
+
# ##################################################
|
77
|
+
# #
|
78
|
+
#
|
79
|
+
# RE_TAG = /\[([^\]]+)\]/
|
80
|
+
#
|
81
|
+
# # extracts tags from directory or file name
|
82
|
+
# def self.extract_tags(dir_or_file_name)
|
83
|
+
# tags = []
|
84
|
+
# match_data = dir_or_file_name.match(RE_TAG)
|
85
|
+
# while match_data
|
86
|
+
# tags << match_data[1]
|
87
|
+
# match_data = dir_or_file_name.match(RE_TAG, match_data.end(0))
|
88
|
+
# end
|
89
|
+
# tags
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# def self.extract_name(dir_or_file_name)
|
93
|
+
# dir_or_file_name.gsub(Tag::RE_TAG, '').strip
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# RE_RATING = /^\d$/
|
97
|
+
# RE_YEAR = /^\d\d\d\d$/
|
98
|
+
#
|
99
|
+
# MATCHES = [
|
100
|
+
# [RE_RATING, "rating", proc { |tag_name| tag_name.to_i }],
|
101
|
+
# [RE_YEAR, "year", proc { |tag_name| tag_name.to_i }]
|
102
|
+
# ]
|
103
|
+
#
|
104
|
+
# #
|
105
|
+
# # decode standard tags
|
106
|
+
# #
|
107
|
+
# def self.match_category(tag_name)
|
108
|
+
# MATCHES.each do |re, category_name, convert|
|
109
|
+
# if re.match tag_name
|
110
|
+
# category = Category.first_or_create(:name => category_name)
|
111
|
+
# tag = Tag.first_or_create(
|
112
|
+
# :name => convert.call(tag_name),
|
113
|
+
# :category => category
|
114
|
+
# )
|
115
|
+
# return tag
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
# nil
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# end # class Tag
|
122
|
+
#
|
123
|
+
#end # module SimpleCatalog
|
@@ -7,3 +7,16 @@ module SimpleCataloger
|
|
7
7
|
end
|
8
8
|
|
9
9
|
end # module
|
10
|
+
|
11
|
+
|
12
|
+
## -*- coding: utf-8 -*-
|
13
|
+
#module SimpleCataloger
|
14
|
+
#
|
15
|
+
# class Tagging
|
16
|
+
# include DataMapper::Resource
|
17
|
+
# property :id, Serial
|
18
|
+
# belongs_to :item
|
19
|
+
# belongs_to :tag
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
#end # module
|
@@ -14,8 +14,8 @@ module SimpleCataloger
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.usage
|
17
|
-
"#{command}
|
18
|
-
"
|
17
|
+
"#{command} <catalog name>\n" +
|
18
|
+
"launch a webs server to browse the content of <catalog name>\n"
|
19
19
|
end
|
20
20
|
|
21
21
|
def defaults(options)
|
data/lib/dircat/version.rb
CHANGED
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dircat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tree.rb
|
@@ -339,16 +339,6 @@ files:
|
|
339
339
|
- lib/simple_cataloger_dm/core/catalog.rb
|
340
340
|
- lib/simple_cataloger_dm/core/extensions.rb
|
341
341
|
- lib/simple_cataloger_dm/core/directory_visitor.rb
|
342
|
-
- lib/simple_cataloger_dm/core.rb
|
343
|
-
- lib/simple_cataloger_dm/cli.rb
|
344
|
-
- lib/simple_cataloger_dm/models/image.rb
|
345
|
-
- lib/simple_cataloger_dm/models/tag.rb
|
346
|
-
- lib/simple_cataloger_dm/models/tagging.rb
|
347
|
-
- lib/simple_cataloger_dm/models/category.rb
|
348
|
-
- lib/simple_cataloger_dm/models/item.rb
|
349
|
-
- lib/simple_cataloger_dm/server/my_static.rb
|
350
|
-
- lib/simple_cataloger_dm/server/helpers.rb
|
351
|
-
- lib/simple_cataloger_dm/server/web_server.rb
|
352
342
|
- lib/dircat.rb
|
353
343
|
- lib/dircat_on_sqlite.rb
|
354
344
|
- examples/example.rb
|
@@ -366,6 +356,8 @@ files:
|
|
366
356
|
- spec/dircat/cat_on_sqlite_web/web_server_spec.rb
|
367
357
|
- spec/fixtures/tmp/test_ar.sqlite3
|
368
358
|
- spec/fixtures/tmp/test_ar.yml
|
359
|
+
- spec/fixtures/tmp/prova.sqlite3
|
360
|
+
- spec/fixtures/tmp/prova.yml
|
369
361
|
- spec/fixtures/dir1/subdir/file3.txt
|
370
362
|
- spec/fixtures/dir1/file1.txt
|
371
363
|
- spec/fixtures/dir2/subdir/file3.txt
|
@@ -426,6 +418,8 @@ test_files:
|
|
426
418
|
- spec/dircat/cat_on_sqlite_web/web_server_spec.rb
|
427
419
|
- spec/fixtures/tmp/test_ar.sqlite3
|
428
420
|
- spec/fixtures/tmp/test_ar.yml
|
421
|
+
- spec/fixtures/tmp/prova.sqlite3
|
422
|
+
- spec/fixtures/tmp/prova.yml
|
429
423
|
- spec/fixtures/dir1/subdir/file3.txt
|
430
424
|
- spec/fixtures/dir1/file1.txt
|
431
425
|
- spec/fixtures/dir2/subdir/file3.txt
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# rubygems
|
5
|
-
#
|
6
|
-
#require 'rubygems'
|
7
|
-
#begin
|
8
|
-
# require "bundler/setup"
|
9
|
-
#rescue LoadError
|
10
|
-
#end
|
11
|
-
|
12
|
-
require 'sinatra/base'
|
13
|
-
|
14
|
-
gem 'sinatra-group-items', "0.0.1"
|
15
|
-
require 'sinatra/group_items'
|
16
|
-
|
17
|
-
require 'haml'
|
18
|
-
require 'sass'
|
19
|
-
require 'json'
|
20
|
-
|
21
|
-
#
|
22
|
-
# server
|
23
|
-
#
|
24
|
-
require 'simple_cataloger_server/helpers'
|
25
|
-
require 'simple_cataloger_server/my_static'
|
26
|
-
require 'simple_cataloger_server/web_server'
|
27
|
-
|
28
|
-
#
|
29
|
-
# cli
|
30
|
-
#
|
31
|
-
require 'simple_cataloger_cli/cli_cat'
|
32
|
-
Dir[ File.join(File.dirname(__FILE__), "simple_cataloger_cli", "cmd*.rb") ].each { |f|require f }
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# std lib
|
4
|
-
#
|
5
|
-
require 'pp'
|
6
|
-
require 'optparse'
|
7
|
-
require 'fileutils'
|
8
|
-
require 'ostruct'
|
9
|
-
|
10
|
-
#
|
11
|
-
# rubygems
|
12
|
-
#
|
13
|
-
gem "treevisitor", "0.2.2"
|
14
|
-
require 'treevisitor'
|
15
|
-
|
16
|
-
gem "optparse-command", "0.1.7"
|
17
|
-
require 'optparse-command'
|
18
|
-
|
19
|
-
require 'dm-core'
|
20
|
-
require 'dm-migrations'
|
21
|
-
|
22
|
-
#
|
23
|
-
# simple catalog
|
24
|
-
#
|
25
|
-
require 'simple_cataloger/version'
|
26
|
-
require 'simple_cataloger/simple_cataloger_error'
|
27
|
-
require 'simple_cataloger/extensions'
|
28
|
-
|
29
|
-
#
|
30
|
-
# db models
|
31
|
-
#
|
32
|
-
require 'simple_cataloger/models/item'
|
33
|
-
require 'simple_cataloger/models/tag'
|
34
|
-
require 'simple_cataloger/models/tagging'
|
35
|
-
require 'simple_cataloger/models/category'
|
36
|
-
require 'simple_cataloger/models/image'
|
37
|
-
|
38
|
-
#
|
39
|
-
# app
|
40
|
-
#
|
41
|
-
require 'simple_cataloger/directory_visitor'
|
42
|
-
require 'simple_cataloger/catalog'
|
43
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
module SimpleCataloger
|
3
|
-
|
4
|
-
class Category
|
5
|
-
include DataMapper::Resource
|
6
|
-
|
7
|
-
property :id, Serial
|
8
|
-
property :name, String
|
9
|
-
|
10
|
-
has n, :tags, :order => [:name]
|
11
|
-
|
12
|
-
def self.order_by_name
|
13
|
-
all(:order => [:name])
|
14
|
-
end
|
15
|
-
|
16
|
-
def items
|
17
|
-
tags.collect { |t| t.items }.flatten
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
module SimpleCataloger
|
3
|
-
|
4
|
-
class Image
|
5
|
-
include DataMapper::Resource
|
6
|
-
|
7
|
-
property :id, Serial
|
8
|
-
property :path, String
|
9
|
-
property :path_from_catalog_root, String
|
10
|
-
|
11
|
-
belongs_to :item, :required => false
|
12
|
-
belongs_to :tag, :required => false
|
13
|
-
|
14
|
-
def to_json(*a)
|
15
|
-
{:item => if item then
|
16
|
-
item.name
|
17
|
-
else
|
18
|
-
nil
|
19
|
-
end,
|
20
|
-
:tag => if tag then
|
21
|
-
tag.name
|
22
|
-
else
|
23
|
-
nil
|
24
|
-
end,
|
25
|
-
:src => path_from_catalog_root}.to_json(*a)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
module SimpleCataloger
|
3
|
-
|
4
|
-
class Item
|
5
|
-
include DataMapper::Resource
|
6
|
-
property :id, Serial
|
7
|
-
property :name, String
|
8
|
-
|
9
|
-
property :added_at, Date
|
10
|
-
property :path, String
|
11
|
-
property :path_from_catalog_root, String
|
12
|
-
property :rating, Integer
|
13
|
-
property :flagged_at, Date
|
14
|
-
|
15
|
-
has n, :taggings
|
16
|
-
has n, :tags, :through => :taggings
|
17
|
-
has n, :images
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
@name
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
module SimpleCataloger
|
3
|
-
|
4
|
-
class Tag
|
5
|
-
include DataMapper::Resource
|
6
|
-
|
7
|
-
property :id, Serial
|
8
|
-
property :name, String
|
9
|
-
|
10
|
-
belongs_to :category, 'Category', :child_key => [:category_id]
|
11
|
-
has n, :taggings
|
12
|
-
has n, :items, :through => :taggings, :order => [:name]
|
13
|
-
has n, :images
|
14
|
-
|
15
|
-
##################################################
|
16
|
-
#
|
17
|
-
|
18
|
-
RE_TAG = /\[([^\]]+)\]/
|
19
|
-
|
20
|
-
# extracts tags from directory or file name
|
21
|
-
def self.extract_tags(dir_or_file_name)
|
22
|
-
tags = []
|
23
|
-
match_data = dir_or_file_name.match(RE_TAG)
|
24
|
-
while match_data
|
25
|
-
tags << match_data[1]
|
26
|
-
match_data = dir_or_file_name.match(RE_TAG, match_data.end(0))
|
27
|
-
end
|
28
|
-
tags
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.extract_name(dir_or_file_name)
|
32
|
-
dir_or_file_name.gsub(Tag::RE_TAG, '').strip
|
33
|
-
end
|
34
|
-
|
35
|
-
RE_RATING = /^\d$/
|
36
|
-
RE_YEAR = /^\d\d\d\d$/
|
37
|
-
|
38
|
-
MATCHES = [
|
39
|
-
[RE_RATING, "rating", proc { |tag_name| tag_name.to_i }],
|
40
|
-
[RE_YEAR, "year", proc { |tag_name| tag_name.to_i }]
|
41
|
-
]
|
42
|
-
|
43
|
-
#
|
44
|
-
# decode standard tags
|
45
|
-
#
|
46
|
-
def self.match_category(tag_name)
|
47
|
-
MATCHES.each do |re, category_name, convert|
|
48
|
-
if re.match tag_name
|
49
|
-
category = Category.first_or_create(:name => category_name)
|
50
|
-
tag = Tag.first_or_create(
|
51
|
-
:name => convert.call(tag_name),
|
52
|
-
:category => category
|
53
|
-
)
|
54
|
-
return tag
|
55
|
-
end
|
56
|
-
end
|
57
|
-
nil
|
58
|
-
end
|
59
|
-
|
60
|
-
end # class Tag
|
61
|
-
|
62
|
-
end # module SimpleCatalog
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
module SimpleCataloger
|
3
|
-
module Helpers
|
4
|
-
|
5
|
-
def partial(template, *args)
|
6
|
-
options = args.extract_options!
|
7
|
-
options.merge!(:layout => false)
|
8
|
-
if collection = options.delete(:collection) then
|
9
|
-
collection.inject([]) do |buffer, member|
|
10
|
-
buffer << haml(template, options.merge(
|
11
|
-
:layout => false,
|
12
|
-
:locals => {template.to_sym => member}
|
13
|
-
)
|
14
|
-
)
|
15
|
-
end.join("\n")
|
16
|
-
else
|
17
|
-
haml(template, options)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def partial_erb(template)
|
22
|
-
erb template
|
23
|
-
end
|
24
|
-
|
25
|
-
def base_url
|
26
|
-
if Sinatra::Application.port == 80
|
27
|
-
"http://#{Sinatra::Application.host}/"
|
28
|
-
else
|
29
|
-
"http://#{Sinatra::Application.host}:#{Sinatra::Application.port}/"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def when_updated(time)
|
34
|
-
days = (Time.now - time) / (60 * 60 * 24)
|
35
|
-
case days.to_i
|
36
|
-
when 0
|
37
|
-
"today"
|
38
|
-
when 1
|
39
|
-
"yesterday"
|
40
|
-
else
|
41
|
-
"#{sprintf("%i", days) } days ago"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def gen_url(field, visible_field = nil)
|
46
|
-
visible_field ||= field
|
47
|
-
pos = request.env['REQUEST_URI'].index "?"
|
48
|
-
url = if pos
|
49
|
-
request.env['REQUEST_URI'][0...pos]
|
50
|
-
else
|
51
|
-
request.env['REQUEST_URI']
|
52
|
-
end
|
53
|
-
"<a href='#{url}?order=#{field}'>#{visible_field}</a>"
|
54
|
-
end
|
55
|
-
|
56
|
-
def rfc_3339(timestamp)
|
57
|
-
timestamp.strftime("%Y-%m-%dT%H:%M:%SZ")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Rack
|
2
|
-
|
3
|
-
# The Rack::Static middleware intercepts requests for static files
|
4
|
-
# (javascript files, images, stylesheets, etc) based on the url prefixes
|
5
|
-
# passed in the options, and serves them using a Rack::File object. This
|
6
|
-
# allows a Rack stack to serve both static and dynamic content.
|
7
|
-
#
|
8
|
-
# Examples:
|
9
|
-
# use Rack::Static, :urls => ["/media"]
|
10
|
-
# will serve all requests beginning with /media from the "media" folder
|
11
|
-
# located in the current directory (ie media/*).
|
12
|
-
#
|
13
|
-
# use Rack::Static, :urls => ["/css", "/images"], :root => "public"
|
14
|
-
# will serve all requests beginning with /css or /images from the folder
|
15
|
-
# "public" in the current directory (ie public/css/* and public/images/*)
|
16
|
-
|
17
|
-
class MyStatic
|
18
|
-
|
19
|
-
def initialize(app, options={})
|
20
|
-
@app = app
|
21
|
-
@urls = options[:urls] || ["/favicon.ico"]
|
22
|
-
root = options[:root] || Dir.pwd
|
23
|
-
@file_server = Rack::File.new(root)
|
24
|
-
end
|
25
|
-
|
26
|
-
def call(env)
|
27
|
-
path = env["PATH_INFO"]
|
28
|
-
puts "mystatic #{path} #{URI.decode(path)}"
|
29
|
-
path = URI.decode(path)
|
30
|
-
can_serve = @urls.any? { |url| path.index(url) == 0 }
|
31
|
-
|
32
|
-
if can_serve
|
33
|
-
@file_server.call(env)
|
34
|
-
else
|
35
|
-
@app.call(env)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
@@ -1,171 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
module SimpleCataloger
|
3
|
-
|
4
|
-
class WebServer < Sinatra::Base
|
5
|
-
|
6
|
-
def self.run!(*args)
|
7
|
-
options = args.last.is_a?(::Hash) ? args.last : {}
|
8
|
-
catalog = options[:catalog]
|
9
|
-
|
10
|
-
catalog.roots.each do |root|
|
11
|
-
use Rack::MyStatic,
|
12
|
-
:urls => ["/#{File.basename(root)}"],
|
13
|
-
:root => File.dirname(root)
|
14
|
-
puts "mount #{File.basename(root)} -> #{File.dirname(root)}"
|
15
|
-
end
|
16
|
-
|
17
|
-
define_method :catalog do
|
18
|
-
catalog
|
19
|
-
end
|
20
|
-
super(*args)
|
21
|
-
end
|
22
|
-
|
23
|
-
# turns on static file serving for Sinatra::Base apps
|
24
|
-
enable :static
|
25
|
-
|
26
|
-
server_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'web'))
|
27
|
-
set :public, File.join(server_dir, 'public')
|
28
|
-
set :views, File.join(server_dir, 'views')
|
29
|
-
|
30
|
-
helpers do
|
31
|
-
include Rack::Utils
|
32
|
-
alias_method :h, :escape_html
|
33
|
-
end
|
34
|
-
|
35
|
-
helpers Sinatra::GroupItems
|
36
|
-
helpers Helpers
|
37
|
-
|
38
|
-
get '/app.css' do
|
39
|
-
content_type 'text/css', :charset => 'utf-8'
|
40
|
-
sass :app
|
41
|
-
end
|
42
|
-
|
43
|
-
get "/js/tooltips/tooltips.css" do
|
44
|
-
content_type 'text/css', :charset => 'utf-8'
|
45
|
-
sass "/js/tooltips/tooltips".to_sym
|
46
|
-
end
|
47
|
-
|
48
|
-
get '/' do
|
49
|
-
@catalog = catalog
|
50
|
-
@items = Item.all
|
51
|
-
order = params[:o] || "alpha"
|
52
|
-
|
53
|
-
@render = proc { |item|
|
54
|
-
"<a href=\"/item/#{item.id}\" rel=\"#{item.id}\">#{item.name}</a>" +
|
55
|
-
if item.rating then
|
56
|
-
" (r:#{item.rating})"
|
57
|
-
else
|
58
|
-
" (r:unrated)"
|
59
|
-
end
|
60
|
-
}
|
61
|
-
|
62
|
-
case order
|
63
|
-
when "alpha"
|
64
|
-
@grouped_items = group_items(@items, :group_size => 5)
|
65
|
-
@title = "Films in alphabetical order (c:#{@items.length})"
|
66
|
-
when "time"
|
67
|
-
@grouped_items = group_items(@items, :group_size => 1, :header => proc { |film| film.added_at })
|
68
|
-
@title = "Films in time added order (c:#{@items.length})"
|
69
|
-
end
|
70
|
-
haml :items
|
71
|
-
end
|
72
|
-
|
73
|
-
get '/item/:id' do
|
74
|
-
@catalog = catalog
|
75
|
-
@item = Item.get(params[:id])
|
76
|
-
@grouped_items = group_items(@item.tags, :group_size => 1, :header => proc { |tag| tag.category.name })
|
77
|
-
haml :item
|
78
|
-
end
|
79
|
-
|
80
|
-
get '/categories' do
|
81
|
-
@catalog = catalog
|
82
|
-
@categories = Category.all
|
83
|
-
haml :categories
|
84
|
-
end
|
85
|
-
|
86
|
-
get "/category/:id" do
|
87
|
-
@catalog = catalog
|
88
|
-
@category = Category.get(params[:id])
|
89
|
-
haml :category
|
90
|
-
end
|
91
|
-
|
92
|
-
get "/tag/:id" do
|
93
|
-
@catalog = catalog
|
94
|
-
@tag = Tag.get(params[:id])
|
95
|
-
haml :tag
|
96
|
-
end
|
97
|
-
|
98
|
-
get "/random" do
|
99
|
-
max_peso = Item.inject.each do |f|
|
100
|
-
f.peso
|
101
|
-
end
|
102
|
-
Random.new.rand(0..maxpeso)
|
103
|
-
end
|
104
|
-
|
105
|
-
#######################################################################################
|
106
|
-
# Ajax
|
107
|
-
|
108
|
-
get '/ajax/ajax_item/:id' do
|
109
|
-
@item = Item.get(params[:id])
|
110
|
-
haml 'ajax/ajax_item'.to_sym, :layout => false
|
111
|
-
end
|
112
|
-
|
113
|
-
post '/ajax/open_folder' do
|
114
|
-
dir = params[:dir] || "/"
|
115
|
-
system("nautilus", dir)
|
116
|
-
"ok"
|
117
|
-
end
|
118
|
-
|
119
|
-
post "/ajax/set-category" do
|
120
|
-
id = params[:tag_id]
|
121
|
-
category_name = params[:category_name]
|
122
|
-
tag = Tag.get(id.to_i)
|
123
|
-
category = Category.first_or_create(:name => category_name)
|
124
|
-
tag.category = category
|
125
|
-
tag.save
|
126
|
-
catalog.update_categories
|
127
|
-
catalog.write_config
|
128
|
-
"ok"
|
129
|
-
end
|
130
|
-
|
131
|
-
get '/ajax/ajax_set_flag/:id' do
|
132
|
-
@film = Item.get(params[:id])
|
133
|
-
if (params[:checked] == "true")
|
134
|
-
@film.flagged_at = Time.new
|
135
|
-
else
|
136
|
-
@film.flagged_at = nil
|
137
|
-
end
|
138
|
-
@film.save
|
139
|
-
"ok"
|
140
|
-
end
|
141
|
-
|
142
|
-
#######################################################################################
|
143
|
-
# Tests
|
144
|
-
|
145
|
-
get "/test/resize" do
|
146
|
-
@catalog = catalog
|
147
|
-
haml "/test/resize".to_sym
|
148
|
-
end
|
149
|
-
|
150
|
-
get "/test/jquery" do
|
151
|
-
@catalog = catalog
|
152
|
-
haml "/test/jquery".to_sym
|
153
|
-
end
|
154
|
-
|
155
|
-
get "/test/lightbox" do
|
156
|
-
@catalog = catalog
|
157
|
-
haml "/test/lightbox".to_sym
|
158
|
-
end
|
159
|
-
|
160
|
-
get "/test/select" do
|
161
|
-
@catalog = catalog
|
162
|
-
haml "/test/select".to_sym
|
163
|
-
end
|
164
|
-
|
165
|
-
get "/test/protovis" do
|
166
|
-
@catalog = catalog
|
167
|
-
haml "/test/protovis".to_sym
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|