coffee_without_nodejs 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 407dd2497ac983b5ed976b70c0b8c0913e6bcbe0
4
- data.tar.gz: 68a2b3e2ee186259bef433ab597dc2661664d4f4
3
+ metadata.gz: 61de08829c462bf882db9eff690eb2c6beb92b82
4
+ data.tar.gz: 6575e27221ed2c3a518d01979fc817a34db62e7c
5
5
  SHA512:
6
- metadata.gz: 4ddca2d3dbb495c368ab7b736f8c9d0c6cac6be305e1c73d15334887611205e6199c0577c2a5c2014bc74fbe87d3613c75c37cdae76d2b56eed9b5c5cca0d781
7
- data.tar.gz: 9e4afe04aa6ef6c2aebafaf15b500750c2bbbee13592242b698e5eaa75dfd3c249294f1cfd999b98d28a850e05943c4ea7ca99154feab16e8e8e7a9e0121e851
6
+ metadata.gz: 00275f2bf31c659e3f94ae43c575004d06d7d153484f29cfaf661cc64af3f81a440117363fa20fb560a042fbfdc5848d811f854aa893bab045d5a8c5b6d70656
7
+ data.tar.gz: 0a5b166a5028434dd1ee0b1165d0f893c671f6bb2788753592ac944c26282822d25cfd5ae08a081d0c5a5c887e2277b4cd6c79398deae658a8e6639f4cc3c74d
data/bin/coff CHANGED
@@ -2,25 +2,24 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  require 'coffee_without_nodejs'
5
+ require 'coderay'
5
6
 
6
7
  if ARGV.first == '-e'
7
8
  ARGV.shift
8
- content = CoffeeWithoutNodejs.compile(ARGV.first)
9
- system "echo \"#{content}\" |coderay -js" unless content.empty?
9
+ content = CoffeeWithoutNodejs.compile(ARGV.first).to_s
10
+ print CodeRay.scan(content, :js).terminal unless content.empty?
10
11
  else
11
12
  if ARGV.empty?
12
13
  `notify-send 'Starting coffee compiler.' -t 1000` if system 'which notify-send &>/dev/null'
13
14
  CoffeeWithoutNodejs.watch!
15
+ elsif test 'd', ARGV.first
16
+ Dir.chdir(ARGV.first) { CoffeeWithoutNodejs.watch! }
14
17
  else
15
18
  ARGV.each do |file|
16
19
  fail "`#{file}' is not valid filename." unless File.exist? file
17
20
 
18
- if test ?d, file
19
- Dir.chdir(file) { CoffeeWithoutNodejs.watch! }
20
- else
21
- js_file = CoffeeWithoutNodejs.compile(file).to_s
22
- system "coderay -js \"#{js_file}\"" unless js_file.empty?
23
- end
21
+ content = CoffeeWithoutNodejs.compile(file).to_s
22
+ print CodeRay.scan(content, :js).terminal unless content.empty?
24
23
  end
25
24
  end
26
25
  end
@@ -5,9 +5,9 @@ require 'coffee_without_nodejs/compiler'
5
5
  require 'coffee_without_nodejs/watcher'
6
6
 
7
7
  module CoffeeWithoutNodejs
8
- def self.compile(coffee, bare=true)
8
+ def self.compile(coffee, bare=true, create_target_jsfile=false)
9
9
  if File.file?(coffee)
10
- CoffeeCompiler.compile_file(coffee, bare)
10
+ CoffeeCompiler.compile_file(coffee, bare, create_target_jsfile)
11
11
  else
12
12
  CoffeeCompiler.compile(coffee, bare)
13
13
  end
@@ -14,7 +14,7 @@ module CoffeeWithoutNodejs
14
14
  end
15
15
 
16
16
  def wrapper
17
- wrapper = <<-WRAPPER
17
+ <<-WRAPPER
18
18
  (function(script, options) {
19
19
  try {
20
20
  return CoffeeScript.compile(script, options);
@@ -35,33 +35,41 @@ WRAPPER
35
35
 
36
36
  def compile(script, bare=true)
37
37
  compiler.call(wrapper, script, bare: bare)
38
+ rescue ExecJS::RuntimeError
39
+ puts $!.message
38
40
  end
39
41
 
40
- def compile_file(file, bare=true)
42
+ def compile_file(file, bare=true, create_target_jsfile=false)
41
43
  root_dir = Pathname(Dir.pwd)
42
44
  file_path = Pathname(File.expand_path(file))
43
45
  source_code = file_path.read
44
46
 
45
- js_path, map_path = create_js_path_from(file_path)
47
+ target_js_content = compiler.call(wrapper, source_code, bare: bare)
46
48
 
47
- source_files = file_path.relative_path_from(js_path.dirname).to_s
48
- generated_file = js_path.relative_path_from(js_path.dirname).to_s
49
- relative_map_path = map_path.relative_path_from(js_path.dirname).to_s
49
+ if create_target_jsfile
50
+ js_path, map_path = create_js_path_from(file_path)
51
+ source_files = file_path.relative_path_from(js_path.dirname).to_s
52
+ generated_file = js_path.relative_path_from(js_path.dirname).to_s
53
+ relative_map_path = map_path.relative_path_from(js_path.dirname).to_s
50
54
 
51
- File.open(js_path, 'wb') do |f|
52
- f.print "#{ENV['JS_SHEBANG']}\n\n" if ENV['JS_SHEBANG']
53
- f.print compiler.call(wrapper, source_code, bare: bare), "\n//# sourceMappingURL=#{relative_map_path}"
54
- end
55
- File.open(map_path, 'wb') do |f|
56
- f.print compiler.call(wrapper, source_code,
57
- sourceMap: true,
58
- sourceFiles: [source_files],
59
- generatedFile: generated_file)["v3SourceMap"]
60
- end
55
+ File.open(js_path, 'wb') do |f|
56
+ f.print "#{ENV['JS_SHEBANG']}\n\n" if ENV['JS_SHEBANG']
57
+ f.print target_js_content, "\n//# sourceMappingURL=#{relative_map_path}"
58
+ end
61
59
 
62
- puts "==> #{js_path.relative_path_from(root_dir)}"
60
+ File.open(map_path, 'wb') do |f|
61
+ f.print compiler.call(wrapper, source_code,
62
+ sourceMap: true,
63
+ sourceFiles: [source_files],
64
+ generatedFile: generated_file)['v3SourceMap']
65
+ end
63
66
 
64
- js_path
67
+ puts "==> #{js_path.relative_path_from(root_dir)}"
68
+ js_path
69
+ else
70
+ puts "==> #{file_path}"
71
+ target_js_content
72
+ end
65
73
  rescue ExecJS::RuntimeError
66
74
  error_msg = "[#{file_path.relative_path_from(root_dir)}]: #{$!.message}"
67
75
  `notify-send "#{error_msg}" -t 5000` if system 'which notify-send &>/dev/null'
@@ -87,7 +95,12 @@ WRAPPER
87
95
  # if not in coffee directory, rename it.
88
96
  js_path = path.sub(/\.js\.coffee$|\.coffee$/, '.js')
89
97
  map_path = js_path.sub_ext('.js.map').sub(/\/([^\/]+)$/, '/.\1')
90
- return [js_path, map_path]
98
+
99
+ if path == js_path
100
+ warn 'filename extension is .coffee or .js.coffee?'
101
+ exit
102
+ end
103
+ [js_path, map_path]
91
104
  end
92
105
  end
93
106
  end
@@ -2,7 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  module CoffeeWithoutNodejs
5
- VERSION = [0, 4, 0]
5
+ VERSION = [0, 5, 0]
6
6
 
7
7
  class << VERSION
8
8
  def to_s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coffee_without_nodejs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Billy.Zheng(zw963)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-24 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs