Sha256: 7791d35634226dc330236f87b10f12f72a86505d6e346160991fe13b377f0016

Contents?: true

Size: 1.72 KB

Versions: 36

Compression:

Stored size: 1.72 KB

Contents

module Redcar
  class ExecuteCurrentTab

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

    class Execute < EditTabCommand

      TITLE = "Output"

      def execute
        path = doc.path
        if path
          execute_file(path)
        else
          path = File.join(Redcar.tmp_dir, "execute_file.rb")
          File.open(path, "w") { |file| file.puts doc.to_s }
          execute_file(path)
          FileUtils.rm(path)
        end
      end
      
      def output_tab
        tabs = win.notebooks.map {|nb| nb.tabs }.flatten
        tabs.detect {|t| t.title == TITLE} || Top::OpenNewEditTabCommand.new.run
      end

      def execute_file(path)
        command = "ruby \"#{path}\""
        output = `#{command} 2>&1`
        tab = output_tab
        title = "[#{DateTime.now}]$ #{command}"
        tab.document.text = "#{tab.document.to_s}" +
          "#{"="*title.length}\n#{title}\n#{"="*title.length}\n\n#{output}"
        tab.title = TITLE
        tab.focus
      end
    end

    class EmbeddedExecute < EditTabCommand

      def execute
        out = doc.get_all_text
        if out
          begin
            eval(out, TOPLEVEL_BINDING, doc.path || doc.title || '')
          rescue Object => e
            Application::Dialog.message_box(
							"#{e.class}\n#{e.message}",
							:type => :error )
              
          end
        end
      end

    end

  end

end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
redcar-0.13 plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.13.5dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.13.4dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.13.3dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.13.2dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.13.1dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-0.12.1 plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.13.0dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-0.12 plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.27dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.26dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.25dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.24dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.23dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.22dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.21dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.20dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.19dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.18dev plugins/execute_current_tab/lib/execute_current_tab.rb
redcar-dev-0.12.17dev plugins/execute_current_tab/lib/execute_current_tab.rb