Sha256: 99fa3c36da527bd93e00f598707bc376de55e2190a2a0b85f822b01244f0ce6f

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 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.
#
# === 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
          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

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.26.0 lib/nitro/helper.rb
nitro-0.25.0 lib/nitro/helper.rb