Sha256: f79de206c039307271410236df7e35b36857059050bc633f19200d0bbf571049

Contents?: true

Size: 1.7 KB

Versions: 43

Compression:

Stored size: 1.7 KB

Contents

require 'English'
require 'erb'

require 'rabbit/element'

module Rabbit
  module Parser
    class RD
      module Ext
        class Base
          include ERB::Util
          extend ERB::Util

          include Element

          class << self
            def inherited(klass)
              klass.const_set("EXTENSIONS", [])
            end

            def add_extension(name)
              extensions.push(name)
            end

            def extensions
              self::EXTENSIONS
            end

            def method_added(name)
              if /^ext_/ =~ name.to_s
                add_extension(name.to_s)
              end
            end
          end

          def apply(label, source, content, visitor)
            result = nil
            extensions.find do |entry|
              begin
                result = __send__(entry, label, source, content, visitor)
              rescue NameError
                visitor.logger.error($!)
                raise
              end
            end
            result
          end

          def extensions
            self.class.extensions
          end

          private
          def parse_source(source)
            prop = {}
            in_src = false
            src = ""
            source.each_line do |line|
              if in_src
                src << line
              else
                case line
                when /^\s*$/
                  in_src = true
                when /^(?:#\s*)?(\S+)\s*=\s*(.+)\s*$/
                  prop[$1] = $2
                else
                  in_src = true
                  src << line
                end
              end
            end
            [src, prop]
          end
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
rabbit-3.0.3 lib/rabbit/parser/rd/ext/base.rb
rabbit-3.0.2 lib/rabbit/parser/rd/ext/base.rb
rabbit-3.0.1 lib/rabbit/parser/rd/ext/base.rb
rabbit-3.0.0 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.2.1 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.2.0 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.9 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.8 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.7 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.6 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.5 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.4 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.3 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.2 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.1 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.1.0 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.0.9 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.0.8 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.0.7 lib/rabbit/parser/rd/ext/base.rb
rabbit-2.0.6 lib/rabbit/parser/rd/ext/base.rb