require 'masterview' MasterView::Log.level = Logger::ERROR namespace :mv do desc 'Display list and status about each MasterView template' task :list do template_specs, content_hash = MasterView::TemplateSpec.scan @template_specs_sorted = template_specs.sort @template_specs_sorted.each do |path, ts| puts "#{path}\t#{ts.status}\t#{ts.message}" end end desc 'Display list, status, and full details about each MasterView template' task :list_all do template_specs, content_hash = MasterView::TemplateSpec.scan @template_specs_sorted = template_specs.sort @template_specs_sorted.each do |path, ts| puts "#{path}\t#{ts.status}\t#{ts.message}" puts "\tgenerates: #{ts.gen_parts.join(', ')}\n\n" end end desc 'Rebuild/update template imports, specify TEMPLATE=foo.html' task :rebuild do raise "Usage: rake mv:rebuild TEMPLATE=foo.html" unless ENV['TEMPLATE'] path = ENV['TEMPLATE'] short_name = File.basename(path) short_name = short_name+'.html' unless short_name.index('.') path = File.join('app/views', MasterView::TemplateSrcRelativePath, short_name) template_specs, content_hash = MasterView::TemplateSpec.scan template_spec = template_specs[path] raise 'Template '+path+' not found' unless template_spec if template_spec.rebuild_template(content_hash, :write_to_file => true) puts 'File '+path+' updated' puts 'Note: Backup was created in '+MasterView::DirectoryForRebuildBackups else puts 'Identical content - no update needed for '+path end end desc 'Rebuild all outdated template imports' task :rebuild_all do files_rebuilt = [] MasterView::TemplateSpec.scan do |template_spec, content_hash| if template_spec.status == MasterView::TemplateSpec::Status::ImportsOutdated && template_spec.rebuild_template(content_hash, :write_to_file => true) files_rebuilt << template_spec.path end end files_rebuilt.each do |f| puts f+' updated' end unless files_rebuilt.empty? || MasterView::DirectoryForRebuildBackups.nil? puts 'Note: Backups were created in '+MasterView::DirectoryForRebuildBackups end end # checks app path first for views and files, then falls back to files in MV def find_path(path) mv_path = File.join(File.dirname(__FILE__), '../lib/masterview/extras', path) working_path = (File.exist?(path)) ? path : mv_path end desc 'Create shell template using layout of existing masterview template, requires TEMPLATE=foo.html ACTION=list' task :copy_layout do raise "Usage: rake mv:copy_layout TEMPLATE=foo.html ACTION=list" unless ENV['TEMPLATE'] && ENV['ACTION'] action_to_create = ENV['ACTION'] short_name = File.basename(ENV['TEMPLATE']) empty_file_path = find_path('app/views/masterview/admin/empty.rhtml') empty_insert_erb = File.readlines(empty_file_path).join src_file = File.join('app/views', MasterView::TemplateSrcRelativePath, short_name) dst_file = MasterView::TemplateSpec.create_empty_shell_for_action(src_file, action_to_create, empty_insert_erb, :write_to_file => true) puts dst_file+' created' end desc "Run parser manually on masterview html files to generate the erb/rhtml files" task :parse do OutputDir = 'app/views' filelist = Dir.glob('app/views/masterview/**/*.html') filelist.each do |file| MasterView::Parser.parse_file( file, OutputDir) puts 'Generated erb/rhtml files from '+file end puts 'Generated erb/rhtml output was created in app/views/** tree' end end