Class: LanguageExtensionGenerator

Inherits:
Rails::Generator::NamedBase
  • Object
show all
Defined in:
lib/generators/language_extension/language_extension_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_args, runtime_options = {}) ⇒ LanguageExtensionGenerator

Returns a new instance of LanguageExtensionGenerator.



6
7
8
9
10
11
# File 'lib/generators/language_extension/language_extension_generator.rb', line 6

def initialize(runtime_args, runtime_options = {})
  super
  @extension_file_name = "#{file_name}_language_pack_extension"
  @extension_path = "vendor/extensions/#{file_name}_language_pack"
  @localization_name = localization_name
end

Instance Attribute Details

#extension_file_nameObject (readonly)

Returns the value of attribute extension_file_name.



4
5
6
# File 'lib/generators/language_extension/language_extension_generator.rb', line 4

def extension_file_name
  @extension_file_name
end

#extension_pathObject (readonly)

Returns the value of attribute extension_path.



4
5
6
# File 'lib/generators/language_extension/language_extension_generator.rb', line 4

def extension_path
  @extension_path
end

#localization_nameObject (readonly)

Returns the value of attribute localization_name.



4
5
6
# File 'lib/generators/language_extension/language_extension_generator.rb', line 4

def localization_name
  @localization_name
end

Instance Method Details

#add_options!(opt) ⇒ Object



57
58
59
60
61
62
# File 'lib/generators/language_extension/language_extension_generator.rb', line 57

def add_options!(opt)
  # opt.separator ''
  # opt.separator 'Options:'
  # opt.on("--with-test-unit",
  #        "Use Test::Unit for this extension instead of RSpec") { |v| options[:with_test_unit] = v }
end

#author_emailObject



49
50
51
# File 'lib/generators/language_extension/language_extension_generator.rb', line 49

def author_email
  author_info['user.email'] || 'your email'
end

#author_infoObject



37
38
39
40
41
42
43
# File 'lib/generators/language_extension/language_extension_generator.rb', line 37

def author_info
  @author_info ||= begin
    Git.global_config
  rescue NameError
    {}
  end
end

#author_nameObject



53
54
55
# File 'lib/generators/language_extension/language_extension_generator.rb', line 53

def author_name
  author_info['user.name'] || 'Your Name'
end

#class_nameObject



29
30
31
# File 'lib/generators/language_extension/language_extension_generator.rb', line 29

def class_name
  super.to_name.gsub(' ', '') + 'LanguagePackExtension'
end

#copy_filesObject



68
69
70
# File 'lib/generators/language_extension/language_extension_generator.rb', line 68

def copy_files
  FileUtils.cp("#{TRUSTY_CMS_ROOT}/config/locales/en_available_tags.yml","#{TRUSTY_CMS_ROOT}/#{extension_path}/config/locales/#{localization_name}_available_tags.yml")
end

#extension_nameObject



33
34
35
# File 'lib/generators/language_extension/language_extension_generator.rb', line 33

def extension_name
  class_name.to_name('Extension')
end

#homepageObject



45
46
47
# File 'lib/generators/language_extension/language_extension_generator.rb', line 45

def homepage
  author_info['github.user'] ? "http://github.com/#{author_info['github.user']}/radiant-#{file_name}-extension" : "http://example.com/#{file_name}"
end

#manifestObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/generators/language_extension/language_extension_generator.rb', line 13

def manifest
  record do |m|
    m.directory "#{extension_path}/config/locales"
    m.directory "#{extension_path}/lib/tasks"

    m.template 'README',                "#{extension_path}/README"
    m.template 'extension.rb',          "#{extension_path}/#{extension_file_name}.rb"
    # m.template 'tasks.rake',            "#{extension_path}/lib/tasks/#{extension_file_name}_tasks.rake"
    m.template 'lang.yml',              "#{extension_path}/config/locales/#{localization_name}.yml"
    m.template 'available_tags.yml',    "#{extension_path}/config/locales/#{localization_name}_available_tags.yml"
    m.template 'lib.rb',                "#{extension_path}/lib/radiant-#{file_name}_language_pack-extension.rb"
    m.template 'gemspec.rb',            "#{extension_path}/radiant-#{file_name}_language_pack-extension.gemspec"
  end

end