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



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

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



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

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

#author_infoObject



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

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

#author_nameObject



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

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

#class_nameObject



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

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

#copy_filesObject



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

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



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

def extension_name
  class_name.to_name('Extension')
end

#homepageObject



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

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
# 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