Browse files

gemify the plugin

  • Loading branch information...
1 parent cb1b91a commit 549cbb858b4c58cbe72f23923aa37cf2e8968eb3 @vhochstein vhochstein committed Jan 24, 2011
View
5 .document
@@ -0,0 +1,5 @@
+lib/**/*.rb
+bin/*
+-
+features/**/*.feature
+LICENSE.txt
View
43 .gitignore
@@ -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
View
0 MIT-LICENSE → LICENSE.txt
File renamed without changes.
View
52 Rakefile
@@ -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
View
12 init.rb
@@ -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
View
38 install_assets.rb
@@ -1,38 +0,0 @@
-unless defined?(ACTIVE_SCAFFOLD_INSTALL_ASSETS) && ACTIVE_SCAFFOLD_INSTALL_ASSETS == false
- # Workaround a problem with script/plugin and http-based repos.
- # See http://dev.rubyonrails.org/ticket/8189
- Dir.chdir(Dir.getwd.sub(/vendor.*/, '')) do
-
- ##
- ## Copy over asset files (javascript/css/images) from the plugin directory to public/
- ##
-
- def copy_files(source_path, destination_path, directory)
- source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path)
- FileUtils.mkdir_p(destination) unless File.exist?(destination)
- FileUtils.cp_r(Dir.glob(source+'/*.*'), destination)
- end
-
- directory = File.dirname(__FILE__)
-
- copy_files("/public", "/public", directory)
-
- available_frontends = Dir[File.join(directory, 'frontends', '*')].collect { |d| File.basename d }
- [ :stylesheets, :javascripts, :images].each do |asset_type|
- path = "/public/#{asset_type}/active_scaffold"
- copy_files(path, path, directory)
-
- File.open(File.join(Rails.root, path, 'DO_NOT_EDIT'), 'w') do |f|
- f.puts "Any changes made to files in sub-folders will be lost."
- f.puts "See http://activescaffold.com/tutorials/faq#custom-css."
- end
-
- available_frontends.each do |frontend|
- source = "/frontends/#{frontend}/#{asset_type}/"
- destination = "/public/#{asset_type}/active_scaffold/#{frontend}"
- copy_files(source, destination, directory)
- end
- end
-
- end
-end
View
2 lib/active_scaffold/actions/sortable.rb
@@ -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
View
3 lib/active_scaffold/config/sortable.rb
@@ -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
View
25 lib/active_scaffold_sortable.rb
@@ -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
View
4 lib/active_scaffold_sortable/config/core.rb
@@ -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
View
13 lib/active_scaffold_sortable/core.rb
@@ -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
View
9 lib/active_scaffold_sortable/version.rb
@@ -0,0 +1,9 @@
+module ActiveScaffoldSortable
+ module Version
+ MAJOR = 3
+ MINOR = 0
+ PATCH = 0
+
+ STRING = [MAJOR, MINOR, PATCH].compact.join('.')
+ end
+end
View
11 lib/active_scaffold_sortable/view_helpers.rb
@@ -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
View
8 lib/sortable.rb
@@ -1,8 +0,0 @@
-module Sortable
- def self.plugin_name
- @plugin_name ||= (/.+vendor\/plugins\/(.+)\/lib/.match(File.expand_path(__FILE__)))[1]
- end
-end
-ActiveScaffold::Config::Core.send :include, Sortable::Core
-ActiveScaffold::Helpers::ViewHelpers.send :include, Sortable::ViewHelpers
-ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:reorder] = :post
View
11 lib/sortable/core.rb
@@ -1,11 +0,0 @@
-module Sortable::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
View
9 lib/sortable/view_helpers.rb
@@ -1,9 +0,0 @@
-module Sortable::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

0 comments on commit 549cbb8

Please sign in to comment.