Sha256: 6f2bd38331a510b75542a3751fe02f71f489d14bdc62248b8abeb09135ead289

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

require 'ramaze/gestalt'

module Ramaze
  module Helper
    # Gestalt is the custom HTML/XML builder for Ramaze, based on a very simple 
    # DSL it will build your markup.
    module Gestalt
      CACHE_G = {}

      def gestalt(&block)
        Ramaze::Gestalt.new(&block)
      end

      def build(&block)
        Ramaze::Gestalt.build(&block)
      end

      def g(meth = nil, view = nil)
        meth ||= caller[0].slice(/`(.*)'?/).gsub(/[\`\']/, '')
        view_name = (self.class.to_s.sub('Controller', '') + 'View').split('::')
        view ||= view_name.inject(Object){ |ns, name| ns.const_get(name) }

        gestalt_class = CACHE_G[view] ||= g_class
        gestalt = gestalt_class.new
        gestalt.extend(view)
        instance_variables.each do |iv|
          gestalt.instance_variable_set(iv, instance_variable_get(iv))
        end
        gestalt.__send__(meth)
        gestalt.to_s
      end

      def g_class
        ancs = self.class.ancestors
        helpers = Ramaze::Helper.constants.map{ |c| Ramaze::Helper.const_get(c)}
        our_helpers = ancs & helpers
        our_helpers.delete(Ramaze::Helper::Gestalt)
        gestalt_class = Class.new(Ramaze::Gestalt){ include(*our_helpers) }
      end

      def method_missing(sym, *args, &block)
        @gestalt ||= gestalt
        @gestalt.send(sym, *args, &block)
      end
    end
  end
end

module Ramaze::Helper::Link; undef :a end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ramaze-2023.01.06 lib/ramaze/helper/gestalt.rb
ramaze-2012.12.08 lib/ramaze/helper/gestalt.rb
ramaze-2012.12.08b lib/ramaze/helper/gestalt.rb
ramaze-2012.04.14 lib/ramaze/helper/gestalt.rb
ramaze-2012.03.07 lib/ramaze/helper/gestalt.rb
ramaze-2011.12.28 lib/ramaze/helper/gestalt.rb
ramaze-2011.10.23 lib/ramaze/helper/gestalt.rb
ramaze-2011.07.25 lib/ramaze/helper/gestalt.rb