Sha256: 1450f5c374e404e1cc2d7f52b6f3d6cb3791c63a4e658c4ade81f0083a6d278c

Contents?: true

Size: 1.86 KB

Versions: 7

Compression:

Stored size: 1.86 KB

Contents

require 'zafu/node_context'

module Zafu
  module ControllerMethods
    def self.included(base)
      base.helper Common
      if RAILS_ENV == 'development'
        base.class_eval do
          def render_for_file_with_rebuild(template_path, status = nil, layout = nil, locals = {}) #:nodoc:
            path = template_path.respond_to?(:path_without_format_and_extension) ? template_path.path_without_format_and_extension : template_path
            logger.info("Rendering #{path}" + (status ? " (#{status})" : '')) if logger
            # if params[:rebuild] == 'true'
              t = self.view_paths.find_template(template_path, 'html')
              t.previously_last_modified = nil
            # end
            render_for_text @template.render(:file => template_path, :locals => locals, :layout => layout), status
          rescue => err
            puts err.backtrace.join("\n")
          end
          alias_method_chain :render_for_file, :rebuild
        end
      end
    end

    def zafu_node(name, klass)
      zafu_context[:node] = Zafu::NodeContext.new(name, klass)
    end

    module Common
      def zafu_context
        @zafu_context ||= {}
      end

      # Quote for html attributes (field quote). There might be a better rails alternative to this.
      def fquote(text)
        text.to_s.gsub("'",''')
      end

      # This method should return the template for a given 'src' and
      # 'base_path'.
      def get_template_text(path, base_path)
        [path, "#{base_path}/#{path}"].each do |p|
          begin
            t = self.view_paths.find_template(p, 'html') # FIXME: format ?
          rescue ActionView::MissingTemplate
            t = nil
          end
          return [t.source, t.path, t.base_path] if t
        end
        nil
      end

      def template_url_for_asset(opts)
        opts[:src]
      end
    end # Common

    include Common
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zafu-0.7.4 lib/zafu/controller_methods.rb
zafu-0.7.3 lib/zafu/controller_methods.rb
zafu-0.7.2 lib/zafu/controller_methods.rb
zafu-0.7.1 lib/zafu/controller_methods.rb
zafu-0.7.0 lib/zafu/controller_methods.rb
zafu-0.6.3 lib/zafu/controller_methods.rb
zafu-0.6.2 lib/zafu/controller_methods.rb