Sha256: f1730ae3b30a4b3f35204b52d8e96b9434076059e60fb0b4382188a5ba3a54b5

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

=begin
  parser/erb.rb - parser for ERB

  Copyright (C) 2005  Masao Mutoh
 
  You may redistribute it and/or modify it under the same
  license terms as Ruby.

  $Id: erb.rb,v 1.5 2007/08/01 01:39:14 mutoh Exp $
=end

require 'erb'
require 'gettext/parser/ruby.rb'

module GetText
  module ErbParser
    extend self

    @config = {
      :extnames => ['.rhtml', '.erb']
    }

    # Sets some preferences to parse ERB files.
    # * config: a Hash of the config. It can takes some values below:
    #   * :extnames: An Array of target files extension. Default is [".rhtml"].
    def init(config)
      config.each{|k, v|
	@config[k] = v
      }
    end

    def parse(file, targets = []) # :nodoc:
      src = ERB.new(IO.readlines(file).join).src
      # Remove magic comment prepended by erb in Ruby 1.9.
      src.sub!(/\A#.*?coding[:=].*?\n/, '') if src.respond_to?(:encode)
      erb = src.split(/$/)
      RubyParser.parse_lines(file, erb, targets)
    end

    def target?(file) # :nodoc:
      @config[:extnames].each do |v|
	return true if File.extname(file) == v
      end
      false
    end
  end
end

if __FILE__ == $0
  # ex) ruby glade.rhtml foo.rhtml  bar.rhtml
  ARGV.each do |file|
    p GetText::ErbParser.parse(file)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gettext-2.0.2 lib/gettext/parser/erb.rb
gettext-2.0.1 lib/gettext/parser/erb.rb
gettext-2.0.3 lib/gettext/parser/erb.rb
gettext-2.0.4 lib/gettext/parser/erb.rb