Sha256: 7fb92348de3a42ea5ac17f66a390441e34c9cc805e317031a8ed5e92cf1122aa

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

module Redcar
  class ExecuteCurrentTab

    def self.menus
      Menu::Builder.build do
        sub_menu "Plugins" do
          sub_menu "Execute" do
            item "Execute Current Tab as Ruby File", ExecuteCurrentTab::Execute
            item "Eval Current Tab (within Redcar itself)", ExecuteCurrentTab::EmbeddedExecute
          end
        end
      end
    end

    def self.keymaps
      [Keymap.build("main", [:osx, :linux, :windows]) { 
        link "Ctrl+R", ExecuteCurrentTab::Execute 
        link "Ctrl+Shift+R", ExecuteCurrentTab::EmbeddedExecute 
      }]
    end

    class Execute < Command

      def execute
        doc = win.focussed_notebook_tab_document
        path = doc.path if doc
        if path
          command = "ruby #{path} 2>&1"
          out = `#{command}`
          new_tab = Top::NewCommand.new.run          
          new_tab.document.text = "***** generated output from #{command} ***\n" + out
          new_tab.title= 'exec output'
        else
          puts 'unable to execute--maybe you need to save it first, so it has a filename?'
        end
      end

    end

    class EmbeddedExecute < Command

      def execute
        doc = win.focussed_notebook_tab_document
        out = doc.get_all_text if doc
        if out
          eval out, TOPLEVEL_BINDING, doc.path || doc.title || ''
        else
          puts 'unable to eval embedded'
        end
      end

    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
redcar-0.3.4.3 plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-0.3.4.2 plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-0.3.4.1 plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-0.3.4 plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-0.3.3 plugins/execute_current_tab/lib/execute_current_tab.rb