How to use the @aurelia/jit.attributePattern function in @aurelia/jit

To help you get started, we’ve selected a few @aurelia/jit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / i18n / src / t / translation-parameters-renderer.ts View on Github external
IDOM,
  IExpressionParser,
  IInstructionRenderer,
  instructionRenderer,
  IObserverLocator,
  IRenderContext,
  IsBindingBehavior,
  LifecycleFlags
} from '@aurelia/runtime';
import { TranslationBinding } from './translation-binding';

export const TranslationParametersInstructionType = 'tpt';
// `.bind` part is needed here only for vCurrent compliance
const attribute = 't-params.bind';

@attributePattern({ pattern: attribute, symbols: '' })
export class TranslationParametersAttributePattern {
  public [attribute](rawName: string, rawValue: string, parts: string[]): AttrSyntax {
    return new AttrSyntax(rawName, rawValue, '', attribute);
  }
}

export class TranslationParametersBindingInstruction {
  public readonly type: string = TranslationParametersInstructionType;
  public mode: BindingMode.toView = BindingMode.toView;

  public constructor(
    public from: IsBindingBehavior,
    public to: string,
  ) {}
}
github aurelia / aurelia / packages / __tests__ / 4-jit / attribute-pattern.spec.ts View on Github external
it(`parse [${defs.map(d => d.pattern)}] -> interpret [${value}] -> match=[${match}]`, function () {
          let receivedRawName: string;
          let receivedRawValue: string;
          let receivedParts: string[];
          @attributePattern(...defs)
          class ThePattern {}
          for (const { pattern } of defs) {
            ThePattern.prototype[pattern] = (rawName, rawValue, parts) => {
              receivedRawName = rawName;
              receivedRawValue = rawValue;
              receivedParts = parts;
            };
          }
          const container = DI.createContainer();
          container.register(ThePattern as any);
          const interpreter = container.get(ISyntaxInterpreter);
          const attrPattern = container.get(IAttributePattern);
          interpreter.add(attrPattern.$patternDefs);

          const result = interpreter.interpret(value);
          if (match != null) {
github aurelia / aurelia / packages / __tests__ / 5-jit-html / attribute-pattern.ts View on Github external
public ['PART.style'](rawName: string, rawValue: string, parts: string[]): AttrSyntax {
    return new AttrSyntax(rawName, rawValue, parts[0], 'style');
  }
}

/**
 * Class syntax pattern recognizer, helps Aurelia understand template:
 * ```html
 * <div></div>
 * <div></div>
 * <div></div>
 * <div></div>
 * ```
 */
@attributePattern(
  { pattern: 'class.PART', symbols: '.' },
  { pattern: 'PART.class', symbols: '.' }
)
export class ClassAttributePattern {
  public ['class.PART'](rawName: string, rawValue: string, parts: string[]): AttrSyntax {
    return new AttrSyntax(rawName, rawValue, parts[1], 'class');
  }

  public ['PART.class'](rawName: string, rawValue: string, parts: string[]): AttrSyntax {
    return new AttrSyntax(rawName, rawValue, parts[0], 'class');
  }
}
github aurelia / aurelia / packages / __tests__ / 5-jit-html / attribute-pattern.ts View on Github external
}

/**
 * Style syntax pattern recognizer, helps Aurelia understand template:
 * ```html
 * <div></div>
 * <div></div>
 * <div></div>
 * <div></div>
 * <div></div>
 * <div></div>
 * <div></div>
 * <div></div>
 * ```
 */
@attributePattern(
  { pattern: 'style.PART', symbols: '.' },
  { pattern: 'PART.style', symbols: '.' }
)
export class StyleAttributePattern {
  public ['style.PART'](rawName: string, rawValue: string, parts: string[]): AttrSyntax {
    return new AttrSyntax(rawName, rawValue, parts[1], 'style');
  }

  public ['PART.style'](rawName: string, rawValue: string, parts: string[]): AttrSyntax {
    return new AttrSyntax(rawName, rawValue, parts[0], 'style');
  }
}

/**
 * Class syntax pattern recognizer, helps Aurelia understand template:
 * ```html
github aurelia / aurelia / packages / __tests__ / 5-jit-html / attribute-pattern.ts View on Github external
import { attributePattern, AttrSyntax } from '@aurelia/jit';

/**
 * Attribute syntax pattern recognizer, helping Aurelia understand template:
 * ```html
 * <div></div>
 * <div></div>
 * ````
 */
@attributePattern(
  { pattern: 'attr.PART', symbols: '.' },
  { pattern: 'PART.attr', symbols: '.' }
)
export class AttrAttributePattern {
  public ['attr.PART'](rawName: string, rawValue: string, parts: string[]): AttrSyntax {
    return new AttrSyntax(rawName, rawValue, parts[1], 'attr');
  }

  public ['PART.attr'](rawName: string, rawValue: string, parts: string[]): AttrSyntax {
    return new AttrSyntax(rawName, rawValue, parts[0], 'attr');
  }
}

/**
 * Style syntax pattern recognizer, helps Aurelia understand template:
 * ```html