1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Specs for locals

This commit is contained in:
kbparagua 2013-03-02 22:49:24 +08:00
parent 0f6d591084
commit 36e2179463
6 changed files with 84 additions and 10 deletions

View file

@ -0,0 +1,17 @@
(function(){
Paloma.locals['/'] = {};
locals = Paloma.locals['/'];
// Locals starts here
locals.applicationHelperMethod = function(){
return "I'm from application locals!"
};
locals.toBeOverriden = function(){
return "Override me!"
};
// Locals ends here
})();

View file

@ -1,12 +1,21 @@
(function(){
Paloma.callbacks['foo'] = {};
Paloma.locals['foo'] = {};
locals = Paloma.locals['foo'];
Paloma.helpers['foo'] = {
helperMethod : function(){
return 100;
},
helperVariable : 99
// Locals starts here
locals.helperMethod = function(){
return 100;
};
locals.helperVariable = 99;
locals.toBeOverriden = function(){
return "Override!"
};
// Locals ends here
Paloma.inheritLocals({from : '/', to : 'foo'});
})();

View file

@ -1,15 +1,21 @@
(function(){
var _x = Paloma.variableContainer,
_H = Paloma.helpers,
_h = _H['foo'];
_L= Paloma.locals,
_l = _L['foo'];
Paloma.callbacks['foo']['basic_action'] = function(params)
{
window.callback = "['foo']['basic_action']";
window.params = params;
window.helperMethodValue = _l.helperMethod();
window.helperVariableValue = _l.helperVariable;
window.overriden = _l.toBeOverriden();
_x.xVisibility.push('Foo');
window.locals = _l;
};
})();

View file

@ -1,4 +1,6 @@
//= require paloma_core.js
//= require ./_filters.js
//= require ./_locals.js
//= require ./foo/_callbacks.js
//= require ./bar/_callbacks.js
//= require ./sample_namespace/_callbacks.js

View file

@ -0,0 +1,27 @@
require 'spec_helper'
describe 'Locals', :type => :feature, :js => true do
before do
visit basic_action_foo_path
end
describe '_l' do
it 'has access to local methods' do
page.evaluate_script('helperMethodValue').should be 100
end
it 'has access to local variables' do
page.evaluate_script('helperVariableValue').should be 99
end
it 'can override locals from its parent scope' do
page.evaluate_script('overriden').should eq 'Override!'
end
end
end

View file

@ -2,7 +2,7 @@
window.Paloma = {
callbacks : {},
filterScopes : {},
helpers : {},
locals : {},
variableContainer : {}
};
@ -21,6 +21,19 @@ INCLUSION_TYPES.ONLY = 4;
INCLUSION_TYPES.EXCEPT = 5;
Paloma.inheritLocals = function(options){
var from = Paloma.locals[options['from']],
to = Paloma.locals[options['to']];
for (var local in from){
// Overriding is allowed.
if ( to.hasOwnProperty(local) ){ continue; }
to[local] = from[local];
}
};
Paloma.FilterScope = function(name){
this.name = name;