From b1c66b79dded378bbc4d7b21b692b6c741c75605 Mon Sep 17 00:00:00 2001 From: Sam Whited Date: Wed, 15 Aug 2012 19:19:55 -0400 Subject: [PATCH] Created extension with basic configuration --- .gitignore | 18 ++++ README.md | 6 ++ Rakefile | 109 ++++++++++++++++++++++++ config/initializers/radiant_config.rb | 3 + config/locales/en.yml | 3 + config/routes.rb | 5 ++ cucumber.yml | 1 + dtconfig_extension.rb | 23 +++++ features/support/env.rb | 11 +++ features/support/paths.rb | 22 +++++ lib/radiant-dtconfig-extension.rb | 8 ++ lib/tasks/dtconfig_extension_tasks.rake | 47 ++++++++++ radiant-dtconfig-extension.gemspec | 29 +++++++ spec/spec.opts | 6 ++ spec/spec_helper.rb | 36 ++++++++ 15 files changed, 327 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 Rakefile create mode 100644 config/initializers/radiant_config.rb create mode 100644 config/locales/en.yml create mode 100644 config/routes.rb create mode 100644 cucumber.yml create mode 100644 dtconfig_extension.rb create mode 100644 features/support/env.rb create mode 100644 features/support/paths.rb create mode 100644 lib/radiant-dtconfig-extension.rb create mode 100644 lib/tasks/dtconfig_extension_tasks.rake create mode 100644 radiant-dtconfig-extension.gemspec create mode 100644 spec/spec.opts create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..560d1a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +*.gem +*.rbc +.bundle +.config +coverage +InstalledFiles +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp + +# YARD artifacts +.yardoc +_yardoc +doc/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..2147934 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# DT Config + +Some basic settings for the [DramaTech Theat(er|re)](http://dramatech.org) +website. There's not much to see here. Move along now. + +Created by [Sam Whited](https://samwhited.com). diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..53579c7 --- /dev/null +++ b/Rakefile @@ -0,0 +1,109 @@ +# Determine where the RSpec plugin is by loading the boot +unless defined? RADIANT_ROOT + ENV["RAILS_ENV"] = "test" + case + when ENV["RADIANT_ENV_FILE"] + require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot" + when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions} + require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot" + else + require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot" + end +end + +require 'rake' +require 'rdoc/task' +require 'rake/testtask' + +rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib') +$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) +require 'spec/rake/spectask' +require 'cucumber' +require 'cucumber/rake/task' + +# Cleanup the RADIANT_ROOT constant so specs will load the environment +Object.send(:remove_const, :RADIANT_ROOT) + +extension_root = File.expand_path(File.dirname(__FILE__)) + +task :default => [:spec, :features] +task :stats => "spec:statsetup" + +desc "Run all specs in spec directory" +Spec::Rake::SpecTask.new(:spec) do |t| + t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""] + t.spec_files = FileList['spec/**/*_spec.rb'] +end + +task :features => 'spec:integration' + +namespace :spec do + desc "Run all specs in spec directory with RCov" + Spec::Rake::SpecTask.new(:rcov) do |t| + t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""] + t.spec_files = FileList['spec/**/*_spec.rb'] + t.rcov = true + t.rcov_opts = ['--exclude', 'spec', '--rails'] + end + + desc "Print Specdoc for all specs" + Spec::Rake::SpecTask.new(:doc) do |t| + t.spec_opts = ["--format", "specdoc", "--dry-run"] + t.spec_files = FileList['spec/**/*_spec.rb'] + end + + [:models, :controllers, :views, :helpers].each do |sub| + desc "Run the specs under spec/#{sub}" + Spec::Rake::SpecTask.new(sub) do |t| + t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""] + t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] + end + end + + desc "Run the Cucumber features" + Cucumber::Rake::Task.new(:integration) do |t| + t.fork = true + t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')] + # t.feature_pattern = "#{extension_root}/features/**/*.feature" + t.profile = "default" + end + + # Setup specs for stats + task :statsetup do + require 'code_statistics' + ::STATS_DIRECTORIES << %w(Model\ specs spec/models) + ::STATS_DIRECTORIES << %w(View\ specs spec/views) + ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) + ::STATS_DIRECTORIES << %w(Helper\ specs spec/views) + ::CodeStatistics::TEST_TYPES << "Model specs" + ::CodeStatistics::TEST_TYPES << "View specs" + ::CodeStatistics::TEST_TYPES << "Controller specs" + ::CodeStatistics::TEST_TYPES << "Helper specs" + ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/} + end + + namespace :db do + namespace :fixtures do + desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y" + task :load => :environment do + require 'active_record/fixtures' + ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) + (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| + Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*')) + end + end + end + end +end + +desc 'Generate documentation for the dtconfig extension.' +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'DtconfigExtension' + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +# Load any custom rakefiles for extension +Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f } diff --git a/config/initializers/radiant_config.rb b/config/initializers/radiant_config.rb new file mode 100644 index 0000000..5550a34 --- /dev/null +++ b/config/initializers/radiant_config.rb @@ -0,0 +1,3 @@ +Radiant.config do |config| + # config.define "setting.name", :default => 'value', :select_from => ['foo', 'bar'] +end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..a8cb50c --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,3 @@ +--- +en: + dtconfig: Dtconfig \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..580816e --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,5 @@ +ActionController::Routing::Routes.draw do |map| + # map.namespace :admin, :member => { :remove => :get } do |admin| + # admin.resources :dtconfig + # end +end \ No newline at end of file diff --git a/cucumber.yml b/cucumber.yml new file mode 100644 index 0000000..7a03ee6 --- /dev/null +++ b/cucumber.yml @@ -0,0 +1 @@ +default: --format progress features --tags ~@proposed,~@in_progress \ No newline at end of file diff --git a/dtconfig_extension.rb b/dtconfig_extension.rb new file mode 100644 index 0000000..ea385e5 --- /dev/null +++ b/dtconfig_extension.rb @@ -0,0 +1,23 @@ +# Uncomment this if you reference any of your controllers in activate +# require_dependency "application_controller" +require "radiant-dtconfig-extension" + +class DtconfigExtension < Radiant::Extension + version RadiantDtconfigExtension::VERSION + description RadiantDtconfigExtension::DESCRIPTION + url RadiantDtconfigExtension::URL + + # See your config/routes.rb file in this extension to define custom routes + + extension_config do |config| + end + + def activate + # Set the types of meetings that the minutes extension should display + MinutesExtension.meeting_types = ['Club', 'EC', 'PPM', 'Open House', 'Banquet', 'Historian', 'Social', 'Other'] unless not defined? MinutesExtension + + # Set the title of the admin interface + Radiant::Config['admin.title'] = 'DramaTech Theat(er|re)' if Radiant::Config['admin.title'] =~ /Radiant CMS/ + Radiant::Config['admin.subtitle'] = 'Music, theater, toasters' if Radiant::Config['admin.subtitle'] =~ /Publishing for Small Teams/ + end +end diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..78a56bc --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,11 @@ +# Sets up the Rails environment for Cucumber +ENV["RAILS_ENV"] = "test" +# Extension root +extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment') +require extension_env+'.rb' + +Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step unless step =~ /datasets_loader\.rb$/} + +Cucumber::Rails::World.class_eval do + dataset :dtconfig +end \ No newline at end of file diff --git a/features/support/paths.rb b/features/support/paths.rb new file mode 100644 index 0000000..a9f1099 --- /dev/null +++ b/features/support/paths.rb @@ -0,0 +1,22 @@ +module NavigationHelpers + + # Extend the standard PathMatchers with your own paths + # to be used in your features. + # + # The keys and values here may be used in your standard web steps + # Using: + # + # When I go to the "dtconfig" admin page + # + # would direct the request to the path you provide in the value: + # + # admin_dtconfig_path + # + PathMatchers = {} unless defined?(PathMatchers) + PathMatchers.merge!({ + # /dtconfig/i => 'admin_dtconfig_path' + }) + +end + +World(NavigationHelpers) \ No newline at end of file diff --git a/lib/radiant-dtconfig-extension.rb b/lib/radiant-dtconfig-extension.rb new file mode 100644 index 0000000..a11fb8d --- /dev/null +++ b/lib/radiant-dtconfig-extension.rb @@ -0,0 +1,8 @@ +module RadiantDtconfigExtension + VERSION = "1.0.0" + SUMMARY = "Custom RadiantCMS configuration for DT" + DESCRIPTION = "Custom RadiantCMS config for DramaTech" + URL = "http://dramatech.org" + AUTHORS = ["Sam Whited"] + EMAIL = ["sam@dramatech.org"] +end diff --git a/lib/tasks/dtconfig_extension_tasks.rake b/lib/tasks/dtconfig_extension_tasks.rake new file mode 100644 index 0000000..b37a8ad --- /dev/null +++ b/lib/tasks/dtconfig_extension_tasks.rake @@ -0,0 +1,47 @@ +namespace :radiant do + namespace :extensions do + namespace :dtconfig do + + desc "Runs the migration of the Dtconfig extension" + task :migrate => :environment do + require 'radiant/extension_migrator' + if ENV["VERSION"] + DtconfigExtension.migrator.migrate(ENV["VERSION"].to_i) + Rake::Task['db:schema:dump'].invoke + else + DtconfigExtension.migrator.migrate + Rake::Task['db:schema:dump'].invoke + end + end + + desc "Copies public assets of the Dtconfig to the instance public/ directory." + task :update => :environment do + is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) } + puts "Copying assets from DtconfigExtension" + Dir[DtconfigExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file| + path = file.sub(DtconfigExtension.root, '') + directory = File.dirname(path) + mkdir_p RAILS_ROOT + directory, :verbose => false + cp file, RAILS_ROOT + path, :verbose => false + end + end + + desc "Syncs all available translations for this ext to the English ext master" + task :sync => :environment do + # The main translation root, basically where English is kept + language_root = DtconfigExtension.root + "/config/locales" + words = TranslationSupport.get_translation_keys(language_root) + + Dir["#{language_root}/*.yml"].each do |filename| + next if filename.match('_available_tags') + basename = File.basename(filename, '.yml') + puts "Syncing #{basename}" + (comments, other) = TranslationSupport.read_file(filename, basename) + words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist + other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml + TranslationSupport.write_file(filename, basename, comments, other) + end + end + end + end +end diff --git a/radiant-dtconfig-extension.gemspec b/radiant-dtconfig-extension.gemspec new file mode 100644 index 0000000..57d509f --- /dev/null +++ b/radiant-dtconfig-extension.gemspec @@ -0,0 +1,29 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "radiant-dtconfig-extension" + +Gem::Specification.new do |s| + s.name = "radiant-dtconfig-extension" + s.version = RadiantDtconfigExtension::VERSION + s.platform = Gem::Platform::RUBY + s.authors = RadiantDtconfigExtension::AUTHORS + s.email = RadiantDtconfigExtension::EMAIL + s.homepage = RadiantDtconfigExtension::URL + s.summary = RadiantDtconfigExtension::SUMMARY + s.description = RadiantDtconfigExtension::DESCRIPTION + + # Define gem dependencies here. + # Don't include a dependency on radiant itself: it causes problems when radiant is in vendor/radiant. + # s.add_dependency "something", "~> 1.0.0" + # s.add_dependency "radiant-some-extension", "~> 1.0.0" + + ignores = if File.exist?('.gitignore') + File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] } + else + [] + end + s.files = Dir['**/*'] - ignores + s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores + # s.executables = Dir['bin/*'] - ignores + s.require_paths = ["lib"] +end diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..d8c8db5 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,6 @@ +--colour +--format +progress +--loadby +mtime +--reverse diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..0adbf9f --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,36 @@ +unless defined? RADIANT_ROOT + ENV["RAILS_ENV"] = "test" + case + when ENV["RADIANT_ENV_FILE"] + require ENV["RADIANT_ENV_FILE"] + when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions} + require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment" + else + require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment" + end +end +require "#{RADIANT_ROOT}/spec/spec_helper" + +Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets") + +if File.directory?(File.dirname(__FILE__) + "/matchers") + Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file } +end + +Spec::Runner.configure do |config| + # config.use_transactional_fixtures = true + # config.use_instantiated_fixtures = false + # config.fixture_path = RAILS_ROOT + '/spec/fixtures' + + # You can declare fixtures for each behaviour like this: + # describe "...." do + # fixtures :table_a, :table_b + # + # Alternatively, if you prefer to declare them only once, you can + # do so here, like so ... + # + # config.global_fixtures = :table_a, :table_b + # + # If you declare global fixtures, be aware that they will be declared + # for all of your examples, even those that don't use them. +end \ No newline at end of file