1 class LanguageExtensionGenerator < Rails::Generator::NamedBase
2 default_options :with_test_unit => false
3
4 attr_reader :extension_path, :extension_file_name, :localization_name
5
6 def initialize(runtime_args, runtime_options = {})
7 super
8 @extension_file_name = "#{file_name}_language_pack_extension"
9 @extension_path = "vendor/extensions/#{file_name}_language_pack"
10 @localization_name = localization_name
11 end
12
13 def manifest
14 record do |m|
15 m.directory "#{extension_path}/config/locales"
16 m.directory "#{extension_path}/lib/tasks"
17
18 m.template 'README', "#{extension_path}/README"
19 m.template 'extension.rb', "#{extension_path}/#{extension_file_name}.rb"
20 # m.template 'tasks.rake', "#{extension_path}/lib/tasks/#{extension_file_name}_tasks.rake"
21 m.template 'lang.yml', "#{extension_path}/config/locales/#{localization_name}.yml"
22 m.template 'available_tags.yml', "#{extension_path}/config/locales/#{localization_name}_available_tags.yml"
23 m.template 'lib.rb', "#{extension_path}/lib/radiant-#{file_name}_language_pack-extension.rb"
24 m.template 'gemspec.rb', "#{extension_path}/radiant-#{file_name}_language_pack-extension.gemspec"
25 end
26
27 end
28
29 def class_name
30 super.to_name.gsub(' ', '') + 'LanguagePackExtension'
31 end
32
33 def extension_name
34 class_name.to_name('Extension')
35 end
36
37 def author_info
38 @author_info ||= begin
39 Git.global_config
40 rescue NameError
41 {}
42 end
43 end
44
45 def homepage
46 author_info['github.user'] ? "http://github.com/#{author_info['github.user']}/radiant-#{file_name}-extension" : "http://example.com/#{file_name}"
47 end
48
49 def author_email
50 author_info['user.email'] || 'your email'
51 end
52
53 def author_name
54 author_info['user.name'] || 'Your Name'
55 end
56
57 def add_options!(opt)
58 # opt.separator ''
59 # opt.separator 'Options:'
60 # opt.on("--with-test-unit",
61 # "Use Test::Unit for this extension instead of RSpec") { |v| options[:with_test_unit] = v }
62 end
63
64 def localization_name
65 file_name.split('_')[1] ? "#{file_name.split('_')[0]}-#{file_name.split('_')[1].upcase}" : file_name
66 end
67
68 def copy_files
69 FileUtils.cp("#{RADIANT_ROOT}/config/locales/en_available_tags.yml","#{RADIANT_ROOT}/#{extension_path}/config/locales/#{localization_name}_available_tags.yml")
70 end
71 en