lib/rid/actions/routes.rb in rid-0.3.1 vs lib/rid/actions/routes.rb in rid-0.4.0
- old
+ new
@@ -2,35 +2,38 @@
module Rid
module Actions
class Routes < Base
def routes
- say 'Static:'
- Dir.glob(File.join(destination_root, "_attachments/*.html")).each do |file|
- say ' %s' % attachment_url(file)
- end
+ static_files = Dir.glob(File.join(destination_root, "_attachments/*.html"))
+ longest_name = (%w[show list] + static_files.map { |f| File.basename(f, '.html') }).map(&:length).sort.last + 1
- say 'Lists:'
- Dir.glob(File.join(destination_root, "lists/*")).each do |list|
- Dir.glob(File.join(destination_root, "views/*")).each do |view|
- say ' %s' % list_url(list, view)
+ unless static_files.empty?
+ say 'Static'
+ static_files.each do |file|
+ say ' %s %s' % [(File.basename(file, '.html') + ":").ljust(longest_name), attachment_url(file)]
end
end
- say 'Shows:'
- Dir.glob(File.join(destination_root, "shows/*")).each do |show|
- say ' %s' % show_url(show)
- say ' %s' % show_url(show, '/:id')
+ Dir.glob(File.join(destination_root, "views/*")).each do |model|
+ model_name = File.basename(model).singularize
+ say model_name.humanize
+ Dir.glob(File.join(destination_root, "shows/#{model_name}*")).each do |show|
+ say ' %s %s' % ["show:".ljust(longest_name), show_url(show, '/:id')]
+ end
+ Dir.glob(File.join(destination_root, "views/#{model_name}*")).each do |view|
+ say ' %s %s' % ["list:".ljust(longest_name), list_url(view, model)]
+ end
end
end
protected
def attachment_url(file)
File.join(Rid.database, '_design', File.basename(Rid.database), File.basename(file))
end
- def list_url(list, view)
+ def list_url(view, list)
File.join(Rid.database, '_design', File.basename(Rid.database), '_list', File.basename(view), File.basename(list, '.js'))
end
def show_url(show, id = '/')
File.join(Rid.database, '_design', File.basename(Rid.database), '_show', File.basename(show, '.js'), id)