Show:
  1. /**
  2. * The ACE Editor Velocity Plugin
  3. *
  4. * @module aui-ace-editor
  5. * @submodule aui-ace-autocomplete-velocity
  6. */
  7. var Lang = A.Lang,
  8. MATCH_DIRECTIVES = 0,
  9. MATCH_VARIABLES = 1,
  10. /**
  11. * A base class for Velocity plugin.
  12. *
  13. * @class A.AceEditor.AutoCompleteVelocity
  14. * @extends A.AceEditor.TemplateProcessor
  15. * @param {Object} config Object literal specifying widget configuration
  16. * properties.
  17. * @constructor
  18. */
  19. Velocity = A.Base.create('aui-ace-autocomplete-velocity', A.AceEditor.TemplateProcessor, [], {
  20. /**
  21. * Checks if the provided content contains directive or variable.
  22. *
  23. * @method getMatch
  24. * @param {String} content The content which should be traversed for
  25. * matches
  26. * @return {Object} An Object which contains the following properties:
  27. * content - the found content
  28. * start - the start index of the match
  29. * type - match type, could be 0 (DIRECTIVES) or 1 (VARIABLES)
  30. */
  31. getMatch: function(content) {
  32. var instance = this,
  33. match,
  34. matchIndex;
  35. if ((matchIndex = content.lastIndexOf('#')) >= 0) {
  36. content = content.substring(matchIndex);
  37. if (instance.get('directivesMatcher').test(content)) {
  38. match = {
  39. content: content.substring(1),
  40. start: matchIndex,
  41. type: MATCH_DIRECTIVES
  42. };
  43. }
  44. }
  45. else if ((matchIndex = content.lastIndexOf('$')) >= 0) {
  46. content = content.substring(matchIndex);
  47. if (instance.get('variablesMatcher').test(content)) {
  48. match = {
  49. content: content.substring(1),
  50. start: matchIndex,
  51. type: MATCH_VARIABLES
  52. };
  53. }
  54. }
  55. return match;
  56. }
  57. }, {
  58. /**
  59. * Static property which provides a string to identify the class.
  60. *
  61. * @property NAME
  62. * @type String
  63. * @static
  64. */
  65. NAME: 'aui-ace-autocomplete-velocity',
  66. /**
  67. * Static property provides a string to identify the namespace.
  68. *
  69. * @property NS
  70. * @type String
  71. * @static
  72. */
  73. NS: 'aui-ace-autocomplete-velocity',
  74. /**
  75. * Static property used to define the default attribute
  76. * configuration for the Velocity.
  77. *
  78. * @property ATTRS
  79. * @type Object
  80. * @static
  81. */
  82. ATTRS: {
  83. /**
  84. * Contains the list of supported directives according to Velocity
  85. * specification.
  86. *
  87. * @attribute directives
  88. * @default
  89. * value: [
  90. * 'else',
  91. * 'elseif',
  92. * 'foreach',
  93. * 'if',
  94. * 'include',
  95. * 'macro',
  96. * 'parse',
  97. * 'set',
  98. * 'stop'
  99. *]
  100. * @type Array
  101. */
  102. directives: {
  103. validator: Lang.isArray,
  104. value: [
  105. 'else',
  106. 'elseif',
  107. 'foreach',
  108. 'if',
  109. 'include',
  110. 'macro',
  111. 'parse',
  112. 'set',
  113. 'stop'
  114. ]
  115. },
  116. /**
  117. * Contains the regular expression which checks for directive.
  118. *
  119. * @attribute directivesMatcher
  120. * @default /#[\w]*[^#]*$/
  121. */
  122. directivesMatcher: {
  123. setter: '_setRegexValue',
  124. value: /#[\w]*[^#]*$/
  125. },
  126. /**
  127. * The Editor in which the current instance is plugged.
  128. *
  129. * @attribute host
  130. * @type Object
  131. */
  132. host: {
  133. validator: Lang.isObject
  134. },
  135. /**
  136. * Contains the supported variables.
  137. *
  138. * @attribute variables
  139. * @type Object
  140. */
  141. variables: {
  142. validator: Lang.isObject
  143. },
  144. /**
  145. * Contains the regular expression which will check for variable
  146. * match.
  147. *
  148. * @attribute variablesMatcher
  149. * @default /\$[\w., ()"]*(?:[^$]|\\\$)*$/
  150. */
  151. variablesMatcher: {
  152. setter: '_setRegexValue',
  153. value: /\$[\w., ()"]*(?:[^$]|\\\$)*$/
  154. }
  155. }
  156. });
  157. A.AceEditor.AutoCompleteVelocity = Velocity;