class RDoc::Generator::POT::MessageExtractor

RDoc::Store 中提取消息

公共类方法

new(store) 点击切换源代码

store 创建一个消息提取器。

# File rdoc/generator/pot/message_extractor.rb, line 10
def initialize store
  @store = store
  @po = RDoc::Generator::POT::PO.new
end

公共实例方法

extract() 点击切换源代码

store 中提取消息,将它们存储到 RDoc::Generator::POT::PO 中并返回它。

# File rdoc/generator/pot/message_extractor.rb, line 19
def extract
  @store.all_classes_and_modules.each do |klass|
    extract_from_klass(klass)
  end
  @po
end

私有实例方法

entry(msgid, options) 点击切换源代码
# File rdoc/generator/pot/message_extractor.rb, line 64
def entry msgid, options
  RDoc::Generator::POT::POEntry.new(msgid, options)
end
extract_from_klass(klass) 点击切换源代码
# File rdoc/generator/pot/message_extractor.rb, line 28
def extract_from_klass klass
  extract_text(klass.comment_location, klass.full_name)

  klass.each_section do |section, constants, attributes|
    extract_text(section.title, "#{klass.full_name}: section title")
    section.comments.each do |comment|
      extract_text(comment, "#{klass.full_name}: #{section.title}")
    end
  end

  klass.each_constant do |constant|
    extract_text(constant.comment, constant.full_name)
  end

  klass.each_attribute do |attribute|
    extract_text(attribute.comment, attribute.full_name)
  end

  klass.each_method do |method|
    extract_text(method.comment, method.full_name)
  end
end
extract_text(text, comment, location = nil) 点击切换源代码
# File rdoc/generator/pot/message_extractor.rb, line 51
def extract_text text, comment, location = nil
  return if text.nil?

  options = {
    :extracted_comment => comment,
    :references => [location].compact,
  }
  i18n_text = RDoc::I18n::Text.new(text)
  i18n_text.extract_messages do |part|
    @po.add(entry(part[:paragraph], options))
  end
end