Sha256: c745e1e6408e2928521476904e6c9374c5f48a5dd1973d7193fcbf3ac8a94953

Contents?: true

Size: 882 Bytes

Versions: 3

Compression:

Stored size: 882 Bytes

Contents

require 'erb'
require 'moblues/generator/base/type'

module Moblues
  module Generator
    module Swift
      class Base
        def initialize
          @type = Generator::Base::Type.new
        end

        protected
        attr_reader :type

        def write_swift(output_dir, entity, file_type)
          write_file(file_path(output_dir, entity), render(entity, file_type))
        end

        def write_file(file, text)
          File.open(file, 'w+') do |f|
            f.write(text)
          end
        end

        def file_path(output_dir, entity)
          raise NotImplemented
        end

        def render(entity, file_type)
          ERB.new(template(file_type), 0, '-').result(entity.send(:binding))
        end

        def template(file_type)
          File.read(File.expand_path("../#{file_type}.swift.erb", __FILE__))
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
moblues-0.4.0 lib/moblues/generator/swift/base.rb
moblues-0.3.0 lib/moblues/generator/swift/base.rb
moblues-0.2.0 lib/moblues/generator/swift/base.rb