module Templates class TemplatesController < ApplicationController unloadable def index render :json => collect_templates end def mtime render :text => last_modify end protected def collect_templates app_templates = { :mtime => last_modify } Dir.new("#{Rails.root}/app/controllers").entries.each do |controller_file_name| if controller_file_name =~ /_controller/ controller_name = controller_file_name.camelize.gsub('.rb', '') if controller_name != 'ApplicationController' controller = controller_name.constantize templates_hash = {} unless controller.templates_options.nil? if controller.templates_options[:layout] templates_hash[:layout] = render_to_string(:file => "layouts/#{controller.controller_name}", :layout => false) end if controller.templates_options[:partials].count > 0 templates_hash[:partials] = {} controller.templates_options[:partials].each do |partial| templates_hash[:partials][partial] = render_to_string(:file => "#{controller.controller_name}/_#{partial}", :layout => false) end end end if not controller.templates_list.nil? and controller.templates_list.count > 0 templates_hash[:templates] = {} controller.templates_list.each do |template| templates_hash[:templates][template] = render_to_string(:file => "#{controller.controller_name}/#{template}", :layout => false) end end app_templates[controller.controller_name] = templates_hash unless templates_hash.empty? end end end app_templates end def last_modify `stat -f %m $(ls -t $(find #{Rails.root}/app/ -type f) | head -n 1)`.strip end end end