bowtie 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +44 -0
- data/bowtie.gemspec +4 -4
- data/lib/bowtie/admin.rb +8 -3
- data/lib/bowtie/core_extensions.rb +6 -1
- data/lib/bowtie/helpers.rb +16 -11
- metadata +46 -23
- data/README +0 -20
data/README.rdoc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= Bowtie for Sinatra.
|
2
|
+
|
3
|
+
Zeroconf admin generator for DataMapper models, written in Sinatra.
|
4
|
+
|
5
|
+
= What it does
|
6
|
+
|
7
|
+
Reads the information on your models and creates a nice panel in which you can view, edit and destroy records easily.
|
8
|
+
|
9
|
+
= Installation
|
10
|
+
|
11
|
+
$ sudo gem install bowtie
|
12
|
+
|
13
|
+
= Configuration
|
14
|
+
|
15
|
+
Mount Bowtie wherever you want by editing your config.ru file, optionally including the admin/pass combination for the panel.
|
16
|
+
|
17
|
+
require 'myapp'
|
18
|
+
require 'bowtie'
|
19
|
+
|
20
|
+
BOWTIE_AUTH = {:user => 'admin', :pass => '12345' }
|
21
|
+
|
22
|
+
app = Rack::Builder.new {
|
23
|
+
map "/admin" do
|
24
|
+
run Bowtie::Admin
|
25
|
+
end
|
26
|
+
|
27
|
+
map '/' do
|
28
|
+
run MyApp
|
29
|
+
end
|
30
|
+
}
|
31
|
+
|
32
|
+
run app
|
33
|
+
|
34
|
+
Now you can go to /admin in your app's path and try out Bowtie using your user/pass combination. If not set, it defaults to admin/bowtie.
|
35
|
+
|
36
|
+
= TODO
|
37
|
+
|
38
|
+
* Better handling of types (Text, JSON, IPAddress) in #show
|
39
|
+
* Better handling of relationships in #show
|
40
|
+
|
41
|
+
= Copyright
|
42
|
+
|
43
|
+
(c) 2010 - Tomás Pollak for Fork Ltd.
|
44
|
+
Released under the MIT license.
|
data/bowtie.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = %q{bowtie}
|
4
|
-
s.version = "0.
|
4
|
+
s.version = "0.2"
|
5
5
|
|
6
6
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
7
7
|
s.authors = ["Tomás Pollak"]
|
8
|
-
s.date = %q{2010-
|
9
|
-
s.description = %q{
|
8
|
+
s.date = %q{2010-06-06}
|
9
|
+
s.description = %q{Admin scaffold for DataMapper models, on Sinatra.}
|
10
10
|
s.email = %q{tomas@usefork.com}
|
11
11
|
s.extra_rdoc_files = ["lib/bowtie.rb", "lib/bowtie/admin.rb", "lib/bowtie/core_extensions.rb", "lib/bowtie/helpers.rb"]
|
12
|
-
s.files = ["README", "bowtie.gemspec", "lib/bowtie.rb", "lib/bowtie/admin.rb", "lib/bowtie/core_extensions.rb", "lib/bowtie/helpers.rb", "lib/bowtie/views/errors.erb", "lib/bowtie/views/field.erb", "lib/bowtie/views/flash.erb", "lib/bowtie/views/form.erb", "lib/bowtie/views/index.erb", "lib/bowtie/views/layout.erb", "lib/bowtie/views/new.erb", "lib/bowtie/views/search.erb", "lib/bowtie/views/search.erb", "lib/bowtie/views/show.erb", "lib/bowtie/views/subtypes.erb", "lib/bowtie/views/table.erb", "lib/bowtie/views/row.erb", "lib/bowtie/public/css/bowtie.css", "lib/bowtie/public/js/bowtie.js", "lib/bowtie/public/js/jquery.tablesorter.pack.js", "lib/bowtie/public/js/jquery.jeditable.pack.js"]
|
12
|
+
s.files = ["README.rdoc", "bowtie.gemspec", "lib/bowtie.rb", "lib/bowtie/admin.rb", "lib/bowtie/core_extensions.rb", "lib/bowtie/helpers.rb", "lib/bowtie/views/errors.erb", "lib/bowtie/views/field.erb", "lib/bowtie/views/flash.erb", "lib/bowtie/views/form.erb", "lib/bowtie/views/index.erb", "lib/bowtie/views/layout.erb", "lib/bowtie/views/new.erb", "lib/bowtie/views/search.erb", "lib/bowtie/views/search.erb", "lib/bowtie/views/show.erb", "lib/bowtie/views/subtypes.erb", "lib/bowtie/views/table.erb", "lib/bowtie/views/row.erb", "lib/bowtie/public/css/bowtie.css", "lib/bowtie/public/js/bowtie.js", "lib/bowtie/public/js/jquery.tablesorter.pack.js", "lib/bowtie/public/js/jquery.jeditable.pack.js"]
|
13
13
|
s.homepage = %q{http://github.com/tomas/bowtie}
|
14
14
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bowtie", "--main", "README"]
|
15
15
|
s.require_paths = ["lib"]
|
data/lib/bowtie/admin.rb
CHANGED
@@ -4,9 +4,15 @@ module Bowtie
|
|
4
4
|
|
5
5
|
PER_PAGE = 25
|
6
6
|
|
7
|
-
# TODO: make this easily modifiable
|
8
7
|
use Rack::Auth::Basic do |username, password|
|
9
|
-
|
8
|
+
begin
|
9
|
+
user = ::BOWTIE_AUTH[:user]
|
10
|
+
pass = ::BOWTIE_AUTH[:pass]
|
11
|
+
rescue NameError
|
12
|
+
user = 'admin'
|
13
|
+
pass = 'bowtie'
|
14
|
+
end
|
15
|
+
username == user && password == pass
|
10
16
|
end
|
11
17
|
|
12
18
|
use Rack::MethodOverride
|
@@ -88,7 +94,6 @@ module Bowtie
|
|
88
94
|
end
|
89
95
|
|
90
96
|
put "/:model/:id" do
|
91
|
-
puts params[:resource].inspect
|
92
97
|
if resource.update(params[:resource].normalize)
|
93
98
|
request.xhr? ? resource.to_json : redirect("/#{model.pluralize}/#{params[:id]}?notice=saved")
|
94
99
|
else
|
@@ -25,7 +25,12 @@ class Class
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def subtypes
|
28
|
-
|
28
|
+
begin
|
29
|
+
self.validators.first.last.map{|a,b| b = {a.field_name => a.options[:set]} if a.class == DataMapper::Validate::WithinValidator}.compact
|
30
|
+
rescue NoMethodError
|
31
|
+
# puts ' -- dm-validations gem not included. Cannot check subtypes for class.'
|
32
|
+
[]
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
def options_for_subtype(field)
|
data/lib/bowtie/helpers.rb
CHANGED
@@ -2,6 +2,12 @@ module Bowtie
|
|
2
2
|
|
3
3
|
module Helpers
|
4
4
|
|
5
|
+
def base_path
|
6
|
+
env['SCRIPT_NAME']
|
7
|
+
end
|
8
|
+
|
9
|
+
# requests, redirects
|
10
|
+
|
5
11
|
def deliver_file
|
6
12
|
file = File.expand_path(File.dirname(__FILE__)) + "/public/#{@env['PATH_INFO']}"
|
7
13
|
return false unless File.exist?(file)
|
@@ -9,19 +15,16 @@ module Bowtie
|
|
9
15
|
File.read(file)
|
10
16
|
end
|
11
17
|
|
12
|
-
def base_path
|
13
|
-
env['SCRIPT_NAME']
|
14
|
-
end
|
15
|
-
|
16
|
-
# Sinatra's redirect is not adding path prefix. Seems like a bug to me.
|
17
18
|
def redirect(uri, *args)
|
18
19
|
super base_path + uri.downcase, *args
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
|
22
|
+
def clean_params
|
23
|
+
@env['rack.request.query_hash'].delete_if{|a,b| %w(model page notice error q).include?(a) }
|
23
24
|
end
|
24
25
|
|
26
|
+
# models, resources
|
27
|
+
|
25
28
|
def get_model_class
|
26
29
|
begin
|
27
30
|
Kernel.const_get(params[:model].singularize.capitalize)
|
@@ -30,10 +33,6 @@ module Bowtie
|
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
33
|
-
def clean_params
|
34
|
-
@env['rack.request.query_hash'].delete_if{|a,b| %w(model page notice error q).include?(a) }
|
35
|
-
end
|
36
|
-
|
37
36
|
def model
|
38
37
|
@model ||= get_model_class
|
39
38
|
end
|
@@ -46,6 +45,12 @@ module Bowtie
|
|
46
45
|
model
|
47
46
|
end
|
48
47
|
|
48
|
+
# views, paths
|
49
|
+
|
50
|
+
def partial(name, *args)
|
51
|
+
erb(name, :layout => false, *args)
|
52
|
+
end
|
53
|
+
|
49
54
|
def model_path(m = current_model)
|
50
55
|
string = m.name ||= m
|
51
56
|
base_path + '/' + string.to_s.pluralize.downcase
|
metadata
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bowtie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
version: "0.2"
|
5
9
|
platform: ruby
|
6
10
|
authors:
|
7
11
|
- "Tom\xC3\xA1s Pollak"
|
@@ -9,50 +13,66 @@ autorequire:
|
|
9
13
|
bindir: bin
|
10
14
|
cert_chain: []
|
11
15
|
|
12
|
-
date: 2010-
|
16
|
+
date: 2010-06-06 00:00:00 -04:00
|
13
17
|
default_executable:
|
14
18
|
dependencies:
|
15
19
|
- !ruby/object:Gem::Dependency
|
16
20
|
name: sinatra
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
23
|
requirements:
|
21
24
|
- - ">="
|
22
25
|
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 0
|
28
|
+
- 9
|
29
|
+
- 4
|
23
30
|
version: 0.9.4
|
24
|
-
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
25
33
|
- !ruby/object:Gem::Dependency
|
26
34
|
name: dm-core
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
38
|
- - ">="
|
32
39
|
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
- 10
|
43
|
+
- 2
|
33
44
|
version: 0.10.2
|
34
|
-
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
35
47
|
- !ruby/object:Gem::Dependency
|
36
48
|
name: dm-aggregates
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
51
|
requirements:
|
41
52
|
- - ">="
|
42
53
|
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
- 10
|
57
|
+
- 2
|
43
58
|
version: 0.10.2
|
44
|
-
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
45
61
|
- !ruby/object:Gem::Dependency
|
46
62
|
name: dm-pager
|
47
|
-
|
48
|
-
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
65
|
requirements:
|
51
66
|
- - ">="
|
52
67
|
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 1
|
70
|
+
- 0
|
71
|
+
- 1
|
53
72
|
version: 1.0.1
|
54
|
-
|
55
|
-
|
73
|
+
type: :runtime
|
74
|
+
version_requirements: *id004
|
75
|
+
description: Admin scaffold for DataMapper models, on Sinatra.
|
56
76
|
email: tomas@usefork.com
|
57
77
|
executables: []
|
58
78
|
|
@@ -64,7 +84,7 @@ extra_rdoc_files:
|
|
64
84
|
- lib/bowtie/core_extensions.rb
|
65
85
|
- lib/bowtie/helpers.rb
|
66
86
|
files:
|
67
|
-
- README
|
87
|
+
- README.rdoc
|
68
88
|
- bowtie.gemspec
|
69
89
|
- lib/bowtie.rb
|
70
90
|
- lib/bowtie/admin.rb
|
@@ -104,18 +124,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
124
|
requirements:
|
105
125
|
- - ">="
|
106
126
|
- !ruby/object:Gem::Version
|
127
|
+
segments:
|
128
|
+
- 0
|
107
129
|
version: "0"
|
108
|
-
version:
|
109
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
131
|
requirements:
|
111
132
|
- - ">="
|
112
133
|
- !ruby/object:Gem::Version
|
134
|
+
segments:
|
135
|
+
- 1
|
136
|
+
- 2
|
113
137
|
version: "1.2"
|
114
|
-
version:
|
115
138
|
requirements: []
|
116
139
|
|
117
140
|
rubyforge_project: bowtie
|
118
|
-
rubygems_version: 1.3.
|
141
|
+
rubygems_version: 1.3.6
|
119
142
|
signing_key:
|
120
143
|
specification_version: 3
|
121
144
|
summary: Bowtie Admin
|
data/README
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Bowtie for Sinatra.
|
2
|
-
|
3
|
-
Seems to work but need to do a lot of testing yet.
|
4
|
-
|
5
|
-
To try out, download and put in /lib in your app. Then in your config.ru do something like:
|
6
|
-
|
7
|
-
require 'app'
|
8
|
-
require 'bowtie'
|
9
|
-
|
10
|
-
app = Rack::Builder.new {
|
11
|
-
map "/admin" do
|
12
|
-
run Bowtie::Admin
|
13
|
-
end
|
14
|
-
|
15
|
-
map '/' do
|
16
|
-
run MyApp
|
17
|
-
end
|
18
|
-
}
|
19
|
-
|
20
|
-
run app
|