Skip to content

Commit

Permalink
Fix oppia#5426: Lint check to ensure that each Angular file contains …
Browse files Browse the repository at this point in the history
…exactly one service/directive/etc. inside it. (oppia#6202)

* Check js file has only one property

* Check js file has only one property

* Check js file has only one property

* Refactor extensions/

* Resolved conflicts

* Fix errors

* Fix errors

* Fix errors

* Lint errors

* Lint errors

* Fix errors

* Fix errors

* Fix errors

* Fix errors

* Fix errors

* Fix base test

* admin-roles-tab

* Removed unneccessary scripts

* Change string patterns

* Fix lint errors

* Fix e2e tests

* Address review comments

* Addressed comments

* Addressed comments

* Final reviews

* Improve docstring

* Improved docstring

* addressed review comments

* lint checks

* Nit

* Resolve conflicts

* Minor nit

* Resolve errors

* Fix spaces

* Fix spaces

* Fix spaces

* Fix spaces

* Fix spaces
  • Loading branch information
Rishav Chakraborty authored and seanlip committed Mar 19, 2019
1 parent 7555cd7 commit d4cc8d1
Show file tree
Hide file tree
Showing 182 changed files with 1,884 additions and 1,221 deletions.
3 changes: 2 additions & 1 deletion core/domain/rte_component_registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def test_rte_components_are_valid(self):
self.assertTrue(os.path.isfile(protractor_file))

main_js_file = os.path.join(
directives_dir, '%sDirective.js' % component_id)
directives_dir, 'OppiaNoninteractive%sDirective.js'
% component_id)
main_html_file = os.path.join(
directives_dir, '%s_directive.html' % component_id.lower())

Expand Down
2 changes: 1 addition & 1 deletion core/domain/value_generators_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_js_template(cls):
# customizationArgs and objType.
return utils.get_file_contents(os.path.join(
os.getcwd(), feconf.VALUE_GENERATORS_DIR, 'templates',
'%s.js' % cls.__name__))
'%sDirective.js' % cls.__name__))

def generate_value(self, *args, **kwargs):
"""Generates a new value, using the given customization args.
Expand Down
10 changes: 8 additions & 2 deletions core/domain/visualization_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ def _refresh_registry(cls):
@classmethod
def get_full_html(cls):
"""Returns the HTML bodies for all visualizations."""
js_directives = utils.get_file_contents(os.path.join(
feconf.VISUALIZATIONS_DIR, 'visualizations.js'))
js_directives = ''
for visualization_class in cls.get_all_visualization_ids():
filename = (
'OppiaVisualization%sDirective.js' % (visualization_class))
js_directives += (
utils.get_file_contents(os.path.join(
feconf.VISUALIZATIONS_DIR, filename)))

return '<script>%s</script>\n' % (js_directives)

@classmethod
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2019 The Oppia Authors. All Rights Reserved.
//
// 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.

/**
* @fileoverview Directive for applying validation.
*/

/* eslint-disable angular/directive-restrict */
oppia.directive('applyValidation', ['$filter', function($filter) {
return {
require: 'ngModel',
restrict: 'A',
link: function(scope, elm, attrs, ctrl) {
// Add validators in reverse order.
if (scope.validators()) {
scope.validators().forEach(function(validatorSpec) {
var frontendName = $filter('underscoresToCamelCase')(
validatorSpec.id);

// Note that there may not be a corresponding frontend filter for
// each backend validator.
try {
$filter(frontendName);
} catch (err) {
return;
}

var filterArgs = {};
for (var key in validatorSpec) {
if (key !== 'id') {
filterArgs[$filter('underscoresToCamelCase')(key)] =
angular.copy(validatorSpec[key]);
}
}

var customValidator = function(viewValue) {
ctrl.$setValidity(
frontendName, $filter(frontendName)(viewValue,
filterArgs));
return viewValue;
};

ctrl.$parsers.unshift(customValidator);
ctrl.$formatters.unshift(customValidator);
});
}
}
};
}]);
/* eslint-enable angular/directive-restrict */
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2019 The Oppia Authors. All Rights Reserved.
//
// 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.

/**
* @fileoverview Converts HTML to unicode.
*/

oppia.filter('convertHtmlToUnicode', [function() {
return function(html) {
return angular.element('<div>' + html + '</div>').text();
};
}]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2019 The Oppia Authors. All Rights Reserved.
//
// 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.

/**
* @fileoverview Converts unicode to HTML.
*/

oppia.filter('convertUnicodeToHtml', [
'$sanitize', 'HtmlEscaperService',
function($sanitize, HtmlEscaperService) {
return function(text) {
return $sanitize(HtmlEscaperService.unescapedStrToEscapedStr(text));
};
}
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2019 The Oppia Authors. All Rights Reserved.
//
// 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.

/**
* @fileoverview Converts {{name}} substrings to
* <oppia-parameter>name</oppia-parameter> tags and unescapes the
* {, } and \ characters. This is done by reading the given string from
* left to right: if we see a backslash, we use the following character;
* if we see a '{{', this is the start of a parameter; if we see a '}}';
* this is the end of a parameter.
*/

oppia.filter('convertUnicodeWithParamsToHtml', ['$filter', function($filter) {
var assert = function(text) {
if (!text) {
throw 'Invalid unicode-string-with-parameters: ' + text;
}
};

return function(text) {
// The parsing here needs to be done with more care because we are replacing
// two-character strings. We can't naively break by {{ because in strings
// like \{{{ the second and third characters will be taken as the opening
// brackets, which is wrong. We can't unescape characters because then the
// { characters that remain will be ambiguous (they may either be the
// openings of parameters or literal '{' characters entered by the user.
// So we build a standard left-to-right parser which examines each
// character of the string in turn, and processes it accordingly.
var textFragments = [];
var currentFragment = '';
var currentFragmentIsParam = false;
for (var i = 0; i < text.length; i++) {
if (text[i] === '\\') {
assert(!currentFragmentIsParam && text.length > i + 1 && {
'{': true,
'}': true,
'\\': true
}[text[i + 1]]);
currentFragment += text[i + 1];
i++;
} else if (text[i] === '{') {
assert(
text.length > i + 1 && !currentFragmentIsParam &&
text[i + 1] === '{');
textFragments.push({
type: 'text',
data: currentFragment
});
currentFragment = '';
currentFragmentIsParam = true;
i++;
} else if (text[i] === '}') {
assert(
text.length > i + 1 && currentFragmentIsParam &&
text[i + 1] === '}');
textFragments.push({
type: 'parameter',
data: currentFragment
});
currentFragment = '';
currentFragmentIsParam = false;
i++;
} else {
currentFragment += text[i];
}
}

assert(!currentFragmentIsParam);
textFragments.push({
type: 'text',
data: currentFragment
});

var result = '';
textFragments.forEach(function(fragment) {
result += (
fragment.type === 'text' ?
$filter('convertUnicodeToHtml')(fragment.data) :
'<oppia-parameter>' + fragment.data +
'</oppia-parameter>');
});
return result;
};
}]);
Loading

0 comments on commit d4cc8d1

Please sign in to comment.