Sha256: 7c6578ea081b7e5d56051661c9ec570399a03366274e5fd2c894bfa5d572a5aa

Contents?: true

Size: 1.18 KB

Versions: 14

Compression:

Stored size: 1.18 KB

Contents

module Cream
  module Generators
    module HamlUtil
      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

      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

      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
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cream-0.8.6 lib/generators/cream/views/haml_util.rb
cream-0.8.5 lib/generators/cream/views/haml_util.rb
cream-0.8.4 lib/generators/cream/views/haml_util.rb
cream-0.8.3 lib/generators/cream/views/haml_util.rb
cream-0.8.2 lib/generators/cream/views/haml_util.rb
cream-0.8.1 lib/generators/cream/views/haml_util.rb
cream-0.8.0 lib/generators/cream/views/haml_util.rb
cream-0.7.10 lib/generators/cream/views/haml_util.rb
cream-0.7.8 lib/generators/cream/views/haml_util.rb
cream-0.7.7 lib/generators/cream/views/haml_util.rb
cream-0.7.6 lib/generators/cream/views/haml_util.rb
cream-0.7.5 lib/generators/cream/views/haml_util.rb
cream-0.7.3 lib/generators/cream/views/haml_util.rb
cream-0.7.2 lib/generators/cream/views/haml_util.rb