app/controllers/templates/templates_controller.rb in templates-0.2.1 vs app/controllers/templates/templates_controller.rb in templates-0.2.2
- old
+ new
@@ -19,50 +19,62 @@
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 = {}
- controller = controller_name.constantize
- templates_hash = {}
+ unless controller.templates_options.nil?
- 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[:layout]
- templates_hash[:layout] = render_to_string(:file => "layouts/#{controller.controller_name}", :layout => false)
- end
+ if controller.templates_options[:partials].count > 0
- if controller.templates_options[:partials].count > 0
+ templates_hash[:partials] = {}
- 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
+ controller.templates_options[:partials].each do |partial|
+ templates_hash[:partials][partial] = render_to_string(:file => "#{controller.controller_name}/_#{partial}", :layout => false)
end
-
end
- if not controller.templates_list.nil? and controller.templates_list.count > 0
+ end
- templates_hash[:templates] = {}
+ if not controller.templates_list.nil? and controller.templates_list.count > 0
- controller.templates_list.each do |template|
- templates_hash[:templates][template] = render_to_string(:file => "#{controller.controller_name}/#{template}", :layout => false)
- end
- end
+ templates_hash[:templates] = {}
- app_templates[controller.controller_name] = templates_hash unless templates_hash.empty?
+ 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
app_templates
end
def last_modify
- `stat -f %m $(ls -t $(find #{Rails.root}/app/ -type f) | head -n 1)`.strip
+ # Watched files (and dirs) list
+ watched_files = %w[
+ app/views
+ app/helpers
+ config/locales
+ config/routes.rb
+ ].map { |f| [Rails.root, f].join('/') }
+
+ stat_flags = if RUBY_PLATFORM =~ /darwin/
+ # Mac OS X
+ '-f %m'
+ else
+ # Linux (it may work on Windows, but in fact I'm really don't care about this crap)
+ '--format=%Y'
+ end
+ `stat #{stat_flags} $(ls -t $(find #{ watched_files.join(' ') } -type f) | head -n 1)`.strip
end
end
end