Sha256: 55dfe0cb454d0d6ecb21c384ded3bd7c69d41606c9938c4468808902fc6fdfca

Contents?: true

Size: 1.36 KB

Versions: 20

Compression:

Stored size: 1.36 KB

Contents

#          Copyright (c) 2008 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

    # Is responsible for compiling a template using the Markaby templating engine.
    # Can be found at: http://code.whytheluckystiff.net/markaby/

    class Markaby < Template
      include Ramaze::Helper::Methods

      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

20 entries across 20 versions & 5 rubygems

Version Path
Pistos-ramaze-2008.09 lib/ramaze/template/markaby.rb
Pistos-ramaze-2008.12 lib/ramaze/template/markaby.rb
Pistos-ramaze-2009.01 lib/ramaze/template/markaby.rb
Pistos-ramaze-2009.02 lib/ramaze/template/markaby.rb
clivecrous-ramaze-0.3.9.5 lib/ramaze/template/markaby.rb
manveru-ramaze-2008.07 lib/ramaze/template/markaby.rb
manveru-ramaze-2008.08 lib/ramaze/template/markaby.rb
manveru-ramaze-2008.09 lib/ramaze/template/markaby.rb
manveru-ramaze-2008.10 lib/ramaze/template/markaby.rb
manveru-ramaze-2008.12 lib/ramaze/template/markaby.rb
manveru-ramaze-2009.01 lib/ramaze/template/markaby.rb
ptomato-ramaze-2009.02.1 lib/ramaze/template/markaby.rb
ptomato-ramaze-2009.02 lib/ramaze/template/markaby.rb
ramaze-2009.01 lib/ramaze/template/markaby.rb
ramaze-2008.06 lib/ramaze/template/markaby.rb
ramaze-2008.11 lib/ramaze/template/markaby.rb
ramaze-0.3.9 lib/ramaze/template/markaby.rb
ramaze-0.3.9.1 lib/ramaze/template/markaby.rb
ramaze-2009.03 lib/ramaze/template/markaby.rb
ramaze-2009.02 lib/ramaze/template/markaby.rb