Sha256: b97cab0cd3748b9fb33333811b542dc168be555711dc2cdf2566a6c00ce81b49

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

class GettextSimpleRails::SetupHelper
  def initialize(args)
    @args = args
  end
  
  def poedit_config_path
    if @args[:poedit_config_path]
      return @args[:poedit_config_path]
    else
      "#{ENV["HOME"]}/.poedit/config"
    end
  end
  
  def poedit_config_has_ruby_parser?
    config_content = File.read(poedit_config_path)
    return config_content.include?("[Parsers/Ruby]")
  end
  
  def poedit_add_ruby_parser_to_config
    sample_path = "#{File.dirname(__FILE__)}/../../config/poedit_ruby_parser.conf"
    sample_content = File.read(sample_path).strip
    config_content = File.read(poedit_config_path).strip
    
    File.open(poedit_config_path, "w") do |fp|
      fp.puts(config_content)
      fp.puts(sample_content)
    end
  end
  
  def poedit_config_has_ruby_in_list_of_parsers?
    config_content = File.read(poedit_config_path).strip
    parsers_list_match = config_content.match(/\[Parsers\]\s+List=(.+?)\n/)
    list = parsers_list_match[1].split(";")
    return list.include?("Ruby")
  end
  
  def poedit_config_add_ruby_to_list_of_parsers
    config_content = File.read(poedit_config_path).strip
    parsers_list_match = config_content.match(/\[Parsers\]\s+List=(.+?)\n/)
    list = parsers_list_match[1].split(";")
    list << "Ruby"
    
    new_config = config_content.gsub(parsers_list_match[0], "[Parsers]\nList=#{list.join(";")}\n")
    raise "Could not add Ruby to list of parsers." if new_config == config_content
    
    File.open(poedit_config_path, "w") do |fp|
      fp.puts(new_config)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gettext_simple_rails-0.0.13 lib/gettext_simple_rails/setup_helper.rb
gettext_simple_rails-0.0.12 lib/gettext_simple_rails/setup_helper.rb
gettext_simple_rails-0.0.11 lib/gettext_simple_rails/setup_helper.rb
gettext_simple_rails-0.0.10 lib/gettext_simple_rails/setup_helper.rb
gettext_simple_rails-0.0.9 lib/gettext_simple_rails/setup_helper.rb