Sha256: 34a72ec691c501c9e583960bdb06ed222553a1b98561c7a29db88e34f310eefb

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

module Lolita
  module Controllers

    module InternalHelpers

      def include_application_assets
        result = ""
        Lolita.application.assets.each do |asset_name|
          if asset_name.match(/\.js(\.|$)/)
            result << javascript_include_tag(asset_name)
          elsif asset_name.match(/\.css(\.|$)/)
            result << stylesheet_link_tag(asset_name)
          end
        end
        raw(result)
      end

      def resource
        instance_variable_get(:"@#{resource_name}")
      end
      
      def resource_name
        lolita_mapping.class_name.underscore.to_sym
      end
      
      def resource_class
        lolita_mapping.to
      end
      
      def lolita_mapping(new_mapping = nil)
        @lolita_mapping ||= request.env["lolita.mapping"]
      end

      def current_form=(form)
        @current_form = form
      end

      def current_form(temp_form = nil)
        if block_given?
          old_form = @current_form
          @current_form = temp_form
          content = yield
          @current_form = old_form
        end
        @current_form
      end

      def use_mapping(new_mapping)
        if block_given? 
          begin
            @old_mapping = lolita_mapping
            @lolita_mapping = new_mapping
            yield
          ensure
            @lolita_mapping = @old_mapping
            @old_mapping = nil
          end
        end
      end

      def is_lolita_resource?
        raise ActionController::UnknownAction unless lolita_mapping
        true
      end

      protected


      def resource=(new_resource)
        instance_variable_set(:"@#{resource_name}",new_resource)
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lolita-3.4.1 lib/lolita/controllers/internal_helpers.rb
lolita-3.4.0 lib/lolita/controllers/internal_helpers.rb
lolita-3.3.9 lib/lolita/controllers/internal_helpers.rb
lolita-3.3.8 lib/lolita/controllers/internal_helpers.rb
lolita-3.3.7 lib/lolita/controllers/internal_helpers.rb