radiant-exporter-extension 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,5 @@
1
+ = Exporter
2
+
3
+ Export your models to YAML at yoursite.com/admin/export
4
+
5
+ If you want to add models for exporting, add them to the Radiant::Exporter.exportable_models array.
@@ -0,0 +1,116 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
10
+ end
11
+ end
12
+
13
+ require 'rake'
14
+ require 'rake/rdoctask'
15
+ require 'rake/testtask'
16
+
17
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
18
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
19
+ require 'spec/rake/spectask'
20
+ require 'cucumber'
21
+ require 'cucumber/rake/task'
22
+
23
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
24
+ Object.send(:remove_const, :RADIANT_ROOT)
25
+
26
+ extension_root = File.expand_path(File.dirname(__FILE__))
27
+
28
+ task :default => :spec
29
+ task :stats => "spec:statsetup"
30
+
31
+ desc "Run all specs in spec directory"
32
+ Spec::Rake::SpecTask.new(:spec) do |t|
33
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
34
+ t.spec_files = FileList['spec/**/*_spec.rb']
35
+ end
36
+
37
+ task :features => 'spec:integration'
38
+
39
+ namespace :spec do
40
+ desc "Run all specs in spec directory with RCov"
41
+ Spec::Rake::SpecTask.new(:rcov) do |t|
42
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
43
+ t.spec_files = FileList['spec/**/*_spec.rb']
44
+ t.rcov = true
45
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
46
+ end
47
+
48
+ desc "Print Specdoc for all specs"
49
+ Spec::Rake::SpecTask.new(:doc) do |t|
50
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
51
+ t.spec_files = FileList['spec/**/*_spec.rb']
52
+ end
53
+
54
+ [:models, :controllers, :views, :helpers].each do |sub|
55
+ desc "Run the specs under spec/#{sub}"
56
+ Spec::Rake::SpecTask.new(sub) do |t|
57
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
58
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
59
+ end
60
+ end
61
+
62
+ desc "Run the Cucumber features"
63
+ Cucumber::Rake::Task.new(:integration) do |t|
64
+ t.fork = true
65
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
66
+ # t.feature_pattern = "#{extension_root}/features/**/*.feature"
67
+ t.profile = "default"
68
+ end
69
+
70
+ # Setup specs for stats
71
+ task :statsetup do
72
+ require 'code_statistics'
73
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
74
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
75
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
76
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
77
+ ::CodeStatistics::TEST_TYPES << "Model specs"
78
+ ::CodeStatistics::TEST_TYPES << "View specs"
79
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
80
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
81
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
82
+ end
83
+
84
+ namespace :db do
85
+ namespace :fixtures do
86
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
87
+ task :load => :environment do
88
+ require 'active_record/fixtures'
89
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
90
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
91
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ desc 'Generate documentation for the exporter extension.'
99
+ Rake::RDocTask.new(:rdoc) do |rdoc|
100
+ rdoc.rdoc_dir = 'rdoc'
101
+ rdoc.title = 'ExporterExtension'
102
+ rdoc.options << '--line-numbers' << '--inline-source'
103
+ rdoc.rdoc_files.include('README')
104
+ rdoc.rdoc_files.include('lib/**/*.rb')
105
+ end
106
+
107
+ # For extensions that are in transition
108
+ desc 'Test the exporter extension.'
109
+ Rake::TestTask.new(:test) do |t|
110
+ t.libs << 'lib'
111
+ t.pattern = 'test/**/*_test.rb'
112
+ t.verbose = true
113
+ end
114
+
115
+ # Load any custom rakefiles for extension
116
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,5 @@
1
+ class Admin::ExportController < ApplicationController
2
+ def export
3
+ render :text => Radiant::Exporter.export(params[:type] || 'yaml'), :content_type => "text/yaml"
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ module Radiant
2
+ class Exporter
3
+ cattr_accessor :exportable_models
4
+ @@exportable_models = [Radiant::Config, User, Page, PagePart, PageField, Snippet, Layout]
5
+ cattr_accessor :template_models
6
+ @@template_models = [Layout, Snippet, Page, PagePart, PageField]
7
+ cattr_accessor :ignored_template_attributes
8
+ @@ignored_template_attributes = [:lock_version, :created_at, :updated_at, :created_by_id, :updated_by_id]
9
+
10
+ class << self
11
+ def export(type='yaml')
12
+ if self.respond_to?("export_#{type}")
13
+ self.send("export_#{type}")
14
+ else
15
+ ''
16
+ end
17
+ end
18
+
19
+ def export_yaml
20
+ hash = ActiveSupport::OrderedHash.new
21
+ @@exportable_models.each do |klass|
22
+ hash[klass.name.pluralize] = klass.find(:all).inject(ActiveSupport::OrderedHash.new) { |h, record| h[record.id.to_i] = record.attributes; h }
23
+ end
24
+ hash.to_yaml
25
+ end
26
+
27
+ def export_template
28
+ hash = ActiveSupport::OrderedHash.new
29
+ hash['name'] = hash['description'] = "Exported Template #{Time.zone.now.to_i}"
30
+ records = hash['records'] = ActiveSupport::OrderedHash.new
31
+ @@template_models.each do |klass|
32
+ records[klass.name.pluralize] = klass.find(:all).inject(ActiveSupport::OrderedHash.new) { |h, record|
33
+ h[record.id.to_i] = record.attributes.delete_if{|att| @@ignored_template_attributes.include?(att[0].to_sym) };
34
+ h
35
+ }
36
+ end
37
+ hash.to_yaml
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ en:
3
+ exporter: Exporter
@@ -0,0 +1,6 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.with_options(:controller => 'admin/export') do |export|
3
+ export.export 'admin/export', :action => 'export'
4
+ export.export_type 'admin/export/:type', :action => 'export'
5
+ end
6
+ end
@@ -0,0 +1 @@
1
+ default: --format progress features --tags ~@proposed,~@in_progress
@@ -0,0 +1,8 @@
1
+ class ExporterExtension < Radiant::Extension
2
+ version "1.0"
3
+ description "Export your models from Radiant"
4
+ url "http://github.com/radiant/radiant"
5
+
6
+ def activate
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV["RAILS_ENV"] = "test"
3
+ # Extension root
4
+ extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
5
+ require extension_env+'.rb'
6
+
7
+ Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step}
8
+
9
+ Cucumber::Rails::World.class_eval do
10
+ include Dataset
11
+ datasets_directory "#{RADIANT_ROOT}/spec/datasets"
12
+ Dataset::Resolver.default = Dataset::DirectoryResolver.new("#{RADIANT_ROOT}/spec/datasets", File.dirname(__FILE__) + '/../../spec/datasets', File.dirname(__FILE__) + '/../datasets')
13
+ self.datasets_database_dump_path = "#{Rails.root}/tmp/dataset"
14
+
15
+ # dataset :exporter
16
+ end
@@ -0,0 +1,14 @@
1
+ def path_to(page_name)
2
+ case page_name
3
+
4
+ when /the homepage/i
5
+ root_path
6
+
7
+ when /login/i
8
+ login_path
9
+ # Add more page name => path mappings here
10
+
11
+ else
12
+ raise "Can't find mapping from \"#{page_name}\" to a path."
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ module RadiantExporterExtension
2
+ end
@@ -0,0 +1,3 @@
1
+ module RadiantExporterExtension
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,55 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :exporter do
4
+
5
+ desc "Runs the migration of the Exporter extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ ExporterExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ Rake::Task['db:schema:dump'].invoke
11
+ else
12
+ ExporterExtension.migrator.migrate
13
+ Rake::Task['db:schema:dump'].invoke
14
+ end
15
+ end
16
+
17
+ desc "Copies public assets of the Exporter to the instance public/ directory."
18
+ task :update => :environment do
19
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
20
+ puts "Copying assets from ExporterExtension"
21
+ Dir[ExporterExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(ExporterExtension.root, '')
23
+ directory = File.dirname(path)
24
+ mkdir_p RAILS_ROOT + directory, :verbose => false
25
+ cp file, RAILS_ROOT + path, :verbose => false
26
+ end
27
+ unless ExporterExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
28
+ puts "Copying rake tasks from ExporterExtension"
29
+ local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
30
+ mkdir_p local_tasks_path, :verbose => false
31
+ Dir[File.join ExporterExtension.root, %w(lib tasks *.rake)].each do |file|
32
+ cp file, local_tasks_path, :verbose => false
33
+ end
34
+ end
35
+ end
36
+
37
+ desc "Syncs all available translations for this ext to the English ext master"
38
+ task :sync => :environment do
39
+ # The main translation root, basically where English is kept
40
+ language_root = ExporterExtension.root + "/config/locales"
41
+ words = TranslationSupport.get_translation_keys(language_root)
42
+
43
+ Dir["#{language_root}/*.yml"].each do |filename|
44
+ next if filename.match('_available_tags')
45
+ basename = File.basename(filename, '.yml')
46
+ puts "Syncing #{basename}"
47
+ (comments, other) = TranslationSupport.read_file(filename, basename)
48
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
49
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
50
+ TranslationSupport.write_file(filename, basename, comments, other)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-exporter-extension/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-exporter-extension"
7
+ s.version = RadiantExporterExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Radiant CMS Dev Team"]
10
+ s.email = ["radiant@radiantcms.org"]
11
+ s.homepage = "http://radiantcms.org/"
12
+ s.summary = %q{Export your models from Radiant}
13
+ s.description = %q{Export your models from Radiant}
14
+
15
+ ignores = if File.exist?(".gitignore")
16
+ File.read(".gitignore").split("\n").inject([]) {|a,p| a + Dir[p] }
17
+ else
18
+ []
19
+ end
20
+ s.files = Dir["**/*"] - ignores
21
+ s.test_files = Dir["test/**/*","spec/**/*","features/**/*"] - ignores
22
+ s.require_paths = ["lib"]
23
+
24
+ # s.add_dependency "some_gem", "~> 1.0.0"
25
+
26
+ s.post_install_message = %{
27
+ Add this to your radiant project with:
28
+ config.gem "radiant-exporter-extension", :version => "~> #{RadiantExporterExtension::VERSION}"
29
+ }
30
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Admin::ExportController do
4
+ dataset :users_and_pages
5
+
6
+ before :each do
7
+ login_as :designer
8
+ end
9
+
10
+ it "should export a YAML file" do
11
+ get :export
12
+ response.should be_success
13
+ response.content_type.should == "text/yaml"
14
+ YAML.load(response.body).should be_kind_of(Hash)
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Radiant::Exporter do
4
+ dataset :pages_with_layouts, :users_and_pages, :snippets
5
+
6
+ let(:exporter){ Radiant::Exporter }
7
+ let(:exported_content){ exporter.export }
8
+ let(:exported_hash){ YAML::load(exported_content) }
9
+ subject { exporter }
10
+
11
+ specify{ exported_content.should be_kind_of(String) }
12
+
13
+ it "should output all exportable_models with pluralized class names as keys" do
14
+ exporter.exportable_models.all? { |c| exported_hash.has_key?(c.to_s.pluralize) }.should be_true
15
+ end
16
+
17
+ it "should output the models by id as hashes" do
18
+ exported_hash['Pages'][page_id(:home)]['title'].should == pages(:home).title
19
+ exported_hash['Users'][user_id(:admin)]['name'].should == users(:admin).name
20
+ end
21
+
22
+ its(:exportable_models){ should == [Radiant::Config, User, Page, PagePart, PageField, Snippet, Layout] }
23
+ its(:template_models){ should == [Layout, Snippet, Page, PagePart, PageField] }
24
+ its(:ignored_template_attributes){ should == [:lock_version, :created_at, :updated_at, :created_by_id, :updated_by_id] }
25
+ it "should allow setting exportable_models" do
26
+ exporter.exportable_models = [Page]
27
+ exporter.exportable_models.should == [Page]
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,36 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
15
+
16
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
17
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ # config.use_transactional_fixtures = true
22
+ # config.use_instantiated_fixtures = false
23
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
24
+
25
+ # You can declare fixtures for each behaviour like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so here, like so ...
31
+ #
32
+ # config.global_fixtures = :table_a, :table_b
33
+ #
34
+ # If you declare global fixtures, be aware that they will be declared
35
+ # for all of your examples, even those that don't use them.
36
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-exporter-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Radiant CMS Dev Team
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-12 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Export your models from Radiant
23
+ email:
24
+ - radiant@radiantcms.org
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - app/controllers/admin/export_controller.rb
33
+ - app/models/radiant/exporter.rb
34
+ - config/locales/en.yml
35
+ - config/routes.rb
36
+ - cucumber.yml
37
+ - exporter_extension.rb
38
+ - features/support/env.rb
39
+ - features/support/paths.rb
40
+ - lib/radiant-exporter-extension/version.rb
41
+ - lib/radiant-exporter-extension.rb
42
+ - lib/tasks/exporter_extension_tasks.rake
43
+ - radiant-exporter-extension.gemspec
44
+ - Rakefile
45
+ - README
46
+ - spec/controllers/admin/export_controller_spec.rb
47
+ - spec/models/radiant/exporter_spec.rb
48
+ - spec/spec.opts
49
+ - spec/spec_helper.rb
50
+ has_rdoc: true
51
+ homepage: http://radiantcms.org/
52
+ licenses: []
53
+
54
+ post_install_message: "\n Add this to your radiant project with:\n config.gem \"radiant-exporter-extension\", :version => \"~> 1.0.0\"\n "
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.6.2
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Export your models from Radiant
84
+ test_files:
85
+ - spec/controllers/admin/export_controller_spec.rb
86
+ - spec/models/radiant/exporter_spec.rb
87
+ - spec/spec.opts
88
+ - spec/spec_helper.rb
89
+ - features/support/env.rb
90
+ - features/support/paths.rb