Adding Google Apps Script (.gs) as a JavaScript extension.

This commit is contained in:
Michael Johnson
2014-08-24 17:00:37 -04:00
parent edaea7bede
commit 410aace222
6 changed files with 759 additions and 74 deletions

View File

@@ -31,6 +31,9 @@ module Linguist
if languages.all? { |l| ["Rebol", "R"].include?(l) }
disambiguate_r(data, languages)
end
if languages.all? { |l| ["Gosu", "JavaScript"].include?(l) }
disambiguate_gosu(data, languages)
end
end
end
@@ -83,6 +86,12 @@ module Linguist
matches
end
def self.disambiguate_gosu(data, languages)
matches = []
matches << Language["Gosu"] if /^uses java\./.match(data)
matches
end
def self.active?
!!ACTIVE
end

View File

@@ -1142,6 +1142,7 @@ JavaScript:
- .bones
- .es6
- .frag
- .gs
- .jake
- .jsfl
- .jsm

View File

@@ -288,6 +288,7 @@
],
"JavaScript": [
".frag",
".gs",
".js",
".script!",
".xsjs",
@@ -839,8 +840,8 @@
"exception.zep.php"
]
},
"tokens_total": 654479,
"languages_total": 898,
"tokens_total": 655811,
"languages_total": 901,
"tokens": {
"ABAP": {
"*/**": 1,
@@ -26433,46 +26434,46 @@
"in": 3,
"Hello": 2,
"gst": 1,
"<": 1,
"<": 2,
"%": 2,
"@": 1,
"params": 1,
"(": 53,
"(": 122,
"users": 2,
"Collection": 1,
"<User>": 1,
")": 54,
")": 123,
"<%>": 2,
"for": 2,
"user": 1,
"{": 28,
"{": 72,
"user.LastName": 1,
"}": 28,
"}": 72,
"user.FirstName": 1,
"user.Department": 1,
"package": 2,
"package": 3,
"example": 2,
"enhancement": 1,
"String": 6,
"function": 11,
"String": 14,
"function": 16,
"toPerson": 1,
"Person": 7,
"var": 10,
"var": 17,
"vals": 4,
"this.split": 1,
"return": 4,
"new": 6,
"return": 17,
"new": 8,
"[": 4,
"]": 4,
"as": 3,
"as": 7,
"int": 2,
"Relationship.valueOf": 2,
"hello": 1,
"print": 3,
"uses": 2,
"uses": 8,
"java.util.*": 1,
"java.io.File": 1,
"class": 1,
"class": 2,
"extends": 1,
"Contact": 1,
"implements": 1,
@@ -26488,24 +26489,24 @@
"delegate": 1,
"_emailHelper": 2,
"represents": 1,
"enum": 1,
"enum": 2,
"FRIEND": 1,
"FAMILY": 1,
"BUSINESS_CONTACT": 1,
"static": 7,
"static": 26,
"ALL_PEOPLE": 2,
"HashMap": 1,
"<String,>": 1,
"construct": 1,
"name": 4,
"construct": 2,
"name": 12,
"age": 4,
"relationship": 2,
"EmailHelper": 1,
"this": 1,
"property": 2,
"get": 1,
"property": 13,
"get": 11,
"Name": 3,
"set": 1,
"set": 2,
"override": 1,
"getEmailName": 1,
"incrementAge": 1,
@@ -26514,10 +26515,10 @@
"printPersonInfo": 1,
"addPerson": 4,
"p": 5,
"if": 4,
"if": 19,
"ALL_PEOPLE.containsKey": 2,
".Name": 1,
"throw": 1,
"throw": 5,
"IllegalArgumentException": 1,
"p.Name": 2,
"addAllPeople": 1,
@@ -26525,7 +26526,7 @@
"List": 1,
"<Contact>": 1,
"contact": 3,
"typeis": 1,
"typeis": 2,
"and": 1,
"not": 1,
"contact.Name": 1,
@@ -26551,7 +26552,7 @@
"result.getInt": 1,
"loadFromFile": 1,
"file": 3,
"File": 2,
"File": 3,
"file.eachLine": 1,
"line": 1,
"line.HasContent": 1,
@@ -26560,7 +26561,123 @@
"writer": 2,
"FileWriter": 1,
"PersonCSVTemplate.renderToString": 1,
"PersonCSVTemplate.render": 1
"PersonCSVTemplate.render": 1,
"ronin": 1,
"gw.util.concurrent.LockingLazyVar": 1,
"gw.lang.reflect.*": 1,
"java.lang.*": 1,
"java.io.*": 1,
"ronin.config.*": 1,
"org.slf4j.*": 1,
"Ronin": 1,
"_CONFIG": 13,
"IRoninConfig": 2,
"Config": 1,
"_CURRENT_REQUEST": 1,
"ThreadLocal": 1,
"<RoninRequest>": 1,
";": 1,
"private": 1,
"internal": 2,
"init": 1,
"servlet": 3,
"RoninServlet": 3,
"m": 3,
"ApplicationMode": 2,
"src": 2,
"null": 15,
"cfg": 2,
"TypeSystem.getByFullNameIfValid": 2,
"defaultWarning": 3,
"false": 1,
"ctor": 2,
"cfg.TypeInfo.getConstructor": 1,
"ronin.config.ApplicationMode": 1,
"ronin.RoninServlet": 1,
"ctor.Constructor.newInstance": 1,
"else": 9,
"DefaultRoninConfig": 1,
"true": 2,
"roninLogger": 2,
"roninLogger.TypeInfo.getMethod": 1,
"ronin.config.LogLevel": 1,
".CallHandler.handleCall": 1,
"LogLevel": 5,
"log": 2,
"level": 7,
"WARN": 2,
"Quartz.maybeStart": 1,
"ReloadManager.setSourceRoot": 1,
"CurrentRequest": 3,
"req": 2,
"RoninRequest": 2,
"_CURRENT_REQUEST.set": 1,
"//": 2,
"CurrentTrace": 1,
"Trace": 1,
".Trace": 1,
"_CURRENT_REQUEST.get": 1,
"Mode": 1,
".Mode": 1,
"TESTING": 1,
".LogLevel": 1,
"DEBUG": 2,
"TraceEnabled": 1,
"boolean": 1,
"_CONFIG.TraceEnabled": 1,
"DefaultAction": 1,
".DefaultAction": 1,
"DefaultController": 1,
"Type": 1,
".DefaultController": 1,
".RoninServlet": 1,
"ErrorHandler": 1,
"IErrorHandler": 1,
".ErrorHandler": 1,
"LogHandler": 1,
"ILogHandler": 1,
".LogHandler": 2,
"msg": 4,
"Object": 1,
"component": 7,
"exception": 7,
"java.lang.Throwable": 1,
"INFO": 2,
"msgStr": 9,
"block": 3,
"_CONFIG.LogHandler.log": 1,
"switch": 1,
"case": 6,
"TRACE": 1,
"LoggerFactory.getLogger": 5,
"Logger.ROOT_LOGGER_NAME": 5,
".trace": 1,
"break": 5,
".debug": 1,
".info": 1,
".warn": 1,
"ERROR": 1,
"FATAL": 1,
".error": 1,
"CacheStore": 3,
"REQUEST": 3,
"SESSION": 3,
"APPLICATION": 3,
"cache": 1,
"<T>": 2,
"value": 4,
"T": 2,
"store": 10,
"or": 2,
"_CONFIG.RequestCache.getValue": 1,
"_CONFIG.SessionCache.getValue": 1,
"_CONFIG.ApplicationCache.getValue": 1,
"invalidate": 1,
"_CONFIG.RequestCache.invalidate": 1,
"_CONFIG.SessionCache.invalidate": 1,
"_CONFIG.ApplicationCache.invalidate": 1,
"loadChanges": 1,
"ReloadManager.detectAndReloadChangedResources": 1
},
"Grace": {
"method": 10,
@@ -29432,15 +29549,15 @@
".internalBuildGeneratedFileFrom": 1
},
"JavaScript": {
"function": 1214,
"(": 8528,
")": 8536,
"{": 2742,
";": 4066,
"function": 1235,
"(": 8618,
")": 8626,
"{": 2780,
";": 4151,
"//": 410,
"jshint": 1,
"_": 9,
"var": 916,
"var": 944,
"Modal": 2,
"content": 5,
"options": 56,
@@ -29451,20 +29568,20 @@
".proxy": 1,
"this.hide": 1,
"this": 578,
"}": 2718,
"}": 2756,
"Modal.prototype": 1,
"constructor": 8,
"toggle": 10,
"return": 947,
"[": 1461,
"return": 962,
"[": 1476,
"this.isShown": 3,
"]": 1458,
"]": 1473,
"show": 10,
"that": 33,
"e": 663,
".Event": 1,
"element.trigger": 1,
"if": 1230,
"if": 1243,
"||": 648,
"e.isDefaultPrevented": 2,
".addClass": 1,
@@ -29473,7 +29590,7 @@
"backdrop.call": 1,
"transition": 1,
".support.transition": 1,
"&&": 1017,
"&&": 1021,
"that.": 3,
"element.hasClass": 1,
"element.parent": 1,
@@ -29486,7 +29603,7 @@
"hide": 8,
"body": 22,
"modal": 4,
"-": 706,
"-": 719,
"open": 2,
"fade": 4,
"hidden": 12,
@@ -29508,6 +29625,36 @@
"target.modal": 1,
"option": 12,
"window.jQuery": 7,
"TagsTotalPerMonth": 4,
"TagsTotalPerMonth.getDatasource": 1,
"category": 6,
"months": 8,
"values": 20,
"new": 91,
"CategoryMonthlyExpenseBarChartDataSource": 1,
"TagsTotalPerMonth.getType": 1,
"Charts.ChartType.COLUMN": 2,
"TagsTotalPerMonthWithMean": 4,
"TagsTotalPerMonthWithMean.getDatasource": 1,
"CategoryMonthlyWithMeanExpenseDataSource": 1,
"TagsTotalPerMonthWithMean.getType": 1,
"Charts.ChartType.LINE": 1,
"TagsAccumulatedPerMonth": 4,
"TagsAccumulatedPerMonth.getDatasource": 1,
"CategoryMonthlyAccumulated": 1,
"TagsAccumulatedPerMonth.getType": 1,
"Charts.ChartType.AREA": 1,
"MonthTotalsPerTags": 4,
"MonthTotalsPerTags.getDatasource": 1,
"month": 3,
"tags": 2,
"CategoryExpenseDataSource": 1,
"MonthTotalsPerTags.getType": 1,
"Charts.ChartType.PIE": 1,
"SavingsFlowChartComposer": 3,
"SavingsFlowChartComposer.getDatasource": 1,
"SavingsFlowDataSource": 1,
"SavingsFlowChartComposer.getType": 1,
"Animal": 12,
"Horse": 12,
"Snake": 12,
@@ -29518,7 +29665,7 @@
"__extends": 6,
"child": 17,
"parent": 15,
"for": 262,
"for": 264,
"key": 85,
"__hasProp.call": 2,
"ctor": 6,
@@ -29526,14 +29673,13 @@
"ctor.prototype": 3,
"parent.prototype": 6,
"child.prototype": 4,
"new": 86,
"child.__super__": 3,
"name": 161,
"this.name": 7,
"Animal.prototype.move": 2,
"meters": 4,
"alert": 11,
"+": 1136,
"+": 1155,
"Snake.__super__.constructor.apply": 2,
"arguments": 83,
"Snake.prototype.move": 2,
@@ -29552,7 +29698,7 @@
"console.log": 3,
"hanaMath": 1,
".import": 1,
"x": 41,
"x": 46,
"parseFloat": 32,
".request.parameters.get": 2,
"y": 109,
@@ -29588,11 +29734,11 @@
"process.env.NODE_DEBUG": 2,
"/http/.test": 1,
"console.error": 3,
"else": 307,
"else": 309,
"parserOnHeaders": 2,
"headers": 41,
"this.maxHeaderPairs": 2,
"<": 209,
"<": 211,
"this._headers.length": 1,
"this._headers": 13,
"this._headers.concat": 1,
@@ -29613,11 +29759,11 @@
"info.versionMinor": 2,
"parser.incoming.httpVersion": 1,
"parser.incoming.url": 1,
"n": 874,
"n": 875,
"headers.length": 2,
"parser.maxHeaderPairs": 4,
"Math.min": 5,
"i": 853,
"i": 857,
"k": 302,
"v": 135,
"parser.incoming._addHeaderLine": 2,
@@ -29748,7 +29894,7 @@
"IncomingMessage.prototype._emitEnd": 1,
"IncomingMessage.prototype._addHeaderLine": 1,
"field": 36,
"value": 98,
"value": 103,
"dest": 12,
"field.toLowerCase": 1,
"switch": 30,
@@ -29859,7 +30005,7 @@
"DTRACE_HTTP_CLIENT_REQUEST": 1,
"OutgoingMessage.prototype._flush": 1,
"this.socket.writable": 2,
"XXX": 1,
"XXX": 2,
"Necessary": 1,
"this.socket.write": 1,
"req": 32,
@@ -30169,7 +30315,87 @@
"this.length": 41,
"app": 3,
"angular.module": 1,
"A": 24,
"sendToGoogleDrive": 1,
"gmailLabels": 2,
"driveFolder": 3,
"spreadsheetName": 3,
"archiveLabel": 4,
"itauNotificationEmail": 2,
"filter": 12,
"moveToLabel": 4,
"GmailApp.getUserLabelByName": 1,
"GmailApp.createLabel": 1,
"folders": 1,
"DriveApp.getFoldersByName": 1,
"folder": 3,
"folders.hasNext": 1,
"folders.next": 1,
"DriveApp.createFolder": 1,
"files": 1,
"folder.getFilesByName": 1,
"file": 10,
"doc": 7,
"files.hasNext": 1,
"files.next": 1,
"SpreadsheetApp.openById": 1,
"file.getId": 1,
"SpreadsheetApp.create": 1,
"DriveApp.getFileById": 1,
"doc.getId": 1,
"folder.addFile": 1,
"DriveApp.removeFile": 1,
"sheet": 1,
"doc.getSheets": 1,
"sheet.getLastRow": 1,
"sheet.appendRow": 2,
"message": 7,
"messages": 3,
"account": 5,
"operation": 7,
"date": 7,
"hour": 6,
"emailID": 4,
"plainBody": 9,
"accountRegex": 1,
"/Conta": 1,
"/": 298,
"operationRegex": 1,
"/Tipo": 1,
"de": 3,
"opera": 5,
"o": 323,
"A": 26,
"Z": 7,
"paymentRegex": 1,
"/Pagamento": 1,
"Za": 3,
"z": 22,
"valueRegex": 1,
"/Valor": 1,
"R": 3,
".": 92,
"dateRegex": 1,
"/Data": 1,
"hourRegex": 1,
"/Hora": 1,
"emailIDRegex": 1,
"/E": 1,
"mail": 1,
"threads": 3,
"GmailApp.search": 1,
"threads.length": 1,
".getMessages": 1,
"messages.length": 1,
"message.getPlainBody": 1,
"accountRegex.test": 1,
"RegExp.": 10,
"operationRegex.test": 1,
"valueRegex.test": 1,
"dateRegex.test": 1,
"hourRegex.test": 1,
"emailIDRegex.test": 1,
"paymentRegex.test": 1,
".addLabel": 1,
"w": 110,
"ma": 3,
"c.isReady": 4,
@@ -30191,13 +30417,11 @@
"X": 6,
"f": 666,
"a.length": 23,
"o": 322,
"c.isFunction": 9,
"d.call": 3,
"J": 5,
".getTime": 3,
"Y": 3,
"Z": 6,
"na": 1,
".type": 2,
"c.event.handle.apply": 1,
@@ -30236,7 +30460,6 @@
"j.handleObj.origHandler.apply": 1,
"pa": 1,
"b.replace": 3,
"/": 290,
"./g": 2,
".replace": 38,
"/g": 37,
@@ -30283,7 +30506,6 @@
"|": 206,
"#": 13,
"Ua": 1,
".": 91,
"Va": 1,
"S/": 4,
"Wa": 2,
@@ -30300,7 +30522,6 @@
"aa": 1,
"ba": 3,
"Array.prototype.push": 4,
"R": 2,
"ya": 2,
"Array.prototype.indexOf": 4,
"c.fn": 2,
@@ -30436,7 +30657,6 @@
"webkit": 6,
"w.": 17,
"/.exec": 4,
"opera": 4,
".*version": 4,
"msie": 4,
"/compatible/.test": 1,
@@ -30561,7 +30781,6 @@
"Aa": 3,
"t": 436,
"ca": 6,
"Za": 2,
"r/g": 2,
"/href": 1,
"src": 7,
@@ -30705,7 +30924,6 @@
"_change_data": 6,
"focusout": 11,
"change": 16,
"file": 5,
".specialChange": 4,
"focusin": 9,
"bind": 3,
@@ -30753,7 +30971,6 @@
"expr": 2,
"p.pop": 4,
"set": 22,
"z": 21,
"h.parentNode": 3,
"D": 9,
"k.error": 2,
@@ -30815,7 +31032,6 @@
"CLASS": 1,
"HTML": 9,
"find": 7,
"filter": 10,
"nextSibling": 3,
"iframe": 3,
"</\"+d+\">": 1,
@@ -30952,7 +31168,6 @@
"jQuery.fn": 4,
"jQuery.prototype": 2,
"match": 30,
"doc": 4,
"Handle": 14,
"DOMElement": 2,
"selector.nodeType": 2,
@@ -31000,7 +31215,6 @@
"Only": 5,
"deal": 2,
"null/undefined": 2,
"values": 10,
"Extend": 2,
"base": 2,
"Prevent": 2,
@@ -32430,7 +32644,6 @@
"bt": 42,
"bu": 11,
"bv": 2,
"de": 1,
"bw": 2,
"bz": 7,
"bA": 3,
@@ -32468,7 +32681,6 @@
"a.currentStyle": 4,
"a.currentStyle.filter": 1,
"a.style.filter": 1,
"RegExp.": 1,
"c.zoom": 1,
"b*100": 1,
"d.filter": 1,
@@ -32503,10 +32715,8 @@
"/mg": 1,
"bJ": 1,
"color": 4,
"date": 1,
"datetime": 1,
"email": 2,
"month": 1,
"range": 2,
"search": 5,
"tel": 2,
@@ -35329,7 +35539,6 @@
"RE_OCT_NUMBER.test": 1,
"RE_DEC_NUMBER.test": 1,
"JS_Parse_Error": 2,
"message": 5,
"this.col": 2,
"ex": 3,
"ex.name": 1,
@@ -72585,7 +72794,7 @@
"GLSL": 4076,
"Game Maker Language": 13310,
"Gnuplot": 1023,
"Gosu": 410,
"Gosu": 1008,
"Grace": 1381,
"Grammatical Framework": 10607,
"Groovy": 93,
@@ -72608,7 +72817,7 @@
"JSONiq": 151,
"Jade": 3,
"Java": 8987,
"JavaScript": 77056,
"JavaScript": 77790,
"Julia": 247,
"KRL": 25,
"Kit": 6,
@@ -72796,7 +73005,7 @@
"GLSL": 7,
"Game Maker Language": 13,
"Gnuplot": 6,
"Gosu": 4,
"Gosu": 5,
"Grace": 2,
"Grammatical Framework": 41,
"Groovy": 5,
@@ -72819,7 +73028,7 @@
"JSONiq": 2,
"Jade": 1,
"Java": 6,
"JavaScript": 24,
"JavaScript": 26,
"Julia": 1,
"KRL": 1,
"Kit": 1,
@@ -72949,5 +73158,5 @@
"fish": 3,
"wisp": 1
},
"md5": "b7e3e6804093f11267b22f781f54de75"
"md5": "37d31e7fbe17f173ee31e228d9928be6"
}

238
samples/Gosu/Ronin.gs Normal file
View File

@@ -0,0 +1,238 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
package ronin
uses gw.util.concurrent.LockingLazyVar
uses gw.lang.reflect.*
uses java.lang.*
uses java.io.*
uses ronin.config.*
uses org.slf4j.*
/**
* The central location for Ronin utility methods. Controllers and templates should generally access the
* methods and properties they inherit from {@link ronin.IRoninUtils} instead of using the methods and
* properties here.
*/
class Ronin {
// One static field to rule the all...
static var _CONFIG : IRoninConfig as Config
// And one thread local to bind them
static var _CURRENT_REQUEST = new ThreadLocal<RoninRequest>();
// That's inconstructable
private construct() {}
internal static function init(servlet : RoninServlet, m : ApplicationMode, src : File) {
if(_CONFIG != null) {
throw "Cannot initialize a Ronin application multiple times!"
}
var cfg = TypeSystem.getByFullNameIfValid("config.RoninConfig")
var defaultWarning = false
if(cfg != null) {
var ctor = cfg.TypeInfo.getConstructor({ronin.config.ApplicationMode, ronin.RoninServlet})
if(ctor == null) {
throw "config.RoninConfig must have a constructor with the same signature as ronin.config.RoninConfig"
}
_CONFIG = ctor.Constructor.newInstance({m, servlet}) as IRoninConfig
} else {
_CONFIG = new DefaultRoninConfig(m, servlet)
defaultWarning = true
}
var roninLogger = TypeSystem.getByFullNameIfValid("ronin.RoninLoggerFactory")
if(roninLogger != null) {
roninLogger.TypeInfo.getMethod("init", {ronin.config.LogLevel}).CallHandler.handleCall(null, {LogLevel})
}
if(defaultWarning) {
log("No configuration was found at config.RoninConfig, using the default configuration...", :level=WARN)
}
Quartz.maybeStart()
ReloadManager.setSourceRoot(src)
}
internal static property set CurrentRequest(req : RoninRequest) {
_CURRENT_REQUEST.set(req)
}
//============================================
// Public API
//============================================
/**
* The trace handler for the current request.
*/
static property get CurrentTrace() : Trace {
return CurrentRequest?.Trace
}
/**
* Ronin's representation of the current request.
*/
static property get CurrentRequest() : RoninRequest {
return _CURRENT_REQUEST.get()
}
/**
* The mode in which this application is running.
*/
static property get Mode() : ApplicationMode {
return _CONFIG?.Mode ?: TESTING
}
/**
* The log level at and above which log messages should be displayed.
*/
static property get LogLevel() : LogLevel {
return _CONFIG?.LogLevel ?: DEBUG
}
/**
* Whether or not to display detailed trace information on each request.
*/
static property get TraceEnabled() : boolean {
return _CONFIG != null ? _CONFIG.TraceEnabled : true
}
/**
* The default controller method to call when no method name is present in the request URL.
*/
static property get DefaultAction() : String {
return _CONFIG?.DefaultAction
}
/**
* The default controller to call when no controller name is present in the request URL.
*/
static property get DefaultController() : Type {
return _CONFIG?.DefaultController
}
/**
* The servlet responsible for handling Ronin requests.
*/
static property get RoninServlet() : RoninServlet {
return _CONFIG?.RoninServlet
}
/**
* The handler for request processing errors.
*/
static property get ErrorHandler() : IErrorHandler {
return _CONFIG?.ErrorHandler
}
/**
* The custom handler for logging messages.
*/
static property get LogHandler() : ILogHandler {
return _CONFIG?.LogHandler
}
/**
* Logs a message using the configured log handler.
* @param msg The text of the message to log, or a block which returns said text.
* @param level (Optional) The level at which to log the message.
* @param component (Optional) The logical component from whence the message originated.
* @param exception (Optional) An exception to associate with the message.
*/
static function log(msg : Object, level : LogLevel = null, component : String = null, exception : java.lang.Throwable = null) {
if(level == null) {
level = INFO
}
if(LogLevel <= level) {
var msgStr : String
if(msg typeis block():String) {
msgStr = (msg as block():String)()
} else {
msgStr = msg as String
}
if(_CONFIG?.LogHandler != null) {
_CONFIG.LogHandler.log(msgStr, level, component, exception)
} else {
switch(level) {
case TRACE:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).trace(msgStr, exception)
break
case DEBUG:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).debug(msgStr, exception)
break
case INFO:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).info(msgStr, exception)
break
case WARN:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).warn(msgStr, exception)
break
case ERROR:
case FATAL:
LoggerFactory.getLogger(component?:Logger.ROOT_LOGGER_NAME).error(msgStr, exception)
break
}
}
}
}
/**
* The caches known to Ronin.
*/
static enum CacheStore {
REQUEST,
SESSION,
APPLICATION
}
/**
* Retrieves a value from a cache, or computes and stores it if it is not in the cache.
* @param value A block which will compute the desired value.
* @param name (Optional) A unique identifier for the value. Default is null, which means one will be
* generated from the type of the value.
* @param store (Optional) The cache store used to retrieve or store the value. Default is the request cache.
* @return The retrieved or computed value.
*/
static function cache<T>(value : block():T, name : String = null, store : CacheStore = null) : T {
if(store == null or store == REQUEST) {
return _CONFIG.RequestCache.getValue(value, name)
} else if (store == SESSION) {
return _CONFIG.SessionCache.getValue(value, name)
} else if (store == APPLICATION) {
return _CONFIG.ApplicationCache.getValue(value, name)
} else {
throw "Don't know about CacheStore ${store}"
}
}
/**
* Invalidates a cached value in a cache.
* @param name The unique identifier for the value.
* @param store The cache store in which to invalidate the value.
*/
static function invalidate<T>(name : String, store : CacheStore) {
if(store == null or store == REQUEST) {
_CONFIG.RequestCache.invalidate(name)
} else if (store == SESSION) {
_CONFIG.SessionCache.invalidate(name)
} else if (store == APPLICATION) {
_CONFIG.ApplicationCache.invalidate(name)
} else {
throw "Don't know about CacheStore ${store}"
}
}
/**
* Detects changes made to resources in the Ronin application and
* reloads them. This function should only be called when Ronin is
* in development mode.
*/
static function loadChanges() {
ReloadManager.detectAndReloadChangedResources()
}
}

View File

@@ -0,0 +1,78 @@
/*
License
Copyright [2013] [Farruco Sanjurjo Arcay]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
var TagsTotalPerMonth;
TagsTotalPerMonth = (function(){
function TagsTotalPerMonth(){};
TagsTotalPerMonth.getDatasource = function (category, months, values){
return new CategoryMonthlyExpenseBarChartDataSource(category, months, values);
};
TagsTotalPerMonth.getType = function (){ return Charts.ChartType.COLUMN};
return TagsTotalPerMonth;
})();
var TagsTotalPerMonthWithMean;
TagsTotalPerMonthWithMean = (function(){
function TagsTotalPerMonthWithMean(){};
TagsTotalPerMonthWithMean.getDatasource = function (category, months, values){
return new CategoryMonthlyWithMeanExpenseDataSource(category, months, values);
};
TagsTotalPerMonthWithMean.getType = function (){ return Charts.ChartType.LINE};
return TagsTotalPerMonthWithMean;
})();
var TagsAccumulatedPerMonth;
TagsAccumulatedPerMonth = (function(){
function TagsAccumulatedPerMonth(){};
TagsAccumulatedPerMonth.getDatasource = function (category, months, values){
return new CategoryMonthlyAccumulated(category, months, values);
};
TagsAccumulatedPerMonth.getType = function (){ return Charts.ChartType.AREA};
return TagsAccumulatedPerMonth;
})();
var MonthTotalsPerTags;
MonthTotalsPerTags = (function(){
function MonthTotalsPerTags(){};
MonthTotalsPerTags.getDatasource = function (month, tags, values){
return new CategoryExpenseDataSource(tags, month, values);
};
MonthTotalsPerTags.getType = function (){ return Charts.ChartType.PIE; };
return MonthTotalsPerTags;
})();
var SavingsFlowChartComposer = (function(){
function SavingsFlowChartComposer(){};
SavingsFlowChartComposer.getDatasource = function(months, values){
return new SavingsFlowDataSource(months, values);
};
SavingsFlowChartComposer.getType = function(){ return Charts.ChartType.COLUMN; };
return SavingsFlowChartComposer;
})();

150
samples/JavaScript/itau.gs Normal file
View File

@@ -0,0 +1,150 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Thiago Brandão Damasceno
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.
*/
// based on http://ctrlq.org/code/19053-send-to-google-drive
function sendToGoogleDrive() {
var gmailLabels = 'inbox';
var driveFolder = 'Itaú Notifications';
var spreadsheetName = 'itau';
var archiveLabel = 'itau.processed';
var itauNotificationEmail = 'comunicacaodigital@itau-unibanco.com.br';
var filter = "from: " +
itauNotificationEmail +
" -label:" +
archiveLabel +
" label:" +
gmailLabels;
// Create label for 'itau.processed' if it doesn't exist
var moveToLabel = GmailApp.getUserLabelByName(archiveLabel);
if (!moveToLabel) {
moveToLabel = GmailApp.createLabel(archiveLabel);
}
// Create folder 'Itaú Notifications' if it doesn't exist
var folders = DriveApp.getFoldersByName(driveFolder);
var folder;
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(driveFolder);
}
// Create spreadsheet file 'itau' if it doesn't exist
var files = folder.getFilesByName(spreadsheetName);
// File is in DriveApp
// Doc is in SpreadsheetApp
// They are not interchangeable
var file, doc;
// Confusing :\
// As per: https://code.google.com/p/google-apps-script-issues/issues/detail?id=3578
if (files.hasNext()){
file = files.next();
doc = SpreadsheetApp.openById(file.getId());
} else {
doc = SpreadsheetApp.create(spreadsheetName);
file = DriveApp.getFileById(doc.getId());
folder.addFile(file);
DriveApp.removeFile(file);
}
var sheet = doc.getSheets()[0];
// Append header if first line
if(sheet.getLastRow() == 0){
sheet.appendRow(['Conta', 'Operação', 'Valor', 'Data', 'Hora', 'Email ID']);
}
var message, messages, account, operation, value, date, hour, emailID, plainBody;
var accountRegex = /Conta: (XXX[0-9\-]+)/;
var operationRegex = /Tipo de operação: ([A-Z]+)/;
var paymentRegex = /Pagamento de ([0-9A-Za-z\-]+)\ ?([0-9]+)?/;
var valueRegex = /Valor: R\$ ([0-9\,\.]+)/;
var dateRegex = /Data: ([0-9\/]+)/;
var hourRegex = /Hora: ([0-9\:]+)/;
var emailIDRegex = /E-mail nº ([0-9]+)/;
var threads = GmailApp.search(filter, 0, 100);
for (var x = 0; x < threads.length; x++) {
messages = threads[x].getMessages();
for (var i = 0; i < messages.length; i++) {
account, operation, value, date, hour, emailID = [];
message = messages[i];
plainBody = message.getPlainBody();
if(accountRegex.test(plainBody)) {
account = RegExp.$1;
}
if(operationRegex.test(plainBody)) {
operation = RegExp.$1;
}
if(valueRegex.test(plainBody)) {
value = RegExp.$1;
}
if(dateRegex.test(plainBody)) {
date = RegExp.$1;
}
if(hourRegex.test(plainBody)) {
hour = RegExp.$1;
}
if(emailIDRegex.test(plainBody)){
emailID = RegExp.$1;
}
if(paymentRegex.test(plainBody)){
operation = RegExp.$1;
if(RegExp.$2){
operation += ' ' + RegExp.$2
}
date = hour = ' - ';
}
if(account && operation && value && date && hour){
sheet.appendRow([account, operation, value, date, hour, emailID]);
}
// Logger.log(account);
// Logger.log(operation);
// Logger.log(value);
// Logger.log(date);
// Logger.log(hour);
}
threads[x].addLabel(moveToLabel);
}
}