Ejemplo n.º 1
0
    def run(self, edit):
        cur_pos = self.view.sel()[0].begin()
        start_pos = cur_pos - MAX_SIZE_CSS
        if start_pos < 0:
            start_pos = 0
        # TODO: Move this to the contexts, it's not needed here
        probably_abbr = self.view.substr(sublime.Region(start_pos, cur_pos))
        match = ABBR_REGEX.search(probably_abbr)
        if match is None:
            self.view.insert(edit, cur_pos, '\t')
            return

        abbr = match.group(1)

        # Extracting the data from the abbr
        args = extract(abbr)

        if not args:
            return

        # Getting the options and making a snippet
        # from the extracted data
        get_hayaku_options(self)
        options = get_hayaku_options(self)
        template = make_template(args, options)

        if template is None:
            return

        # Inserting the snippet
        new_cur_pos = cur_pos - len(abbr)
        assert cur_pos - len(abbr) >= 0
        self.view.erase(edit, sublime.Region(new_cur_pos, cur_pos))

        self.view.run_command("insert_snippet", {"contents": template})
Ejemplo n.º 2
0
    def run(self, edit):
        cur_pos = self.view.sel()[0].begin()
        start_pos = cur_pos - MAX_SIZE_CSS
        if start_pos < 0:
            start_pos = 0
        # TODO: Move this to the contexts, it's not needed here
        probably_abbr = self.view.substr(sublime.Region(start_pos, cur_pos))
        match = ABBR_REGEX.search(probably_abbr)
        if match is None:
            self.view.insert(edit, cur_pos, '\t')
            return

        abbr = match.group(1)

        # Extracting the data from the abbr
        args = extract(abbr)

        if not args:
            return

        # Getting the options and making a snippet
        # from the extracted data
        get_hayaku_options(self)
        options = get_hayaku_options(self)
        template = make_template(args, options)

        if template is None:
            return

        # Inserting the snippet
        new_cur_pos = cur_pos - len(abbr)
        assert cur_pos - len(abbr) >= 0
        self.view.erase(edit, sublime.Region(new_cur_pos, cur_pos))

        self.view.run_command("insert_snippet", {"contents": template})
Ejemplo n.º 3
0
    def is_eq(self, k, test_tuple):
        hayaku_result = extract(k)

        self.assertTrue(hayaku_result)

        test_property, test_value = test_tuple
        value_extracted = hayaku_result.get('keyword-value', '')
        self.assertEqual(
            (hayaku_result['property-name'], value_extracted), test_tuple,
            "hayaku: '{0}' and test: '{1}'".format('{0} {1}'.format( hayaku_result['property-name'], value_extracted), '{0} {1}'.format(*test_tuple))
        )
Ejemplo n.º 4
0
    def is_eq(self, k, test_tuple):
        hayaku_result = extract(k)

        self.assertTrue(hayaku_result)

        test_property, test_value = test_tuple
        value_extracted = hayaku_result.get('keyword-value', '')
        self.assertEqual((hayaku_result['property-name'], value_extracted),
                         test_tuple, "hayaku: '{0}' and test: '{1}'".format(
                             '{0} {1}'.format(hayaku_result['property-name'],
                                              value_extracted),
                             '{0} {1}'.format(*test_tuple)))
Ejemplo n.º 5
0
    def run(self, edit):
        regions = self.view.sel()
        if len(regions) > 1:
            # разобраться с многооконными выборками
            # пока что работаем только с одним регионом
            for r in regions:
                self.view.insert(edit, r, '\t')
            return
        region = regions[0]
        if not region.empty():
            # сделать работы с выделенным словом
            self.view.insert(edit, region, '\t')
            return
        cur_pos = region.begin()

        start_pos = cur_pos - MAX_SIZE_CSS
        if start_pos < 0:
            start_pos = 0
        probably_abbr = self.view.substr(sublime.Region(start_pos, cur_pos))
        match = ABBR_REGEX.search(probably_abbr)
        if match is None:
            self.view.insert(edit, cur_pos, '\t')
            return

        abbr = match.group(1)
        # print repr(abbr), 'abbr'
        extracted = extract(abbr)
        # print extracted, '1'
        if not extracted[0]:
            return
        # print extracted, '2'
        template = make_template(self.view.settings().get("hayaku_CSS_whitespace_after_colon"), *extracted)
        new_cur_pos = cur_pos-len(abbr)
        assert cur_pos-len(abbr) >= 0
        self.view.erase(edit, sublime.Region(new_cur_pos, cur_pos))
        self.view.run_command("insert_snippet", {"contents": template})
Ejemplo n.º 6
0
 def test_10(self):
     self.assertEqual(expand_value(extract('w'), {}), '[100%]')
Ejemplo n.º 7
0
 def test_11(self):
     self.assertEqual(expand_value(extract('c#')), '#')
Ejemplo n.º 8
0
 def test_7(self):
     self.assertEqual(expand_value(extract('w10perc'), self.opts), '10%')
Ejemplo n.º 9
0
 def test_8(self):
     self.assertEqual(expand_value(extract('vat')), 'top')
Ejemplo n.º 10
0
 def test_6(self):
     self.assertEqual(expand_value(extract('w10%')), '10%')
Ejemplo n.º 11
0
 def test_5(self):
     self.assertEqual(expand_value(extract('w'), self.opts), '[100%]')
Ejemplo n.º 12
0
 def test_4(self):
     self.assertEqual(expand_value(extract('w0px'), self.opts), '0')
Ejemplo n.º 13
0
 def test_1(self):
     self.assertEqual(expand_value(extract('zi12')), '12')
Ejemplo n.º 14
0
 def test_0(self):
     self.assertEqual(expand_value(extract('z8')), '8')