sherb 1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v1.0. First version
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2011, Andrew Snow
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright
10
+ * notice, this list of conditions and the following disclaimer in the
11
+ * documentation and/or other materials provided with the distribution.
12
+ * Neither the name of the author nor the names of its
13
+ * contributors may be used to endorse or promote products derived from
14
+ * this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
data/Manifest ADDED
@@ -0,0 +1,7 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ Rakefile
5
+ bin/sherb
6
+ lib/sherb.rb
7
+ test/test_all.rb
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'echoe'
2
+
3
+ Echoe.new("sherb") do |p|
4
+ p.author = "Andrew Snow"
5
+ p.email = 'andrew@modulus.org'
6
+ p.summary = "Unix Shell (SH) with Embedded Ruby (ERB)"
7
+ p.url = "http://github.com/andys/sherb"
8
+ end
data/bin/sherb ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/sherb'
4
+ require 'pathname'
5
+
6
+ if source_file = ARGV.shift
7
+ source = Pathname.new(source_file).realpath.to_s
8
+ Sherb.new_with_source(File.new(source).read, source).execute!
9
+ else
10
+ source = '(<STDIN>)'
11
+ Sherb.new_with_source(STDIN.read, source).execute!
12
+ end
data/lib/sherb.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'erb'
2
+
3
+ class Sherb < ERB
4
+ attr_accessor :sourcename
5
+
6
+ def self.new_with_source(template, sourcename)
7
+ erb = self.new(template)
8
+ erb.sourcename = sourcename
9
+ erb
10
+ end
11
+
12
+ def rendered_script
13
+ rendered_script = result
14
+ rescue Exception => e
15
+ if self.sourcename
16
+ e.backtrace.each_with_index do |stack_line, line_number|
17
+ e.backtrace[line_number].gsub!(/^\(erb\):/, "#{sourcename}:")
18
+ end
19
+ end
20
+ raise
21
+ end
22
+
23
+ def execute!
24
+ IO.popen('/bin/bash', 'w') {|io| io.puts rendered_script }
25
+ end
26
+ end
data/sherb.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{sherb}
5
+ s.version = "1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Andrew Snow"]
9
+ s.date = %q{2011-01-28}
10
+ s.default_executable = %q{sherb}
11
+ s.description = %q{Unix Shell (SH) with Embedded Ruby (ERB)}
12
+ s.email = %q{andrew@modulus.org}
13
+ s.executables = ["sherb"]
14
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "bin/sherb", "lib/sherb.rb"]
15
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "Rakefile", "bin/sherb", "lib/sherb.rb", "test/test_all.rb", "sherb.gemspec"]
16
+ s.homepage = %q{http://github.com/andys/sherb}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sherb"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{sherb}
20
+ s.rubygems_version = %q{1.3.7}
21
+ s.summary = %q{Unix Shell (SH) with Embedded Ruby (ERB)}
22
+ s.test_files = ["test/test_all.rb"]
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 3
27
+
28
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
+ else
30
+ end
31
+ else
32
+ end
33
+ end
data/test/test_all.rb ADDED
@@ -0,0 +1,29 @@
1
+
2
+ require 'test/unit'
3
+ require 'tempfile'
4
+
5
+ class TestSherb < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @tempfile = Tempfile.new(self.class.to_s)
9
+ @tempfile.puts "echo -n Hello <%= 'world' %>"
10
+ @tempfile.close
11
+ end
12
+
13
+ def teardown
14
+ @tempfile.unlink
15
+ end
16
+
17
+ def test_stdin
18
+ File.popen("bin/sherb < #{@tempfile.path}", 'r') do |io|
19
+ assert_equal 'Hello world', io.read
20
+ end
21
+ end
22
+
23
+ def test_file
24
+ File.popen("bin/sherb #{@tempfile.path}", 'r') do |io|
25
+ assert_equal 'Hello world', io.read
26
+ end
27
+ end
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sherb
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ version: "1.0"
9
+ platform: ruby
10
+ authors:
11
+ - Andrew Snow
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-01-28 00:00:00 +11:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: Unix Shell (SH) with Embedded Ruby (ERB)
21
+ email: andrew@modulus.org
22
+ executables:
23
+ - sherb
24
+ extensions: []
25
+
26
+ extra_rdoc_files:
27
+ - CHANGELOG
28
+ - LICENSE
29
+ - bin/sherb
30
+ - lib/sherb.rb
31
+ files:
32
+ - CHANGELOG
33
+ - LICENSE
34
+ - Manifest
35
+ - Rakefile
36
+ - bin/sherb
37
+ - lib/sherb.rb
38
+ - test/test_all.rb
39
+ - sherb.gemspec
40
+ has_rdoc: true
41
+ homepage: http://github.com/andys/sherb
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --line-numbers
47
+ - --inline-source
48
+ - --title
49
+ - Sherb
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 1
67
+ - 2
68
+ version: "1.2"
69
+ requirements: []
70
+
71
+ rubyforge_project: sherb
72
+ rubygems_version: 1.3.7
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Unix Shell (SH) with Embedded Ruby (ERB)
76
+ test_files:
77
+ - test/test_all.rb