Skip to content

Instantly share code, notes, and snippets.

@calacitizen
Last active April 21, 2016 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calacitizen/9691c8fed415aa338e136b99e6744519 to your computer and use it in GitHub Desktop.
Save calacitizen/9691c8fed415aa338e136b99e6744519 to your computer and use it in GitHub Desktop.

####Использование контролов в вёрстке

Шаблон компонента MyComponent.tmpl

   <p>hi</p>

Код использования:

// <div class="oh"><p>hi</p></div>

var html = '<div class="oh"><component data-component="MyComponent" /></div>'


tmpl.template(html).handle(function (ast) {

   // 
   //  переменная ast
   //  
   // [
   //    {
   //       type: 'tag',
   //       name: 'div',
   //       attrs: {
   //          class: {
   //               data: {
   //                  type: 'text',
   //                  value: 'oh'
   //               }
   //          }
   //       },
   //       selfclosing: false,
   //       children: [
   //          {
   //             type: 'control',
   //             fn: templateFunction, //// функция шаблонизатора
   //             constructor: constructor //// конструктор контрола
   //         }
   // 
   //       ]
   //    }
   // ]

   tmpl.process(ast, {}); 

   // Результат работы  { html: '<div><p data-template-id="ws-70pocne8diztjpsy0c8ga7zaor1461232438937">hi</p></div>', data: {} }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment