标签: haml

ERB与HAML转换if条件?

我开始使用HAML并正在处理我的第一个文件.表面上正确地省略了" - 结束":

- if current_user
= link_to 'Edit Profile', edit_user_path(current_user.id)
= link_to 'Logout', logout_path
- else
= link_to 'Register', new_user_path
= link_to 'Login', login_path
Run Code Online (Sandbox Code Playgroud)

得到我:

app/views/layouts/application.html.haml:28: syntax error, unexpected kENSURE, expecting kEND
app/views/layouts/application.html.haml:30: syntax error, unexpected $end, expecting kEND
Run Code Online (Sandbox Code Playgroud)

虽然合乎逻辑

- if current_user
= link_to 'Edit Profile', edit_user_path(current_user.id)
= link_to 'Logout', logout_path
- else
= link_to 'Register', new_user_path
= link_to 'Login', login_path
- end
Run Code Online (Sandbox Code Playgroud)

得到我:

You don't need to use "- end" in Haml. Use indentation instead:
- if …
Run Code Online (Sandbox Code Playgroud)

haml ruby-on-rails erb

11
推荐指数
1
解决办法
1万
查看次数

格式化填充的textarea,回车符,换行符和HAML

当我使用\ r \n(回车 - 换行)填充文本textarea中的文本格式不正确[更新:\ r \n是填写一个textarea时产生什么,我只是从数据库中什么是拉以前填写.还要注意,在生产环境中我似乎没有这个问题.END UPDATE]例如:

%textarea  
  = "hello\r\nHow are you?"
Run Code Online (Sandbox Code Playgroud)

像这样出来:

hello  
        How are you?
Run Code Online (Sandbox Code Playgroud)

我想这可能与HAML有关.谁能帮我吗?注意:如果我使用\n\r \n它工作正常,但这在技术上是不正确的,并且id必须做一些gsubs来反转它们以便正确显示.

haml textarea newline ruby-on-rails carriage-return

11
推荐指数
1
解决办法
8209
查看次数

与Haml/Sass的Wordpress

使用HamlSass进行一些Rails项目后,我发现它们极大地加快了我的前端开发速度.但是,我还没有找到像Wordpress一样强大或熟悉客户的Rails博客平台,因此对于需要具有基本CMS /博客功能的轻量级网站的项目来说,这仍然是我的首选.(我已经看过Radiant,Mephisto等,虽然我当然很欣赏Rails博客引擎的建议,但这不是我想在这里回答的问题.)

我真的希望能够在Wordpress网站的上下文中使用Haml和Sass,虽然我知道各种PHP实现的存在,但大多数似乎不活跃或有缺陷.有没有人在这里使用Haml和Sass与Wordpress网站成功?我在Wordpress模板文件(为Wordpress主题提供动力的.php文件)和Wordpress编辑器的HTML编辑模式中都要求这一点,尽管后者远不那么重要.

注意:我知道我可以安装适当的ruby gems并从Haml/Sass源编译我自己的HTML/CSS; 我正在寻找的东西更多的是我在Rails中习惯的功能,其中编译的HTML/CSS是基于每个请求自动生成的(缓存行为也很好,但肯定不是必需的) ).

提前致谢!

php wordpress haml sass

11
推荐指数
2
解决办法
6729
查看次数

SASS Global Variables + Rails 3.1

我正在使用Rails 3.1RC4和默认的SASS设置.我有以下文件

application.css.scss

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree . 
*/
Run Code Online (Sandbox Code Playgroud)

_variables.css.scss

$var1 : somevalue;
...
Run Code Online (Sandbox Code Playgroud)

site_layout.css.scss

@import "variables";
... Some Sass Code
Run Code Online (Sandbox Code Playgroud)

但我无法访问site_layout中_variables.css.scss中定义的变量.我究竟做错了什么?Rails显然找到了变量文件,因为它不会抛出"找不到文件"错误,如果我更改导入文件名就会出错.这些变量还没有结转.

有任何想法吗?

谢谢!

haml ruby-on-rails sass

11
推荐指数
1
解决办法
4405
查看次数

任何客户端haml解析器?

我希望使用JavaScript在客户端渲染我的haml代码.服务器端有很好的haml解析器,比如Jadehaml.js,但我不知道客户端有任何haml解析器/解码器.

更新:现在这是相当多HAML支持客户端.

html javascript haml

11
推荐指数
1
解决办法
1780
查看次数

Haml :: SyntaxError - 非法嵌套:内容不能与%a在同一行上给出并嵌套在其中

我正在使用来自Twitter Bootstrap和HAML的"按钮下拉列表".在Bootstrap文档中,我找到了这个例子:

<div class="btn-group">
  <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
    Action
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu">
    <!-- dropdown menu links -->
  </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

我试过用HAML重写它:

%div{:class => 'btn-group task_controller'}
  %a{:class => 'btn-mini dropdown-toggle', "data-toggle" => 'dropdown', :href => '#'} Action
    %span{:class => 'caret'}
  %ul{:class => 'dropdown-menu'}
    %a{:class => 'close_task', :name => task.name, :href => '#' } Close        
Run Code Online (Sandbox Code Playgroud)

但得到了错误信息:

Haml::SyntaxError - Illegal nesting: content can't be both given on the same line as %a and nested within it.
Run Code Online (Sandbox Code Playgroud)

所以Bootstrap说我把元素放在-tag中,但是HAML不允许这样做.我该如何解决这个问题?

haml twitter-bootstrap

11
推荐指数
2
解决办法
2万
查看次数

如何使用ng-checked预先选择angularJs中的复选框

我似乎无法让这个工作.所以我有很多类型的电影,如果那些是用户数据库中的类型,我希望它们被检查.这是我的代码


%section(ng-controller="UserCtrl" ng-init="user_genres=#{preferred_genres}")
    %ul
         %li(ng:repeat="genre in preferred_genres")
            %input(type = "checkbox" ng:model="preferred_genres[genre]" id="genre-{{$index + 1}}" ng-checked="user_genres['{{genre}}']")
            %label{:for => "genre-{{$index + 1}}"} {{genre}}

这是#{preferred_genres}来自haml


{"Action & Adventure":true,"Animation":true,"Art House & International":true,"Classics":true,"Comedy":true,"Documentary":true,"Drama":true,"Horror":true,"Kids & Family":true,"Musical & Performing Arts":true,"Mystery & Suspense":true,"Romance":true,"Science Fiction & Fantasy":true,"Special Interest":true,"Sports & Fitness":true,"Television":true,"Western":true}

这意味着应该检查每个复选框.但是,当我加载页面时,没有选中复选框.但是,如果我硬编码ng-checked成这样的东西就可以了.


ng-checked="user_genres['Western']"

这真的很奇怪.请帮忙.

javascript ruby haml sinatra angularjs

11
推荐指数
1
解决办法
2万
查看次数

我怎样才能获得current_page?匹配多个动作?

我的问题是我正在尝试做类似的事情

current_page?(controller: 'tigers', action:('index'||'new'||'edit'))
Run Code Online (Sandbox Code Playgroud)

当控制器是老虎并且操作是索引,新建或编辑时,它返回true.

以上内容不会引发错误,只会匹配第一个操作.

救命!

haml ruby-on-rails

11
推荐指数
2
解决办法
8989
查看次数

如何解决在bootstrap.min.css上有完整性属性问题

我在我的项目中使用bootstrap图标,这给了我错误

子资源完整性:资源" http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css "具有完整性属性,但资源要求启用CORS的请求以检查完整性,它不是.资源已被阻止,因为无法强制执行完整性.

任何人都可以帮我解决这个问题,当我们搬到生产时,图标没有加载.

所以我在下面的链接使用bootstrap图标

%link{:href => "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css", :integrity => "sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7", :rel => "stylesheet"}/
Run Code Online (Sandbox Code Playgroud)

haml css3 twitter-bootstrap ruby-on-rails-4 twitter-bootstrap-3

11
推荐指数
2
解决办法
9850
查看次数

HAML - if/elsif建设

我需要在我的HAML代码中使用这种结构:

- if something1
  %div.a
- elsif something2
  %div.b
- elsif something3
  %div.c
- else
  %div.d
    %div another content
Run Code Online (Sandbox Code Playgroud)

我希望我会得到类似的东西:

<div class="a|b|c|d">
  <div>another content</div>
</div>
Run Code Online (Sandbox Code Playgroud)

但事实上我得到了

   <div class="a|b|c|d"></div>
   <div>another content</div>
Run Code Online (Sandbox Code Playgroud)

如果需要,我必须如何更新我的代码:

另一个内容

ruby haml if-statement ruby-on-rails-3

10
推荐指数
2
解决办法
2万
查看次数