bowtie 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +26 -10
- data/bowtie.gemspec +30 -30
- data/lib/bowtie/admin.rb +5 -13
- data/lib/bowtie/helpers.rb +32 -14
- data/lib/bowtie/public/css/bowtie.css +0 -15
- data/lib/bowtie/views/errors.erb +2 -2
- data/lib/bowtie/views/layout.erb +4 -4
- data/lib/bowtie/views/show.erb +0 -10
- metadata +6 -6
data/README.md
CHANGED
@@ -22,14 +22,14 @@ Or install it by hand:
|
|
22
22
|
|
23
23
|
## Configuration
|
24
24
|
|
25
|
-
|
25
|
+
### Sinatra
|
26
|
+
Mount Bowtie wherever you want by editing your `config.ru` file, after loading your models. You can optionally include the admin/pass combination for the panel.
|
26
27
|
|
27
28
|
require 'my_app' # models are loaded
|
28
29
|
require 'bowtie'
|
29
30
|
|
30
|
-
BOWTIE_AUTH = {:user => 'admin', :pass => '12345'}
|
31
|
-
|
32
31
|
map "/admin" do
|
32
|
+
BOWTIE_AUTH = {:user => 'admin', :pass => '12345'}
|
33
33
|
run Bowtie::Admin
|
34
34
|
end
|
35
35
|
|
@@ -37,12 +37,33 @@ Mount Bowtie wherever you want by editing your config.ru file, after loading you
|
|
37
37
|
run MyApp
|
38
38
|
end
|
39
39
|
|
40
|
+
### Rails 3
|
41
|
+
Mount Bowtie in your `config/routes.rb` file with the new Rails 3 mount function. You can also optionally include the admin/pass combination for the panel.
|
42
|
+
|
43
|
+
Rails::Application.routes.draw.do
|
44
|
+
# your other routes
|
45
|
+
BOWTIE_AUTH = {:user => 'admin', :pass => '12345'}
|
46
|
+
mount Bowtie::Admin, :at => '/admin'
|
47
|
+
end
|
48
|
+
|
49
|
+
Additionally you need to make sure that all models have been loaded because Rails only models them on demand and Bowtie only sees loaded models. Paste this into a new initializer `config/initializers/bowtie.rb`
|
50
|
+
|
51
|
+
Dir[Rails.root + 'app/models/**/*.rb'].each do |path|
|
52
|
+
require path
|
53
|
+
end
|
54
|
+
|
55
|
+
### Try it out!
|
40
56
|
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.
|
41
57
|
|
42
58
|
## Important notes
|
43
59
|
|
44
60
|
Bowtie requires a few gems but they're not included in the gemspec to prevent forcing your from installing unneeded gems. Therefore you need to make sure that Bowtie will have the following gems to work with:
|
45
61
|
|
62
|
+
For MongoMapper models:
|
63
|
+
|
64
|
+
* mongo_mapper
|
65
|
+
* bson_ext (not required, but recommended)
|
66
|
+
|
46
67
|
For DataMapper models:
|
47
68
|
|
48
69
|
* dm-core
|
@@ -50,13 +71,8 @@ For DataMapper models:
|
|
50
71
|
* dm-aggregates
|
51
72
|
* dm-pager
|
52
73
|
|
53
|
-
For
|
54
|
-
|
55
|
-
* mongo_mapper
|
56
|
-
* bson_ext (not required, but recommended)
|
57
|
-
|
58
|
-
From version 0.3, Bowtie is meant to be used from DataMapper 1.0.0 on. For previous versions of DM please install with -v=0.2.5.
|
74
|
+
Note: From version 0.3, Bowtie is meant to be used from DataMapper 1.0.0 on. For previous versions of DM please install with -v=0.2.5.
|
59
75
|
|
60
76
|
## Copyright
|
61
77
|
|
62
|
-
(c) 2010-
|
78
|
+
(c) 2010-2012 - Tomás Pollak for Fork Ltd. Released under the MIT license.
|
data/bowtie.gemspec
CHANGED
@@ -1,48 +1,48 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{bowtie}
|
3
|
-
s.version = "0.5.
|
3
|
+
s.version = "0.5.2"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Tomás Pollak"]
|
7
|
-
s.date = %q{2010-06-06}
|
8
|
-
s.description = %q{Simple admin scaffold for MongoMapper and DataMapper models.}
|
9
7
|
s.email = %q{tomas@forkhq.com}
|
10
|
-
s.
|
11
|
-
|
12
|
-
|
8
|
+
s.date = %q{2012-04-16}
|
9
|
+
s.description = %q{Simple admin scaffold for MongoMapper and DataMapper models.}
|
10
|
+
s.rubyforge_project = %q{bowtie}
|
11
|
+
s.summary = %q{MongoMapper & DataMapper admin interface}
|
12
|
+
s.extra_rdoc_files = [ "lib/bowtie.rb",
|
13
|
+
"lib/bowtie/admin.rb",
|
14
|
+
"lib/bowtie/core_extensions.rb",
|
13
15
|
"lib/bowtie/helpers.rb" ]
|
14
16
|
|
15
|
-
s.files = [ "README.md",
|
16
|
-
"bowtie.gemspec",
|
17
|
-
"lib/bowtie.rb",
|
18
|
-
"lib/bowtie/adapters/datamapper.rb",
|
19
|
-
"lib/bowtie/adapters/mongomapper.rb",
|
20
|
-
"lib/bowtie/admin.rb",
|
21
|
-
"lib/bowtie/core_extensions.rb",
|
22
|
-
"lib/bowtie/helpers.rb",
|
23
|
-
"lib/bowtie/views/errors.erb",
|
24
|
-
"lib/bowtie/views/field.erb",
|
25
|
-
"lib/bowtie/views/flash.erb",
|
26
|
-
"lib/bowtie/views/form.erb",
|
27
|
-
"lib/bowtie/views/index.erb",
|
28
|
-
"lib/bowtie/views/layout.erb",
|
29
|
-
"lib/bowtie/views/new.erb",
|
30
|
-
"lib/bowtie/views/search.erb",
|
31
|
-
"lib/bowtie/views/show.erb",
|
17
|
+
s.files = [ "README.md",
|
18
|
+
"bowtie.gemspec",
|
19
|
+
"lib/bowtie.rb",
|
20
|
+
"lib/bowtie/adapters/datamapper.rb",
|
21
|
+
"lib/bowtie/adapters/mongomapper.rb",
|
22
|
+
"lib/bowtie/admin.rb",
|
23
|
+
"lib/bowtie/core_extensions.rb",
|
24
|
+
"lib/bowtie/helpers.rb",
|
25
|
+
"lib/bowtie/views/errors.erb",
|
26
|
+
"lib/bowtie/views/field.erb",
|
27
|
+
"lib/bowtie/views/flash.erb",
|
28
|
+
"lib/bowtie/views/form.erb",
|
29
|
+
"lib/bowtie/views/index.erb",
|
30
|
+
"lib/bowtie/views/layout.erb",
|
31
|
+
"lib/bowtie/views/new.erb",
|
32
|
+
"lib/bowtie/views/search.erb",
|
33
|
+
"lib/bowtie/views/show.erb",
|
32
34
|
"lib/bowtie/views/subtypes.erb",
|
33
|
-
"lib/bowtie/views/table.erb",
|
34
|
-
"lib/bowtie/views/row.erb",
|
35
|
-
"lib/bowtie/public/css/bowtie.css",
|
36
|
-
"lib/bowtie/public/js/bowtie.js",
|
37
|
-
"lib/bowtie/public/js/jquery.tablesorter.pack.js",
|
35
|
+
"lib/bowtie/views/table.erb",
|
36
|
+
"lib/bowtie/views/row.erb",
|
37
|
+
"lib/bowtie/public/css/bowtie.css",
|
38
|
+
"lib/bowtie/public/js/bowtie.js",
|
39
|
+
"lib/bowtie/public/js/jquery.tablesorter.pack.js",
|
38
40
|
"lib/bowtie/public/js/jquery.jeditable.pack.js" ]
|
39
41
|
|
40
42
|
s.homepage = %q{http://github.com/tomas/bowtie}
|
41
43
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bowtie", "--main", "README"]
|
42
44
|
s.require_paths = ["lib"]
|
43
|
-
s.rubyforge_project = %q{bowtie}
|
44
45
|
s.rubygems_version = %q{1.3.5}
|
45
|
-
s.summary = %q{Bowtie Admin Scaffold}
|
46
46
|
|
47
47
|
if s.respond_to? :specification_version then
|
48
48
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/lib/bowtie/admin.rb
CHANGED
@@ -6,11 +6,9 @@ module Bowtie
|
|
6
6
|
|
7
7
|
use Rack::Auth::Basic do |username, password|
|
8
8
|
begin
|
9
|
-
user = ::BOWTIE_AUTH[:user]
|
10
|
-
pass = ::BOWTIE_AUTH[:pass]
|
9
|
+
user, pass = ::BOWTIE_AUTH[:user], ::BOWTIE_AUTH[:pass]
|
11
10
|
rescue NameError
|
12
|
-
user = 'admin'
|
13
|
-
pass = 'bowtie'
|
11
|
+
user, pass = 'admin', 'bowtie'
|
14
12
|
end
|
15
13
|
username == user && password == pass
|
16
14
|
end
|
@@ -18,28 +16,22 @@ module Bowtie
|
|
18
16
|
use Rack::MethodOverride
|
19
17
|
|
20
18
|
set :views, File.dirname(__FILE__) + '/views'
|
21
|
-
set :absolute_redirects, false # otherwise Sinatra appends the domain name to the redirect
|
22
19
|
|
23
20
|
helpers do
|
24
21
|
include Helpers
|
25
22
|
end
|
26
23
|
|
27
|
-
before do
|
28
|
-
@app_name = ENV['APP_NAME'] ? [self.class.name, ENV['APP_NAME']].join(' > ') : self.class.name
|
29
|
-
@models = Bowtie.models
|
30
|
-
end
|
31
|
-
|
32
24
|
get '/*.js|css|png|jpg|ico' do
|
33
25
|
deliver_file or status 404
|
34
26
|
end
|
35
27
|
|
36
28
|
get '/' do
|
37
29
|
# redirect '' results in an endless redirect on the current version of sinatra/rack
|
38
|
-
redirect '/' +
|
30
|
+
redirect '/' + mappings.keys.first
|
39
31
|
end
|
40
32
|
|
41
33
|
get '' do
|
42
|
-
redirect '/' +
|
34
|
+
redirect '/' + mappings.keys.first
|
43
35
|
end
|
44
36
|
|
45
37
|
get '/search*' do
|
@@ -79,7 +71,7 @@ module Bowtie
|
|
79
71
|
res = Bowtie.get_associated(model, params)
|
80
72
|
|
81
73
|
@model = get_model_class(params[:association])
|
82
|
-
redirect
|
74
|
+
redirect('/' + model.linkable + '?error=doesnt+exist') if res.nil? or (res.is_a?(Array) and res.empty?)
|
83
75
|
|
84
76
|
if res.is_a?(Array)
|
85
77
|
@resources = Bowtie.add_paging(res, params[:page])
|
data/lib/bowtie/helpers.rb
CHANGED
@@ -2,6 +2,18 @@ module Bowtie
|
|
2
2
|
|
3
3
|
module Helpers
|
4
4
|
|
5
|
+
def app_name
|
6
|
+
defined?(APP_NAME) ? APP_NAME : ENV['APP_NAME'] || "Bowtie::#{adapter_name}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def adapter_name
|
10
|
+
defined?(DataMapper) ? "DataMapper" : "MongoMapper"
|
11
|
+
end
|
12
|
+
|
13
|
+
def action_name
|
14
|
+
current_model.pluralize
|
15
|
+
end
|
16
|
+
|
5
17
|
def base_path
|
6
18
|
env['SCRIPT_NAME']
|
7
19
|
end
|
@@ -18,10 +30,6 @@ module Bowtie
|
|
18
30
|
def redirect(uri, *args)
|
19
31
|
super base_path + uri.downcase, *args
|
20
32
|
end
|
21
|
-
|
22
|
-
def referer
|
23
|
-
URI.parse(@env['HTTP_REFERER']).path.sub("#{base_path}", '')
|
24
|
-
end
|
25
33
|
|
26
34
|
def clean_params
|
27
35
|
@env['rack.request.query_hash'].delete_if{|a,b| %w(model page notice error q).include?(a) }
|
@@ -29,26 +37,32 @@ module Bowtie
|
|
29
37
|
|
30
38
|
# models, resources
|
31
39
|
|
40
|
+
def mappings
|
41
|
+
@mappings ||= get_mappings
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_mappings
|
45
|
+
mappings = {}
|
46
|
+
Bowtie.models.collect{|m| mappings[m.linkable] = m }
|
47
|
+
mappings
|
48
|
+
end
|
49
|
+
|
32
50
|
def get_model_class(mod = params[:model])
|
33
|
-
|
34
|
-
Kernel.const_get(mod.singularize.capitalize)
|
35
|
-
rescue NameError
|
36
|
-
halt 404, "Model not found!"
|
37
|
-
end
|
51
|
+
mappings[mod] or halt(404, "Model not found.")
|
38
52
|
end
|
39
53
|
|
40
54
|
def model
|
41
55
|
@model ||= get_model_class
|
42
56
|
end
|
43
57
|
|
44
|
-
def resource
|
45
|
-
Bowtie.get_one(model, params[:id]) or halt(404, 'Resource not found!')
|
46
|
-
end
|
47
|
-
|
48
58
|
def current_model
|
49
59
|
model
|
50
60
|
end
|
51
61
|
|
62
|
+
def resource
|
63
|
+
Bowtie.get_one(model, params[:id]) or halt(404, 'Resource not found!')
|
64
|
+
end
|
65
|
+
|
52
66
|
# views, paths
|
53
67
|
|
54
68
|
def partial(name, *args)
|
@@ -57,7 +71,11 @@ module Bowtie
|
|
57
71
|
|
58
72
|
def model_path(m = current_model)
|
59
73
|
string = m.name ||= m
|
60
|
-
|
74
|
+
linkable_path(string.to_s.pluralize.downcase)
|
75
|
+
end
|
76
|
+
|
77
|
+
def linkable_path(linkable)
|
78
|
+
base_path + '/' + linkable
|
61
79
|
end
|
62
80
|
|
63
81
|
def url_for(resource)
|
@@ -287,21 +287,6 @@ table tr:hover td{
|
|
287
287
|
background: #ffffed;
|
288
288
|
}
|
289
289
|
|
290
|
-
|
291
|
-
/* show resource
|
292
|
-
-------------------------------------------------------------*/
|
293
|
-
|
294
|
-
#assocs{
|
295
|
-
float: right;
|
296
|
-
font-size: 1.2em;
|
297
|
-
border: 1px solid #333;
|
298
|
-
padding: 5px 10px;
|
299
|
-
margin-top: 15px;
|
300
|
-
-moz-border-radius: 5px;
|
301
|
-
-webkit-border-radius: 5px;
|
302
|
-
background-color: #fafafa;
|
303
|
-
}
|
304
|
-
|
305
290
|
/* forms
|
306
291
|
-------------------------------------------------------------*/
|
307
292
|
|
data/lib/bowtie/views/errors.erb
CHANGED
data/lib/bowtie/views/layout.erb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
3
3
|
<head profile="http://gmpg.org/xfn/11">
|
4
4
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
5
|
-
<title><%=
|
5
|
+
<title><%= action_name %> - <%= app_name %></title>
|
6
6
|
<link rel="stylesheet" href="<%= base_path %>/css/bowtie.css" type="text/css" media="screen" charset="utf-8" />
|
7
7
|
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
|
8
8
|
<script type="text/javascript" src="<%= base_path %>/js/jquery.jeditable.pack.js"></script>
|
@@ -18,12 +18,12 @@
|
|
18
18
|
<div id="header">
|
19
19
|
|
20
20
|
<h1>
|
21
|
-
<a href="<%= base_path %>"><%=
|
21
|
+
<a href="<%= base_path %>"><%= app_name %></a>
|
22
22
|
</h1>
|
23
23
|
|
24
24
|
<ul class="nav">
|
25
|
-
<%
|
26
|
-
<li class="<%= 'current' if @model && @model ==
|
25
|
+
<% mappings.each do |linkable, model| %>
|
26
|
+
<li class="<%= 'current' if @model && @model == model %>"><a href="<%= linkable_path(linkable) %>"><%= model.pluralize %></a></li>
|
27
27
|
<% end %>
|
28
28
|
</ul>
|
29
29
|
|
data/lib/bowtie/views/show.erb
CHANGED
@@ -1,13 +1,3 @@
|
|
1
|
-
|
2
|
-
<div id="assocs">
|
3
|
-
|
4
|
-
<% @model.model_associations.each do |rel_name, assoc| %>
|
5
|
-
<%= rel_name %>: <strong><%= render_assoc_row(@resource, rel_name, assoc) %></strong>
|
6
|
-
<% end %>
|
7
|
-
|
8
|
-
</div><!-- /assocs -->
|
9
|
-
|
10
|
-
|
11
1
|
<h1><%= @title || @model.name + ':' + @resource.id.to_s %></h1>
|
12
2
|
|
13
3
|
<form class="big destroy" method="post" action="<%= model_path(@resource.class) %>/<%= @resource.id %>" onsubmit="return confirm('Are you sure?');">
|
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: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Tom\xC3\xA1s Pollak"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-04-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: sinatra
|
@@ -104,9 +104,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
requirements: []
|
105
105
|
|
106
106
|
rubyforge_project: bowtie
|
107
|
-
rubygems_version: 1.8.
|
107
|
+
rubygems_version: 1.8.21
|
108
108
|
signing_key:
|
109
109
|
specification_version: 3
|
110
|
-
summary:
|
110
|
+
summary: MongoMapper & DataMapper admin interface
|
111
111
|
test_files: []
|
112
112
|
|