capistrano-syntax-checking 0.1.0 → 0.1.1

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/README.markdown CHANGED
@@ -1,4 +1,8 @@
1
- This is a simple extension to Capistrano that adds a few tasks to syntax-check source files.
1
+ This is a simple extension to Capistrano that adds a few pre-deploy
2
+ syntax-checks for source files.
3
+
4
+ Currently supported syntaxes are Ruby, ERB, JavaScript (using the Google
5
+ Closure compiler) and HAML.
2
6
 
3
7
  Installation
4
8
  ------------
@@ -40,6 +44,25 @@ Then build your own tasks by calling the syntax check API, perhaps like this:
40
44
  Capistrano::SyntaxChecking.check_javascript('src', :verbose => false)
41
45
  end
42
46
 
47
+ Configuration
48
+ -------------
49
+
50
+ You can override the paths that the checker will look in. For the Rails
51
+ recipe, the paths are the usual directoryes -- `app`, `lib` and `config` for
52
+ Ruby files, `app/views` for ERB, and so on. If your Rails layout is a little
53
+ different, then you may have to extend the path list.
54
+
55
+ To override the path list, set the `syntax_check_paths` variable in
56
+ Capistrano. For example:
57
+
58
+ set :syntax_check_paths, :ruby => %w(app lib bin config vendor)
59
+
60
+ The keys you may override are `:ruby`, `:erb`, `:javascript` and `:haml`.
61
+
62
+ You can also override the task output verbosity:
63
+
64
+ set :syntax_check_verbose, false
65
+
43
66
  Licensing
44
67
  ---------
45
68
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'capistrano'
4
- require "capistrano/ext/syntax_checking/erb"
5
- require "capistrano/ext/syntax_checking/javascript"
6
- require "capistrano/ext/syntax_checking/ruby"
4
+ require 'capistrano/ext/syntax_checking/erb'
5
+ require 'capistrano/ext/syntax_checking/javascript'
6
+ require 'capistrano/ext/syntax_checking/ruby'
7
+ require 'capistrano/ext/syntax_checking/haml'
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+
3
+ begin
4
+ require 'haml'
5
+ rescue LoadError
6
+ # Ignore
7
+ end
8
+
9
+ module Capistrano
10
+ module SyntaxChecks
11
+
12
+ class << self
13
+
14
+ # Check syntax in HAML files. The +paths+ argument takes a single string
15
+ # or array of paths to check. Options may be:
16
+ #
17
+ # * +verbose+ - if true, enable verbose output to standard output. If false,
18
+ # only errors will be output.
19
+ #
20
+ def check_haml(paths, options = {})
21
+ if defined?(::Haml)
22
+ verbose = options[:verbose]
23
+ begin
24
+ errors = false
25
+ file_names = [paths].flatten.compact.map { |path|
26
+ Dir.glob(File.join(path, "**", "*.haml"))
27
+ }.flatten
28
+ file_names.delete_if { |d| File.directory?(d) }
29
+ if file_names.any?
30
+ file_names.each_with_index do |file_name, index|
31
+ begin
32
+ ::Haml::Engine.new(File.read(file_name), :cache => false, :read_cache => false)
33
+ rescue => e
34
+ puts "\r#{file_name}:#{e.line}: #{e.message}"
35
+ errors = true
36
+ end
37
+ if verbose
38
+ $stdout.write("\r#{index + 1} files checked (ctrl-C to skip)")
39
+ $stdout.flush
40
+ end
41
+ end
42
+ if errors
43
+ print("\r")
44
+ abort("One or more syntax errors found. Fix and try again.")
45
+ else
46
+ puts ", no problems found."
47
+ end
48
+ else
49
+ if verbose
50
+ puts("No HAML files to check.")
51
+ end
52
+ end
53
+ rescue Interrupt
54
+ puts
55
+ puts("Canceled, skipping.")
56
+ end
57
+ else
58
+ $stderr << "HAML syntax checks disabled as HAML is not installed.\n"
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
@@ -14,39 +14,46 @@ module Capistrano
14
14
  def check_ruby(paths, options = {})
15
15
  verbose = options[:verbose]
16
16
  begin
17
- ignore_patterns = %w(
18
- )
19
17
  errors = false
20
- directories = %w(
21
- app
22
- bin
23
- lib
24
- config
25
- )
26
- files = directories.map { |d| Dir.glob(File.join(d, "**", "*.rb")) }.flatten
18
+ files = [paths].flatten.compact.map { |path|
19
+ Dir.glob(File.join(path, "**", "*.rb"))
20
+ }.flatten
27
21
  files.delete_if { |d| File.directory?(d) }
28
- files.delete_if { |d| ignore_patterns.find { |p| d.index(p) } }
29
- files.each_with_index do |file_name, index|
30
- $stdout.write("\r#{index} files checked (ctrl-C to skip)")
31
- $stdout.flush
32
- IO.popen("ruby -c '#{file_name}' 2>&1", "r") do |input|
33
- input.each_line do |line|
34
- unless line =~ /Syntax OK|\d: warning:/
35
- print("\r")
36
- puts(line)
37
- errors = true
22
+ if files.any?
23
+ files.each_with_index do |file_name, index|
24
+ IO.popen("ruby -c '#{file_name}' 2>&1", "r") do |input|
25
+ input.each_line do |line|
26
+ unless line =~ /Syntax OK|\d: warning:/
27
+ print("\r")
28
+ puts(line)
29
+ errors = true
30
+ end
38
31
  end
39
32
  end
33
+ if verbose
34
+ $stdout.write("\r#{index + 1} files checked (ctrl-C to skip)")
35
+ $stdout.flush
36
+ end
37
+ end
38
+ if errors
39
+ if verbose
40
+ print("\r")
41
+ end
42
+ abort("One or more syntax errors found. Fix and try again.")
43
+ else
44
+ if verbose
45
+ puts ", no problems found."
46
+ end
40
47
  end
41
- end
42
- if errors
43
- print("\r")
44
- abort("One or more syntax errors found. Fix and try again.")
45
48
  else
46
- puts ", no problems found."
49
+ if verbose
50
+ puts("No files to check.")
51
+ end
47
52
  end
48
53
  rescue Interrupt
49
- puts
54
+ if verbose
55
+ puts
56
+ end
50
57
  puts("Canceled, skipping.")
51
58
  end
52
59
  end
@@ -4,6 +4,7 @@ require 'capistrano'
4
4
  require 'capistrano/ext/syntax_checking/erb'
5
5
  require 'capistrano/ext/syntax_checking/javascript'
6
6
  require 'capistrano/ext/syntax_checking/ruby'
7
+ require 'capistrano/ext/syntax_checking/haml'
7
8
 
8
9
  unless Capistrano::Configuration.respond_to?(:instance)
9
10
  abort "Capistrano syntax checks extensions requires Capistrano 2"
@@ -17,21 +18,46 @@ Capistrano::Configuration.instance.load do
17
18
  ruby
18
19
  erb
19
20
  javascript
21
+ haml
20
22
  end
21
23
 
22
24
  desc "Test syntax of all JavaScript files"
23
25
  task :javascript do
24
- Capistrano::SyntaxChecks.check_javascript('public/javascripts', :verbose => true)
26
+ paths = fetch(:syntax_check_paths, {})[:javascript]
27
+ paths ||= %w(
28
+ public/javascripts
29
+ )
30
+ Capistrano::SyntaxChecks.check_javascript(paths, :verbose => fetch(:syntax_check_verbose, true))
25
31
  end
26
32
 
27
33
  desc "Test syntax of all Ruby files"
28
34
  task :ruby do
29
- Capistrano::SyntaxChecks.check_ruby(%w(app lib), :verbose => true)
35
+ paths = fetch(:syntax_check_paths, {})[:ruby]
36
+ paths ||= %w(
37
+ app
38
+ lib
39
+ config
40
+ scripts
41
+ )
42
+ Capistrano::SyntaxChecks.check_ruby(paths, :verbose => fetch(:syntax_check_verbose, true))
30
43
  end
31
44
 
32
45
  desc "Test syntax of all ERB files"
33
46
  task :erb do
34
- Capistrano::SyntaxChecks.check_erb('app', :verbose => true)
47
+ paths = fetch(:syntax_check_paths, {})[:erb]
48
+ paths ||= %w(
49
+ app
50
+ )
51
+ Capistrano::SyntaxChecks.check_erb(paths, :verbose => fetch(:syntax_check_verbose, true))
52
+ end
53
+
54
+ desc "Test syntax of all HAML files"
55
+ task :haml do
56
+ paths = fetch(:syntax_check_paths, {})[:haml]
57
+ paths ||= %w(
58
+ app
59
+ )
60
+ Capistrano::SyntaxChecks.check_haml(paths, :verbose => fetch(:syntax_check_verbose, true))
35
61
  end
36
62
 
37
63
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-syntax-checking
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Staubo
@@ -43,7 +43,6 @@ extra_rdoc_files:
43
43
  - LICENSE
44
44
  - LICENSE.closure
45
45
  - README.markdown
46
- - README.rdoc
47
46
  files:
48
47
  - LICENSE
49
48
  - LICENSE.closure
@@ -51,11 +50,11 @@ files:
51
50
  - VERSION
52
51
  - lib/capistrano/ext/syntax_checking.rb
53
52
  - lib/capistrano/ext/syntax_checking/erb.rb
53
+ - lib/capistrano/ext/syntax_checking/haml.rb
54
54
  - lib/capistrano/ext/syntax_checking/javascript.rb
55
55
  - lib/capistrano/ext/syntax_checking/ruby.rb
56
56
  - lib/capistrano/recipes/syntax_checking.rb
57
57
  - lib/closure/compiler.jar
58
- - README.rdoc
59
58
  has_rdoc: true
60
59
  homepage: http://github.com/alexstaubo/capistrano-syntax-checking
61
60
  licenses: []
data/README.rdoc DELETED
@@ -1 +0,0 @@
1
- This is a simple extension to Capistrano that adds a few tasks to syntax-check source files.