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的博客文章。