Skip to content
Browse files

Import from the rails app

  • Loading branch information...
1 parent b0a855e commit 9a245c34387ea8ec861b418041a839968b5e12a1 @elia elia committed Mar 17, 2012
View
2 README.md
@@ -1,4 +1,4 @@
-# Activeadmin::Mongoid
+# ActiveAdmin::Mongoid
TODO: Write a gem description
View
21 activeadmin-mongoid.gemspec
@@ -1,17 +1,20 @@
-# -*- encoding: utf-8 -*-
+# coding: utf-8
require File.expand_path('../lib/activeadmin-mongoid/version', __FILE__)
Gem::Specification.new do |gem|
- gem.authors = ["Elia Schito"]
- gem.email = ["perlelia@gmail.com"]
- gem.description = %q{TODO: Write a gem description}
- gem.summary = %q{TODO: Write a gem summary}
- gem.homepage = ""
+ gem.authors = ['Elia Schito']
+ gem.email = ['elia@schito.me']
+ gem.description = %q{ActiveAdmin hacks to support Mongoid (some ActiveAdmin features are disabled)}
+ gem.summary = %q{ActiveAdmin hacks to support Mongoid}
+ gem.homepage = ''
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- gem.name = "activeadmin-mongoid"
- gem.require_paths = ["lib"]
- gem.version = Activeadmin::Mongoid::VERSION
+ gem.name = 'activeadmin-mongoid'
+ gem.require_paths = ['lib']
+ gem.version = ActiveAdmin::Mongoid::VERSION
+
+ gem.add_runtime_dependency 'mongoid', '~> 2.0'
+ gem.add_runtime_dependency 'activeadmin', '~> 0.4'
end
View
8 lib/active_admin-mongoid.rb
@@ -0,0 +1,8 @@
+require 'activeadmin-mongoid/version'
+
+require 'active_admin'
+require 'active_admin/resource_controller'
+require 'active_admin/mongoid/form_builder'
+
+module ActiveAdmin::Mongoid
+end
View
8 lib/active_admin/mongoid.rb
@@ -0,0 +1,8 @@
+require 'active_admin'
+require 'active_admin/mongoid/comments'
+require 'active_admin/mongoid/form_builder'
+require 'active_admin/mongoid/resource'
+require 'active_admin/mongoid/document'
+
+module ActiveAdmin::Mongoid
+end
View
6 lib/active_admin/mongoid/comments.rb
@@ -0,0 +1,6 @@
+module ActiveAdmin::Namespace
+ # Disable comments
+ def comments?
+ false
+ end
+end
View
19 lib/active_admin/mongoid/document.rb
@@ -0,0 +1,19 @@
+module ActiveAdmin::Mongoid::Document
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ def content_columns
+ @content_columns ||= fields.map(&:second).select {|f| f.name !~ /(^_|^(created|updated)_at)/}
+ end
+
+ def columns
+ @columns ||= fields.map(&:second)
+ end
+
+ def reorder *args
+ scoped
+ end
+ end
+end
+
+Mongoid::Document.send :include, ActiveAdmin::Mongoid::Document
View
13 lib/active_admin/mongoid/form_builder.rb
@@ -0,0 +1,13 @@
+require 'active_admin/form_builder'
+
+class ActiveAdmin::FormBuilder
+ def inputs(*args, &block)
+ # Store that we are creating inputs without a block
+ @inputs_with_block = block_given? ? true : false
+ content = with_new_form_buffer do
+ super
+ # form_buffers.last
+ end
+ form_buffers.last << content.html_safe
+ end
+end
View
33 lib/active_admin/mongoid/resource.rb
@@ -0,0 +1,33 @@
+require 'active_admin/resource'
+require 'active_admin/resource_controller'
+
+module ActiveAdmin
+ class Resource
+ def resource_table_name
+ resource.collection_name
+ end
+
+ # Disable filters
+ def add_default_sidebar_sections
+ end
+ end
+
+ ResourceController # autoload
+ class ResourceController
+ # Use #desc and #asc for sorting.
+ def sort_order(chain)
+ params[:order] ||= active_admin_config.sort_order
+ table_name = active_admin_config.resource_table_name
+ if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
+ chain.send($2, $1)
+ else
+ chain # just return the chain
+ end
+ end
+
+ # Disable filters
+ def search(chain)
+ chain
+ end
+ end
+end
View
5 lib/active_admin/mongoid/version.rb
@@ -0,0 +1,5 @@
+module ActiveAdmin
+ module Mongoid
+ VERSION = '0.0.1'
+ end
+end
View
8 lib/activeadmin-mongoid.rb
@@ -1,7 +1 @@
-require "activeadmin-mongoid/version"
-
-module Activeadmin
- module Mongoid
- # Your code goes here...
- end
-end
+require 'active_admin-mongoid'
View
5 lib/activeadmin-mongoid/version.rb
@@ -1,5 +0,0 @@
-module Activeadmin
- module Mongoid
- VERSION = "0.0.1"
- end
-end

0 comments on commit 9a245c3

Please sign in to comment.
Something went wrong with that request. Please try again.