コード例 #1
0
ファイル: main.py プロジェクト: Camru/SublimeText3-Settings
 def run(self, edit, **args):
   from node.main import NodeJS
   node = NodeJS()
   view = self.view
   selections = view.sel()
   for selection in selections :
     scope = view.scope_name(selection.begin()).strip()
     result = Util.get_region_scope_first_match(view, scope, selection, "meta.brackets.js")
     if result :
       region = result.get("region")
       array_string = result.get("region_string_stripped")
       from node.main import NodeJS
       node = NodeJS()
       case = args.get("case")
       sort_func = ""
       if case == "compare_func_desc" :
         sort_func = "function(x,y){return y-x;}"
       elif case == "compare_func_asc" :
         sort_func = "function(x,y){return x-y;}"
       elif case == "alpha_asc" :
         sort_func = ""
       elif case == "alpha_desc" :
         sort_func = ""
       sort_result = node.eval("var array = "+array_string+"; console.log(array.sort("+sort_func+")"+( ".reverse()" if case == "alpha_desc" else "" )+")").strip()
       view.replace(edit, region, sort_result)
コード例 #2
0
 def run(self, edit, **args):
   from node.main import NodeJS
   node = NodeJS()
   view = self.view
   selections = view.sel()
   for selection in selections :
     scope = view.scope_name(selection.begin()).strip()
     result = Util.get_region_scope_first_match(view, scope, selection, "meta.brackets.js")
     if result :
       region = result.get("region")
       array_string = result.get("region_string_stripped")
       from node.main import NodeJS
       node = NodeJS()
       case = args.get("case")
       sort_func = ""
       if case == "compare_func_desc" :
         sort_func = "function(x,y){return y-x;}"
       elif case == "compare_func_asc" :
         sort_func = "function(x,y){return x-y;}"
       elif case == "alpha_asc" :
         sort_func = ""
       elif case == "alpha_desc" :
         sort_func = ""
       sort_result = node.eval("var array = "+array_string+"; console.log(array.sort("+sort_func+")"+( ".reverse()" if case == "alpha_desc" else "" )+")").strip()
       view.replace(edit, region, sort_result)
    def run(self, edit, is_line=False, eval_type="eval"):
        global result_js
        global region_selected
        global popup_is_showing

        view = self.view
        sel = view.sel()[0]
        popup_is_showing = False
        str_selected = view.substr(sel).strip()

        if is_line:
            lines = view.lines(sel)
            region_selected = lines[0]
            str_selected = view.substr(region_selected)
        else:
            if not str_selected and region_selected:
                region = get_start_end_code_highlights_eval()
                region_selected = sublime.Region(region[0], region[1])
                lines = view.lines(region_selected)
                str_selected = ""
                for line in lines:
                    str_selected += view.substr(view.full_line(line))
            elif str_selected:
                lines = view.lines(sel)
                region_selected = sublime.Region if not region_selected else region_selected
                region_selected = sublime.Region(lines[0].begin(),
                                                 lines[-1:][0].end())
            elif not str_selected:
                return

        if not region_selected:
            return

        view.run_command("show_start_end_dot_eval")

        try:
            from node.main import NodeJS
            node = NodeJS()
            result_js = node.eval(str_selected, eval_type, True)
            popup_is_showing = True
            view.show_popup(
                "<html><head></head><body>" + ej_css +
                """<div class=\"container\">
        <p class="result">Result: """ + result_js + """</p>
        <div><a href="view_result_formatted">View result formatted(\\t,\\n,...)</a></div>
        <div><a href="copy_to_clipboard">Copy result to clipboard</a></div>
        <div><a href="replace_text">Replace text with result</a></div>
        </div>
      </body></html>""", sublime.COOPERATE_WITH_AUTO_COMPLETE, -1, 400, 400,
                action_result)
        except Exception as e:
            #sublime.error_message("Error: "+traceback.format_exc())
            sublime.active_window().show_input_panel(
                "Result", "Error: " + traceback.format_exc(), lambda x: "",
                lambda x: "", lambda: "")
コード例 #4
0
 def exec_node(self, folder_path, node_command_args) :
   os.chdir(folder_path)
   from node.main import NodeJS
   node = NodeJS()
   animation_loader = AnimationLoader(["[=     ]", "[ =    ]", "[   =  ]", "[    = ]", "[     =]", "[    = ]", "[   =  ]", "[ =    ]"], 0.067, "Generating docs ")
   interval_animation = RepeatedTimer(animation_loader.sec, animation_loader.animate)
   result = node.execute("jsdoc", node_command_args, True)
   if not result[0] :
     sublime.error_message(result[1])
   animation_loader.on_complete()
   interval_animation.stop()
コード例 #5
0
 def exec_node(self, folder_path, node_command_args) :
   os.chdir(folder_path)
   from node.main import NodeJS
   node = NodeJS()
   animation_loader = AnimationLoader(["[=     ]", "[ =    ]", "[   =  ]", "[    = ]", "[     =]", "[    = ]", "[   =  ]", "[ =    ]"], 0.067, "Generating docs ")
   interval_animation = RepeatedTimer(animation_loader.sec, animation_loader.animate)
   result = node.execute("jsdoc", node_command_args, True)
   if not result[0] :
     sublime.error_message(result[1])
   animation_loader.on_complete()
   interval_animation.stop()
コード例 #6
0
  def run(self, edit, is_line=False, eval_type="eval"):
    global result_js
    global region_selected
    global popup_is_showing

    view = self.view
    sel = view.sel()[0]
    popup_is_showing = False
    str_selected = view.substr(sel).strip()

    if is_line:
      lines = view.lines(sel)
      region_selected = lines[0]
      str_selected = view.substr(region_selected)
    else: 
      if not str_selected and region_selected : 
        region = get_start_end_code_highlights_eval()
        region_selected = sublime.Region(region[0], region[1])
        lines = view.lines(region_selected)
        str_selected = ""
        for line in lines:
          str_selected += view.substr(view.full_line(line))
      elif str_selected:
        lines = view.lines(sel)
        region_selected = sublime.Region if not region_selected else region_selected
        region_selected = sublime.Region(lines[0].begin(), lines[-1:][0].end())
      elif not str_selected :
        return
    
    if not region_selected :
      return

    view.run_command("show_start_end_dot_eval")

    try:
      from node.main import NodeJS
      node = NodeJS()
      result_js = node.eval(str_selected, eval_type, True)
      popup_is_showing = True
      view.show_popup("<html><head></head><body>"+ej_css+"""<div class=\"container\">
        <p class="result">Result: """+result_js+"""</p>
        <div><a href="view_result_with_allspaces">View result with all spaces(\\t,\\n,...)</a></div>
        <div><a href="copy_to_clipboard">Copy result to clipboard</a></div>
        <div><a href="replace_text">Replace text with result</a></div>
        </div>
      </body></html>""", sublime.COOPERATE_WITH_AUTO_COMPLETE, -1, 400, 400, action_result)
    except Exception as e:
      #sublime.error_message("Error: "+traceback.format_exc())
      sublime.active_window().show_input_panel("Result", "Error: "+traceback.format_exc(), lambda x: "" , lambda x: "", lambda : "")
コード例 #7
0
  def run(self, edit, **args):
    view = self.view
    selections = view.sel()
    for selection in selections :
      scope = view.scope_name(selection.begin()).strip()
      depth_level = Util.split_string_and_find(scope, "meta.object-literal.js")
      item_object_literal = Util.get_region_scope_first_match(view, scope, selection, "meta.object-literal.js")

      if item_object_literal :

        scope = item_object_literal.get("scope")
        object_literal_region = item_object_literal.get("region")
        selection = item_object_literal.get("selection")
        object_literal = item_object_literal.get("region_string_stripped")
        from node.main import NodeJS
        node = NodeJS()
        object_literal = re.sub(r'[\n\r\t]', ' ', object_literal)
        object_literal = json.loads(node.eval("JSON.stringify("+object_literal+")", "print"))
        object_literal = [(key, json.dumps(value)) for key, value in object_literal.items()]

        list_ordered = ("keyword.operator.assignment.js", "variable.other.readwrite.js", "storage.type.js")
        items = Util.find_regions_on_same_depth_level(view, scope, selection, list_ordered, depth_level, False)
        if items :
          last_selection = items[-1:][0].get("selection")
          class_name = items[1].get("region_string_stripped")
          regions = [(item.get("region")) for item in items]
          regions.append(object_literal_region)
          regions = Util.cover_regions(regions)
          parameters = list()
          constructor_body = list()
          get_set = list()
          for parameter in object_literal: 
            parameters.append( parameter[0] + ( "="+parameter[1] if json.loads(parameter[1]) != "required" else "") )
            constructor_body.append( "\t\tthis."+parameter[0]+" = "+parameter[0]+";" )
            get_set.append("\tget "+parameter[0]+"() {\n\t\treturn this."+parameter[0]+";\n\t}")
            get_set.append("\tset "+parameter[0]+"("+parameter[0]+") {\n\t\tthis."+parameter[0]+" = "+parameter[0]+";\n\t}")
          parameters = ", ".join(parameters)
          constructor_body = '\n'.join(constructor_body)
          get_set = '\n\n'.join(get_set)
          js_syntax  = "class "+class_name+" {\n"
          js_syntax += "\n\tconstructor ("+parameters+") {\n"
          js_syntax += constructor_body
          js_syntax += "\n\t}\n\n"
          js_syntax += get_set
          js_syntax += "\n}"
          js_syntax = Util.add_whitespace_indentation(view, regions, js_syntax)
          view.replace(edit, regions, js_syntax)