Beispiel #1
0
    def test_basic(self):
        self.assertEqual(
            expand('input[value="text$"]*2'),
            '<input type="text" value="text1"><input type="text" value="text2">'
        )
        self.assertEqual(
            expand('ul>.item$*2'),
            '<ul>\n\t<li class="item1"></li>\n\t<li class="item2"></li>\n</ul>'
        )

        # insert text into abbreviation
        self.assertEqual(
            expand('ul>.item$*', {'text': ['foo', 'bar']}),
            '<ul>\n\t<li class="item1">foo</li>\n\t<li class="item2">bar</li>\n</ul>'
        )

        # Wrap with Abbreviation, skip empty lines
        self.assertEqual(
            expand('ul>.item$*', {'text': ['foo', '', 'bar', '', '']}),
            '<ul>\n\t<li class="item1">foo</li>\n\t<li class="item2">bar</li>\n</ul>'
        )

        # insert TextMate-style fields/tabstops in output
        self.assertEqual(
            expand('ul>.item$*2', {'options': {
                'output.field': field
            }}),
            '<ul>\n\t<li class="item1">${1}</li>\n\t<li class="item2">${2}</li>\n</ul>'
        )
Beispiel #2
0
def help_command(message):
    TgSessions.get_session(message.from_user.id)

    print("Message text:" + message.text)
    print("Reply to:" + message.reply_to_message.text)
    cmd, spl, title = message.text.partition(' ')
    if title != "":
        try:
            emmet.expand(message.reply_to_message.text)
            em_tpl = EmmetTemplates(tgUser_tg_id=message.from_user.id,
                                    title=title,
                                    template=message.reply_to_message.text)
            db.session.add(em_tpl)
            db.session.commit()
            bot.send_message(message.chat.id,
                             f'Шаблон *{title}* сохранен',
                             parse_mode='Markdown',
                             reply_markup=types.ReplyKeyboardRemove())
        except:
            bot.send_message(message.chat.id,
                             'Некорректное Emmet-выражение',
                             reply_markup=types.ReplyKeyboardRemove())
    else:
        bot.send_message(
            message.chat.id,
            'Шаблону нужен заголовок. Выберите сообщение с Emmet-выражением, '
            'нажмите Ответить и в качестве команды напишите */save Заголовок*',
            parse_mode='Markdown',
            reply_markup=types.ReplyKeyboardRemove())
Beispiel #3
0
 def test_custom_variables(self):
     variables = {'charset': 'ru-RU'}
     self.assertEqual(expand('[charset=${charset}]{${charset}}'),
                      '<div charset="UTF-8">UTF-8</div>')
     self.assertEqual(
         expand('[charset=${charset}]{${charset}}',
                {'variables': variables}),
         '<div charset="ru-RU">ru-RU</div>')
Beispiel #4
0
 def test_jsx(self):
     config = {'syntax': 'jsx'}
     self.assertEqual(expand('div#foo.bar', config),
                      '<div id="foo" className="bar"></div>')
     self.assertEqual(expand('label[for=a]', config),
                      '<label htmlFor="a"></label>')
     self.assertEqual(expand('Foo.Bar', config), '<Foo.Bar></Foo.Bar>')
     self.assertEqual(expand('div.{theme.style}', config),
                      '<div className={theme.style}></div>')
Beispiel #5
0
 def test_syntax(self):
     self.assertEqual(
         expand('ul>.item$*2', {'syntax': 'html'}),
         '<ul>\n\t<li class="item1"></li>\n\t<li class="item2"></li>\n</ul>'
     )
     self.assertEqual(expand('ul>.item$*2', {'syntax': 'slim'}),
                      'ul\n\tli.item1 \n\tli.item2 ')
     self.assertEqual(
         expand('xsl:variable[name=a select=b]>div', {'syntax': 'xsl'}),
         '<xsl:variable name="a">\n\t<div></div>\n</xsl:variable>')
Beispiel #6
0
    def test_abbreviations(self):
        snippets = {'test': 'test[!foo bar. baz={}]'}
        opt = {'snippets': snippets}
        reverse = {
            'options': {
                'output.reverseAttributes': True
            },
            'snippets': snippets
        }

        self.assertEqual(expand('a.test'), '<a href="" class="test"></a>')
        self.assertEqual(expand('a.test', reverse),
                         '<a class="test" href=""></a>')

        self.assertEqual(expand('test', opt), '<test bar="bar" baz={}></test>')
        self.assertEqual(expand('test[foo]', opt),
                         '<test bar="bar" baz={}></test>')
        self.assertEqual(expand('test[baz=a foo=1]', opt),
                         '<test foo="1" bar="bar" baz={a}></test>')

        # Apply attributes in reverse order
        self.assertEqual(expand('test', reverse),
                         '<test bar="bar" baz={}></test>')
        self.assertEqual(expand('test[foo]', reverse),
                         '<test bar="bar" baz={}></test>')
        self.assertEqual(expand('test[baz=a foo=1]', reverse),
                         '<test baz={a} foo="1" bar="bar"></test>')
Beispiel #7
0
    def test_html(self):
        for _, v in enumerate(markup_snippets):
            self.assertTrue(parse(v))

        self.assertEqual(
            expand('fset>input:c'),
            '<fieldset><input type="checkbox" name="" id=""></fieldset>')
Beispiel #8
0
    def formatter_options(self):
        self.assertEqual(
            expand('ul>.item$*2'),
            '<ul>\n\t<li class="item1"></li>\n\t<li class="item2"></li>\n</ul>'
        )
        self.assertEqual(
            expand('ul>.item$*2', {'options': {
                'comment.enabled': True
            }}),
            '<ul>\n\t<li class="item1"></li>\n\t<!-- /.item1 -->\n\t<li class="item2"></li>\n\t<!-- /.item2 -->\n</ul>'
        )

        self.assertEqual(expand('div>p'), '<div>\n\t<p></p>\n</div>')
        self.assertEqual(
            expand('div>p', {'options': {
                'output.formatLeafNode': True
            }}), '<div>\n\t<p>\n\t\t\n\t</p>\n</div>')
Beispiel #9
0
    def test_single(self):
        output = expand('lorem')
        self.assertTrue(re.match(r'^Lorem,?\sipsum', output))
        self.assertTrue(word_count(output) > 20)

        output = expand('lorem5')
        self.assertTrue(re.match(r'^Lorem,?\sipsum', output))
        self.assertEqual(word_count(output), 5)

        output = expand('lorem5-10')
        self.assertTrue(re.match(r'^Lorem,?\sipsum', output))
        self.assertTrue(5 <= word_count(output) <= 10)

        output = expand('loremru4')
        self.assertTrue(re.match(r'^Далеко-далеко,?\sза,?\sсловесными',
                                 output))
        self.assertEqual(word_count(output), 4)

        output = expand('p>lorem')
        self.assertTrue(re.match(r'^<p>Lorem,?\sipsum', output))

        # https://github.com/emmetio/expand-abbreviation/issues/24
        output = expand('(p)lorem2')
        self.assertTrue(re.match(r'^<p><\/p>\nLorem,?\sipsum', output))

        output = expand('p(lorem10)')
        self.assertTrue(re.match(r'^<p><\/p>\nLorem,?\sipsum', output))
Beispiel #10
0
    def test_multiple(self):
        output = expand('lorem6*3')
        lines = output.splitlines()
        self.assertTrue(re.match(r'^Lorem,?\sipsum', output))
        self.assertEqual(len(lines), 3)

        output = expand('lorem6*2')
        lines = output.splitlines()
        self.assertTrue(re.match(r'^Lorem,?\sipsum', output))
        self.assertEqual(len(lines), 2)

        output = expand('p*3>lorem')
        lines = output.splitlines()
        self.assertTrue(re.match(r'^<p>Lorem,?\sipsum', lines[0]))
        self.assertFalse(re.match(r'^<p>Lorem,?\sipsum', lines[1]))

        output = expand('ul>lorem5*3', {'options': {'output.indent': ''}})
        lines = output.splitlines()
        self.assertEqual(len(lines), 5)
        self.assertTrue(re.match(r'^^<li>Lorem,?\sipsum', lines[1]))
        self.assertFalse(re.match(r'^^<li>Lorem,?\sipsum', lines[2]))
Beispiel #11
0
    def test_custom_snippets(self):
        snippets = {
            'link': 'link[foo=bar href]/',
            'foo': '.foo[bar=baz]',
            'repeat': 'div>ul>li{Hello World}*3'
        }

        self.assertEqual(expand('foo', {'snippets': snippets}),
                         '<div class="foo" bar="baz"></div>')

        # `link:css` depends on `link` snippet so changing it will result in
        # altered `link:css` result
        self.assertEqual(expand('link:css'),
                         '<link rel="stylesheet" href="style.css">')
        self.assertEqual(expand('link:css', {'snippets': snippets}),
                         '<link foo="bar" href="style.css">')

        # https://github.com/emmetio/emmet/issues/468
        self.assertEqual(
            expand('repeat', {'snippets': snippets}),
            '<div>\n\t<ul>\n\t\t<li>Hello World</li>\n\t\t<li>Hello World</li>\n\t\t<li>Hello World</li>\n\t</ul>\n</div>'
        )
Beispiel #12
0
def repeat_all_messages(message):
    TgSessions.get_session(message.from_user.id)
    print(message)
    try:
        bot.send_message(message.chat.id,
                         '`' + emmet.expand(message.text) + '`',
                         parse_mode='Markdown',
                         reply_markup=types.ReplyKeyboardRemove())
    except (emmet.token_scanner.TokenScannerException,
            emmet.scanner.ScannerException):
        bot.send_message(message.chat.id,
                         'Выражение *' + message.text +
                         '* не поддается расшифровке',
                         parse_mode='Markdown',
                         reply_markup=types.ReplyKeyboardRemove())
Beispiel #13
0
 def test_numbering(self):
     self.assertEqual(
         expand('ul>li.item$@-*5'),
         '<ul>\n\t<li class="item5"></li>\n\t<li class="item4"></li>\n\t<li class="item3"></li>\n\t<li class="item2"></li>\n\t<li class="item1"></li>\n</ul>'
     )
Beispiel #14
0
 def test_expressions(self):
     self.assertEqual(expand('span{{foo}}'), '<span>{foo}</span>')
     self.assertEqual(expand('span{foo}'), '<span>foo</span>')
     self.assertEqual(expand('span[foo={bar}]'), '<span foo={bar}></span>')
     self.assertEqual(expand('span[foo={{bar}}]'),
                      '<span foo={{bar}}></span>')
Beispiel #15
0
 def test_basics(self):
     self.assertEqual(
         expand('!', {'syntax': 'pug'}),
         'doctype html\nhtml(lang="en")\n\thead\n\t\tmeta(charset="UTF-8")\n\t\tmeta(name="viewport", content="width=device-width, initial-scale=1.0")\n\t\ttitle Document\n\tbody '
     )
Beispiel #16
0
 def test_class_names(self):
     self.assertEqual(expand('div.foo/'), '<div class="foo">')
     self.assertEqual(expand('div.foo1/2'), '<div class="foo1/2"></div>')
     self.assertEqual(expand('div.foo.1/2'), '<div class="foo 1/2"></div>')
Beispiel #17
0
    def test_wrap_with_abbreviation(self):
        self.assertEqual(
            expand('img[src="$#"]*', {'text': ['foo.jpg', 'bar.jpg']}),
            '<img src="foo.jpg" alt=""><img src="bar.jpg" alt="">')
        self.assertEqual(
            expand('div>ul', {'text': ['<div>line1</div>\n<div>line2</div>']}),
            '<div>\n\t<ul>\n\t\t<div>line1</div>\n\t\t<div>line2</div>\n\t</ul>\n</div>'
        )

        self.assertEqual(expand('a', {'text': 'foo'}), '<a href="">foo</a>')
        self.assertEqual(expand('a', {'text': 'emmet//io'}),
                         '<a href="">emmet//io</a>')
        self.assertEqual(expand('a', {'text': 'http://emmet.io'}),
                         '<a href="http://emmet.io">http://emmet.io</a>')
        self.assertEqual(expand('a', {'text': '//emmet.io'}),
                         '<a href="//emmet.io">//emmet.io</a>')
        self.assertEqual(expand('a', {'text': 'www.emmet.io'}),
                         '<a href="http://www.emmet.io">www.emmet.io</a>')
        self.assertEqual(expand('a', {'text': 'emmet.io'}),
                         '<a href="">emmet.io</a>')
        self.assertEqual(expand('a', {'text': '*****@*****.**'}),
                         '<a href="mailto:[email protected]">[email protected]</a>')

        self.assertEqual(expand('p', {'text': 'foo\nbar'}),
                         '<p>\n\tfoo\n\tbar\n</p>')
        self.assertEqual(expand('p', {'text': '<div>foo</div>'}),
                         '<p>\n\t<div>foo</div>\n</p>')
Beispiel #18
0
 def test_custom_profile(self):
     self.assertEqual(expand('img'), '<img src="" alt="">')
     self.assertEqual(
         expand('img', {'options': {
             'output.selfClosingStyle': 'xhtml'
         }}), '<img src="" alt="" />')
Beispiel #19
0
 def validate_template(self, template):
     try:
         emmet.expand(template.data)
     except:
         raise ValidationError(f"Не удалось разобрать шаблон")