bowtie 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bowtie.gemspec +1 -1
- data/lib/bowtie/adapters/datamapper.rb +13 -18
- data/lib/bowtie/adapters/mongomapper.rb +9 -6
- data/lib/bowtie/admin.rb +4 -3
- data/lib/bowtie/helpers.rb +8 -8
- data/lib/bowtie/views/errors.erb +2 -8
- data/lib/bowtie/views/layout.erb +0 -1
- metadata +3 -3
data/bowtie.gemspec
CHANGED
@@ -4,27 +4,22 @@ module Bowtie
|
|
4
4
|
DataMapper::Model.descendants.to_a
|
5
5
|
end
|
6
6
|
|
7
|
-
def self.search(
|
8
|
-
|
9
|
-
params.each do |key, val|
|
10
|
-
query1 << "#{model}.all(:#{key} => '#{val}')"
|
11
|
-
end
|
7
|
+
def self.search(model, q, page)
|
8
|
+
query = {}
|
12
9
|
model.searchable_fields.each do |field|
|
13
|
-
|
10
|
+
query[field.like] = "%#{q}%"
|
14
11
|
end
|
15
|
-
|
16
|
-
@resources = eval(query).page(page, :per_page => PER_PAGE)
|
17
|
-
@subtypes = model.subtypes
|
12
|
+
model.all(query).page(page, :per_page => PER_PAGE)
|
18
13
|
end
|
19
14
|
|
20
15
|
def self.get_many(model, params, page)
|
21
16
|
add_paging(model.all(params), page)
|
22
17
|
end
|
23
|
-
|
18
|
+
|
24
19
|
def self.get_one(model, id)
|
25
|
-
model.get(id)
|
20
|
+
model.get(id)
|
26
21
|
end
|
27
|
-
|
22
|
+
|
28
23
|
def self.create(model, params)
|
29
24
|
model.create(params)
|
30
25
|
end
|
@@ -35,7 +30,7 @@ module Bowtie
|
|
35
30
|
# add_paging(res, params)
|
36
31
|
# end
|
37
32
|
end
|
38
|
-
|
33
|
+
|
39
34
|
# doesnt trigger validations or callbacks
|
40
35
|
def self.update!(resource, params)
|
41
36
|
resource.update!(params)
|
@@ -48,7 +43,7 @@ module Bowtie
|
|
48
43
|
def self.add_paging(resources, page)
|
49
44
|
resources.respond_to?(:page) ? resources.page(page, :per_page => PER_PAGE) : resources
|
50
45
|
end
|
51
|
-
|
46
|
+
|
52
47
|
def self.belongs_to_association?(assoc)
|
53
48
|
assoc.class == DataMapper::Associations::ManyToOne::Relationship
|
54
49
|
end
|
@@ -57,13 +52,13 @@ module Bowtie
|
|
57
52
|
assoc.class == DataMapper::Associations::OneToOne::Relationship
|
58
53
|
end
|
59
54
|
|
60
|
-
# i have to say this: datamapper sucks. when calling record.association.count
|
55
|
+
# i have to say this: datamapper sucks. when calling record.association.count
|
61
56
|
# it actually fetches all the records, builds an array and then calls count on
|
62
57
|
# that array.
|
63
58
|
def self.get_count(record, association)
|
64
59
|
association_key = "#{record.class.name.downcase}_#{record.class.primary_key}"
|
65
60
|
begin
|
66
|
-
repository.adapter.select("select count(*) from #{association} where #{association_key} = ?", record.primary_key)
|
61
|
+
repository.adapter.select("select count(*) from #{association} where #{association_key} = ?", record.primary_key)
|
67
62
|
rescue DataObjects::SQLError => e # probably has_many :through => association
|
68
63
|
''
|
69
64
|
end
|
@@ -74,11 +69,11 @@ module Bowtie
|
|
74
69
|
def total_entries(resources)
|
75
70
|
resources.respond_to?(:pager) ? resources.pager.total : resources.count
|
76
71
|
end
|
77
|
-
|
72
|
+
|
78
73
|
def show_pager(resources, path)
|
79
74
|
resources.pager.to_html(base_path + path) if resources.respond_to?(:pager)
|
80
75
|
end
|
81
|
-
|
76
|
+
|
82
77
|
end
|
83
78
|
|
84
79
|
end
|
@@ -6,9 +6,12 @@ module Bowtie
|
|
6
6
|
# models
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.search(
|
10
|
-
|
11
|
-
|
9
|
+
def self.search(model, q, page)
|
10
|
+
res = []
|
11
|
+
model.searchable_fields.each do |field|
|
12
|
+
res = res + model.all(field.to_sym => /#{q}/i)
|
13
|
+
end
|
14
|
+
res.uniq
|
12
15
|
end
|
13
16
|
|
14
17
|
def self.get_many(model, params, page)
|
@@ -16,7 +19,7 @@ module Bowtie
|
|
16
19
|
end
|
17
20
|
|
18
21
|
def self.get_one(model, id)
|
19
|
-
model.find(id)
|
22
|
+
model.find(id)
|
20
23
|
end
|
21
24
|
|
22
25
|
def self.create(model, params)
|
@@ -43,7 +46,7 @@ module Bowtie
|
|
43
46
|
def self.belongs_to_association?(assoc)
|
44
47
|
assoc.class == MongoMapper::Plugins::Associations::BelongsToAssociation
|
45
48
|
end
|
46
|
-
|
49
|
+
|
47
50
|
def self.has_one_association?(assoc)
|
48
51
|
assoc.class == MongoMapper::Plugins::Associations::OneAssociation
|
49
52
|
end
|
@@ -105,7 +108,7 @@ class Class
|
|
105
108
|
|
106
109
|
def searchable_fields
|
107
110
|
s = []
|
108
|
-
self.keys.each {|k,v| s << k if v.type == String}
|
111
|
+
self.keys.each {|k,v| s << k if v.type == String && k != "_type"}
|
109
112
|
s.compact
|
110
113
|
end
|
111
114
|
|
data/lib/bowtie/admin.rb
CHANGED
@@ -28,7 +28,7 @@ module Bowtie
|
|
28
28
|
@models = Bowtie.models
|
29
29
|
end
|
30
30
|
|
31
|
-
get '/*.js|css|png|jpg' do
|
31
|
+
get '/*.js|css|png|jpg|ico' do
|
32
32
|
deliver_file or status 404
|
33
33
|
end
|
34
34
|
|
@@ -42,8 +42,8 @@ module Bowtie
|
|
42
42
|
end
|
43
43
|
|
44
44
|
get '/search*' do
|
45
|
-
redirect('/' + params[:model] ||= '') if params[:q].
|
46
|
-
@resources = Bowtie.search(
|
45
|
+
redirect('/' + params[:model] ||= '') if params[:q].nil? or params[:q].empty?
|
46
|
+
@resources = Bowtie.search(model, params[:q], params[:page])
|
47
47
|
@subtypes = model.subtypes
|
48
48
|
erb :index
|
49
49
|
end
|
@@ -77,6 +77,7 @@ module Bowtie
|
|
77
77
|
@title = "#{params[:association].titleize} for #{model.to_s.titleize} ##{params[:id]}"
|
78
78
|
res = Bowtie.get_associated(model, params)
|
79
79
|
|
80
|
+
@model = get_model_class(params[:association])
|
80
81
|
redirect('/' + model.linkable + '?error=doesnt+exist') if res.nil? or (res.is_a?(Array) and res.empty?)
|
81
82
|
|
82
83
|
if res.is_a?(Array)
|
data/lib/bowtie/helpers.rb
CHANGED
@@ -9,10 +9,10 @@ module Bowtie
|
|
9
9
|
# requests, redirects
|
10
10
|
|
11
11
|
def deliver_file
|
12
|
-
|
13
|
-
return false unless File.exist?(
|
14
|
-
content_type(Rack::Mime::MIME_TYPES[File.extname(
|
15
|
-
File.read(
|
12
|
+
path = File.expand_path(File.dirname(__FILE__)) + "/public#{@env['PATH_INFO']}"
|
13
|
+
return false unless File.exist?(path)
|
14
|
+
content_type(Rack::Mime::MIME_TYPES[File.extname(path)], :charset => 'utf-8')
|
15
|
+
File.read(path)
|
16
16
|
end
|
17
17
|
|
18
18
|
def redirect(uri, *args)
|
@@ -20,14 +20,14 @@ module Bowtie
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def clean_params
|
23
|
-
|
23
|
+
@env['rack.request.query_hash'].delete_if{|a,b| %w(model page notice error q).include?(a) }
|
24
24
|
end
|
25
25
|
|
26
26
|
# models, resources
|
27
27
|
|
28
|
-
def get_model_class
|
28
|
+
def get_model_class(mod = params[:model])
|
29
29
|
begin
|
30
|
-
Kernel.const_get(
|
30
|
+
Kernel.const_get(mod.singularize.capitalize)
|
31
31
|
rescue NameError
|
32
32
|
halt 404, "Model not found!"
|
33
33
|
end
|
@@ -72,7 +72,7 @@ module Bowtie
|
|
72
72
|
def render_assoc_header(rel_name, assoc)
|
73
73
|
"<th title='#{assoc.class.name.to_s[/.*::(.*)$/, 1]}' class='rel-col #{rel_name}-col'>#{rel_name.to_s.titleize}</th>"
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def render_assoc_row(r, rel_name, assoc)
|
77
77
|
html = "<td class='rel-col #{rel_name.to_s}-col'>"
|
78
78
|
html += "<a href='#{model_path}/#{r.id}/#{rel_name.to_s}'>"
|
data/lib/bowtie/views/errors.erb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
<%
|
2
|
-
|
3
|
-
if @resource and @resource.errors.any? %>
|
1
|
+
<% if @resource and @resource.errors.any? %>
|
4
2
|
|
5
3
|
<div class="errorlist">
|
6
4
|
|
@@ -12,8 +10,4 @@ if @resource and @resource.errors.any? %>
|
|
12
10
|
|
13
11
|
</div>
|
14
12
|
|
15
|
-
<% end
|
16
|
-
|
17
|
-
rescue NoMethodError => e
|
18
|
-
# dm-validations not included
|
19
|
-
end %>
|
13
|
+
<% end %>
|
data/lib/bowtie/views/layout.erb
CHANGED
@@ -8,7 +8,6 @@
|
|
8
8
|
<script type="text/javascript" src="<%= base_path %>/js/jquery.jeditable.pack.js"></script>
|
9
9
|
<script type="text/javascript" src="<%= base_path %>/js/jquery.tablesorter.pack.js"></script>
|
10
10
|
<script type="text/javascript" src="<%= base_path %>/js/bowtie.js">
|
11
|
-
|
12
11
|
</script>
|
13
12
|
</head>
|
14
13
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bowtie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 7
|
10
|
+
version: 0.4.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Tom\xC3\xA1s Pollak"
|