Class: TextmateFcsh
- Inherits:
-
Object
- Object
- TextmateFcsh
- Defined in:
- lib/textmate_fcsh.rb
Constant Summary collapse
- CONFIG_FILE =
'.textmate_fcsh'
- TEXTMATE_BUNDLE_LOCATION =
"git://github.com/japetheape/textmate_fcsh_bundle.git"
Class Method Summary collapse
-
.create_config! ⇒ Object
Create the config file.
-
.create_textmate_bundle! ⇒ Object
Clones the textmate bundle.
Instance Method Summary collapse
- #check_preconditions ⇒ Object
- #get_compile_command ⇒ Object
-
#initialize(options = {}) ⇒ TextmateFcsh
constructor
A new instance of TextmateFcsh.
-
#open_browser ⇒ Object
Open the report in the browser.
- #open_browser_first_time ⇒ Object
-
#read_config! ⇒ Object
Read configurion file, stored in .textmate_fcsh.
-
#run ⇒ Object
Compile the mxmlc, extract errors, create a report.
-
#run_bogus_mxmlc ⇒ Object
Run a bogus mxmlc command, not used anymore.
-
#run_mxmlc ⇒ Object
Runs the mxmlc in the fcsh compiler.
- #write_report! ⇒ Object
-
#write_to_tempfile(txt) ⇒ Object
Write report to file.
Constructor Details
#initialize(options = {}) ⇒ TextmateFcsh
Returns a new instance of TextmateFcsh.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/textmate_fcsh.rb', line 18 def initialize( = {}) @options = @server = WebsocketServer.new open_browser_first_time check_preconditions read_config! write_to_tempfile("Waiting for run...") if [:standalone] puts "Running standalone" run else @fcsh = Fcsh.new d = DirWatcher.new('src libs') do run end end end |
Class Method Details
.create_config! ⇒ Object
Create the config file
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/textmate_fcsh.rb', line 147 def self.create_config! if File.exist?(CONFIG_FILE) raise "Before recreating, first remove %s" % CONFIG_FILE end example_config = {:mxmlc_options => {:default_background_color => '#FFFFFF', :default_frame_rate => 24, :default_size => "970 550", :output => "bin/project-debug.swf", :source_path => "src,assets,lib/mvc,lib/editor_core", :verbose_stacktraces => true, :warnings => true}} example_config[:main_file] = 'src/editor.mxml' File.open('.textmate_fcsh', 'w+') do |f| f.write(YAML::dump(example_config)) end end |
.create_textmate_bundle! ⇒ Object
Clones the textmate bundle
160 161 162 163 164 165 166 |
# File 'lib/textmate_fcsh.rb', line 160 def self.create_textmate_bundle! puts "Installing textmate bundle." `mkdir -p ~/Library/Application\\ Support/TextMate/Bundles` `cd ~/Library/Application\\ Support/TextMate/Bundles/ && git clone #{TEXTMATE_BUNDLE_LOCATION} "textmate_fcsh.tmbundle"` `osascript -e 'tell app "TextMate" to reload bundles'` puts "Textmate bundle installed." end |
Instance Method Details
#check_preconditions ⇒ Object
135 136 137 |
# File 'lib/textmate_fcsh.rb', line 135 def check_preconditions raise "Configuration file does not exist, first run textmate_fcsh --setup" if !File.exist?(CONFIG_FILE) end |
#get_compile_command ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/textmate_fcsh.rb', line 91 def get_compile_command mxmlc_command = "" #" -default-background-color=#FFFFFF -default-frame-rate=24 -default-size 970 550 -output=bin/editor-debug.swf -source-path+=src -source-path+=assets -source-path+=lib/mvc -source-path+=lib/editor_core -verbose-stacktraces=true -warnings=true src/editor.mxml" @config[:mxmlc_options].each do |k,v| #next if v splitted = v.to_s.split(",") splitted.each do |vsplitted| splitter = splitted.length > 1 ? '+=' : '=' if k == :default_size splitter = ' ' end if k == :library_path splitter = '+=' end mxmlc_command << " -%s%s%s" % [k.to_s.gsub(/\_/, '-'),splitter,vsplitted] end end mxmlc_command << " %s" % @config[:main_file] mxmlc_command end |
#open_browser ⇒ Object
Open the report in the browser
58 59 60 |
# File 'lib/textmate_fcsh.rb', line 58 def open_browser `open #{@report_file.path}` end |
#open_browser_first_time ⇒ Object
50 51 52 53 54 55 |
# File 'lib/textmate_fcsh.rb', line 50 def open_browser_first_time if !@options[:standalone] f = File.join(File.dirname(__FILE__), '..','templates', 'standard.html') `open #{f}` end end |
#read_config! ⇒ Object
Read configurion file, stored in .textmate_fcsh
141 142 143 |
# File 'lib/textmate_fcsh.rb', line 141 def read_config! @config = YAML.load_file(CONFIG_FILE) end |
#run ⇒ Object
Compile the mxmlc, extract errors, create a report.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/textmate_fcsh.rb', line 63 def run if @options[:standalone] puts get_compile_command output_watcher = OutputWatcher.new("mxmlc " + get_compile_command) output_watcher.stdout.each_line do |line| puts " -->\t" + line end output = output_watcher.stderr errors = MxmlcOutputReader.new(output) @report = HtmlMxmlcErrorFormatter.new(errors) write_report! open_browser else output = run_mxmlc errors = @fcsh.errors puts "Complete: %d errors, %d warnings" % [errors.errors.size, errors.warnings.size] error_array = errors..map {|x| {"filename" => x.filename, "line" => x.line, "level" => x.level, "message" => x., "content" => x.content, "column" => x.column } } @server.send JSON.generate(error_array) end end |
#run_bogus_mxmlc ⇒ Object
Run a bogus mxmlc command, not used anymore.
122 123 124 125 126 127 |
# File 'lib/textmate_fcsh.rb', line 122 def run_bogus_mxmlc out = '' mxmlc_output_file = File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'mxmlc_output.txt') File.open(mxmlc_output_file).each_line {|l| out << l} out end |
#run_mxmlc ⇒ Object
Runs the mxmlc in the fcsh compiler
113 114 115 116 117 118 119 |
# File 'lib/textmate_fcsh.rb', line 113 def run_mxmlc if @target_id.nil? @target_id = @fcsh.mxmlc(get_compile_command) else @fcsh.compile(@target_id) end end |
#write_report! ⇒ Object
130 131 132 |
# File 'lib/textmate_fcsh.rb', line 130 def write_report! write_to_tempfile(@report.out) end |
#write_to_tempfile(txt) ⇒ Object
Write report to file
44 45 46 47 48 |
# File 'lib/textmate_fcsh.rb', line 44 def write_to_tempfile(txt) @report_file = File.new('/tmp/mxmlc_error_report.html', 'w+') @report_file.write(txt) @report_file.close end |