Created
December 20, 2019 21:03
-
-
Save tatums/420f048e4c6ca84d2d58de15eb1dfccd to your computer and use it in GitHub Desktop.
A script to convert a slim template to good ol' HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "slim" | |
| require 'fileutils' | |
| # allows single line html element followed by {{}} tags | |
| Slim::Engine.set_options :attr_list_delims => {'(' => ')', '[' => ']'} | |
| def convert(file, destination) | |
| s = File::open(file).read() | |
| t = Slim::Template.new({pretty: true}) { |x| s } | |
| t.render | |
| File.write(destination, t.render) | |
| end | |
| ## These files used a rails helper (image_path) for images and needed to be manually converted. | |
| ignore_files = %w( | |
| js_apps/journal_create/templates/done.html.slim | |
| js_apps/simple_journal_profile/templates/includes/footer.html.slim | |
| ) | |
| Dir.glob("js_apps/**/*.slim").each do |file| | |
| next if ignore_files.include?(file) | |
| app_name = file.split("/")[1] | |
| file_name = file.gsub("js_apps/#{app_name}/templates/", "").gsub(".slim", "") | |
| destination = "public/templates/#{app_name}/templates/#{file_name}" | |
| puts "#{file} -> #{destination}" | |
| items = destination.split("/") | |
| file_directory = items.reverse.drop(1).reverse.join("/") | |
| # puts file_directory | |
| FileUtils.mkdir_p file_directory | |
| convert(file, destination) | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment