Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # first, run 'ls -R > filemap.txt', then run this script on that file.
- # css div classes:
- # folder
- # title
- # file
- require 'pp'
- doc = <<EOF
- <html>
- <head>
- <style type='text/css'>
- <!--
- .folder {
- background-color: #99CCCC;
- border: 1px solid #333333;
- display: block;
- margin-top: 3px;
- margin-right: 3px;
- margin-left: 6px;
- margin-bottom: 6px;
- }
- .title {
- background-color: #D5EAEA;
- width: 99%;
- padding-left: 1%;
- border-bottom-width: 1px;
- border-bottom-style: dotted;
- border-bottom-color: #333333;
- }
- .file {
- padding-right: 12px;
- padding-left: 12px;
- } //-->
- </style>
- </head>
- <body>
- EOF
- example = <<EOF
- Migratus
- filemap.txt
- images
- index.html
- index.php
- linkcheck
- modules
- phpMyAdmin
- sandbox
- site_administration.rb
- sitemap
- ./Migratus:
- Migratus 2.zip
- Rakefile
- app
- backup-sunday
- config
- db
- doc
- lib
- log
- migratus.rb
- public
- script
- test
- tmp
- vendor
- ./Migratus/app:
- controllers
- helpers
- models
- views
- ./Migratus/app/controllers:
- application.rb
- projects_controller.rb
- tasks_controller.rb
- ./Migratus/app/helpers:
- application_helper.rb
- application_helper.rb.bak
- projects_helper.rb
- ./Migratus/app/models:
- project.rb
- task.rb
- ./Migratus/app/views:
- layouts
- projects
- tasks
- ./Migratus/app/views/layouts:
- application.html.erb
- ./Migratus/app/views/projects:
- edit.html.erb
- index.html.erb
- new.html.erb
- show.html.erb
- ./Migratus/app/views/tasks:
- edit.html.erb
- index.html.erb
- new.html.erb
- show.html.erb
- ./Migratus/backup-sunday:
- Migratus.tmproj
- ./Migratus/config:
- boot.rb
- database.yml
- environment.rb
- environments
- initializers
- routes.rb
- ./Migratus/config/environments:
- development.rb
- production.rb
- test.rb
- ./Migratus/config/initializers:
- inflections.rb
- mime_types.rb
- ./Migratus/db:
- development.sqlite3
- migrate
- schema.rb
- ./Migratus/db/migrate:
- 001_create_tasks.rb
- 002_fix_tasks.rb
- 003_add_finished.rb
- 004_add_finished_to_tasks.rb
- 005_create_projects.rb
- 006_create_table_projects_tasks.rb
- ./Migratus/doc:
- README_FOR_APP
- ./Migratus/lib:
- tasks
- ./Migratus/lib/tasks:
- file_map.rake
- migratus.rake
- probe.rake
- ./Migratus/log:
- development.log
- mongrel.log
- production.log
- server.log
- test.log
- ./Migratus/public:
- 404.html
- 422.html
- 500.html
- dispatch.cgi
- dispatch.fcgi
- dispatch.rb
- favicon.ico
- images
- javascripts
- stylesheets
- ./Migratus/public/images:
- bar_yellow.gif
- dot_pattern.png
- rails.png
- ./Migratus/public/javascripts:
- application.js
- controls.js
- dragdrop.js
- effects.js
- prototype.js
- ./Migratus/public/stylesheets:
- main.css
- scaffold.css
- ./Migratus/script:
- about
- console
- destroy
- generate
- performance
- plugin
- process
- runner
- server
- ./Migratus/script/performance:
- benchmarker
- profiler
- request
- ./Migratus/script/process:
- inspector
- reaper
- spawner
- ./Migratus/test:
- fixtures
- functional
- unit
- ./Migratus/test/fixtures:
- projects.yml
- ./Migratus/test/functional:
- projects_controller_test.rb
- ./Migratus/test/unit:
- project_test.rb
- ./Migratus/tmp:
- cache
- pids
- sessions
- sockets
- ./Migratus/tmp/cache:
- ./Migratus/tmp/pids:
- ./Migratus/tmp/sessions:
- ./Migratus/tmp/sockets:
- ./Migratus/vendor:
- plugins
- ./Migratus/vendor/plugins:
- ./images:
- apache_pb.gif
- gradient.jpg
- macosxlogo.png
- web_share.gif
- EOF
- def transform_nested data
- result = {:name => "root", :elements => []}
- data.each do |item|
- index = result
- item.each do |sub|
- sub.gsub! /:$/, ''
- new_index = index[:elements].find {|e| e[:name] == sub}
- unless new_index
- new_index = {:name => sub, :elements => []}
- index[:elements] << new_index
- end
- index = new_index
- end
- end
- result
- end
- data = Array.new
- final_document = File.open('/Users/John/Sites/newmap.html', 'w') do |f|
- f << doc
- f << "Version 25: <br />"
- f << "<div class='folder'>\n\t"
- # File.open('/Users/John/Sites/filemap.txt').each do |x|
- example.each do |x|
- if x =~ /.*:$/
- x.gsub!('.', '')
- data << x.chomp!.split('/')
- end
- @map = transform_nested(data)
- case x
- when /.*:$/ # trailing ':'
- f << "\n<div class='folder'><div class='title'>\n\t"
- f << x
- f << "\n\t</div>"
- when /^\n/ # leading '\n'
- f << "</div>"
- else
- f << "\n<span class='file'>\n\t"
- f << x
- f << "\n\t</span>"
- end
- end
- @map.each do |k, v|
- f << "#{k} is: #{v}<br />"
- end
- f << "</div>"
- f << "\n</body></html>"
- end
Add Comment
Please, Sign In to add comment