Sha256: 8b69a3088a8eb3e6ac26534b19e90c8b0fcdb40915a1b335ca77ae6bce7b8d6b

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

require 'markaby'

module Ramaze
  module Template
    class Markaby < Template
      ENGINES[self] = %w[ mab ]

      class << self

        # Entry point for Action#render

        def transform action
          result, file = result_and_file(action)

          result = transform_string(file, action) if file
          result.to_s
        end

        # Takes a string and action, instance_evals the string inside a mab
        # block that gets the instance_variables of the original
        # action.instance passed.

        def transform_string string, action
          instance = action.instance
          ivs = extract_ivs(instance)

          instance.send(:mab, ivs) do
            instance_eval(string)
          end
        end

        # Generate a hash from instance-variables

        def extract_ivs(controller)
          controller.instance_variables.inject({}) do |hash, iv|
            sym = iv.gsub('@', '').to_sym
            hash.merge! sym => controller.instance_variable_get(iv)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ramaze-0.1.2 lib/ramaze/template/markaby.rb