Permalink
Browse files

Resolved conflicts from origin

  • Loading branch information...
2 parents 475ba99 + e9173b7 commit ca5b9c34199652918ce0113bb788ab006497d15d @tomas committed Apr 17, 2012
Showing with 84 additions and 67 deletions.
  1. +2 −0 .gitignore
  2. +30 −30 bowtie.gemspec
  3. +4 −11 lib/bowtie/admin.rb
  4. +32 −10 lib/bowtie/helpers.rb
  5. +2 −2 lib/bowtie/views/errors.erb
  6. +4 −4 lib/bowtie/views/layout.erb
  7. +10 −10 test/mongomapper.rb
View
@@ -0,0 +1,2 @@
+*~
+*.sqlite3
View
@@ -1,48 +1,48 @@
Gem::Specification.new do |s|
s.name = %q{bowtie}
- s.version = "0.5.0"
+ s.version = "0.5.2"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Tomás Pollak"]
- s.date = %q{2010-06-06}
- s.description = %q{Simple admin scaffold for MongoMapper and DataMapper models.}
s.email = %q{tomas@forkhq.com}
- s.extra_rdoc_files = [ "lib/bowtie.rb",
- "lib/bowtie/admin.rb",
- "lib/bowtie/core_extensions.rb",
+ s.date = %q{2012-04-16}
+ s.description = %q{Simple admin scaffold for MongoMapper and DataMapper models.}
+ s.rubyforge_project = %q{bowtie}
+ s.summary = %q{MongoMapper & DataMapper admin interface}
+ s.extra_rdoc_files = [ "lib/bowtie.rb",
+ "lib/bowtie/admin.rb",
+ "lib/bowtie/core_extensions.rb",
"lib/bowtie/helpers.rb" ]
- s.files = [ "README.md",
- "bowtie.gemspec",
- "lib/bowtie.rb",
- "lib/bowtie/adapters/datamapper.rb",
- "lib/bowtie/adapters/mongomapper.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/show.erb",
+ s.files = [ "README.md",
+ "bowtie.gemspec",
+ "lib/bowtie.rb",
+ "lib/bowtie/adapters/datamapper.rb",
+ "lib/bowtie/adapters/mongomapper.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/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/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" ]
s.homepage = %q{http://github.com/tomas/bowtie}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bowtie", "--main", "README"]
s.require_paths = ["lib"]
- s.rubyforge_project = %q{bowtie}
s.rubygems_version = %q{1.3.5}
- s.summary = %q{Bowtie Admin Scaffold}
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
View
@@ -6,11 +6,9 @@ class Admin < Sinatra::Base
use Rack::Auth::Basic do |username, password|
begin
- user = ::BOWTIE_AUTH[:user]
- pass = ::BOWTIE_AUTH[:pass]
+ user, pass = ::BOWTIE_AUTH[:user], ::BOWTIE_AUTH[:pass]
rescue NameError
- user = 'admin'
- pass = 'bowtie'
+ user, pass = 'admin', 'bowtie'
end
username == user && password == pass
end
@@ -23,22 +21,17 @@ class Admin < Sinatra::Base
include Helpers
end
- before do
- @app_name = ENV['APP_NAME'] ? [self.class.name, ENV['APP_NAME']].join(' > ') : self.class.name
- @models = Bowtie.models
- end
-
get '/*.js|css|png|jpg|ico' do
deliver_file or status 404
end
get '/' do
# redirect '' results in an endless redirect on the current version of sinatra/rack
- redirect '/' + @models.first.linkable
+ redirect '/' + mappings.keys.first
end
get '' do
- redirect '/' + @models.first.linkable
+ redirect '/' + mappings.keys.first
end
get '/search*' do
View
@@ -2,6 +2,18 @@ module Bowtie
module Helpers
+ def app_name
+ defined?(APP_NAME) ? APP_NAME : ENV['APP_NAME'] || "Bowtie::#{adapter_name}"
+ end
+
+ def adapter_name
+ defined?(DataMapper) ? "DataMapper" : "MongoMapper"
+ end
+
+ def action_name
+ current_model.pluralize
+ end
+
def base_path
env['SCRIPT_NAME']
end
@@ -29,26 +41,32 @@ def clean_params
# models, resources
+ def mappings
+ @mappings ||= get_mappings
+ end
+
+ def get_mappings
+ mappings = {}
+ Bowtie.models.collect{|m| mappings[m.linkable] = m }
+ mappings
+ end
+
def get_model_class(mod = params[:model])
- begin
- Kernel.const_get(mod.singularize.capitalize)
- rescue NameError
- halt 404, "Model not found!"
- end
+ mappings[mod] or halt(404, "Model not found.")
end
def model
@model ||= get_model_class
end
- def resource
- Bowtie.get_one(model, params[:id]) or halt(404, 'Resource not found!')
- end
-
def current_model
model
end
+ def resource
+ Bowtie.get_one(model, params[:id]) or halt(404, 'Resource not found!')
+ end
+
# views, paths
def partial(name, *args)
@@ -57,7 +75,11 @@ def partial(name, *args)
def model_path(m = current_model)
string = m.name ||= m
- base_path + '/' + string.to_s.pluralize.downcase
+ linkable_path(string.to_s.pluralize.downcase)
+ end
+
+ def linkable_path(linkable)
+ base_path + '/' + linkable
end
def url_for(resource)
@@ -3,8 +3,8 @@
<div class="errorlist">
<ul>
- <% @resource.errors.each do |message| %>
- <li><%= message %></li>
+ <% @resource.errors.each do |key, message| %>
+ <li><strong><%= key %></strong> <%= ":#{message}" if message %></li>
<% end %>
</ul>
@@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
- <title><%= @app_name %></title>
+ <title><%= action_name %> - <%= app_name %></title>
<link rel="stylesheet" href="<%= base_path %>/css/bowtie.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="<%= base_path %>/js/jquery.jeditable.pack.js"></script>
@@ -18,12 +18,12 @@
<div id="header">
<h1>
- <a href="<%= base_path %>"><%= @app_name %></a>
+ <a href="<%= base_path %>"><%= app_name %></a>
</h1>
<ul class="nav">
- <% @models.each do |m| %>
- <li class="<%= 'current' if @model && @model == m %>"><a href="<%= model_path(m) %>"><%= m.pluralize %></a></li>
+ <% mappings.each do |linkable, model| %>
+ <li class="<%= 'current' if @model && @model == model %>"><a href="<%= linkable_path(linkable) %>"><%= model.pluralize %></a></li>
<% end %>
</ul>
View
@@ -5,7 +5,7 @@
db = MongoMapper.database = 'bowtie_test'
class City
- include MongoMapper::Document
+ include MongoMapper::Document
many :places
one :major
@@ -15,23 +15,23 @@ class City
end
class Major
- include MongoMapper::Document
+ include MongoMapper::Document
- belongs_to :city
+ belongs_to :city
- key :first_name, String
- key :last_name, String
+ key :first_name, String
+ key :last_name, String
end
class Place
- include MongoMapper::Document
+ include MongoMapper::Document
belongs_to :city
- key :name, String, :required => true
- key :address, String
- key :open_on_sundays, Boolean, :default => true
- key :created_at, Time
+ key :name, String, :required => true
+ key :address, String
+ key :open_on_sundays, Boolean, :default => true
+ key :created_at, Time
end
class Restaurant < Place

0 comments on commit ca5b9c3

Please sign in to comment.