erbgood 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ Ruby gem and command line tool to verify that a binding can satisfy ERB templates.
2
+
3
+ ```bash
4
+ mmb@mmb ~/src/erbgood git:master ?1 $ erbgood spec/support/binding/binding1.rb spec/support/erb/*
5
+ Binding: /Users/mmb/src/erbgood/spec/support/binding/binding1.rb
6
+
7
+ spec/support/erb/a.erb: ok
8
+ spec/support/erb/b.erb: ok
9
+ spec/support/erb/bad.erb:
10
+ undefined local variable or method `foo' for #<Module:0x007fb3008301e8>
11
+ ```
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'erbgood'
4
+
5
+ binding_path, *erb_paths = ARGV
6
+
7
+ binding_path = File.expand_path(binding_path)
8
+
9
+ bindin = Module.new.module_eval("#{File.read(binding_path)}\nbinding")
10
+
11
+ return_code = 0
12
+
13
+ puts "Binding: #{binding_path}\n\n"
14
+
15
+ erb_paths.each do |erb|
16
+ print "#{erb}: "
17
+
18
+ error = Erbgood::ErbBindingCheck.new(bindin, File.read(erb)).error
19
+
20
+ if error
21
+ puts "\n #{error}"
22
+ return_code = 1
23
+ else
24
+ puts 'ok'
25
+ end
26
+ end
27
+
28
+ exit return_code
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
4
+
5
+ require 'erbgood/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'erbgood'
9
+ s.version = Erbgood::VERSION
10
+ s.summary = 'Verify that a binding can satisfy ERB templates'
11
+ s.description = s.summary
12
+ s.homepage = 'https://github.com/mmb/erbgood'
13
+ s.authors = ['Matthew M. Boedicker']
14
+ s.email = %w{matthewm@boedicker.org}
15
+
16
+ s.add_development_dependency 'rspec'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.executables = %w{erbgood}
20
+ end
@@ -0,0 +1 @@
1
+ require 'erbgood/erb_binding_check'
@@ -0,0 +1,21 @@
1
+ require 'erb'
2
+
3
+ module Erbgood
4
+
5
+ class ErbBindingCheck
6
+
7
+ def initialize(bindin, erb)
8
+ @bindin = bindin
9
+ @erb = erb
10
+ end
11
+
12
+ def error
13
+ ERB.new(@erb).result(@bindin)
14
+ nil
15
+ rescue => detail
16
+ detail
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,3 @@
1
+ module Erbgood
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Erbgood::ErbBindingCheck do
4
+
5
+ subject { Erbgood::ErbBindingCheck.new(bindin, erb).error }
6
+
7
+ context 'when the binding satisfies the ERB' do
8
+ let(:bindin) {
9
+ x = 1
10
+ binding
11
+ }
12
+
13
+ let(:erb) { <<-eos
14
+ <%= x %>
15
+ eos
16
+ }
17
+
18
+ it { should be_nil }
19
+
20
+ end
21
+
22
+ context 'when the binding does not satisfy the ERB' do
23
+ let(:bindin) {
24
+ x = 1
25
+ binding
26
+ }
27
+
28
+ let(:erb) { <<-eos
29
+ <%= y %>
30
+ eos
31
+ }
32
+
33
+ its(:message) { should include "undefined local variable or method `y'" }
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1 @@
1
+ require 'erbgood'
@@ -0,0 +1,3 @@
1
+ a = 1
2
+ b = 'x'
3
+ c = [2, 3, 4]
@@ -0,0 +1 @@
1
+ <%= a %>
@@ -0,0 +1,3 @@
1
+ <% c.each do |i| %>
2
+ <%= i %>
3
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= foo %>
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erbgood
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthew M. Boedicker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Verify that a binding can satisfy ERB templates
31
+ email:
32
+ - matthewm@boedicker.org
33
+ executables:
34
+ - erbgood
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - README.md
39
+ - bin/erbgood
40
+ - erbgood.gemspec
41
+ - lib/erbgood.rb
42
+ - lib/erbgood/erb_binding_check.rb
43
+ - lib/erbgood/version.rb
44
+ - spec/erb_binding_check_spec.rb
45
+ - spec/spec_helper.rb
46
+ - spec/support/binding/binding1.rb
47
+ - spec/support/erb/a.erb
48
+ - spec/support/erb/b.erb
49
+ - spec/support/erb/bad.erb
50
+ homepage: https://github.com/mmb/erbgood
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.23
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Verify that a binding can satisfy ERB templates
74
+ test_files: []