jsc 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,8 +1,10 @@
1
1
  == 0.2.2 / 2010-02-27
2
+
2
3
  added support for different types of formatters with a new parser module
3
4
  added --flymake option to return a flymake compatible output
4
5
 
5
6
  == 0.2.1 / 2010-02-25
7
+
6
8
  FIX: user ActiveSupport JSON decoding (JSON.parse fail randomly)
7
9
  moved from bones to jeweler
8
10
  term/ansicolor module configured as Mixin for strings
data/README.rdoc CHANGED
@@ -10,18 +10,19 @@ Ruby API to Google Closure Compiler Web service.
10
10
 
11
11
  With <b>jsc</b> you can compile your JavaScript code throught {Google Closure Compiler REST service}[http://code.google.com/closure/compiler/].
12
12
 
13
- The package comes with a jsc commands which accepts several options, run:
13
+ The package comes with a jsc command which accepts several options, run:
14
14
 
15
15
  jsc --help
16
16
 
17
17
  for help.
18
18
 
19
19
  More in details:
20
- * Ruby API actually is a single function call (ex: JSCompiler.compile(file_name, "statistics", "SIMPLE_OPTIMIZATIONS") )
20
+ * Ruby API actually is a single function call, JSCompiler.compile()
21
21
  * Handling of JSON responses, parse and print them (same output of the Google web interface!)
22
22
  * Handling of Server Errors responses
23
- * Compile a piece of code, a file or a whole directory
23
+ * Compile a file or a piece of code
24
24
  * <b>Emacs snippet</b> to compile code your code for errors and warnings
25
+ * flymake compatible
25
26
 
26
27
  Check {Google API Reference}[http://code.google.com/intl/it-IT/closure/compiler/docs/api-ref.html] for more info about accepted parameters.
27
28
 
@@ -47,13 +48,24 @@ Compile a piece of code, check for errors:
47
48
 
48
49
  jsc -e -c "function("
49
50
 
50
- Compile a file and get compiled code if no errors or warnings are found:
51
+ Compile a file for both errors and warnings:
51
52
 
52
53
  jsc js/compiled_code.js -a
53
54
 
54
- == Emacs Snippet
55
+ == Install
56
+
57
+ If you have gemcutter in your gem sources, run:
58
+
59
+ [sudo] gem install jsc
60
+
61
+ == Emacs+flymake+jsc
62
+
63
+ For GNU Emacs users, jsc provides a {flymake}[http://www.emacswiki.org/emacs/FlyMake] compatible output. So you can use jsc+flymake to have a syntax check tool running in the background while editing your javascript files.
64
+ Look at the {wiki page}[http://wiki.github.com/sub/jsc/flymake] for more info.
65
+
66
+ == Emacs snippet
55
67
 
56
- Wants to compile your code right from Emacs?
68
+ Do you want to compile your code right from Emacs?
57
69
 
58
70
  Copy
59
71
 
@@ -65,12 +77,6 @@ Now, select the code to compile and run:
65
77
  * <em>CcJe</em> to check for errors
66
78
  * <em>CcJw</em> to check for warnings.
67
79
 
68
- == Install
69
-
70
- If you have gemcutter in your gem sources, run:
71
-
72
- [sudo] gem install jsc
73
-
74
80
  == Copyright
75
81
 
76
82
  Copyright (c) 2010 Davide Saurino. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/bin/jsc CHANGED
@@ -30,7 +30,10 @@ jsc [options] ... ARG
30
30
  get statistics for compiled code
31
31
 
32
32
  --all, -a:
33
- execute every check for this code
33
+ execute error and warnings check for this code
34
+
35
+ --cleancode:
36
+ returns compiled code if no errors or warnings are found
34
37
 
35
38
  --level value, -l value:
36
39
  compile with level value
@@ -51,12 +54,12 @@ jsc [options] ... ARG
51
54
 
52
55
  ARG: A path to a javascript file or the code that will be compiled.
53
56
 
54
- If one of the following options is not specified
57
+ You can use only ONE of the following options
55
58
 
56
- -e, -w, -s, -a
59
+ -e, -w, -s, -a, --cleancode
57
60
 
58
- the code will be first compiled for errors and only if no errors are found
59
- it will return the compiled code
61
+ If none is specified then the code will be first compiled for errors
62
+ and only if no errors are found it will return the compiled code.
60
63
  EOU
61
64
 
62
65
  opts = GetoptLong.new(
@@ -67,6 +70,7 @@ opts = GetoptLong.new(
67
70
  [ '--warns', '-w', GetoptLong::NO_ARGUMENT ],
68
71
  [ '--stats', '-s', GetoptLong::NO_ARGUMENT ],
69
72
  [ '--all', '-a', GetoptLong::NO_ARGUMENT ],
73
+ [ '--cleancode', GetoptLong::NO_ARGUMENT ],
70
74
  [ '--level','-l', GetoptLong::REQUIRED_ARGUMENT ],
71
75
  [ '--debug', GetoptLong::NO_ARGUMENT ],
72
76
  [ '--flymake','-f', GetoptLong::NO_ARGUMENT ]
@@ -102,6 +106,8 @@ opts.each do |opt, arg|
102
106
  output_info = "statistics"
103
107
  when '--all'
104
108
  output_info = "all"
109
+ when '--cleancode'
110
+ output_info = "clean"
105
111
  when '--flymake'
106
112
  type = "flymake"
107
113
  end
@@ -116,8 +122,14 @@ end
116
122
  arg = code.blank? ? ARGV.shift : code
117
123
 
118
124
  if output_info.eql?("all")
119
- puts JSCompiler.full_compile(arg, file, level, type)
125
+ full_compile_log = JSCompiler.full_compile(arg, file, level, type)
126
+ puts full_compile_log unless full_compile_log.blank?
127
+ elsif output_info.eql?("clean")
128
+ clean_compile_log = JSCompiler.cleancode(arg, file, level, type)
129
+ puts clean_compile_log unless clean_compile_log.blank?
120
130
  elsif output_info.blank?
131
+ # I'm here if none of -e,-w,-a,-s is specified so
132
+ # I compile only for errors and, if not, for compiled_code
121
133
  errors_output = JSCompiler.compile(arg, file, "errors", level, type)
122
134
  unless errors_output.eql?("No errors")
123
135
  puts errors_output
@@ -125,5 +137,6 @@ elsif output_info.blank?
125
137
  puts JSCompiler.compile(arg, file, "", level, type)
126
138
  end
127
139
  else
140
+ # Some option is specified, I pass that to compile()
128
141
  puts JSCompiler.compile(arg, file, output_info, level, type)
129
142
  end
@@ -44,7 +44,7 @@ Feature: Run jsc command
44
44
 
45
45
  Scenario: Get version
46
46
  When I run "jsc --version"
47
- Then I should see "0.2.2"
47
+ Then I should see "0.2.3"
48
48
  And the exit status should be 0
49
49
 
50
50
  # Scenario: Get compiled code
data/lib/jsc.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module JSCompiler
2
2
 
3
3
  # :stopdoc:
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  # LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  # PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # :startdoc:
@@ -108,29 +108,52 @@ module JSCompiler
108
108
  # * <b>file</b>: 0 => arg is code
109
109
  # 1 => arg is a file path
110
110
  # * <b>level</b>: compilation_level parameter
111
- def full_compile(arg, file, level, type)
112
- ['errors', 'warnings','compiled_code'].each do |x|
111
+ def cleancode(arg, file, level, type)
112
+ ['errors', 'warnings', 'compiled_code'].each do |x|
113
113
  str = JSCompiler.compile(arg, file, x, level, type)
114
114
  return str unless str.eql?("No " + x)
115
115
  end
116
116
  end
117
-
117
+
118
+ # Compiles a file or a piece of code for
119
+ # errors or warnings. Returns nothing if no
120
+ # errors or warnings are found
121
+ #
122
+ # Accepted parameters:
123
+ # * <b>arg</b>: the code or the file path to compile
124
+ # * <b>file</b>: 0 => arg is code
125
+ # 1 => arg is a file path
126
+ # * <b>level</b>: compilation_level parameter
127
+ def full_compile(arg, file, level, type)
128
+ errors_log = compile(arg, file, "errors", level, type)
129
+ str = ""
130
+ if errors_log.eql?("No errors")
131
+ warnings_log = compile(arg, file, "warnings", level, type)
132
+ str = warnings_log unless warnings_log.eql?("No warnings")
133
+ else
134
+ str = errors_log
135
+ end
136
+
137
+ str
138
+
139
+ end
140
+
118
141
  # Calls compile method for every file in <em>dir</em> directory
119
142
  #
120
143
  # Accepted parameters:
121
144
  # * <b>dir</b>: the directory
122
145
  # * <b>op</b>: output_info parameter
123
146
  # * <b>level</b>: compilation_level parameter
124
- def compile_dir(dir, op, level)
125
- out = ""
126
- Dir.entries(dir).each do |file|
127
- if File.extname(file) == ".js"
128
- out << "Statistics for file #{file}...\n"
129
- out << compile(file, true, op, level) + "\n***************\n"
130
- end
131
- end
132
- return out
133
- end
147
+ # def compile_dir(dir, op, level)
148
+ # out = ""
149
+ # Dir.entries(dir).each do |file|
150
+ # if File.extname(file) == ".js"
151
+ # out << "Statistics for file #{file}...\n"
152
+ # out << compile(file, true, op, level) + "\n***************\n"
153
+ # end
154
+ # end
155
+ # return out
156
+ # end
134
157
 
135
158
  # Parses and returns JSON server <em>response</em>
136
159
  #
data/spec/jsc_spec.rb CHANGED
@@ -128,7 +128,40 @@ describe JSCompiler do
128
128
  end
129
129
 
130
130
  it 'should receive the compiled code' do
131
- @resp.should_not be_nil
131
+ @resp.should match("")
132
+ end
133
+ end
134
+
135
+ describe 'and get errors' do
136
+ before do
137
+ @resp = JSCompiler.full_compile(ERROR_CODE, false, "SIMPLE_OPTIMIZATIONS", "")
138
+ end
139
+
140
+ it 'should return the result string' do
141
+ @resp.should match(/Error n./)
142
+ end
143
+ end
144
+
145
+ describe 'and get warnings' do
146
+ before do
147
+ @resp = JSCompiler.full_compile(WARNING_CODE, false, "SIMPLE_OPTIMIZATIONS", "")
148
+ end
149
+
150
+ it 'should return the result string' do
151
+ @resp.should match(/Warning n./)
152
+ end
153
+ end
154
+
155
+ end
156
+
157
+ describe 'CLEAN code compile' do
158
+ describe 'without errors or warnings' do
159
+ before do
160
+ @resp = JSCompiler.full_compile(COMPILE_CODE, false, "SIMPLE_OPTIMIZATIONS", "")
161
+ end
162
+
163
+ it 'should receive the compiled code' do
164
+ @resp.should be_nil
132
165
  end
133
166
  end
134
167
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Davide Saurino
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-02-27 00:00:00 +01:00
17
+ date: 2010-03-03 00:00:00 +01:00
18
18
  default_executable: jsc
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency