Sha256: c3f5217f8a83cd5bf32aefcbad7472cad99ab5434e512717602ffca6527ce3a9

Contents?: true

Size: 922 Bytes

Versions: 2

Compression:

Stored size: 922 Bytes

Contents

require 'erb'

module Space
  class Screen
    class View
      include Helpers

      attr_reader :project

      def initialize(project)
        @project = project
      end

      private

        def clear
          print "\e[2J\e[0;0H" # clear screen, move cursor to home
        end

        def render_header
          puts "Project #{project.name}\n\n"
        end

        def render_template(name, assigns)
          assigns.each { |name, value| assign(name, value) }
          print template(name).result(binding)
        end

        def assign(key, value)
          instance_variable_set(:"@#{key}", value)
          (class << self; self; end).send(:attr_reader, key)
        end

        def templates
          @templates ||= {}
        end

        def template(name)
          templates[name] ||= ERB.new(File.read("#{project.config.template_dir}/#{name}.erb"), nil, '%<>-')
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
space-0.0.5 lib/space/screen/view.rb
space-0.0.4 lib/space/screen/view.rb