flexlayout-rails 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +20 -0
- data/README.md +140 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/flexlayout-rails.gemspec +79 -0
- data/lib/flexlayout-rails.rb +6 -0
- data/spec/regions/img/lorem-ipsum-logo.jpeg +0 -0
- data/spec/regions/index.html +120 -0
- data/spec/regions/js/detection.js +9 -0
- data/spec/regions/js/layout.js +43 -0
- data/spec/regions/js/setup.js +0 -0
- data/spec/spec_helper.rb +12 -0
- data/vendor/assets/javascripts/feature-detects/cssregions.js +6 -0
- data/vendor/assets/javascripts/flexie.js +2039 -0
- data/vendor/assets/javascripts/flexie.min.js +1 -0
- data/vendor/assets/javascripts/jquery.lettering.js +66 -0
- data/vendor/assets/javascripts/jquery.lettering.min.js +13 -0
- data/vendor/assets/javascripts/regions.jquery.js +204 -0
- data/vendor/assets/javascripts/regions.jquery.min.js +7 -0
- data/vendor/assets/javascripts/template_layout/jquery/jquery.tpl_layout1.1.6.js +1256 -0
- data/vendor/assets/javascripts/template_layout/jquery/jquery.tpl_layout1.1.6.min.js +1 -0
- data/vendor/assets/javascripts/template_layout/templateLayout.compiler.js +1049 -0
- data/vendor/assets/javascripts/template_layout/templateLayout.generator.js +615 -0
- data/vendor/assets/javascripts/template_layout/templateLayout.js +339 -0
- metadata +158 -0
@@ -0,0 +1,339 @@
|
|
1
|
+
/*!
|
2
|
+
* CSS Template Layout
|
3
|
+
* Copyright (c) 2011-2012 Pablo Escalada
|
4
|
+
*
|
5
|
+
* Contributor(s):
|
6
|
+
* César Acebal
|
7
|
+
*
|
8
|
+
* MIT Licensed
|
9
|
+
*/
|
10
|
+
(function (global) {
|
11
|
+
var log = wef.logger("templateLayout"),
|
12
|
+
templateLayout,
|
13
|
+
buffer = {},
|
14
|
+
tom,
|
15
|
+
parser;
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Create the prototype main class
|
19
|
+
*
|
20
|
+
* @param {string|strings[]}[templateSource] template source.
|
21
|
+
* Supports 0..* strings containing valid CSS text or URL.
|
22
|
+
* </p>
|
23
|
+
* Empty constructor searches parent HTML file for STYLE tags and uses its
|
24
|
+
* CSS content as template source.
|
25
|
+
* </p>
|
26
|
+
* String params are analyzed and loaded in this way:
|
27
|
+
* <ul>
|
28
|
+
* <li>"htttp[s]://..." entries are loaded as files and content extracted</li>
|
29
|
+
* <li>"file://..." entries are loaded as files and content extracted</li>
|
30
|
+
* <li>Unmatched entries are loaded as CSS text</li>
|
31
|
+
* </ul>
|
32
|
+
* Multiple strings are first analyzed and then concatenated
|
33
|
+
*
|
34
|
+
* @class TemplateLayout is a CSS Template Layout prototype that implements
|
35
|
+
* some basic features defined in W3C working draft "Template Layout Module".
|
36
|
+
* Features:
|
37
|
+
* <ul>
|
38
|
+
* <li>basic template definition: letters, . (dot) and @</li>
|
39
|
+
* <li>column width in pixels and %</li>
|
40
|
+
* <li>row height imn pixels and %</li>
|
41
|
+
* </ul>
|
42
|
+
*/
|
43
|
+
templateLayout = function (templateSource) {
|
44
|
+
log.info("create templateLayout...");
|
45
|
+
return new templateLayout.prototype.init(arguments);
|
46
|
+
};
|
47
|
+
|
48
|
+
|
49
|
+
templateLayout.prototype = {
|
50
|
+
constructor:templateLayout,
|
51
|
+
/**
|
52
|
+
* Version number
|
53
|
+
*/
|
54
|
+
version:"1.0.0",
|
55
|
+
/**
|
56
|
+
* Template sources store
|
57
|
+
*/
|
58
|
+
templateSources:[],
|
59
|
+
/**
|
60
|
+
* Constant object that stores CSS properties names used as triggers
|
61
|
+
* </p>
|
62
|
+
* Currently used:
|
63
|
+
* <ul>
|
64
|
+
* <li>constants.DISPLAY = "display"</li>
|
65
|
+
* <li>constants.POSITION = "position"</li>
|
66
|
+
* </ul>
|
67
|
+
*/
|
68
|
+
constants:{
|
69
|
+
DISPLAY:"display",
|
70
|
+
POSITION:"position"
|
71
|
+
},
|
72
|
+
/**
|
73
|
+
* Template compiler
|
74
|
+
*/
|
75
|
+
compiler:null,
|
76
|
+
/**
|
77
|
+
* Template output generator
|
78
|
+
*/
|
79
|
+
generator:null,
|
80
|
+
|
81
|
+
/**
|
82
|
+
* @ignore
|
83
|
+
* see templateLayout constructor
|
84
|
+
*/
|
85
|
+
init:function (templateSources) {
|
86
|
+
var args, firstSource, internalSources = [];
|
87
|
+
log.debug("sources:", templateSources);
|
88
|
+
|
89
|
+
log.debug("init subsystems...");
|
90
|
+
parser = wef.cssParser();
|
91
|
+
log.debug("subsystems... [OK]");
|
92
|
+
|
93
|
+
args = Array.prototype.slice.call(templateSources);
|
94
|
+
firstSource = args[0];
|
95
|
+
|
96
|
+
//templateLayout()
|
97
|
+
if (!firstSource) {
|
98
|
+
log.info("no external template loaded!!!");
|
99
|
+
Array.prototype.forEach.call(document.styleSheets, function (sheet) {
|
100
|
+
if (sheet.href !== null) {
|
101
|
+
//load external CSS
|
102
|
+
log.info("load external CSS", sheet.href);
|
103
|
+
internalSources.push(sheet.href);
|
104
|
+
}
|
105
|
+
else {
|
106
|
+
var text = sheet.ownerNode.innerHTML;
|
107
|
+
log.info("load style tag", text);
|
108
|
+
internalSources.push(text);
|
109
|
+
}
|
110
|
+
});
|
111
|
+
|
112
|
+
this.templateSources = internalSources.map(getContent);
|
113
|
+
log.info("templateLayout... [OK]");
|
114
|
+
return this;
|
115
|
+
}
|
116
|
+
|
117
|
+
//templateLayout("aString") and templateLayout("aString", "anotherString", ...)
|
118
|
+
if (args.length >= 1 && args.every(function (element) {
|
119
|
+
return typeof element == "string";
|
120
|
+
})) {
|
121
|
+
this.templateSources = args.map(getContent);
|
122
|
+
log.info("templateLayout... [OK]");
|
123
|
+
return this;
|
124
|
+
}
|
125
|
+
|
126
|
+
log.error("Invalid argument");
|
127
|
+
throw new Error("Invalid argument");
|
128
|
+
},
|
129
|
+
/**
|
130
|
+
* Reads, compiles and generates the template
|
131
|
+
*
|
132
|
+
* @param {string}[options=all] Only for testing purposes.
|
133
|
+
* Supported values [none|parse|compile]
|
134
|
+
* </p>
|
135
|
+
* Stops transform process at different points:
|
136
|
+
* <ul>
|
137
|
+
* <li>none: transform does nothing</li>
|
138
|
+
* <li>parse: transform only parses template source</li>
|
139
|
+
* <li>compile: transform parses source and compiles the template</li>
|
140
|
+
* </ul>
|
141
|
+
*/
|
142
|
+
transform:function () {
|
143
|
+
log.debug("transform...");
|
144
|
+
var options = parseTransformOptions(arguments);
|
145
|
+
|
146
|
+
if (options.parse) {
|
147
|
+
log.info("Step 1: parse");
|
148
|
+
log.group();
|
149
|
+
parser.whenStart(this.parserStarts);
|
150
|
+
parser.whenProperty(this.propertyFound);
|
151
|
+
parser.whenStop(this.parserDone);
|
152
|
+
|
153
|
+
parser.parse(this.templateSources.reduce(function (previous, source) {
|
154
|
+
return previous + source.sourceText;
|
155
|
+
}, ""));
|
156
|
+
|
157
|
+
log.groupEnd();
|
158
|
+
log.info("Step 1: parse... [OK]");
|
159
|
+
}
|
160
|
+
if (options.compile) {
|
161
|
+
log.info("Step 2: compile");
|
162
|
+
log.group();
|
163
|
+
tom = this.compiler().compile(buffer);
|
164
|
+
// log.info("TOM: ", tom);
|
165
|
+
log.groupEnd();
|
166
|
+
log.info("Step 2: compile... [OK]");
|
167
|
+
}
|
168
|
+
if (options.generate) {
|
169
|
+
log.info("Step 3: generate");
|
170
|
+
log.group();
|
171
|
+
this.generator(tom).patchDOM();
|
172
|
+
log.groupEnd();
|
173
|
+
log.info("Step 3: generate... [OK]");
|
174
|
+
}
|
175
|
+
|
176
|
+
log.info("transform... [OK]");
|
177
|
+
return this;
|
178
|
+
},
|
179
|
+
/**
|
180
|
+
* Returns the info from the parsing step
|
181
|
+
* @returns {ParserBufferEntry[]}buffer
|
182
|
+
*/
|
183
|
+
getBuffer:function () {
|
184
|
+
return buffer;
|
185
|
+
},
|
186
|
+
/**
|
187
|
+
* Returns TOM (Template Object Model)
|
188
|
+
* @returns {rootTemplate}tom
|
189
|
+
*/
|
190
|
+
getTOM:function () {
|
191
|
+
return tom;
|
192
|
+
},
|
193
|
+
/**
|
194
|
+
* "Parser start" callback. Prints start time and resets buffer
|
195
|
+
*
|
196
|
+
* @param o Information sent by parser
|
197
|
+
* @param o.time Start time in milliseconds
|
198
|
+
*/
|
199
|
+
parserStarts:function (o) {
|
200
|
+
log.info("start parsing at", new Date(o.time).toLocaleTimeString());
|
201
|
+
buffer = {};
|
202
|
+
},
|
203
|
+
/**
|
204
|
+
* "Property has been found" callback. Stores in buffer valid properties
|
205
|
+
*
|
206
|
+
* @param {CSSParserProperty}property found property information
|
207
|
+
*/
|
208
|
+
propertyFound:function (property) {
|
209
|
+
log.info("templateLayout listens: property found");
|
210
|
+
if (templateLayout.fn.isSupportedProperty(property)) {
|
211
|
+
store(property);
|
212
|
+
}
|
213
|
+
},
|
214
|
+
/**
|
215
|
+
* "Parser stop" callback. Prints stop time
|
216
|
+
* @param {StopCallbackData}o Information sent by parser
|
217
|
+
*/
|
218
|
+
parserDone:function (o) {
|
219
|
+
log.info("parsing done at", new Date(o.time).toLocaleTimeString());
|
220
|
+
},
|
221
|
+
/**
|
222
|
+
* Checks if given property is a valid one.
|
223
|
+
* If property name exists in constants then is a valid one
|
224
|
+
*
|
225
|
+
* @param {CSSParserProperty}property the property
|
226
|
+
* @returns {boolean}true if exists constants[???] == property.declaration.property
|
227
|
+
*/
|
228
|
+
isSupportedProperty:function (property) {
|
229
|
+
var iterator;
|
230
|
+
for (iterator in templateLayout.fn.constants) {
|
231
|
+
if (templateLayout.fn.constants.hasOwnProperty(iterator)) {
|
232
|
+
if (templateLayout.fn.constants[iterator] == property.declaration.property) {
|
233
|
+
log.info("supported property found: ", property.declaration.property);
|
234
|
+
return true;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
238
|
+
return false;
|
239
|
+
}
|
240
|
+
};
|
241
|
+
|
242
|
+
templateLayout.fn = templateLayout.prototype;
|
243
|
+
|
244
|
+
templateLayout.fn.init.prototype = templateLayout.fn;
|
245
|
+
|
246
|
+
function getSourceType(templateSource) {
|
247
|
+
var rxHttp = /^http[s]?:\/\/.*\.css$/i, rxFile = /^file:\/\/.*\.css$/i, rxPath = /^(?!\s*.*(http[s]?|file))(\.){0,2}(\/.*)*.*\.css$/i;
|
248
|
+
if (rxHttp.exec(templateSource)) {
|
249
|
+
return "http";
|
250
|
+
}
|
251
|
+
if (rxPath.exec(templateSource) || rxFile.exec(templateSource)) {
|
252
|
+
return "file";
|
253
|
+
}
|
254
|
+
return "css";
|
255
|
+
}
|
256
|
+
|
257
|
+
function getContent(templateSource) {
|
258
|
+
var type = getSourceType(templateSource);
|
259
|
+
if (type == "http" || type == "file") {
|
260
|
+
return {
|
261
|
+
type:type,
|
262
|
+
sourceText:readFile(templateSource)
|
263
|
+
};
|
264
|
+
}
|
265
|
+
if (type == "css") {
|
266
|
+
return {
|
267
|
+
type:type,
|
268
|
+
sourceText:templateSource
|
269
|
+
};
|
270
|
+
} else {
|
271
|
+
throw new Error("unknown sourceType");
|
272
|
+
}
|
273
|
+
}
|
274
|
+
|
275
|
+
function parseTransformOptions(args) {
|
276
|
+
var options = {parse:true, compile:true, generate:true};
|
277
|
+
if (args.length === 0) {
|
278
|
+
return options;
|
279
|
+
}
|
280
|
+
if (args[0].action == "none") {
|
281
|
+
options.parse = options.compile = options.generate = false;
|
282
|
+
}
|
283
|
+
if (args[0].action == "parse") {
|
284
|
+
options.compile = options.generate = false;
|
285
|
+
}
|
286
|
+
if (args[0].action == "compile") {
|
287
|
+
options.generate = false;
|
288
|
+
}
|
289
|
+
return options;
|
290
|
+
}
|
291
|
+
|
292
|
+
function readFile(url) {
|
293
|
+
var templateText="";
|
294
|
+
|
295
|
+
try {
|
296
|
+
log.info("reading file...");
|
297
|
+
wef.net.ajax(url, {
|
298
|
+
asynchronous:false,
|
299
|
+
success:function (request) {
|
300
|
+
templateText = request.responseText;
|
301
|
+
}
|
302
|
+
});
|
303
|
+
log.info("template loaded... [OK]");
|
304
|
+
return templateText;
|
305
|
+
} catch (e) {
|
306
|
+
log.error("Operation not supported", e);
|
307
|
+
throw new Error("Operation not supported", e);
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
function store(rule) {
|
312
|
+
if (!buffer[rule.selectorText]) {
|
313
|
+
buffer[rule.selectorText] =
|
314
|
+
/**
|
315
|
+
* @namespace Data format of parser buffer entry
|
316
|
+
* @name ParserBufferEntry
|
317
|
+
*/
|
318
|
+
/**
|
319
|
+
* @lends ParserBufferEntry#
|
320
|
+
*/
|
321
|
+
{
|
322
|
+
/**
|
323
|
+
* property selector text
|
324
|
+
* @type string
|
325
|
+
*/
|
326
|
+
selectorText:rule.selectorText,
|
327
|
+
/**
|
328
|
+
* array of declarations (property_name:property_value)
|
329
|
+
* @type string[]
|
330
|
+
*/
|
331
|
+
declaration:{}
|
332
|
+
};
|
333
|
+
}
|
334
|
+
buffer[rule.selectorText].declaration[rule.declaration.property] = rule.declaration.valueText;
|
335
|
+
log.info("property stored: ", rule.declaration.property);
|
336
|
+
}
|
337
|
+
|
338
|
+
global.templateLayout = templateLayout;
|
339
|
+
})(window);
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flexlayout-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kristian Mandrup
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.8.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.8.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.3
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.3
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.5'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0.5'
|
94
|
+
description: Use CSS Flex, Regions and Template layout models in your Rails apps
|
95
|
+
email: kmandrup@gmail.com
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files:
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
files:
|
102
|
+
- .document
|
103
|
+
- .rspec
|
104
|
+
- Gemfile
|
105
|
+
- Gemfile.lock
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- VERSION
|
110
|
+
- flexlayout-rails.gemspec
|
111
|
+
- lib/flexlayout-rails.rb
|
112
|
+
- spec/regions/img/lorem-ipsum-logo.jpeg
|
113
|
+
- spec/regions/index.html
|
114
|
+
- spec/regions/js/detection.js
|
115
|
+
- spec/regions/js/layout.js
|
116
|
+
- spec/regions/js/setup.js
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- vendor/assets/javascripts/feature-detects/cssregions.js
|
119
|
+
- vendor/assets/javascripts/flexie.js
|
120
|
+
- vendor/assets/javascripts/flexie.min.js
|
121
|
+
- vendor/assets/javascripts/jquery.lettering.js
|
122
|
+
- vendor/assets/javascripts/jquery.lettering.min.js
|
123
|
+
- vendor/assets/javascripts/regions.jquery.js
|
124
|
+
- vendor/assets/javascripts/regions.jquery.min.js
|
125
|
+
- vendor/assets/javascripts/template_layout/jquery/jquery.tpl_layout1.1.6.js
|
126
|
+
- vendor/assets/javascripts/template_layout/jquery/jquery.tpl_layout1.1.6.min.js
|
127
|
+
- vendor/assets/javascripts/template_layout/templateLayout.compiler.js
|
128
|
+
- vendor/assets/javascripts/template_layout/templateLayout.generator.js
|
129
|
+
- vendor/assets/javascripts/template_layout/templateLayout.js
|
130
|
+
homepage: http://github.com/kristianmandrup/flexlayout-rails
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
hash: 76961756385462174
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 1.8.24
|
155
|
+
signing_key:
|
156
|
+
specification_version: 3
|
157
|
+
summary: CSS3 layout polyfills pre-packaged for Rails asset pipeline
|
158
|
+
test_files: []
|