diff --git a/README.md b/README.md index 377e94c..d04379f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Activeadmin::Mongoid +# ActiveAdmin::Mongoid TODO: Write a gem description diff --git a/activeadmin-mongoid.gemspec b/activeadmin-mongoid.gemspec index c574945..cb318ca 100644 --- a/activeadmin-mongoid.gemspec +++ b/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 diff --git a/lib/active_admin-mongoid.rb b/lib/active_admin-mongoid.rb new file mode 100644 index 0000000..175ccee --- /dev/null +++ b/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 diff --git a/lib/active_admin/mongoid.rb b/lib/active_admin/mongoid.rb new file mode 100644 index 0000000..7520f1d --- /dev/null +++ b/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 diff --git a/lib/active_admin/mongoid/comments.rb b/lib/active_admin/mongoid/comments.rb new file mode 100644 index 0000000..195085d --- /dev/null +++ b/lib/active_admin/mongoid/comments.rb @@ -0,0 +1,6 @@ +module ActiveAdmin::Namespace + # Disable comments + def comments? + false + end +end diff --git a/lib/active_admin/mongoid/document.rb b/lib/active_admin/mongoid/document.rb new file mode 100644 index 0000000..e0afa33 --- /dev/null +++ b/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 diff --git a/lib/active_admin/mongoid/form_builder.rb b/lib/active_admin/mongoid/form_builder.rb new file mode 100644 index 0000000..4c5cf42 --- /dev/null +++ b/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 diff --git a/lib/active_admin/mongoid/resource.rb b/lib/active_admin/mongoid/resource.rb new file mode 100644 index 0000000..66cd1eb --- /dev/null +++ b/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 diff --git a/lib/active_admin/mongoid/version.rb b/lib/active_admin/mongoid/version.rb new file mode 100644 index 0000000..faeed21 --- /dev/null +++ b/lib/active_admin/mongoid/version.rb @@ -0,0 +1,5 @@ +module ActiveAdmin + module Mongoid + VERSION = '0.0.1' + end +end diff --git a/lib/activeadmin-mongoid.rb b/lib/activeadmin-mongoid.rb index d830f05..4fb53a4 100644 --- a/lib/activeadmin-mongoid.rb +++ b/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' diff --git a/lib/activeadmin-mongoid/version.rb b/lib/activeadmin-mongoid/version.rb deleted file mode 100644 index 81e7635..0000000 --- a/lib/activeadmin-mongoid/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Activeadmin - module Mongoid - VERSION = "0.0.1" - end -end