Skip to content

Commit

Permalink
Import from the rails app
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Mar 17, 2012
1 parent b0a855e commit 9a245c3
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Activeadmin::Mongoid
# ActiveAdmin::Mongoid

TODO: Write a gem description

Expand Down
21 changes: 12 additions & 9 deletions activeadmin-mongoid.gemspec
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lib/active_admin-mongoid.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lib/active_admin/mongoid.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions lib/active_admin/mongoid/comments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module ActiveAdmin::Namespace
# Disable comments
def comments?
false
end
end
19 changes: 19 additions & 0 deletions lib/active_admin/mongoid/document.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions lib/active_admin/mongoid/form_builder.rb
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions lib/active_admin/mongoid/resource.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions lib/active_admin/mongoid/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ActiveAdmin
module Mongoid
VERSION = '0.0.1'
end
end
8 changes: 1 addition & 7 deletions lib/activeadmin-mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
require "activeadmin-mongoid/version"

module Activeadmin
module Mongoid
# Your code goes here...
end
end
require 'active_admin-mongoid'
5 changes: 0 additions & 5 deletions lib/activeadmin-mongoid/version.rb

This file was deleted.

1 comment on commit 9a245c3

@dayyan
Copy link

@dayyan dayyan commented on 9a245c3 Mar 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted you to know that you now have two versions of ActiveAdmin in the gemspec.

Please sign in to comment.