Skip to content

Commit

Permalink
gemify the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vhochstein committed Jan 24, 2011
1 parent cb1b91a commit 549cbb8
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .document
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lib/**/*.rb
bin/*
-
features/**/*.feature
LICENSE.txt
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# rcov generated
coverage

# rdoc generated
rdoc

# yard generated
doc
.yardoc

# bundler
.bundle

# jeweler generated
pkg

Gemfile*
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
# * Include files you want ignored
# * Run: git config --global core.excludesfile ~/.gitignore
#
# After doing this, these files will be ignored in all your git projects,
# saving you from having to 'pollute' every project you touch with them
#
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
#
# For MacOS:
#
#.DS_Store
#
# For TextMate
#*.tmproj
#tmtags
#
# For emacs:
#*~
#\#*
#.\#*
#
# For vim:
#*.swp
File renamed without changes.
52 changes: 43 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test
require 'jeweler'
require './lib/active_scaffold_sortable/version.rb'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "active_scaffold_sortable"
gem.version = ActiveScaffoldSortable::Version::STRING
gem.homepage = "http://github.com/vhochstein/active_scaffold_sortable"
gem.license = "MIT"
gem.summary = %Q{Drag n Drop Sorting for Activescaffold}
gem.description = %Q{Sort Tree or List Structures by Drag n Drop}
gem.email = "activescaffold@googlegroups.com"
gem.authors = ["Volker Hochstein"]
gem.add_runtime_dependency 'active_scaffold', '~> 3.0.6'
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
# gem.add_development_dependency 'rspec', '> 1.2.3'
end
Jeweler::RubygemsDotOrgTasks.new

desc 'Test the addresses_engine plugin.'
require 'rake/testtask'
desc 'Test plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the addresses_engine plugin.'
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end

task :default => :test

require 'rake/rdoctask'
desc 'Generate documentation for plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'AddressesEngine'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.title = "active_scaffold_sortable #{ActiveScaffoldSortable::Version::STRING}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
12 changes: 5 additions & 7 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require 'sortable'
ACTIVE_SCAFFOLD_SORTABLE_PLUGIN = true

require 'active_scaffold_sortable'

##
## Run the install assets script, too, just to make sure
## But at least rescue the action in production
##
begin
require File.dirname(__FILE__) + '/install_assets'
ActiveScaffoldAssets.copy_to_public(ActiveScaffoldSortable.root)
rescue
raise $! unless Rails.env == 'production'
end
end
38 changes: 0 additions & 38 deletions install_assets.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/active_scaffold/actions/sortable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.included(base)
action.columns.exclude(sortable_column) if action.respond_to? :columns
end

dir = File.join(Rails.root, 'vendor', 'plugins', ::Sortable.plugin_name, 'frontends')
dir = File.join(ActiveScaffold::Config::Sortable.plugin_directory, 'frontends')
base.add_active_scaffold_path File.join(dir, frontend, 'views') if config.frontend.to_sym != :default
base.add_active_scaffold_path File.join(dir, 'default', 'views')
end
Expand Down
3 changes: 3 additions & 0 deletions lib/active_scaffold/config/sortable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def initialize(core_config)

end

cattr_accessor :plugin_directory
@@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/sortable.rb})[1]

self.crud_type = :update

attr_reader :column
Expand Down
25 changes: 25 additions & 0 deletions lib/active_scaffold_sortable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "#{File.dirname(__FILE__)}/active_scaffold_sortable/config/core.rb"
require "#{File.dirname(__FILE__)}/active_scaffold/config/sortable.rb"
require "#{File.dirname(__FILE__)}/active_scaffold/actions/sortable.rb"
require "#{File.dirname(__FILE__)}/active_scaffold/helpers/sortable_helpers.rb"

module ActiveScaffoldSortable
def self.root
File.dirname(__FILE__) + "/.."
end
end

ActiveScaffold::Config::Core.send :include, ActiveScaffoldSortable::Core
ActiveScaffold::Helpers::ViewHelpers.send :include, ActiveScaffoldSortable::ViewHelpers

##
## Run the install assets script, too, just to make sure
## But at least rescue the action in production
##
Rails::Application.initializer("active_scaffold_sortable.install_assets") do
begin
ActiveScaffoldAssets.copy_to_public(ActiveScaffoldSortable.root)
rescue
raise $! unless Rails.env == 'production'
end
end unless defined?(ACTIVE_SCAFFOLD_SORTABLE_PLUGIN) && ACTIVE_SCAFFOLD_SORTABLE_PLUGIN == true
4 changes: 4 additions & 0 deletions lib/active_scaffold_sortable/config/core.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Need to open the AS module carefully due to Rails 2.3 lazy loading
ActiveScaffold::Config::Core.class_eval do
ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:reorder] = :post
end
13 changes: 13 additions & 0 deletions lib/active_scaffold_sortable/core.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module ActiveScaffoldSortable
module Core
def self.included(base)
base.alias_method_chain :initialize, :sortable
end

def initialize_with_sortable(model_id)
initialize_without_sortable(model_id)
# seems some rubies are returning strings in instance_methods and other symbols...
self.actions << :sortable if !(model.instance_methods & ['acts_as_list_class', :acts_as_list_class, 'nested_set_scope', :nested_set_scope]).empty?
end
end
end
9 changes: 9 additions & 0 deletions lib/active_scaffold_sortable/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module ActiveScaffoldSortable
module Version
MAJOR = 3
MINOR = 0
PATCH = 0

STRING = [MAJOR, MINOR, PATCH].compact.join('.')
end
end
11 changes: 11 additions & 0 deletions lib/active_scaffold_sortable/view_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module ActiveScaffoldSortable
module ViewHelpers
def self.included(base)
base.alias_method_chain :active_scaffold_stylesheets, :sortable
end

def active_scaffold_stylesheets_with_sortable(frontend = :default)
active_scaffold_stylesheets_without_sortable(frontend) + [ActiveScaffold::Config::Core.asset_path('sortable.css', frontend)]
end
end
end
8 changes: 0 additions & 8 deletions lib/sortable.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/sortable/core.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/sortable/view_helpers.rb

This file was deleted.

0 comments on commit 549cbb8

Please sign in to comment.