Sha256: 8d2e96c9c4214644219dd38e9c48cfc54fb79cb3ca1c89974283a316ff8479bb

Contents?: true

Size: 810 Bytes

Versions: 15

Compression:

Stored size: 810 Bytes

Contents

# Processes the ERB files and looks for comments like
#
#     #ERB if @testvar
#     - "some yaml"
#     #ERB end
#
class Kubes::Compiler::Strategy::Erb
  class Comment
    extend Memoist

    def initialize(path)
      @path = path
    end

    def lines
      IO.readlines(@path)
    end
    memoize :lines

    def process?
      !!lines.detect { |l| l.include?('#ERB') }
    end

    def process
      new_lines = lines.map do |line|
        md = line.match(/(.*)#ERB(.*)/)
        if md
          "#{md[1]}<%#{md[2]} %>\n"
        else
          line
        end
      end
      content = new_lines.join('')
      IO.write(erb_path, content)
      erb_path
    end

    def clean
      FileUtils.rm_f(erb_path) unless ENV['KUBES_KEEP_ERB']
    end

    def erb_path
      "#{@path}.erb"
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
kubes-0.9.3 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.9.2 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.9.1 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.9.0 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.10 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.9 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.8 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.7 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.6 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.5 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.4 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.3 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.2 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.1 lib/kubes/compiler/strategy/erb/comment.rb
kubes-0.8.0 lib/kubes/compiler/strategy/erb/comment.rb