Sha256: 80deade7b7df37412fbba0f4c7a245080b0fcfaab2b2be7b6161a6c9c442d6c1

Contents?: true

Size: 999 Bytes

Versions: 30

Compression:

Stored size: 999 Bytes

Contents

require 'tilt'

module Alula
  class Theme
    class View
      attr_reader :theme
      attr_reader :layout
      attr_reader :context
      
      def initialize(opts)
        @theme = opts.delete(:theme)
        @name = opts.delete(:name)
        @file = opts.delete(:file)
        
        # Shortcuts...
        @context = @theme.context
        
        # Load our template
        @template = Tilt.new(@file, nil, @theme.options(@file))
      end
      
      def render(content, &blk)
        _old_values = {}
        
        # Set up context, make sure we don't change anything
        begin
          content.each do |key, value|
            _old_values[key] = self.context[key]
            self.context[key] = value
          end
          
          # Render using our template
          @template.render(self.context, &blk)
          
        ensure
          _old_values.each do |key, value|
            self.context[key] = value
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
alula-0.4.8 lib/alula/theme/view.rb
alula-0.4.7 lib/alula/theme/view.rb
alula-0.4.6 lib/alula/theme/view.rb
alula-0.4.5 lib/alula/theme/view.rb
alula-0.4.4 lib/alula/theme/view.rb
alula-0.4.3 lib/alula/theme/view.rb
alula-0.4.2 lib/alula/theme/view.rb
alula-0.4.1 lib/alula/theme/view.rb
alula-0.4.0 lib/alula/theme/view.rb
alula-0.4.0b lib/alula/theme/view.rb