crouton
1.0.0
轨道上的上下文敏感通知&& xhr。
gem install 'crouton'
只需在您的JavaScript和CSS中需要crouton :
//= require crouton @import ' crouton ' ;然后,使用控制器中的render_crouton方法,您通过的任何选项都将转换为消息。
class PostsController < ActionController :: Base
def update
if @post . save
render_crouton notice : 'Saved'
else
render_crouton errors : @post . errors
end
end
end最后,在Crouton中找到HTML中的好地方,并在选择的容器中添加.crouton-placeholder CSS类。
< div class =" content crouton-placeholder " >
...开头支持三种样式:信息,警告和危险。每条消息的持续时间分别为1500、2000和3000。
您可以通过定义以下SASS变量来自定义这三种样式的颜色:
$crouton-info$crouton-warning$crouton-danger您还可以创建自定义消息:
render_crouton Crouton :: Message . new ( :hint , 'You can double tap for more info.' , duration : 5000 ) , placeholder : '.custom-crouton-placeholder' Copyright (c) 2014 Máximo Mussini
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Crouton的名称和想法起源于Cyril Mottier的博客文章。