Sha256: e03c090318ec30f7fcd08c255c77c18ef9fcae4b7f3df65ef84a2d0bc1e82d4e

Contents?: true

Size: 1.79 KB

Versions: 11

Compression:

Stored size: 1.79 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
          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

11 entries across 11 versions & 1 rubygems

Version Path
zafu-0.8.6 lib/zafu/controller_methods.rb
zafu-0.8.5 lib/zafu/controller_methods.rb
zafu-0.8.4 lib/zafu/controller_methods.rb
zafu-0.8.3 lib/zafu/controller_methods.rb
zafu-0.8.2 lib/zafu/controller_methods.rb
zafu-0.8.0 lib/zafu/controller_methods.rb
zafu-0.7.9 lib/zafu/controller_methods.rb
zafu-0.7.8 lib/zafu/controller_methods.rb
zafu-0.7.7 lib/zafu/controller_methods.rb
zafu-0.7.6 lib/zafu/controller_methods.rb
zafu-0.7.5 lib/zafu/controller_methods.rb