This repository has been archived by the owner on Jan 22, 2020. It is now read-only.
/
exporter_extension_tasks.rake
55 lines (51 loc) · 2.41 KB
/
exporter_extension_tasks.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace :radiant do
namespace :extensions do
namespace :exporter do
desc "Runs the migration of the Exporter extension"
task :migrate => :environment do
require 'radiant/extension_migrator'
if ENV["VERSION"]
ExporterExtension.migrator.migrate(ENV["VERSION"].to_i)
Rake::Task['db:schema:dump'].invoke
else
ExporterExtension.migrator.migrate
Rake::Task['db:schema:dump'].invoke
end
end
desc "Copies public assets of the Exporter to the instance public/ directory."
task :update => :environment do
is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
puts "Copying assets from ExporterExtension"
Dir[ExporterExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
path = file.sub(ExporterExtension.root, '')
directory = File.dirname(path)
mkdir_p RAILS_ROOT + directory, :verbose => false
cp file, RAILS_ROOT + path, :verbose => false
end
unless ExporterExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
puts "Copying rake tasks from ExporterExtension"
local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
mkdir_p local_tasks_path, :verbose => false
Dir[File.join ExporterExtension.root, %w(lib tasks *.rake)].each do |file|
cp file, local_tasks_path, :verbose => false
end
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 = ExporterExtension.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