Class: As3gettext::Command
- Inherits:
-
Object
- Object
- As3gettext::Command
- Includes:
- GetText
- Defined in:
- lib/as3gettext/command.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #as3lib ⇒ Object
- #gettext ⇒ Object
-
#initialize ⇒ Command
constructor
A new instance of Command.
- #parse(argv) ⇒ Object
- #run(argv) ⇒ Object
- #xml ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
11 12 13 14 15 |
# File 'lib/as3gettext/command.rb', line 11 def initialize @config = { :mode => :gettext } end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
16 17 18 |
# File 'lib/as3gettext/command.rb', line 16 def config @config end |
Instance Method Details
#as3lib ⇒ Object
39 40 41 42 43 |
# File 'lib/as3gettext/command.rb', line 39 def as3lib Dir.glob(File.join(File.dirname(__FILE__), '..', '..', 'as3lib', '*')).each do |src| FileUtils.cp_r(src, File.join(config[:as3lib_dir], '')) end end |
#gettext ⇒ Object
23 24 25 26 |
# File 'lib/as3gettext/command.rb', line 23 def gettext RGetText.add_parser As3gettext::As3Parser GetText.rgettext config[:targets], config[:output] || STDOUT end |
#parse(argv) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/as3gettext/command.rb', line 45 def parse(argv) op = OptionParser.new op. = <<-EOF.gsub(/^\s+/, '') Usage: $ as3gettext src/HelloWrold.as src/**/*.mxml -o template.pot $ as3gettext i18n/**.po -x -o langs.xml $ as3gettext -g path/to/your/as3/src EOF op.on('-h', '--help', 'show this message') { puts op; Kernel::exit 1 } op.on('-x', 'export XML') { config[:mode] = :xml } op.on('-o=VAL', 'output file') {|v| config[:output] = v } op.on('-g=VAL', 'generate as3 library') {|v| config[:mode] = :as3lib; config[:as3lib_dir] = v } op.version = IO.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')) op.parse! argv if config[:mode] != :as3lib && argv.empty? puts op exit 1 end config[:targets] = argv end |
#run(argv) ⇒ Object
18 19 20 21 |
# File 'lib/as3gettext/command.rb', line 18 def run(argv) parse argv send @config[:mode] end |
#xml ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/as3gettext/command.rb', line 28 def xml xml_string = GenerateXml.new.generate config[:targets] if config[:output] File.open(config[:output], 'w') do |f| f.puts xml_string end else puts xml_string end end |