Skip to content

Commit

Permalink
prototype: Complete rewrite of the deprecation helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobie committed Mar 15, 2008
1 parent addfdef commit 87ce153
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 142 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
* Complete rewrite of the deprecation helper, now renamed UpdateHelper and useable by third-party libs. [Tobie Langel]

* Make Element#writeAttribute handle frameborder attribute in IE. Closes #11068. [staaky, Tobie Langel]

* Minor clean-up of selector.js. Closes #10844. [RQuadling]
Expand Down
14 changes: 13 additions & 1 deletion Rakefile
Expand Up @@ -7,7 +7,7 @@ PROTOTYPE_DIST_DIR = File.join(PROTOTYPE_ROOT, 'dist')
PROTOTYPE_PKG_DIR = File.join(PROTOTYPE_ROOT, 'pkg')
PROTOTYPE_VERSION = '1.6.0.2'

task :default => [:dist, :package, :clean_package_source]
task :default => [:dist, :dist_helper, :package, :clean_package_source]

desc "Builds the distribution"
task :dist do
Expand All @@ -21,6 +21,18 @@ task :dist do
end
end

desc "Builds the updating helper"
task :dist_helper do
$:.unshift File.join(PROTOTYPE_ROOT, 'lib')
require 'protodoc'

Dir.chdir(File.join(PROTOTYPE_ROOT, 'ext', 'update_helper')) do
File.open(File.join(PROTOTYPE_DIST_DIR, 'prototype_update_helper.js'), 'w+') do |dist|
dist << Protodoc::Preprocessor.new('prototype_update_helper.js')
end
end
end

Rake::PackageTask.new('prototype', PROTOTYPE_VERSION) do |package|
package.need_tar_gz = true
package.package_dir = PROTOTYPE_PKG_DIR
Expand Down
Expand Up @@ -5,7 +5,7 @@
<title>Prototype Unit test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="../../dist/prototype.js" type="text/javascript"></script>
<script src="deprecation.js" type="text/javascript"></script>
<script src="../../dist/prototype_update_helper.js" type="text/javascript"></script>
<script src="../../test/lib/unittest.js" type="text/javascript"></script>
<link rel="stylesheet" href="../../test/test.css" type="text/css" />
</head>
Expand All @@ -29,8 +29,8 @@ <h1>Prototype Unit test file</h1>
message: [],
type: []
};
DeprecationNotifier.notify = DeprecationNotifier.notify.wrap(function(proceed, message, type) {
if (!proceed(message, type)) return; // DeprecationNotifier.notify return false if the message is not logged.
prototypeUpdateHelper.notify = prototypeUpdateHelper.notify.wrap(function(proceed, message, type) {
if (!proceed(message, type)) return; // UpdateHelper#notify return false if the message is not logged.
log.message.push(message);
log.type.push(type);
});
Expand All @@ -40,29 +40,29 @@ <h1>Prototype Unit test file</h1>
}

Test.Unit.Testcase.addMethods({
assertDeprecationNotified: function(expected) {
assertInfoNotified: function(expected) {
var actualMessage = log.message.beforeLast() || log.message.last();
var actualType = log.type.beforeLast() || log.type.last();
this.assertEqual(expected, actualMessage, 'assertDeprecationNotified');
this.assertEqual('deprecation', actualType, 'assertDeprecationNotified');
this.assertEqual(expected, actualMessage, 'assertInfoNotified');
this.assertEqual('info', actualType, 'assertInfoNotified');
log.message.push(null);
log.type.push(null);
},

assertRemovalNotified: function(expected) {
assertErrorNotified: function(expected) {
var actualMessage = log.message.beforeLast() || log.message.last();
var actualType = log.type.beforeLast() || log.type.last();
this.assertEqual(expected, actualMessage, 'assertRemovalNotified');
this.assertEqual('removal', actualType, 'assertRemovalNotified');
this.assertEqual(expected, actualMessage, 'assertErrorNotified');
this.assertEqual('error', actualType, 'assertErrorNotified');
log.message.push(null);
log.type.push(null);
},

assertModificationNotified: function(expected) {
assertWarnNotified: function(expected) {
var actualMessage = log.message.beforeLast() || log.message.last();
var actualType = log.type.beforeLast() || log.type.last();
this.assertEqual(expected, actualMessage, 'assertModificationNotified');
this.assertEqual('modification', actualType, 'assertModificationNotified');
this.assertEqual(expected, actualMessage, 'assertWarnNotified');
this.assertEqual('warn', actualType, 'assertWarnNotified');
log.message.push(null);
log.type.push(null);
},
Expand All @@ -77,15 +77,15 @@ <h1>Prototype Unit test file</h1>

new Test.Unit.Runner({
testGetStack: function(){ with(this) {
assertMatch(/deprecation_test\.html:\d+\n$/, DeprecationNotifier.getStack());
assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack());
}},

testDisplay: function(){ with(this) {
Toggle.display('foo');
assertDeprecationNotified('Toggle.display has been deprecated, please use Element.toggle instead.');
assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.');

Element.show('foo', 'bar', 'bla');
assertRemovalNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Element.show) or $(id_1, id_2, ...).invoke("show") instead.');

$('foo', 'bar', 'bla').each(Element.hide);
Expand All @@ -95,11 +95,11 @@ <h1>Prototype Unit test file</h1>
assertNotNotified();

Element.hide('foo', 'bar', 'bla');
assertRemovalNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Element.hide) or $(id_1, id_2, ...).invoke("hide") instead.');

Element.toggle('foo', 'bar', 'bla');
assertRemovalNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Element.toggle) or $(id_1, id_2, ...).invoke("toggle") instead.');
}},

Expand All @@ -108,151 +108,151 @@ <h1>Prototype Unit test file</h1>
assertNotNotified();

Element.setStyle('foo', { 'font-size': '18px' });
assertRemovalNotified('Use of uncamelized style-property names is no longer supported.\n' +
assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
'Use either camelized style-property names or a regular CSS string instead (see online documentation).')

Element.setStyle('foo', 'font-size: 18px;');
assertNotNotified();

$('foo').setStyle({ 'font-size': '18px' });
assertRemovalNotified('Use of uncamelized style-property names is no longer supported.\n' +
assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
'Use either camelized style-property names or a regular CSS string instead (see online documentation).')
}},

testClassNames: function(){ with(this) {
new Element.ClassNames('foo');
assertDeprecationNotified('Element.ClassNames has been deprecated.')
assertInfoNotified('Element.ClassNames has been deprecated.')

$('foo').classNames();
assertDeprecationNotified('Element#classNames has been deprecated.\n' +
assertInfoNotified('Element#classNames has been deprecated.\n' +
'If you need to access CSS class names as an array, try: $w(element.classname).')

Element.getElementsByClassName('foo', 'className');
assertDeprecationNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.')
assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.')

document.getElementsByClassName('className');
assertDeprecationNotified('document.getElementsByClassName has been deprecated, please use $$ instead.')
assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.')
}},

testDomSelectors: function(){ with(this) {
Element.childOf('foo', 'bar');
assertDeprecationNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.');
assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.');

$('foo').immediateDescendants();
assertDeprecationNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.');
assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.');

$('foo').getElementsBySelector('a');
assertDeprecationNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.');
assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.');

$('foo').select('a');
assertNotNotified();
}},

testField: function(){ with(this) {
Field.clear('foo', 'bar', 'bla');
assertRemovalNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Form.Element.clear) or $(id_1, id_2, ...).invoke("clear") instead.');

Field.present('foo', 'bar', 'bla');
assertRemovalNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Form.Element.present) or $(id_1, id_2, ...).invoke("present") instead.');
}},

testInsertion: function(){ with(this) {
Insertion.Before('foo', 'text');
assertDeprecationNotified('Insertion.Before has been deprecated, please use Element#insert instead.');
assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.');

Insertion.Top('foo', 'text');
assertDeprecationNotified('Insertion.Top has been deprecated, please use Element#insert instead.');
assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.');

Insertion.Bottom('foo', 'text');
assertDeprecationNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.');
assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.');

Insertion.After('foo', 'text');
assertDeprecationNotified('Insertion.After has been deprecated, please use Element#insert instead.');
assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.');
}},

testPosition: function(){ with(this) {
Position.prepare('foo');
assertDeprecationNotified('Position.prepare has been deprecated.');
assertInfoNotified('Position.prepare has been deprecated.');

Position.within('foo');
assertDeprecationNotified('Position.within has been deprecated.');
assertInfoNotified('Position.within has been deprecated.');

Position.withinIncludingScrolloffsets('foo');
assertDeprecationNotified('Position.withinIncludingScrolloffsets has been deprecated.');
assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.');

Position.overlap('foo');
assertDeprecationNotified('Position.overlap has been deprecated.');
assertInfoNotified('Position.overlap has been deprecated.');

Position.cumulativeOffset('foo');
assertDeprecationNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.');
assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.');

Position.positionedOffset('foo');
assertDeprecationNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.');
assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.');

Position.absolutize('foo');
assertDeprecationNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.');
assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.');

Position.relativize('foo');
assertDeprecationNotified('Position.relativize has been deprecated, please use Element#relativize instead.');
assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.');

Position.realOffset('foo');
assertDeprecationNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.');
assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.');

Position.offsetParent('foo');
assertDeprecationNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.');
assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.');

Position.page('foo');
assertDeprecationNotified('Position.page has been deprecated, please use Element#viewportOffset instead.');
assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.');

Position.clone('foo', 'bar');
assertDeprecationNotified('Position.clone has been deprecated, please use Element#clonePosition instead.');
assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.');
}},

testEvent: function(){ with(this) {
Event.unloadCache();
assertRemovalNotified('Event.unloadCache has been deprecated.')
assertErrorNotified('Event.unloadCache has been deprecated.')
}},

testHash: function(){ with(this) {
Hash.toQueryString({});
assertDeprecationNotified('Hash.toQueryString has been deprecated.\n' +
assertInfoNotified('Hash.toQueryString has been deprecated.\n' +
'Use the instance method Hash#toQueryString or Object.toQueryString instead.');

Hash.toJSON({});
assertRemovalNotified('Hash.toJSON has been removed.\n' +
assertErrorNotified('Hash.toJSON has been removed.\n' +
'Use the instance method Hash#toJSON or Object.toJSON instead.');

var h = $H({ foo: 2 });

h.remove('foo');
assertRemovalNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
'Please note that Hash#unset only accepts one argument.');

h.merge('foo');
assertModificationNotified('Hash#merge is no longer destructive: it operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');

h['foo'];
assertRemovalNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
'Please use Hash#get(\'foo\') instead.')

h.foo = 3;
assertRemovalNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
'Please use Hash#set(\'foo\', 3) instead.')

h.bar = 'bar';
h.toJSON();
assertRemovalNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
'Please use Hash#set(\'bar\', \'bar\') instead.')

h.bar;
assertRemovalNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
'Please use Hash#get(\'bar\') instead.')

h.baz = 'baz';
h.bar;
assertRemovalNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
'Please use Hash#set(\'baz\', \'baz\') instead.')

h.set('toJSON', 'arg'); // make sure hash methods are not overwritten
Expand All @@ -261,26 +261,26 @@ <h1>Prototype Unit test file</h1>

testClass: function(){ with(this) {
Class.create();
assertDeprecationNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +
assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +
'You can find more about it here: http://prototypejs.org/learn/class-inheritance');
Class.create({});
assertNotNotified();
}},

testLogDeprecationOption: function(){ with(this) {
DeprecationNotifier.logDeprecation = false;
prototypeUpdateHelper.logLevel = UpdateHelper.Warn;
var h = $H({ foo: 2 });

h.merge({ foo: 3 });
assertModificationNotified('Hash#merge is no longer destructive: it operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');

h.remove('foo');
assertRemovalNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
'Please note that Hash#unset only accepts one argument.');

document.getElementsByClassName('className');
assertNotNotified();
DeprecationNotifier.logDeprecation = true;
prototypeUpdateHelper.logLevel = UpdateHelper.Info;
}}
});

Expand Down

0 comments on commit 87ce153

Please sign in to comment.