/
file.js
51 lines (41 loc) · 1.24 KB
/
file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// ==========================================================================
// Project: Greenhouse.File
// Copyright: ©2010 Mike Ball
// ==========================================================================
/*jslint evil: true*/
/*globals Greenhouse*/
require('core');
/** @class
file properties
@dir
@name
@extends SC.ChildRecord
@version 0.1
*/
Greenhouse.File = SC.ChildRecord.extend(
/** @scope Greenhouse.File.prototype */ {
type: 'File',
childRecordNamespace: Greenhouse,
name: SC.Record.attr(String),
dir: SC.Record.attr(String),
body: SC.Record.attr(String),
primaryKey: 'id',
isFile: YES,
path: function(){
return this.get('dir') + this.get('name');
}.property('name', 'dir').cacheable(),
pageRegex: function(){
var b = this.get('body'), re =/(\w+)\.(\w+)\s*=\s*SC\.Page\.(design|create)/;
return b ? b.match(re): b;
}.property('body').cacheable(),
isPage: function(){
return this.get('pageRegex') !== null;
}.property('pageRegex').cacheable(),
pageName: function(){
var r = this.get('pageRegex') || [];
return "%@.%@".fmt(r[1],r[2]);
}.property('pageRegex').cacheable()
}) ;
Greenhouse.FILES_QUERY = SC.Query.remote(Greenhouse.File);
Greenhouse.File.mixin({
});