query: tag:haml

最近はslimを押してますが、haml中のsassフィルタでインターポレーションを行う方法のメモです。

sassフィルタってのはこんなやつです。

haml>>
head
%style{type="text/css"}
:sass
body
background: #FFF
<<--

インターポレーションには#{ }を使いますが、これがhamlの記法とバッティングしてるので#をエスケープする必要があります。

haml>>
head
%style{type="text/css"}
:sass
@mixin opacity($a)
$A: $a * 100
opacity: $a
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=#{'#'}{$A})"
filter: alpha(opacity=$A)
<<--

こんな感じです。

posted by genki genki on Fri 30 Nov 2012 at 22:49 with 0 comments

答え

"!=", "!==" を使う

詳細

文字列のHTMLエスケープはRailsやRack::Utilによって
hヘルパメソッドとして提供されており、
ユーザはエスケープ処理を「hの有無」によって調整します。

|caption=例: hamlでのHTMLエスケープ
|
|コード,結果
|
|= link_to(...),<a href=...
|=h link_to(...),&lt;a href=...

自動エスケープモード

上記のようなユーザ駆動のエスケープ処理では100%の安全性を保証できないため、
hamlでは「デフォルトでエスケープする」というオプションが存在します。

ruby>>
Haml::Template.options[:escape_html] = true
<<--

これにより常時エスケープされるようになるのですが、
今度はh の逆とも言うべき「エスケープしない」方法が必要になります。
これがずっとわからなくて困っていたのですが、
「ドキュメントを見る」という手段を思い出して解決しました。
"!=" を使えばよいようです。

|caption=例: escape_html: true
|
|コード,結果
|
|!= link_to(...),<a href=...
|= link_to(...),&lt;a href=...
|=h link_to(...),&amp;lt;a href=...

posted by maiha maiha on Mon 8 Feb 2010 at 07:55 with 2 comments
haml は構造化文章をシンプルかつ強力に記述することができるが、 複数行のデータの扱いには以下の理由で不向きである。 * 行指向であるため適切なインデントの記述が強要される * 頑張って埋め込んでも可読性が落ちて全体の構造が把握し辛くなる これを改善するには、コード(構造情報)とデータの分離が必要になる。 ## inline filter module ruby>> module Inline include Haml::Filters::Base def self.[](key) @@data[key.to_s] rescue nil end def render(str) @@data = Hash[*str.split(/^\s*@@\s*(\w+)\s*\n/m)[1..-1]] return nil end end <<-- 上記を評価することで、 sinatra の in file template のようにデータ群を管理できるようになる。 ## 入力(haml) haml>> %h1 Inline Filter .describe= Inline[:describe] .author created by #{Inline[:author]} :inline @@ describe This filter easily separates structure and data. You can use in-file-templates like sinatra. @@ author maiha@wota.jp <<-- ## 出力(html) html>>

Inline Filter

This filter easily separates structure and data. You can use in-file-templates like sinatra.
created by maiha@wota.jp
<<--
posted by maiha maiha on Tue 20 Oct 2009 at 20:39 with 0 comments

行末に|を記述するHamlの複数行記法が書きにくかったので、
Vimで整形出来るようにするための外部プログラムを作ってみました。

http://gist.github.com/112140

pre>>
set fp=/path/to/haml_formatter.rb
<<--

して、visualモードで選択してgqで整形です。

posted by genki genki on Sun 17 May 2009 at 07:32 with 0 comments

hamlでtext_areaヘルパメソッドを使う場合は、以下のように"~"を使うと良い。

haml>>
~ text_area :foo
<<--

~ について (cheat hamlより)

Ruby expression preserving whitespace, e.g. %pre~ @content.body
Works just like =, but calls the find_and_preserve helper to keep
line breaks intact in the output.

posted by genki genki on Wed 6 May 2009 at 11:27 with 0 comments
Contents rssrss
Leading Smart TV App Development Companies | USA | 4 Way Technologies
Apple TV Developer | TVOS Development | USA | 4 Way Technologies
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Value Transformer
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Tags
haml
Comments rssrss
https://bisoncasino-hu.com/ https://bisoncasino-hu.com/: You are so cool! I don't believe I have read a s... 04/26 15:49
https://traversi.ru/kz/ https://traversi.ru/kz/: Независимые обзоры и рейтинги букмекерских контор ... 04/26 10:23
https://meros.ir https://meros.ir: وقت بخیر، بنده امروز در حال جستجو تو اینترنت با ... 04/26 09:37
https://businessrost.ru/bitrix/redirect.php?goto=http%3A%2F%2Feximha.ch%2Fblog%2Findex.php%3Fid%3Dz85yj914%26abuse%3D1636 https://businessrost.ru/bitrix/redirect.php?goto=http%3A%2F%2Feximha.ch%2Fblog%2Findex.php%3Fid%3Dz85yj914%26abuse%3D1636: I have to thank you for the efforts you have put ... 04/26 06:43
http://ldm.sakura.ne.jp/balu+bbbs/album/album.cgi?mode=detail&no=210 http://ldm.sakura.ne.jp/balu+bbbs/album/album.cgi?mode=detail&no=210: Aw, this was an incredibly good post. Taking the t... 04/25 18:19
https://www.bigbeargum.com/2019/02/15/ambrose-redmoon/ https://www.bigbeargum.com/2019/02/15/ambrose-redmoon/: Hello would you mind letting me know which hosting... 04/25 17:39
http://zeroken.jp/1978td/album/album.cgi?mode=detail&no=20 http://zeroken.jp/1978td/album/album.cgi?mode=detail&no=20: Asking questions are genuinely fastidious thing if... 04/25 17:26
https://natucci-estetica.com/?attachment_id=1376 https://natucci-estetica.com/?attachment_id=1376: Hello there, You have done a fantastic job. I wi... 04/25 17:05