crouton
1.0.0
บริบทการแจ้งเตือนที่ละเอียดอ่อนสำหรับราง && xhr
gem install 'crouton'
เพียงแค่ต้องการ crouton ใน JavaScript และ CSS ของคุณ:
//= 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 ในที่สุดค้นหาจุดที่ดีใน HTML ของคุณสำหรับ Crouton และเพิ่มคลาส CSS. .crouton-placeholder ในคอนเทนเนอร์ที่เลือก
< div class =" content crouton-placeholder " >
...ได้รับการสนับสนุนสามรูปแบบนอกกรอบ: ข้อมูล คำเตือน และ อันตราย ระยะเวลาของแต่ละข้อความคือ 1,500, 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