Example #1
0
    def run(self, **kwargs):
        """Run command."""

        inputs = self.process_inputs(**kwargs)
        self.setup(**inputs)

        save_location = inputs["save_location"]
        time_stamp = inputs["time_stamp"]

        if save_location is not None:
            fname = self.view.file_name()
            if (((fname is None or not path.exists(fname))
                 and save_location == ".") or not path.exists(save_location)
                    or not path.isdir(save_location)):
                html_file = ".html"
                save_location = None
            elif save_location == ".":
                html_file = "%s%s.html" % (
                    fname, time.strftime(time_stamp, self.time))
            elif fname is None or not path.exists(fname):
                html_file = path.join(
                    save_location,
                    "Untitled%s.html" % time.strftime(time_stamp, self.time))
            else:
                html_file = path.join(
                    save_location,
                    "%s%s.html" % (path.basename(fname),
                                   time.strftime(time_stamp, self.time)))
        else:
            html_file = ".html"

        with OpenHtml(html_file, save_location) as html:
            self.write_header(html)
            self.write_body(html)
            if inputs["clipboard_copy"]:
                html.seek(0)
                sublime.set_clipboard(html.read())
                notify("HTML copied to clipboard")

        if inputs["view_open"]:
            self.view.window().open_file(html.name)
        else:
            # Open in web browser; check return code, if failed try webbrowser
            status = desktop.open(html.name, status=True)
            if not status:
                webbrowser.open(html.name, new=2)
Example #2
0
    def run(self, **kwargs):
        inputs = self.process_inputs(**kwargs)
        self.setup(**inputs)

        save_location = inputs["save_location"]
        time_stamp = inputs["time_stamp"]

        if save_location is not None:
            fname = self.view.file_name()
            if (
                ((fname is None or not path.exists(fname)) and save_location == ".") or
                not path.exists(save_location)
                or not path.isdir(save_location)
            ):
                html_file = ".html"
                save_location = None
            elif save_location == ".":
                html_file = "%s%s.html" % (fname, time.strftime(time_stamp, self.time))
            elif fname is None or not path.exists(fname):
                html_file = path.join(save_location, "Untitled%s.html" % time.strftime(time_stamp, self.time))
            else:
                html_file = path.join(save_location, "%s%s.html" % (path.basename(fname), time.strftime(time_stamp, self.time)))
        else:
            html_file = ".html"

        if save_location is not None:
            open_html = lambda x: open(x, "w")
        else:
            open_html = lambda x: tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix=x)

        with open_html(html_file) as the_html:
            self.write_header(the_html)
            self.write_body(the_html)
            if inputs["clipboard_copy"]:
                the_html.seek(0)
                sublime.set_clipboard(the_html.read())
                notify("HTML copied to clipboard")

        if inputs["view_open"]:
            self.view.window().open_file(the_html.name)
        else:
            # Open in web browser; check return code, if failed try webbrowser
            status = desktop.open(the_html.name, status=True)
            if not status:
                webbrowser.open(the_html.name, new=2)
Example #3
0
    def run(self, **kwargs):
        """Run command."""

        inputs = self.process_inputs(**kwargs)
        self.setup(**inputs)

        save_location = inputs["save_location"]
        time_stamp = inputs["time_stamp"]

        if save_location is not None:
            fname = self.view.file_name()
            if (
                ((fname is None or not path.exists(fname)) and save_location == ".") or
                not path.exists(save_location) or
                not path.isdir(save_location)
            ):
                html_file = ".html"
                save_location = None
            elif save_location == ".":
                html_file = "%s%s.html" % (fname, time.strftime(time_stamp, self.time))
            elif fname is None or not path.exists(fname):
                html_file = path.join(save_location, "Untitled%s.html" % time.strftime(time_stamp, self.time))
            else:
                html_file = path.join(
                    save_location, "%s%s.html" % (path.basename(fname), time.strftime(time_stamp, self.time))
                )
        else:
            html_file = ".html"

        with OpenHtml(html_file, save_location) as html:
            self.write_header(html)
            self.write_body(html)
            if inputs["clipboard_copy"]:
                html.seek(0)
                sublime.set_clipboard(html.read())
                notify("HTML copied to clipboard")

        if inputs["view_open"]:
            self.view.window().open_file(html.name)
        else:
            # Open in web browser; check return code, if failed try webbrowser
            status = desktop.open(html.name, status=True)
            if not status:
                webbrowser.open(html.name, new=2)