Module: Red::Executable
- Defined in:
- lib/red/executable.rb
Overview
:nodoc:
Instance Method Summary collapse
- #build_red_plugin_for_rails ⇒ Object
- #compile_red_to_js(filename) ⇒ Object
- #direct_translate(string) ⇒ Object
- #hush_warnings ⇒ Object
-
#print_js(js_output, filename) ⇒ Object
:nodoc:.
Instance Method Details
#build_red_plugin_for_rails ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/red/executable.rb', line 3 def build_red_plugin_for_rails unless File.exists?('vendor/plugins') puts "Directory vendor/plugins does not exist." exit end begin Dir.mkdir('vendor/plugins/red') unless File.exists?('vendor/plugins/red') rescue SystemCallError puts "Unable to create directory in vendor/plugins" exit end File.open('vendor/plugins/red/init.rb', 'w') { |f| f.write("require 'rubygems'\nrequire 'red'\n\n# Red is not yet supported for Rails projects.\n")} #Red.for_rails(binding)\n") } puts "Red plugin added to project." exit end |
#compile_red_to_js(filename) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/red/executable.rb', line 52 def compile_red_to_js(filename) unless File.exists?(file = "%s.red" % [filename]) || File.exists?(file = "%sred/%s.red" % [(dir = "public/javascripts/"), filename]) puts "File #{filename}.red does not exist." exit end source = File.read(file) js_output = hush_warnings { source.string_to_node }.compile_node File.open("%s%s.js" % [dir, filename], 'w') {|f| f.write(js_output)} unless filename == 'test' print_js(js_output, filename) end |
#direct_translate(string) ⇒ Object
22 23 24 25 26 |
# File 'lib/red/executable.rb', line 22 def direct_translate(string) js_output = hush_warnings { string.string_to_node }.compile_node print_js(js_output, 'test') exit end |
#hush_warnings ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/red/executable.rb', line 28 def hush_warnings $stderr = File.open('spew', 'w') output = yield $stderr = $> File.delete('spew') return output end |
#print_js(js_output, filename) ⇒ Object
:nodoc:
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/red/executable.rb', line 38 def print_js(js_output, filename) # :nodoc: puts <<-OUTPUT.%([("- #{filename}.js" unless filename == 'test'), js_output, @@red_errors ||= '']) %s ================================= %s ================================= %s OUTPUT end |