Sha256: 6975753b23ed9ee512145e984a64acf7432860970a448bda9db7eefacca430b5

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'nano/kernel/constant'
require 'nano/string/camelize'

require 'glue/attribute'

module Nitro

# Helpers are standard Ruby modules that contain utility 
# methods. By using the special 'helper'
# macro provided by Helpers, the utility methods are
# included as private methods.
#
# The helper also requires the ruby file.
#
# === Examples
#
# class MyController < Nitro::Controller
#   helper :xhtml # == include Nitro::XhtmlHelper
# end

module Helpers

  module Utils
  
    #--
    # gmosx: dont name constant to avoid loop.
    #++
    
    def self.const(mod)
      return constant(mod)
    rescue NameError => ex
      return nil
    end
  end
  
  def self.append_features(base)
    super
    base.module_eval do
      def self.helper(*modules)
        for mod in modules
          #--
          # gmosx, FIXME: temp solution, will fix!
          #++
          
          if mod.is_a? String
            begin
              # gmosx: dont interpolate (RDoc fix).
              require('src/helper/' + mod)
            rescue Object
              require('nitro/helper/' + mod) rescue nil
            end
          end
                    
          unless mod.is_a? Module
            mod = mod.to_s.camelize
            # gmosx: check xxxHelper before xxx.
            mod = Utils.const("#{mod}Helper") || Utils.const("Nitro::#{mod}Helper") || Utils.const(mod) 
          end
          symbols = mod.instance_methods.collect { |m| m.to_sym }
          self.send(:include, mod)
          self.send(:private, *symbols)
        end
      end
    end
  end
  
end

end

# * George Moschovitis <gm@navel.gr>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.27.0 lib/nitro/helper.rb