Google Docs不簡單

今天用Google Docs做Check List,想對Status欄的Done, In progress, Blocked設不同的background-color,Google Docs竟然有App Scripts可以用,完全是Javascript,超讚的。

下面這個就是我從Google spreadsheets conditional formatting抄來改的。

function colorAll() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2;
var endRow = sheet.getLastRow();
var statusCol = getStatusColumn();
//Browser.msgBox(statusCol);
for (var r = startRow; r <= endRow; r++) {
colorRow(r,statusCol);
}
}
function getStatusColumn() {
var sheet = SpreadsheetApp.getActiveSheet();
var startCol = 1;
var maxCol = sheet.getMaxColumns();
var header = sheet.getRange(1, maxCol);
for ( var col = startCol; col <= maxCol; col++){
var value = sheet.getRange(1, col).getValues();
//Browser.msgBox(value);
if (value == 'Status'){
return col;
}
}
}
function colorRow(r,c){
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getRange(r, c);
var data = dataRange.getValues();
if(data == "Done"){
dataRange.setBackgroundRGB(0, 255, 0);
}else if(data == "In progress"){
dataRange.setBackgroundRGB(255, 255, 0);
}else if(data == "Blocked"){
dataRange.setBackgroundRGB(255, 153, 0);
}else {
dataRange.setBackgroundRGB(255, 255, 255);
}
SpreadsheetApp.flush();
}
function onEdit(event)
{
var currentCol = event.source.getActiveRange().getColumnIndex();
var statusCol = getStatusColumn();
if (currentCol === statusCol){
colorRow(event.source.getActiveRange().getRowIndex(),statusCol);
}
}
function onOpen(){
colorAll();
}

在Puppet裡使用ERB模板

Puppet也可以使用erb模板,默認模板的搜尋位置是$vardir/templaters,但是搭配VCS來做還是有Best Practices照做。先在pp文件裡寫

file { '/etc/hosts':
content => template("hosts/hosts.erb"),
}

template()裡的路徑對應的其實是modules/hosts/templates/hosts.erb

erb文件裡的變量有兩個來源,

  1. pp文件裡的定義,如:$var = "aaa",也可以是list/array,如:$var = ["a","b","c"]
  2. facter的定義,這個定義可以用facter --puppet看到。

參考:Docs: Using Puppet Templates