是否可以“观看”? Compass(样式表创作工具)中的 Haml 文件?

发布于 2024-09-06 06:27:55 字数 205 浏览 4 评论 0原文

目前,Compass 正在监视 src 文件夹内的 .scss 文件并自动更新 cs 文件。 (通过输入compass watch myproject)。

有没有办法将 haml 文件包含在“观看过程”中?

(我无法安装StaticMatic,因为我不想安装Ruby1.8)。

Currently, Compass is watching the .scss files inside the src folder and automatically updating the cs files. (by typing compass watch myproject).

Is there any way of including haml files in the "watching process"?

(I couldn't install StaticMatic because I don't want to install Ruby1.8).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情泪▽动烟 2024-09-13 06:27:55

首先,您应该使用 RVM。安装任何版本的 Ruby 都变得轻而易举。

其次,我只是为自己编写了这个,使用 Compass 用于监视文件的相同“fssm”gem。将其添加到您的/创建一个 Rakefile:

require 'rubygems'
require 'fssm'
require 'haml'

class HamlWatcher
  class << self
    def watch
      refresh
      puts ">>> HamlWatcher is watching for changes. Press Ctrl-C to Stop."
      FSSM.monitor('haml', '**/*.haml') do
        update do |base, relative|
          puts ">>> Change detected to: #{relative}"
          HamlWatcher.compile(relative)
        end
        create do |base, relative|
          puts ">>> File created: #{relative}"
          HamlWatcher.compile(relative)
        end
        delete do |base, relative|
          puts ">>> File deleted: #{relative}"
          HamlWatcher.remove(relative)
        end
      end
    end

    def output_file(filename)
      # './haml' retains the base directory structure
      filename.gsub(/\.html\.haml$/,'.html')
    end

    def remove(file)
      output = output_file(file)
      File.delete output
      puts "\033[0;31m   remove\033[0m #{output}"
    end

    def compile(file)
      output_file_name = output_file(file)
      origin = File.open(File.join('haml', file)).read
      result = Haml::Engine.new(origin).render
      raise "Nothing rendered!" if result.empty?
      # Write rendered HTML to file
      color, action = File.exist?(output_file_name) ? [33, 'overwrite'] : [32, '   create']
      puts "\033[0;#{color}m#{action}\033[0m #{output_file_name}"
      File.open(output_file_name,'w') {|f| f.write(result)}
    end

    # Check that all haml templates have been rendered.
    def refresh
      Dir.glob('haml/**/*.haml').each do |file|
        file.gsub!(/^haml\//, '')
        compile(file) unless File.exist?(output_file(file))
      end
    end
  end
end


namespace :haml do
  desc "Watch the site's HAML templates and recompile them when they change"
  task :watch do
    require File.join(File.dirname(__FILE__), 'lib', 'haml_watcher')
    HamlWatcher.watch
  end
end

运行它:

rake haml:watch

Firstly, you should be using RVM. Installing any version of Ruby becomes painless.

Secondly, I just wrote this for myself, using the same 'fssm' gem that Compass uses to watch files. Add this to your / create a Rakefile:

require 'rubygems'
require 'fssm'
require 'haml'

class HamlWatcher
  class << self
    def watch
      refresh
      puts ">>> HamlWatcher is watching for changes. Press Ctrl-C to Stop."
      FSSM.monitor('haml', '**/*.haml') do
        update do |base, relative|
          puts ">>> Change detected to: #{relative}"
          HamlWatcher.compile(relative)
        end
        create do |base, relative|
          puts ">>> File created: #{relative}"
          HamlWatcher.compile(relative)
        end
        delete do |base, relative|
          puts ">>> File deleted: #{relative}"
          HamlWatcher.remove(relative)
        end
      end
    end

    def output_file(filename)
      # './haml' retains the base directory structure
      filename.gsub(/\.html\.haml$/,'.html')
    end

    def remove(file)
      output = output_file(file)
      File.delete output
      puts "\033[0;31m   remove\033[0m #{output}"
    end

    def compile(file)
      output_file_name = output_file(file)
      origin = File.open(File.join('haml', file)).read
      result = Haml::Engine.new(origin).render
      raise "Nothing rendered!" if result.empty?
      # Write rendered HTML to file
      color, action = File.exist?(output_file_name) ? [33, 'overwrite'] : [32, '   create']
      puts "\033[0;#{color}m#{action}\033[0m #{output_file_name}"
      File.open(output_file_name,'w') {|f| f.write(result)}
    end

    # Check that all haml templates have been rendered.
    def refresh
      Dir.glob('haml/**/*.haml').each do |file|
        file.gsub!(/^haml\//, '')
        compile(file) unless File.exist?(output_file(file))
      end
    end
  end
end


namespace :haml do
  desc "Watch the site's HAML templates and recompile them when they change"
  task :watch do
    require File.join(File.dirname(__FILE__), 'lib', 'haml_watcher')
    HamlWatcher.watch
  end
end

Run it with:

rake haml:watch
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文