Module: Cream::Generators::HamlUtil
- Included in:
- ViewsGenerator
- Defined in:
- lib/generators/cream/views/haml_util.rb
Instance Method Summary collapse
Instance Method Details
#create_and_copy_haml_views ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/cream/views/haml_util.rb', line 20 def create_and_copy_haml_views verify_haml_existence verify_haml_version require 'tmpdir' html_root = "#{self.class.source_root}/cream" Dir.mktmpdir("cream-haml.") do |haml_root| Dir["#{html_root}/**/*"].each do |path| relative_path = path.sub(html_root, "") source_path = (haml_root + relative_path).sub(/erb$/, "haml") if File.directory?(path) FileUtils.mkdir_p(source_path) else `html2haml -r #{path} #{source_path}` end end directory haml_root, "app/views/#{scope || 'cream'}" end end |
#verify_haml_existence ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/generators/cream/views/haml_util.rb', line 4 def verify_haml_existence begin require 'haml' rescue LoadError say "HAML is not installed, or it is not specified in your Gemfile." exit end end |
#verify_haml_version ⇒ Object
13 14 15 16 17 18 |
# File 'lib/generators/cream/views/haml_util.rb', line 13 def verify_haml_version unless Haml.version[:major] == 2 and Haml.version[:minor] >= 3 or Haml.version[:major] >= 3 say "To generate HAML templates, you need to install HAML 2.3 or above." exit end end |