Permalink
Browse files

updated for dm-1.1 support, version bump! it's been a while

  • Loading branch information...
1 parent c9b44c9 commit 2f7e8560e2ba2e2dc68d774ca2562f1d723c7b0e @mattking17 committed Jul 1, 2011
View
@@ -8,5 +8,10 @@ def self.models
end
+begin
+ require 'extlib'
+rescue
+ require 'active_support'
+end
require 'togo/model'
require 'togo/support'
View
@@ -62,12 +62,12 @@ class Admin < Dispatch
end
get '/edit/:model/:id' do
- @content = @model.get(params[:id])
+ @content = @model.first(:id => params[:id].to_i)
erb :edit
end
post '/update/:model/:id' do
- @content = @model.stage_content(@model.get(params[:id]),params)
+ @content = @model.stage_content(@model.first(:id => params[:id].to_i),params)
begin
raise "Could not save content" if not @content.save
redirect params[:return_url] || "/#{@model.name}"
@@ -30,7 +30,7 @@ def initialize(opts = {})
@view_path = opts[:view_path] || 'views'
@path_prefix = opts[:path_prefix]
@path_prefix_regexp = Regexp.new("^#{@path_prefix}")
- ENV['RACK_ENV'] = (opts[:environment] || :development) if not ENV['RACK_ENV']
+ #ENV['RACK_ENV'] = (opts[:environment] || :development) if not ENV['RACK_ENV']
end
def symbolize_keys(hash)
View
@@ -50,7 +50,7 @@ def form_for(property,content,opts = {})
end
def update_content!(id,attrs)
- stage_content(get(id),attrs).save
+ stage_content(first(:id => id),attrs).save
end
def create_content!(attrs)
@@ -59,8 +59,8 @@ def create_content!(attrs)
def stage_content(content,attrs)
content.attributes = properties.inject({}){|m,p| attrs[p.name.to_sym] ? m.merge!(p.name.to_sym => attrs[p.name.to_sym]) : m}
- relationships.each do |r|
- val = attrs["related_#{r[0]}".to_sym]
+ relationships.each do |r|
+ val = attrs["related_#{r.name}".to_sym]
next if not val or val == 'unset'
content = RelationshipManager.create(content, r, :ids => val).relate
end
@@ -126,7 +126,7 @@ def type_from_property(property)
when ::DataMapper::Associations::OneToMany::Relationship
'has_n'
when ::DataMapper::Property
- class_variable_get(:@@inflector).demodulize(property.type || property.class).downcase # type seems to be deprecated in 1.0
+ class_variable_get(:@@inflector).demodulize(property.class).downcase # type seems to be deprecated in 1.0
else
'string'
end
@@ -163,18 +163,18 @@ def pick_properties(selection, args)
end
def shown_properties
- skip = relationships.values.collect{|r| r.through if r.respond_to?(:through) }.compact.uniq # don't include join models
- properties.select{|p| not BLACKLIST.include?(p.name) and not p.name =~ /_id$/} + relationships.values.select{|r| not skip.include?(r)}
+ skip = relationships.to_a.collect{|r| r.through if r.respond_to?(:through) }.compact.uniq # don't include join models
+ properties.select{|p| not BLACKLIST.include?(p.name) and not p.name =~ /_id$/} + relationships.to_a.select{|r| not skip.include?(r)}
end
def search_properties
# Support dm 0.10.x and 1.x by checking for deprecated(?) types
- only_properties = [String, ::DataMapper::Types::Text]
+ only_properties = [String]
begin # rescue exception when not using dm-core 1.0, these don't exist in the 0.10.x series
only_properties.concat([::DataMapper::Property::String, ::DataMapper::Property::Text])
rescue
end
- properties.select{|p| only_properties.include?(p.type || p.class)} # type seems to be depracated in 1.0
+ properties.select{|p| only_properties.include?(p.class)} # type seems to be depracated in 1.0
end
end
@@ -3,7 +3,7 @@ module DataMapper
class RelationshipManager
def self.create(content, relationship, opts = {})
- case relationship[1]
+ case relationship
when ::DataMapper::Associations::ManyToOne::Relationship
ManyToOne.new(content, relationship, opts)
when ::DataMapper::Associations::OneToMany::Relationship
@@ -13,8 +13,8 @@ def self.create(content, relationship, opts = {})
def initialize(content, relationship, opts = {})
@content = content
- @relationship = relationship[1]
- @relationship_name = relationship[0]
+ @relationship = relationship
+ @relationship_name = relationship.name
@ids = (opts[:ids] || '').split(',').map(&:to_i)
end
View
Binary file not shown.
View
@@ -1,6 +1,7 @@
$TESTING=true
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib','togo')
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib','togo','admin')
%w(do_sqlite3 togo togo/admin rack rack/test dm-core dm-serializer dm-migrations).each{|l| require l}
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/admin.db")
View
Binary file not shown.
View
@@ -2,8 +2,8 @@ require 'rake/gempackagetask'
Gem::Specification.new do |s|
s.name = %q{togo}
- s.version = "0.6.4"
- s.date = %q{2010-11-21}
+ s.version = "0.7.0"
+ s.date = %q{2011-06-30}
s.authors = ["Matt King"]
s.email = %q{matt@mking.me}
s.summary = %q{CMS Framework for Ruby ORMs}

0 comments on commit 2f7e856

Please sign in to comment.