简体   繁体   English

在非Ruby环境中使用HAML(用于渲染部分)

[英]Use HAML (for rendering partials) in a non-ruby environment

I am trying to use HAML (mainly for the rendering of partials) in a regular HTML/JS environment. 我正在尝试在常规HTML / JS环境中使用HAML(主要用于部分渲染)。

I'm using guard to watch the project, mainly for .scss files and also using Compass. 我正在使用guard来观看项目,主要是.scss文件以及Compass。

The project layout is: 项目布局为:

-public/
  --assets/
    ---css/
    ---fonts/
    ---img/
    ---js/
    ---sass/
 --partials/
-src
  --partials/
    --- header.html.haml
    --- footer.html.haml
  --index.html/haml

Gemfile 的Gemfile

source "https://rubygems.org"

gem 'rake'
gem 'haml'
gem 'coffee-script'
gem 'rb-fsevent'
gem 'rb-inotify'
gem 'sass'
gem 'compass'
gem 'sass-globbing'
gem 'compass-validator'
gem 'oily_png'
gem 'css_parser'
gem 'uglifier'
gem 'guard'
gem 'guard-haml'
gem 'guard-coffeescript'
gem 'guard-sass'
gem 'guard-compass'
gem 'guard-concat'
gem 'guard-process'
gem 'guard-uglify'
gem 'guard-livereload'
gem 'juicer'
gem 'therubyracer'

Guardfile Guardfile

# Compile stylesheet (compass watch)
if File.exists?("./config.rb")
  # Compile on start.
  puts `compass compile --time --quiet`
  # https://github.com/guard/guard-compass
  guard :compass do
    watch(%r{(.*)\.s[ac]ss$})
  end
end

# Minify CSS
guard 'process', :name => 'Minify CSS', :command => 'juicer merge assets/css/style.css --force -c none' do
  watch %r{assets/css/style\.css}
end

# Minify JS
guard 'process', :name => 'Minify application javascript', :command => 'juicer merge assets/js/app.js --force -s' do
  watch %r{assets/js/app\.js}
end

# HAML
guard :haml, input: 'src', output: 'public', run_at_start: true do
  watch %r{^src/.+(\.html\.haml)}
end

# Livereload
guard :livereload do
  watch(%r{.+\.(css|js|html?)$})
end

THE ERROR 错误

The sass renders fine, as does the minifying, livereload, etc. And the haml compiles fine when I dont try to use = render :partial => "header" sass可以很好地渲染,缩小,livereload等也可以。当我不尝试使用= render :partial => "header"时,haml可以很好地编译

The console output is: 控制台输出为:

$ bundle exec guard -i

Compilation took 0.105s
10:55:18 - INFO - Guard is using TerminalTitle to send notifications.
10:55:18 - INFO - Guard::Compass is waiting to compile your stylesheets.
10:55:18 - ERROR - HAML compilation failed!
> [#F8322E875F42] Error: undefined method `render' for #<Object:0x007feb43d1d8b0>

ADDITIONAL NOTES 补充笔记

A similar issue is posted here: Using layouts in HAML files independently of Rails . 这里发布了类似的问题: 在HAML文件中独立于Rails使用布局

I cannot however relate it well enough to my environment to solve the problem. 但是,我不能将其与我的环境足够好地关联以解决问题。

Any help is appreciated! 任何帮助表示赞赏!

This is not a Guard issue. 这不是Guard的问题。 The render method is defined by Rails, that's why you get the error. render方法是由Rails定义的,这就是为什么会出现错误的原因。

That said you can find how to define it in https://stackoverflow.com/a/6131411/304055 (the question you already linked). 也就是说,您可以在https://stackoverflow.com/a/6131411/304055 (您已链接的问题)中找到如何定义它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM